diff options
author | Miklós Máté <mtmkls@gmail.com> | 2017-12-02 23:36:03 +0100 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2018-01-03 16:57:09 -0800 |
commit | 3d489bbe11d9a508edf763e217bc7b1cc9e160a6 (patch) | |
tree | 594242841c8bff342740d3def8923e619b8d165f | |
parent | 7961fd1c57664688be60175445de0f6b14711395 (diff) |
ATI_fs: add render tests
These mainly check the state machine. Compiler checks will come later.
v2: don't exit on first failure, improve some tests, add
license headers, drop redundant error checks, add build
system integration, add tests to all.py
v3: enums instead of magic numbers, style cleanups (by anholt, acked
by Miklós).
Signed-off-by: Miklós Máté <mtmkls@gmail.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Eric Anholt <eric@anholt.net>
-rw-r--r-- | tests/all.py | 7 | ||||
-rw-r--r-- | tests/spec/ati_fragment_shader/CMakeLists.gl.txt | 8 | ||||
-rw-r--r-- | tests/spec/ati_fragment_shader/render-constants.c | 132 | ||||
-rw-r--r-- | tests/spec/ati_fragment_shader/render-default.c | 101 | ||||
-rw-r--r-- | tests/spec/ati_fragment_shader/render-fog.c | 127 | ||||
-rw-r--r-- | tests/spec/ati_fragment_shader/render-notexture.c | 123 | ||||
-rw-r--r-- | tests/spec/ati_fragment_shader/render-precedence.c | 142 | ||||
-rw-r--r-- | tests/spec/ati_fragment_shader/render-sources.c | 176 | ||||
-rw-r--r-- | tests/spec/ati_fragment_shader/render-textargets.c | 121 |
9 files changed, 937 insertions, 0 deletions
diff --git a/tests/all.py b/tests/all.py index b87ed49c1..571976abc 100644 --- a/tests/all.py +++ b/tests/all.py @@ -1905,6 +1905,13 @@ with profile.test_list.group_manager( g(['ati_fragment_shader-error12-invalidsrc']) g(['ati_fragment_shader-error13-invalidarg']) g(['ati_fragment_shader-error14-invalidmod']) + g(['ati_fragment_shader-render-constants']) + g(['ati_fragment_shader-render-default']) + g(['ati_fragment_shader-render-fog']) + g(['ati_fragment_shader-render-notexture']) + g(['ati_fragment_shader-render-precedence']) + g(['ati_fragment_shader-render-sources']) + g(['ati_fragment_shader-render-textargets']) # Group ARB_framebuffer_object with profile.test_list.group_manager( diff --git a/tests/spec/ati_fragment_shader/CMakeLists.gl.txt b/tests/spec/ati_fragment_shader/CMakeLists.gl.txt index f0d578157..5783711d0 100644 --- a/tests/spec/ati_fragment_shader/CMakeLists.gl.txt +++ b/tests/spec/ati_fragment_shader/CMakeLists.gl.txt @@ -23,4 +23,12 @@ piglit_add_executable (ati_fragment_shader-error12-invalidsrc error12-invalidsrc piglit_add_executable (ati_fragment_shader-error13-invalidarg error13-invalidarg.c) piglit_add_executable (ati_fragment_shader-error14-invalidmod error14-invalidmod.c) +piglit_add_executable (ati_fragment_shader-render-default render-default.c) +piglit_add_executable (ati_fragment_shader-render-sources render-sources.c) +piglit_add_executable (ati_fragment_shader-render-notexture render-notexture.c) +piglit_add_executable (ati_fragment_shader-render-constants render-constants.c) +piglit_add_executable (ati_fragment_shader-render-precedence render-precedence.c) +piglit_add_executable (ati_fragment_shader-render-fog render-fog.c) +piglit_add_executable (ati_fragment_shader-render-textargets render-textargets.c) + # vim: ft=cmake: diff --git a/tests/spec/ati_fragment_shader/render-constants.c b/tests/spec/ati_fragment_shader/render-constants.c new file mode 100644 index 000000000..c5ee2c8d8 --- /dev/null +++ b/tests/spec/ati_fragment_shader/render-constants.c @@ -0,0 +1,132 @@ +/* + * Copyright © 2017 Miklós Máté + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** + * Tests rendering with GL_ATI_fragment_shader: + * - using local and global constants + * - updating global constants + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA; + +PIGLIT_GL_TEST_CONFIG_END + +static const float color1[] = {0.4, 0.2, 0.6}; +static const float color2[] = {0.7, 0.2, 0.3}; +static const float color3[] = {0.1, 0.7, 0.2}; +static const float color4[] = {0.8, 0.1, 0.7}; + +static float result1p3[] = {0.0, 0.0, 0.0}; +static float result2p3[] = {0.0, 0.0, 0.0}; +static float result4p3[] = {0.0, 0.0, 0.0}; + +static const unsigned s_local = 42; +static const unsigned s_global = 13; + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glEnable(GL_FRAGMENT_SHADER_ATI); + glSetFragmentShaderConstantATI(GL_CON_7_ATI, color2); + glSetFragmentShaderConstantATI(GL_CON_4_ATI, color3); + glBindFragmentShaderATI(s_global); + piglit_draw_rect(0, 0, piglit_width / 4, piglit_height); /* 2+3 */ + glBindFragmentShaderATI(s_local); + piglit_draw_rect(piglit_width / 4, 0, + piglit_width / 4, piglit_height); /* 1+3 */ + glBindFragmentShaderATI(s_global); + glSetFragmentShaderConstantATI(GL_CON_7_ATI, color4); + piglit_draw_rect(2 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); /* 4+3 */ + glBindFragmentShaderATI(s_local); + piglit_draw_rect(3 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); /*1+3 */ + glDisable(GL_FRAGMENT_SHADER_ATI); + + pass = pass && piglit_probe_rect_rgb(0, 0, + piglit_width / 4, + piglit_height, result2p3); + pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0, + piglit_width / 4, + piglit_height, result1p3); + pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, result4p3); + pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, result1p3); + + piglit_present_results(); + + pass &= piglit_check_gl_error(GL_NO_ERROR); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ + unsigned u; + + piglit_require_extension("GL_ATI_fragment_shader"); + + /* create identical shaders, but one of them has a local constant */ + + glBindFragmentShaderATI(s_global); + glBeginFragmentShaderATI(); + glColorFragmentOp2ATI(GL_ADD_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_CON_7_ATI, GL_NONE, GL_NONE, + GL_CON_4_ATI, GL_NONE, GL_NONE); + glEndFragmentShaderATI(); + + glBindFragmentShaderATI(s_local); + glBeginFragmentShaderATI(); + glColorFragmentOp2ATI(GL_ADD_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_CON_7_ATI, GL_NONE, GL_NONE, + GL_CON_4_ATI, GL_NONE, GL_NONE); + glSetFragmentShaderConstantATI(GL_CON_7_ATI, color1); + glEndFragmentShaderATI(); + + /* compute the expected results */ + + for (u=0; u<3; u++) { + result1p3[u] = color1[u]+color3[u]; + result2p3[u] = color2[u]+color3[u]; + result4p3[u] = color4[u]+color3[u]; + } + + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); +} diff --git a/tests/spec/ati_fragment_shader/render-default.c b/tests/spec/ati_fragment_shader/render-default.c new file mode 100644 index 000000000..e760e065d --- /dev/null +++ b/tests/spec/ati_fragment_shader/render-default.c @@ -0,0 +1,101 @@ +/* + * Copyright © 2017 Miklós Máté + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** + * Tests rendering with GL_ATI_fragment_shader: enable, disable, + * default fragment shader. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA; + +PIGLIT_GL_TEST_CONFIG_END + +static const float color[] = {0.2, 0.3, 0.8}; +static const float texcoord[] = {0.2, 0.7, 0.4}; + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glColor3fv(color); + glTexCoord3fv(texcoord); + + glDisable(GL_FRAGMENT_SHADER_ATI); + piglit_draw_rect(0, 0, piglit_width / 4, piglit_height); + glEnable(GL_FRAGMENT_SHADER_ATI); + piglit_draw_rect(piglit_width / 4, 0, piglit_width / 4, piglit_height); + glDisable(GL_FRAGMENT_SHADER_ATI); + piglit_draw_rect(2 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glEnable(GL_FRAGMENT_SHADER_ATI); + piglit_draw_rect(3 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + + pass = pass && piglit_probe_rect_rgb(0, 0, + piglit_width / 4, + piglit_height, color); + pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0, + piglit_width / 4, + piglit_height, texcoord); + pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, color); + pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, texcoord); + + piglit_present_results(); + + pass &= piglit_check_gl_error(GL_NO_ERROR); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ + piglit_require_extension("GL_ATI_fragment_shader"); + + /* create a default shader that does something different than + * fixed-function + */ + glBeginFragmentShaderATI(); + glPassTexCoordATI(GL_REG_1_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI); + glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_REG_1_ATI, GL_NONE, GL_NONE); + glEndFragmentShaderATI(); + + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); +} diff --git a/tests/spec/ati_fragment_shader/render-fog.c b/tests/spec/ati_fragment_shader/render-fog.c new file mode 100644 index 000000000..7d1d17b93 --- /dev/null +++ b/tests/spec/ati_fragment_shader/render-fog.c @@ -0,0 +1,127 @@ +/* + * Copyright © 2017 Miklós Máté + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** + * Tests rendering with GL_ATI_fragment_shader: using fog. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA; + +PIGLIT_GL_TEST_CONFIG_END + +static const float color1[] = {0.2, 0.3, 0.8}; +static const float color2[] = {0.9, 0.8, 0.3}; + +static float resultLin[] = {0.0, 0.0, 0.0}; +static float resultExp[] = {0.0, 0.0, 0.0}; +static float resultEx2[] = {0.0, 0.0, 0.0}; + +static const float z = 0.8; +static const float dens = 0.4; + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glColor3fv(color2); + + glFogfv(GL_FOG_COLOR, color1); + glFogf(GL_FOG_DENSITY, dens); + glFogf(GL_FOG_START, 0.0); + glFogf(GL_FOG_END, 1.0); + glHint(GL_FOG_HINT, GL_NICEST); + + glEnable(GL_FRAGMENT_SHADER_ATI); + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_LINEAR); + piglit_draw_rect_z(z, 0, 0, + piglit_width / 4, piglit_height); + glFogi(GL_FOG_MODE, GL_EXP); + piglit_draw_rect_z(z, piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glFogi(GL_FOG_MODE, GL_EXP2); + piglit_draw_rect_z(z, 2 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glDisable(GL_FOG); + piglit_draw_rect_z(z, 3 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glDisable(GL_FRAGMENT_SHADER_ATI); + + pass = pass && piglit_probe_rect_rgb(0, 0, + piglit_width / 4, + piglit_height, resultLin); + pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0, + piglit_width / 4, + piglit_height, resultExp); + pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, resultEx2); + pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, color2); + + piglit_present_results(); + + pass &= piglit_check_gl_error(GL_NO_ERROR); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ + unsigned u; + float f; + + piglit_require_extension("GL_ATI_fragment_shader"); + + glBeginFragmentShaderATI(); + glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_PRIMARY_COLOR_ARB, GL_NONE, GL_NONE); + glEndFragmentShaderATI(); + + /* compute the expected results */ + + for (u=0; u<3; u++) { + f = (1.0-z)/(1.0-0.0); + resultLin[u] = f*color2[u] + (1.0-f)*color1[u]; + f = exp(-dens*z); + resultExp[u] = f*color2[u] + (1.0-f)*color1[u]; + f = exp(-pow(dens*z,2.0)); + resultEx2[u] = f*color2[u] + (1.0-f)*color1[u]; + } + + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); +} diff --git a/tests/spec/ati_fragment_shader/render-notexture.c b/tests/spec/ati_fragment_shader/render-notexture.c new file mode 100644 index 000000000..86a5a04c2 --- /dev/null +++ b/tests/spec/ati_fragment_shader/render-notexture.c @@ -0,0 +1,123 @@ +/* + * Copyright © 2017 Miklós Máté + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** + * Tests rendering with GL_ATI_fragment_shader: when no texture is bound + * - glPassTexCoordATI() should work as normal + * - glSampleMapATI() should return all zeros + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA; + +PIGLIT_GL_TEST_CONFIG_END + +static const float color1[] = {0.2, 0.3, 0.8}; +static const float texcoord[] = {0.2, 0.7, 0.4}; +static const float black[] = {0.0, 0.0, 0.0}; + +enum { + SHADER_TEXCOORD = 1, + SHADER_TEX, +}; + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + GLuint tex; + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glTexCoord3fv(texcoord); + + glEnable(GL_FRAGMENT_SHADER_ATI); + glBindFragmentShaderATI(SHADER_TEXCOORD); + piglit_draw_rect(0, 0, piglit_width / 4, piglit_height); + glBindFragmentShaderATI(SHADER_TEX); + piglit_draw_rect(piglit_width / 4, 0, piglit_width / 4, piglit_height); + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, + (void*)color1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + piglit_draw_rect(2 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glEnable(GL_TEXTURE_2D); + piglit_draw_rect(3 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glDisable(GL_TEXTURE_2D); + glDeleteTextures(1, &tex); + glDisable(GL_FRAGMENT_SHADER_ATI); + + pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width / 4, + piglit_height, texcoord); + pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0, + piglit_width / 4, + piglit_height, black); + pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, black); + pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, color1); + + piglit_present_results(); + + pass &= piglit_check_gl_error(GL_NO_ERROR); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ + piglit_require_extension("GL_ATI_fragment_shader"); + + glBindFragmentShaderATI(SHADER_TEXCOORD); + glBeginFragmentShaderATI(); + glPassTexCoordATI(GL_REG_1_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI); + glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_REG_1_ATI, GL_NONE, GL_NONE); + glEndFragmentShaderATI(); + + glBindFragmentShaderATI(SHADER_TEX); + glBeginFragmentShaderATI(); + glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI); + glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_REG_0_ATI, GL_NONE, GL_NONE); + glEndFragmentShaderATI(); + + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); +} diff --git a/tests/spec/ati_fragment_shader/render-precedence.c b/tests/spec/ati_fragment_shader/render-precedence.c new file mode 100644 index 000000000..df47db0a9 --- /dev/null +++ b/tests/spec/ati_fragment_shader/render-precedence.c @@ -0,0 +1,142 @@ +/* + * Copyright © 2017 Miklós Máté + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** + * Tests rendering with GL_ATI_fragment_shader: + * - precedence between ATI_fragment_shader, ARB_fragment_program, GLSL + * - ARB_fragment_program overrides ATI_fragment_shader + * - GLSL overrides both + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA; + +PIGLIT_GL_TEST_CONFIG_END + +static const float color1[] = {0.2, 0.3, 0.8}; +static const float color2[] = {0.9, 0.8, 0.3}; +static const float texcoord[] = {0.2, 0.7, 0.4}; + +static bool have_fp = false; +static bool have_fs = false; + +static GLuint glslprog; + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glColor3fv(color1); + glSecondaryColor3fvEXT(color2); + glTexCoord3fv(texcoord); + + glEnable(GL_FRAGMENT_SHADER_ATI); + piglit_draw_rect(0, 0, piglit_width / 4, piglit_height); + if (have_fp) { + glEnable(GL_FRAGMENT_PROGRAM_ARB); + piglit_draw_rect(piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glDisable(GL_FRAGMENT_PROGRAM_ARB); + } + if (have_fs) { + glUseProgram(glslprog); + piglit_draw_rect(2 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glUseProgram(0); + } + if (have_fp && have_fs) { + glUseProgram(glslprog); + glEnable(GL_FRAGMENT_PROGRAM_ARB); + piglit_draw_rect(3 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glUseProgram(0); + glDisable(GL_FRAGMENT_PROGRAM_ARB); + } + glDisable(GL_FRAGMENT_SHADER_ATI); + + pass = pass && piglit_probe_rect_rgb(0, 0, + piglit_width / 4, + piglit_height, color2); + if (have_fp) + pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0, + piglit_width / 4, + piglit_height, texcoord); + if (have_fs) + pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, color1); + if (have_fp && have_fs) + pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, color1); + + piglit_present_results(); + + pass &= piglit_check_gl_error(GL_NO_ERROR); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +const char *arbfp_str = +"!!ARBfp1.0\n" +"MOV result.color, fragment.texcoord[0];\n" +"END"; + +const char *glslfs_str = +"void main() { gl_FragColor = gl_Color; }"; + +void +piglit_init(int argc, char **argv) +{ + piglit_require_extension("GL_ATI_fragment_shader"); + + /* create shaders */ + + glBeginFragmentShaderATI(); + glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_SECONDARY_INTERPOLATOR_ATI, GL_NONE, GL_NONE); + glEndFragmentShaderATI(); + + if (piglit_is_extension_supported("GL_ARB_fragment_program")) { + have_fp = true; + piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, arbfp_str); + } + + if (piglit_is_extension_supported("GL_ARB_fragment_shader")) { + have_fs = true; + glslprog = piglit_build_simple_program(NULL, glslfs_str); + } + + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); +} diff --git a/tests/spec/ati_fragment_shader/render-sources.c b/tests/spec/ati_fragment_shader/render-sources.c new file mode 100644 index 000000000..9b4f5af33 --- /dev/null +++ b/tests/spec/ati_fragment_shader/render-sources.c @@ -0,0 +1,176 @@ +/* + * Copyright © 2017 Miklós Máté + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** + * Tests rendering with GL_ATI_fragment_shader: + * - various data sources for calculations in fragment shader + * - texture coordinates + * - texture sample + * - constant + * - primary color + * - secondary interpolator + * - one, zero + * - switch between named fragment shaders + * - use undefined default shader (rendering is undefined but shouldn't crash) + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA; + +PIGLIT_GL_TEST_CONFIG_END + +static const float color1[] = {0.2, 0.3, 0.8}; +static const float color2[] = {0.9, 0.8, 0.3}; +static const float texcoord[] = {0.2, 0.7, 0.4}; +static const float texcolor[] = {0.8, 0.1, 0.7}; + +static float result_const[] = {0.0, 0.0, 0.0}; +static float result_tex[] = {0.0, 0.0, 0.0}; +static float result_color[] = {0.0, 0.0, 0.0}; + +static GLuint tex; + +enum { + SHADER_TEX = 1, + SHADER_CONST, + SHADER_COLOR, +}; + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glColor3fv(color1); + glSecondaryColor3fvEXT(color2); + glTexCoord3fv(texcoord); + + glEnable(GL_TEXTURE_2D); + + glEnable(GL_FRAGMENT_SHADER_ATI); + glBindFragmentShaderATI(0); + piglit_draw_rect(0, 0, + piglit_width / 4, piglit_height); + glBindFragmentShaderATI(SHADER_CONST); + piglit_draw_rect(piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glBindFragmentShaderATI(SHADER_COLOR); + piglit_draw_rect(2 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glBindFragmentShaderATI(SHADER_TEX); + piglit_draw_rect(3 * piglit_width / 4, 0, + piglit_width / 4, piglit_height); + glDisable(GL_FRAGMENT_SHADER_ATI); + +#if 0 + /* Mesa uses fixed-function when the shader is invalid, but + * it's undefined + */ + pass = pass && piglit_probe_rect_rgb(0, 0, + piglit_width / 4, + piglit_height, color1 * texcolor); +#endif + pass = pass && piglit_probe_rect_rgb(piglit_width / 4, 0, + piglit_width / 4, + piglit_height, result_const); + pass = pass && piglit_probe_rect_rgb(2 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, result_color); + pass = pass && piglit_probe_rect_rgb(3 * piglit_width / 4, 0, + piglit_width / 4, + piglit_height, result_tex); + + piglit_present_results(); + + pass &= piglit_check_gl_error(GL_NO_ERROR); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ + unsigned u; + + piglit_require_extension("GL_ATI_fragment_shader"); + + /* create shaders that use all possible input sources: + * texcoord, sample, const, zero, one, pri&sec color + */ + + glBindFragmentShaderATI(SHADER_TEX); + glBeginFragmentShaderATI(); + glPassTexCoordATI(GL_REG_1_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI); + glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI); + glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_REG_1_ATI, GL_NONE, GL_NONE); + glEndFragmentShaderATI(); + + glBindFragmentShaderATI(SHADER_CONST); + glBeginFragmentShaderATI(); + glColorFragmentOp3ATI(GL_LERP_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_CON_1_ATI, GL_NONE, GL_NONE, + GL_ONE, GL_NONE, GL_NONE, + GL_ZERO, GL_NONE, GL_NONE); + glSetFragmentShaderConstantATI(GL_CON_1_ATI, color2); + glEndFragmentShaderATI(); + + glBindFragmentShaderATI(SHADER_COLOR); + glBeginFragmentShaderATI(); + glColorFragmentOp2ATI(GL_MUL_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_SECONDARY_INTERPOLATOR_ATI, GL_NONE, GL_NONE, + GL_PRIMARY_COLOR_ARB, GL_NONE, GL_NONE); + glEndFragmentShaderATI(); + + /* create a texture */ + + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, + (void*)texcolor); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + /* compute the expected results */ + + for (u=0; u<3; u++) { + result_const[u] = color2[u]; + result_tex[u] = texcoord[u] * texcolor[u]; + result_color[u] = color1[u] * color2[u]; + } + + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); +} diff --git a/tests/spec/ati_fragment_shader/render-textargets.c b/tests/spec/ati_fragment_shader/render-textargets.c new file mode 100644 index 000000000..c3dfe5f51 --- /dev/null +++ b/tests/spec/ati_fragment_shader/render-textargets.c @@ -0,0 +1,121 @@ +/* + * Copyright © 2017 Miklós Máté + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +/** + * Tests rendering with GL_ATI_fragment_shader: using different + * texture targets with the same shader. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA; + +PIGLIT_GL_TEST_CONFIG_END + +static const float color1[] = {0.2, 0.3, 0.8}; +static const float color2[] = {0.9, 0.8, 0.3}; +static const float texcoord[] = {0.2, 0.7, 0.4}; + +static GLuint tex2D; +static GLuint texCUBE; + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glTexCoord3fv(texcoord); + + glEnable(GL_FRAGMENT_SHADER_ATI); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, tex2D); + piglit_draw_rect(0, 0, piglit_width / 2, piglit_height); + glDisable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_CUBE_MAP); + glBindTexture(GL_TEXTURE_CUBE_MAP, texCUBE); + piglit_draw_rect(piglit_width / 2, 0, piglit_width / 2, piglit_height); + glDisable(GL_TEXTURE_CUBE_MAP); + glDisable(GL_FRAGMENT_SHADER_ATI); + + pass = pass && piglit_probe_rect_rgb(0, 0, + piglit_width / 2, + piglit_height, color1); + pass = pass && piglit_probe_rect_rgb(piglit_width / 2, 0, + piglit_width / 2, + piglit_height, color2); + + piglit_present_results(); + + pass &= piglit_check_gl_error(GL_NO_ERROR); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ + piglit_require_extension("GL_ATI_fragment_shader"); + + glBeginFragmentShaderATI(); + glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI); + glColorFragmentOp1ATI(GL_MOV_ATI, GL_REG_0_ATI, GL_NONE, GL_NONE, + GL_REG_0_ATI, GL_NONE, GL_NONE); + glEndFragmentShaderATI(); + + glGenTextures(1, &tex2D); + glBindTexture(GL_TEXTURE_2D, tex2D); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_FLOAT, + (void*)color1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glGenTextures(1, &texCUBE); + glBindTexture(GL_TEXTURE_CUBE_MAP, texCUBE); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, 1, 1, 0, + GL_RGB, GL_FLOAT, (void*)color2); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, 1, 1, 0, + GL_RGB, GL_FLOAT, (void*)color2); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, 1, 1, 0, + GL_RGB, GL_FLOAT, (void*)color2); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, 1, 1, 0, + GL_RGB, GL_FLOAT, (void*)color2); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, 1, 1, 0, + GL_RGB, GL_FLOAT, (void*)color2); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, 1, 1, 0, + GL_RGB, GL_FLOAT, (void*)color2); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + if (!piglit_check_gl_error(GL_NO_ERROR)) + piglit_report_result(PIGLIT_FAIL); +} |