[Piglit] [PATCH 31/35] arb_gpu_shader5: Add support for testing spirv with XFB streams

Timothy Arceri tarceri at itsqueeze.com
Sat Aug 18 04:36:12 UTC 2018


On 18/08/18 14:32, Timothy Arceri wrote:
> Won't this cause shader runner to needlessly parse the .shader_test file?

The file extension is also confusing. Maybe we should name these type of 
files .shader_source or something similar rather than .shader_test ???

> 
> On 09/08/18 21:36, Alejandro Piñeiro wrote:
>> From: Neil Roberts <nroberts at igalia.com>
>>
>> v2: use shader_test file with the spirv assembly, instead of include
>>      two SPIRV binaries (Alejandro Piñeiro)
>>
>> Signed-off-by: Neil Roberts <nroberts at igalia.com>
>> Signed-off-by: Alejandro Piñeiro <apinheiro at igalia.com>
>> ---
>>   tests/opengl.py                                    |   1 +
>>   .../xfb_streams_without_invocations.shader_test    | 197 
>> +++++++++++++++++++++
>>   .../execution/xfb-streams-without-invocations.c    | 135 ++++++++++----
>>   3 files changed, 300 insertions(+), 33 deletions(-)
>>   create mode 100644 
>> tests/spec/arb_gpu_shader5/execution/shader_test/xfb_streams_without_invocations.shader_test 
>>
>>
>> diff --git a/tests/opengl.py b/tests/opengl.py
>> index 064c43e08..9b1e09564 100644
>> --- a/tests/opengl.py
>> +++ b/tests/opengl.py
>> @@ -1969,6 +1969,7 @@ with profile.test_list.group_manager(
>>       g(['arb_gpu_shader5-emitstreamvertex_stream_too_large'])
>>       g(['arb_gpu_shader5-tf-wrong-stream-value'])
>>       g(['arb_gpu_shader5-xfb-streams-without-invocations'])
>> +    g(['arb_gpu_shader5-xfb-streams-without-invocations', 'spirv'])
>>       g(['arb_gpu_shader5-emitstreamvertex_nodraw'])
>>       g(['arb_gpu_shader5-interpolateAtCentroid'])
>>       g(['arb_gpu_shader5-interpolateAtCentroid-packing'])
>> diff --git 
>> a/tests/spec/arb_gpu_shader5/execution/shader_test/xfb_streams_without_invocations.shader_test 
>> b/tests/spec/arb_gpu_shader5/execution/shader_test/xfb_streams_without_invocations.shader_test 
>>
>> new file mode 100644
>> index 000000000..6611e0bf8
>> --- /dev/null
>> +++ 
>> b/tests/spec/arb_gpu_shader5/execution/shader_test/xfb_streams_without_invocations.shader_test 
>>
>> @@ -0,0 +1,197 @@
>> +[require]
>> +GLSL >= 4.50
>> +
>> +[vertex shader spirv]
>> +; Automatically generated from the GLSL by shader_test_spirv.py. DO 
>> NOT EDIT
>> +; SPIR-V
>> +; Version: 1.0
>> +; Generator: Khronos Glslang Reference Front End; 7
>> +; Bound: 23
>> +; Schema: 0
>> +               OpCapability Shader
>> +          %1 = OpExtInstImport "GLSL.std.450"
>> +               OpMemoryModel Logical GLSL450
>> +               OpEntryPoint Vertex %main "main" %_ %gl_VertexID 
>> %gl_InstanceID
>> +               OpSource GLSL 450
>> +               OpName %_ ""
>> +               OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
>> +               OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
>> +               OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
>> +               OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
>> +               OpDecorate %gl_PerVertex Block
>> +               OpDecorate %gl_VertexID BuiltIn VertexId
>> +               OpDecorate %gl_InstanceID BuiltIn InstanceId
>> +       %void = OpTypeVoid
>> +          %3 = OpTypeFunction %void
>> +      %float = OpTypeFloat 32
>> +    %v4float = OpTypeVector %float 4
>> +       %uint = OpTypeInt 32 0
>> +     %uint_1 = OpConstant %uint 1
>> +%_arr_float_uint_1 = OpTypeArray %float %uint_1
>> +%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 
>> %_arr_float_uint_1
>> +%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
>> +          %_ = OpVariable %_ptr_Output_gl_PerVertex Output
>> +        %int = OpTypeInt 32 1
>> +      %int_0 = OpConstant %int 0
>> +    %float_0 = OpConstant %float 0
>> +         %17 = OpConstantComposite %v4float %float_0 %float_0 
>> %float_0 %float_0
>> +%_ptr_Output_v4float = OpTypePointer Output %v4float
>> +%_ptr_Input_int = OpTypePointer Input %int
>> +%gl_VertexID = OpVariable %_ptr_Input_int Input
>> +%gl_InstanceID = OpVariable %_ptr_Input_int Input
>> +       %main = OpFunction %void None %3
>> +          %5 = OpLabel
>> +         %19 = OpAccessChain %_ptr_Output_v4float %_ %int_0
>> +               OpStore %19 %17
>> +               OpReturn
>> +               OpFunctionEnd
>> +
>> +[vertex shader]
>> +#version 450
>> +
>> +void main() {
>> +     gl_Position = vec4(0.0);
>> +}
>> +
>> +
>> +[geometry shader spirv]
>> +; Automatically generated from the GLSL by shader_test_spirv.py. DO 
>> NOT EDIT
>> +; SPIR-V
>> +; Version: 1.0
>> +; Generator: Khronos Glslang Reference Front End; 7
>> +; Bound: 41
>> +; Schema: 0
>> +               OpCapability Geometry
>> +               OpCapability TransformFeedback
>> +               OpCapability GeometryStreams
>> +          %1 = OpExtInstImport "GLSL.std.450"
>> +               OpMemoryModel Logical GLSL450
>> +               OpEntryPoint Geometry %main "main" %_ %gl_in 
>> %stream0_0_out %stream2_0_out %stream2_1_out %stream1_0_out
>> +               OpExecutionMode %main Xfb
>> +               OpExecutionMode %main InputPoints
>> +               OpExecutionMode %main Invocations 1
>> +               OpExecutionMode %main OutputPoints
>> +               OpExecutionMode %main OutputVertices 3
>> +               OpSource GLSL 450
>> +               OpName %_ ""
>> +               OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
>> +               OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
>> +               OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
>> +               OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
>> +               OpDecorate %gl_PerVertex Block
>> +               OpDecorate %gl_PerVertex Stream 0
>> +               OpDecorate %_ Stream 0
>> +               OpDecorate %_ XfbBuffer 0
>> +               OpDecorate %_ XfbStride 4
>> +               OpMemberDecorate %gl_PerVertex_0 0 BuiltIn Position
>> +               OpMemberDecorate %gl_PerVertex_0 1 BuiltIn PointSize
>> +               OpMemberDecorate %gl_PerVertex_0 2 BuiltIn ClipDistance
>> +               OpMemberDecorate %gl_PerVertex_0 3 BuiltIn CullDistance
>> +               OpDecorate %gl_PerVertex_0 Block
>> +               OpDecorate %stream0_0_out Location 0
>> +               OpDecorate %stream0_0_out Stream 0
>> +               OpDecorate %stream0_0_out XfbBuffer 0
>> +               OpDecorate %stream0_0_out XfbStride 4
>> +               OpDecorate %stream0_0_out Offset 0
>> +               OpDecorate %stream2_0_out Location 2
>> +               OpDecorate %stream2_0_out Stream 2
>> +               OpDecorate %stream2_0_out XfbBuffer 2
>> +               OpDecorate %stream2_0_out XfbStride 20
>> +               OpDecorate %stream2_0_out Offset 0
>> +               OpDecorate %stream2_1_out Location 3
>> +               OpDecorate %stream2_1_out Stream 2
>> +               OpDecorate %stream2_1_out XfbBuffer 2
>> +               OpDecorate %stream2_1_out XfbStride 20
>> +               OpDecorate %stream2_1_out Offset 4
>> +               OpDecorate %stream1_0_out Location 1
>> +               OpDecorate %stream1_0_out Stream 1
>> +               OpDecorate %stream1_0_out XfbBuffer 1
>> +               OpDecorate %stream1_0_out XfbStride 8
>> +               OpDecorate %stream1_0_out Offset 0
>> +       %void = OpTypeVoid
>> +          %3 = OpTypeFunction %void
>> +      %float = OpTypeFloat 32
>> +    %v4float = OpTypeVector %float 4
>> +       %uint = OpTypeInt 32 0
>> +     %uint_1 = OpConstant %uint 1
>> +%_arr_float_uint_1 = OpTypeArray %float %uint_1
>> +%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 
>> %_arr_float_uint_1
>> +%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
>> +          %_ = OpVariable %_ptr_Output_gl_PerVertex Output
>> +        %int = OpTypeInt 32 1
>> +      %int_0 = OpConstant %int 0
>> +%gl_PerVertex_0 = OpTypeStruct %v4float %float %_arr_float_uint_1 
>> %_arr_float_uint_1
>> +%_arr_gl_PerVertex_0_uint_1 = OpTypeArray %gl_PerVertex_0 %uint_1
>> +%_ptr_Input__arr_gl_PerVertex_0_uint_1 = OpTypePointer Input 
>> %_arr_gl_PerVertex_0_uint_1
>> +      %gl_in = OpVariable %_ptr_Input__arr_gl_PerVertex_0_uint_1 Input
>> +%_ptr_Input_v4float = OpTypePointer Input %v4float
>> +%_ptr_Output_v4float = OpTypePointer Output %v4float
>> +%_ptr_Output_float = OpTypePointer Output %float
>> +%stream0_0_out = OpVariable %_ptr_Output_float Output
>> +    %float_0 = OpConstant %float 0
>> +%stream2_0_out = OpVariable %_ptr_Output_float Output
>> +%stream2_1_out = OpVariable %_ptr_Output_v4float Output
>> +    %float_1 = OpConstant %float 1
>> +    %float_2 = OpConstant %float 2
>> +    %float_3 = OpConstant %float 3
>> +    %float_4 = OpConstant %float 4
>> +         %34 = OpConstantComposite %v4float %float_1 %float_2 
>> %float_3 %float_4
>> +      %int_2 = OpConstant %int 2
>> +    %v2float = OpTypeVector %float 2
>> +%_ptr_Output_v2float = OpTypePointer Output %v2float
>> +%stream1_0_out = OpVariable %_ptr_Output_v2float Output
>> +         %39 = OpConstantComposite %v2float %float_0 %float_1
>> +      %int_1 = OpConstant %int 1
>> +       %main = OpFunction %void None %3
>> +          %5 = OpLabel
>> +         %21 = OpAccessChain %_ptr_Input_v4float %gl_in %int_0 %int_0
>> +         %22 = OpLoad %v4float %21
>> +         %24 = OpAccessChain %_ptr_Output_v4float %_ %int_0
>> +               OpStore %24 %22
>> +               OpStore %stream0_0_out %float_0
>> +               OpEmitStreamVertex %int_0
>> +               OpEndStreamPrimitive %int_0
>> +               OpStore %stream2_0_out %float_0
>> +               OpStore %stream2_1_out %34
>> +               OpEmitStreamVertex %int_2
>> +               OpEndStreamPrimitive %int_2
>> +               OpStore %stream1_0_out %39
>> +               OpEmitStreamVertex %int_1
>> +               OpEndStreamPrimitive %int_1
>> +               OpReturn
>> +               OpFunctionEnd
>> +
>> +[geometry shader]
>> +#version 450
>> +
>> +layout(points) in;
>> +layout(points, max_vertices = 3) out;
>> +
>> +layout(xfb_buffer = 0, xfb_stride = 4) out;
>> +layout(xfb_buffer = 1, xfb_stride = 8) out;
>> +layout(xfb_buffer = 2, xfb_stride = 20) out;
>> +
>> +layout(stream = 0, location = 0, xfb_buffer = 0, xfb_offset = 0)
>> +out float stream0_0_out;
>> +layout(stream = 1, location = 1, xfb_buffer = 1, xfb_offset = 0)
>> +out vec2 stream1_0_out;
>> +layout(stream = 2, location = 2, xfb_buffer = 2, xfb_offset = 0)
>> +out float stream2_0_out;
>> +layout(stream = 2, location = 3, xfb_buffer = 2, xfb_offset = 4)
>> +out vec4 stream2_1_out;
>> +
>> +void main() {
>> +  gl_Position = gl_in[0].gl_Position;
>> +  stream0_0_out = 0.0;
>> +  EmitStreamVertex(0);
>> +  EndStreamPrimitive(0);
>> +
>> +  stream2_0_out = 0.0;
>> +  stream2_1_out = vec4(1.0, 2.0, 3.0, 4.0);
>> +  EmitStreamVertex(2);
>> +  EndStreamPrimitive(2);
>> +
>> +  stream1_0_out = vec2(0.0, 1.0);
>> +  EmitStreamVertex(1);
>> +  EndStreamPrimitive(1);
>> +}
>> diff --git 
>> a/tests/spec/arb_gpu_shader5/execution/xfb-streams-without-invocations.c 
>> b/tests/spec/arb_gpu_shader5/execution/xfb-streams-without-invocations.c
>> index 37ca7a141..50f8b101a 100644
>> --- 
>> a/tests/spec/arb_gpu_shader5/execution/xfb-streams-without-invocations.c
>> +++ 
>> b/tests/spec/arb_gpu_shader5/execution/xfb-streams-without-invocations.c
>> @@ -22,6 +22,7 @@
>>    */
>>   #include "piglit-util-gl.h"
>> +#include "piglit-shader-test.h"
>>   /**
>>    * @file xfb-streams-without-invocations.c
>> @@ -41,51 +42,84 @@ PIGLIT_GL_TEST_CONFIG_BEGIN
>>   PIGLIT_GL_TEST_CONFIG_END
>> -static const char vs_pass_thru_text[] =
>> -    "#version 150\n"
>> -    "void main() {\n"
>> -    "  gl_Position = vec4(0.0);\n"
>> -    "}\n";
>> -
>> -static const char gs_text[] =
>> -    "#version 150\n"
>> -    "#extension GL_ARB_gpu_shader5 : enable\n"
>> -    "layout(points) in;\n"
>> -    "layout(points, max_vertices = 3) out;\n"
>> -    "layout(stream = 0) out float stream0_0_out;\n"
>> -    "layout(stream = 1) out vec2 stream1_0_out;\n"
>> -    "layout(stream = 2) out float stream2_0_out;\n"
>> -    "layout(stream = 2) out vec4 stream2_1_out;\n"
>> -    "void main() {\n"
>> -    "  gl_Position = gl_in[0].gl_Position;\n"
>> -    "  stream0_0_out = 0.0;\n"
>> -    "  EmitStreamVertex(0);\n"
>> -    "  EndStreamPrimitive(0);\n"
>> -
>> -    "  stream2_0_out = 0.0;\n"
>> -    "  stream2_1_out = vec4(1.0, 2.0, 3.0, 4.0);\n"
>> -    "  EmitStreamVertex(2);\n"
>> -    "  EndStreamPrimitive(2);\n"
>> -
>> -    "  stream1_0_out = vec2(0.0, 1.0);\n"
>> -    "  EmitStreamVertex(1);\n"
>> -    "  EndStreamPrimitive(1);\n"
>> -    "}";
>> -
>>   int stream_float_counts[] = { 1, 2, 5, 0 };
>> +static bool use_spirv = false;
>>   #define STREAMS 4
>> +#define SHADER_TEST_FILE_NAME 
>> "xfb_streams_without_invocations.shader_test"
>> +char shader_test_filename[4096];
>> +
>>   static const char *varyings[] = {
>>       "stream0_0_out", "gl_NextBuffer",
>>       "stream1_0_out", "gl_NextBuffer",
>>       "stream2_0_out", "stream2_1_out"
>>   };
>> -static void
>> -build_and_use_program()
>> +
>> +static GLuint
>> +assemble_spirv_shader(GLenum shader_type)
>> +{
>> +    char *shader_asm;
>> +    unsigned shader_asm_size;
>> +    GLuint shader;
>> +
>> +    if (!piglit_load_source_from_shader_test(shader_test_filename,
>> +                         shader_type, true,
>> +                         &shader_asm, &shader_asm_size)) {
>> +        piglit_report_result(PIGLIT_FAIL);
>> +    }
>> +
>> +    shader = piglit_assemble_spirv(shader_type,
>> +                       shader_asm_size,
>> +                       shader_asm);
>> +    free(shader_asm);
>> +
>> +    glSpecializeShader(shader,
>> +               "main",
>> +               0, /* numSpecializationConstants */
>> +               NULL /* pConstantIndex */,
>> +               NULL /* pConstantValue */);
>> +
>> +    return shader;
>> +}
>> +
>> +static GLuint
>> +build_spirv_program(void)
>> +{
>> +    GLuint prog, shader;
>> +
>> +    prog = glCreateProgram();
>> +
>> +    shader = assemble_spirv_shader(GL_VERTEX_SHADER);
>> +    glAttachShader(prog, shader);
>> +    glDeleteShader(shader);
>> +
>> +    shader = assemble_spirv_shader(GL_GEOMETRY_SHADER);
>> +    glAttachShader(prog, shader);
>> +    glDeleteShader(shader);
>> +
>> +    return prog;
>> +}
>> +
>> +static GLuint
>> +build_glsl_program()
>>   {
>>       GLuint prog;
>> +    char *gs_text;
>> +    char *vs_pass_thru_text;
>> +
>> +    if (!piglit_load_source_from_shader_test(shader_test_filename,
>> +                         GL_GEOMETRY_SHADER, false,
>> +                         &gs_text, NULL))
>> +        return 0;
>> +
>> +
>> +    if (!piglit_load_source_from_shader_test(shader_test_filename,
>> +                         GL_VERTEX_SHADER, false,
>> +                         &vs_pass_thru_text, NULL))
>> +        return 0;
>> +
>>       prog = piglit_build_simple_program_multiple_shaders(
>>               GL_VERTEX_SHADER, vs_pass_thru_text,
>> @@ -94,6 +128,22 @@ build_and_use_program()
>>       glTransformFeedbackVaryings(prog, ARRAY_SIZE(varyings), varyings,
>>               GL_INTERLEAVED_ATTRIBS);
>> +    free(gs_text);
>> +    free(vs_pass_thru_text);
>> +
>> +    return prog;
>> +}
>> +
>> +static void
>> +build_and_use_program()
>> +{
>> +    GLuint prog;
>> +
>> +    if (use_spirv)
>> +        prog = build_spirv_program();
>> +    else
>> +        prog = build_glsl_program();
>> +
>>       glLinkProgram(prog);
>>       if (!piglit_link_check_status(prog))
>>           piglit_report_result(PIGLIT_FAIL);
>> @@ -193,6 +243,25 @@ piglit_init(int argc, char **argv)
>>       piglit_require_extension("GL_ARB_gpu_shader5");
>>       piglit_require_extension("GL_ARB_transform_feedback3");
>> +    for (i = 1; i < argc; i++) {
>> +        if (!strcmp(argv[i], "spirv"))
>> +            use_spirv = true;
>> +    }
>> +
>> +    if (use_spirv)
>> +        piglit_require_extension("GL_ARB_gl_spirv");
>> +
>> +    piglit_join_paths(shader_test_filename,
>> +              sizeof(shader_test_filename),
>> +              7, /* num parts */
>> +              piglit_source_dir(),
>> +              "tests",
>> +              "spec",
>> +              "arb_gpu_shader5",
>> +              "execution",
>> +              "shader_test",
>> +              SHADER_TEST_FILE_NAME);
>> +
>>       build_and_use_program();
>>       /* Set up the transform feedback buffers. */
>>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list