<div dir="ltr">On 5 January 2013 01:07, Chris Forbes <span dir="ltr"><<a href="mailto:chrisf@ijw.co.nz" target="_blank">chrisf@ijw.co.nz</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Writes a test pattern to individual samples in a multisample texture,<br>
and tests texelFetch() reads the correct values for each sample.<br>
<br>
Signed-off-by: Chris Forbes <<a href="mailto:chrisf@ijw.co.nz">chrisf@ijw.co.nz</a>><br></blockquote><div><br></div><div>Unforunately, I think we need to generalize this test to test a variety of sample counts.  Otherwise, there's just too much danger of a bug that's specific to one particular sample count going undetected.  For example, when we get around to implementing Ivy Bridge's "compressed" layout, the texelFetch() logic will need to load a 32-bit value from the MCS surface in 8x MSAA mode, and only an 8-bit value in 4x MSAA mode.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
 tests/all.tests                                    |   2 +<br>
 .../spec/arb_texture_multisample/CMakeLists.gl.txt |   1 +<br>
 .../texel-fetch-execution.c                        | 159 +++++++++++++++++++++<br>
 3 files changed, 162 insertions(+)<br>
 create mode 100644 tests/spec/arb_texture_multisample/texel-fetch-execution.c<br>
<br>
diff --git a/tests/all.tests b/tests/all.tests<br>
index 19d7cf9..8a56a27 100644<br>
--- a/tests/all.tests<br>
+++ b/tests/all.tests<br>
@@ -850,6 +850,8 @@ add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mas<br>
 add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mask-value')<br>
 add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mask-execution')<br>
 add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-sample-mask-execution -tex')<br>
+add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-texel-fetch-execution vs')<br>
+add_concurrent_test(arb_texture_multisample, 'arb_texture_multisample-texel-fetch-execution fs')<br>
 textureSize_samplers_atm = ['sampler2DMS', 'isampler2DMS', 'usampler2DMS',<br>
                                                        'sampler2DMSArray', 'isampler2DMSArray', 'usampler2DMSArray']<br>
 for stage in ['vs', 'fs']:<br>
diff --git a/tests/spec/arb_texture_multisample/CMakeLists.gl.txt b/tests/spec/arb_texture_multisample/CMakeLists.gl.txt<br>
index f13b062..7bc915f 100644<br>
--- a/tests/spec/arb_texture_multisample/CMakeLists.gl.txt<br>
+++ b/tests/spec/arb_texture_multisample/CMakeLists.gl.txt<br>
@@ -16,5 +16,6 @@ piglit_add_executable (arb_texture_multisample-texstate texstate.c)<br>
 piglit_add_executable (arb_texture_multisample-sample-mask sample-mask.c)<br>
 piglit_add_executable (arb_texture_multisample-sample-mask-value sample-mask-value.c)<br>
 piglit_add_executable (arb_texture_multisample-sample-mask-execution sample-mask-execution.c)<br>
+piglit_add_executable (arb_texture_multisample-texel-fetch-execution texel-fetch-execution.c)<br>
<br>
 # vim: ft=cmake:<br>
diff --git a/tests/spec/arb_texture_multisample/texel-fetch-execution.c b/tests/spec/arb_texture_multisample/texel-fetch-execution.c<br>
new file mode 100644<br>
index 0000000..791643f<br>
--- /dev/null<br>
+++ b/tests/spec/arb_texture_multisample/texel-fetch-execution.c<br>
@@ -0,0 +1,159 @@<br>
+#include "piglit-util-gl-common.h"<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_BEGIN<br>
+<br>
+    config.supports_gl_compat_version = 30;<br>
+<br>
+    config.window_width = 64;<br>
+    config.window_height = 64;<br>
+    config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_ALPHA;<br>
+<br>
+PIGLIT_GL_TEST_CONFIG_END<br>
+<br>
+/* test texelFetch() from multisample textures.<br>
+ * instead of using actual multisample rasterization,<br>
+ * we'll write the test pattern to a MSAA texture via<br>
+ * sample masking.<br>
+ */<br>
+<br>
+GLuint fbo, tex, shader, prog;<br>
+GLint u_sample;<br>
+GLuint shader_stage = 0;<br>
+<br>
+enum piglit_result<br>
+piglit_display(void)<br>
+{<br>
+    float red[] = {1,0,0,1};<br>
+    float green[] = {0,1,0,1};<br>
+    float blue[] = {0,0,1,1};<br>
+    float white[] = {1,1,1,1};<br>
+<br>
+    bool pass = true;<br>
+<br>
+    glClearColor(0.2,0.2,0.2,1.0);<br>
+    glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+    glUseProgram(prog);<br>
+<br>
+    glUniform1i(u_sample, 0);<br>
+    piglit_draw_rect(-1,-1,1,1);<br>
+<br>
+    glUniform1i(u_sample, 1);<br>
+    piglit_draw_rect(0,-1,1,1);<br>
+<br>
+    glUniform1i(u_sample, 2);<br>
+    piglit_draw_rect(0,0,1,1);<br>
+<br>
+    glUniform1i(u_sample, 3);<br>
+    piglit_draw_rect(-1,0,1,1);<br>
+<br>
+    pass = piglit_probe_pixel_rgba(16, 16, red) && pass;<br>
+    pass = piglit_probe_pixel_rgba(48, 16, green) && pass;<br>
+    pass = piglit_probe_pixel_rgba(48, 48, blue) && pass;<br>
+    pass = piglit_probe_pixel_rgba(16, 48, white) && pass;<br>
+<br>
+    piglit_present_results();<br>
+<br>
+    return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
+}<br>
+<br>
+void<br>
+piglit_init(int argc, char **argv)<br>
+{<br>
+    piglit_require_extension("GL_ARB_texture_multisample");<br>
+<br>
+    while (++argv,--argc) {<br>
+        if (!strcmp(*argv, "vs"))<br>
+            shader_stage = GL_VERTEX_SHADER;<br>
+        else if (!strcmp(*argv, "fs"))<br>
+            shader_stage = GL_FRAGMENT_SHADER;<br>
+    }<br>
+<br>
+<br>
+    glGenFramebuffers(1, &fbo);<br>
+    glGenTextures(1, &tex);<br>
+    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex);<br>
+    glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE,<br>
+                            4, GL_RGBA, 64, 64, GL_TRUE);<br>
+<br>
+    glBindFramebuffer(GL_FRAMEBUFFER, fbo);<br>
+    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,<br>
+                           GL_TEXTURE_2D_MULTISAMPLE, tex, 0);<br>
+<br>
+    glClearColor(0.2,0.2,0.2,1.0);<br>
+    glClear(GL_COLOR_BUFFER_BIT);<br>
+<br>
+    /* write test pattern: red,green,blue,white */<br>
+    glEnable(GL_SAMPLE_MASK);<br>
+<br>
+    glSampleMaski(0, (1<<0));<br>
+    glColor4f(1.0,0.0,0.0,1.0);<br>
+    piglit_draw_rect(-1,-1,2,2);<br>
+<br>
+    glSampleMaski(0, (1<<1));<br>
+    glColor4f(0.0,1.0,0.0,1.0);<br>
+    piglit_draw_rect(-1,-1,2,2);<br>
+<br>
+    glSampleMaski(0, (1<<2));<br>
+    glColor4f(0.0,0.0,1.0,1.0);<br>
+    piglit_draw_rect(-1,-1,2,2);<br>
+<br>
+    glSampleMaski(0, (1<<3));<br>
+    glColor4f(1.0,1.0,1.0,1.0);<br>
+    piglit_draw_rect(-1,-1,2,2);<br>
+<br>
+    glDisable(GL_SAMPLE_MASK);<br>
+<br>
+    if (!piglit_check_gl_error(GL_NO_ERROR))<br>
+        piglit_report_result(PIGLIT_FAIL);<br>
+<br>
+    glBindFramebuffer(GL_FRAMEBUFFER, 0);<br>
+<br>
+    switch (shader_stage) {<br>
+    case GL_VERTEX_SHADER:<br>
+        shader = piglit_compile_shader_text(GL_VERTEX_SHADER,<br>
+            "#version 130\n"<br>
+            "#extension GL_ARB_texture_multisample : require\n"<br>
+            "\n"<br>
+            "uniform sampler2DMS s;\n"<br>
+            "uniform int sample;\n"<br>
+            "\n"<br>
+            "void main() {\n"<br>
+            "   gl_Position = ftransform();\n"<br>
+            "   gl_FrontColor = texelFetch(s, ivec2(32, 32), sample); \n"<br>
+            "}\n");<br>
+<br>
+        prog = piglit_link_simple_program(shader, 0);<br>
+        break;<br>
+<br>
+    case GL_FRAGMENT_SHADER:<br>
+        shader = piglit_compile_shader_text(GL_FRAGMENT_SHADER,<br>
+            "#version 130\n"<br>
+            "#extension GL_ARB_texture_multisample : require\n"<br>
+            "\n"<br>
+            "uniform sampler2DMS s;\n"<br>
+            "uniform int sample;\n"<br>
+            "\n"<br>
+            "void main() {\n"<br>
+            "   gl_FragColor = texelFetch(s, ivec2(32,32), sample); \n"<br>
+            "}\n");<br>
+<br>
+        prog = piglit_link_simple_program(0, shader);<br>
+        break;<br>
+<br>
+    default:<br>
+        printf("Please provide shader type: `vs` or `fs`\n");<br>
+        piglit_report_result(PIGLIT_FAIL);<br>
+    }<br>
+<br>
+    if (!prog || !shader)<br>
+        piglit_report_result(PIGLIT_FAIL);<br>
+<br>
+    u_sample = glGetUniformLocation(prog, "sample");<br>
+    printf("sample uniform: %d\n", u_sample);<br>
+    if (u_sample == -1)<br>
+        piglit_report_result(PIGLIT_FAIL);<br>
+<br>
+    if (!piglit_check_gl_error(GL_NO_ERROR))<br>
+        piglit_report_result(PIGLIT_FAIL);<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br></div></div>