diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2022-09-05 14:03:22 +0300 |
---|---|---|
committer | Hans-Kristian Arntzen <post@arntzen-software.no> | 2022-09-05 14:20:57 +0300 |
commit | e9cfdb57ddf4ad50fc58ca233201d5461abd5fdf (patch) | |
tree | a8cc2d935afb7b3ddcfcb15c2cd31cbd8c2bfbe6 | |
parent | c998ec3a7b0eaceb9b4d6ab37e6bacf5e6e3c4d4 (diff) |
Add basic mesh shader tests.
-rw-r--r-- | reference/shaders/stages/mesh-basic-line.mesh | 197 | ||||
-rw-r--r-- | reference/shaders/stages/mesh-basic.mesh | 198 | ||||
-rwxr-xr-x | roundtrip_shaders.py | 2 | ||||
-rw-r--r-- | shaders/stages/mesh-basic-line.mesh | 43 | ||||
-rw-r--r-- | shaders/stages/mesh-basic.mesh | 43 | ||||
-rwxr-xr-x | test_shaders.py | 5 |
6 files changed, 488 insertions, 0 deletions
diff --git a/reference/shaders/stages/mesh-basic-line.mesh b/reference/shaders/stages/mesh-basic-line.mesh new file mode 100644 index 0000000..16e9bdb --- /dev/null +++ b/reference/shaders/stages/mesh-basic-line.mesh @@ -0,0 +1,197 @@ +#version 460 +#extension GL_EXT_mesh_shader : require +layout(local_size_x = 2, local_size_y = 3, local_size_z = 4) in; +layout(max_vertices = 24, max_primitives = 8, lines) out; + +struct _36 +{ + float _m0; +}; + +layout(location = 1) out vec4 B[24]; +layout(location = 3) perprimitiveEXT out vec4 C[8]; +shared float _32[64]; +taskPayloadSharedEXT _36 _38; + +void main() +{ + _32[gl_LocalInvocationIndex] = float(gl_LocalInvocationIndex); + barrier(); + SetMeshOutputsEXT(24u, 8u); + gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.x = _32[gl_LocalInvocationIndex]; + gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.y = _32[gl_LocalInvocationIndex]; + gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.z = _32[gl_LocalInvocationIndex]; + gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.w = _32[gl_LocalInvocationIndex]; + float _59 = _38._m0 + _32[gl_LocalInvocationIndex ^ 1u]; + B[gl_LocalInvocationIndex].x = _59; + B[gl_LocalInvocationIndex].y = _59; + B[gl_LocalInvocationIndex].z = _59; + B[gl_LocalInvocationIndex].w = _59; + if (gl_LocalInvocationIndex < 8u) + { + uint _65 = gl_LocalInvocationIndex * 3u; + gl_PrimitiveLineIndicesEXT[gl_LocalInvocationIndex] = uvec2(_65, _65 + 1u); + gl_MeshPrimitivesEXT[gl_LocalInvocationIndex].gl_CullPrimitiveEXT = (gl_LocalInvocationIndex & 1u) != 0u; + gl_MeshPrimitivesEXT[gl_LocalInvocationIndex].gl_PrimitiveID = int(gl_LocalInvocationIndex); + gl_MeshPrimitivesEXT[gl_LocalInvocationIndex].gl_Layer = int(gl_LocalInvocationIndex); + uint _77 = gl_LocalInvocationIndex ^ 2u; + C[gl_LocalInvocationIndex].x = _32[_77]; + C[gl_LocalInvocationIndex].y = _32[_77]; + C[gl_LocalInvocationIndex].z = _32[_77]; + C[gl_LocalInvocationIndex].w = _32[_77]; + } +} + + +#if 0 +// SPIR-V disassembly +; SPIR-V +; Version: 1.4 +; Generator: Unknown(30017); 21022 +; Bound: 88 +; Schema: 0 +OpCapability Shader +OpCapability Geometry +OpCapability ShaderViewportIndexLayerEXT +OpCapability MeshShadingEXT +OpExtension "SPV_EXT_mesh_shader" +OpExtension "SPV_EXT_shader_viewport_index_layer" +OpMemoryModel Logical GLSL450 +OpEntryPoint MeshEXT %3 "main" %11 %12 %17 %20 %21 %24 %28 %32 %34 %38 +OpExecutionMode %3 OutputVertices 24 +OpExecutionMode %3 OutputPrimitivesNV 8 +OpExecutionMode %3 OutputLinesNV +OpExecutionMode %3 LocalSize 2 3 4 +OpName %3 "main" +OpName %11 "SV_Position" +OpName %12 "B" +OpName %17 "SV_CullPrimitive" +OpName %20 "SV_RenderTargetArrayIndex" +OpName %21 "SV_PrimitiveID" +OpName %24 "C" +OpName %28 "indices" +OpName %36 "" +OpDecorate %11 BuiltIn Position +OpDecorate %12 Location 1 +OpDecorate %17 BuiltIn CullPrimitiveEXT +OpDecorate %17 PerPrimitiveNV +OpDecorate %20 BuiltIn Layer +OpDecorate %20 PerPrimitiveNV +OpDecorate %21 BuiltIn PrimitiveId +OpDecorate %21 PerPrimitiveNV +OpDecorate %24 Location 3 +OpDecorate %24 PerPrimitiveNV +OpDecorate %28 BuiltIn PrimitiveLineIndicesEXT +OpDecorate %34 BuiltIn LocalInvocationIndex +%1 = OpTypeVoid +%2 = OpTypeFunction %1 +%5 = OpTypeFloat 32 +%6 = OpTypeVector %5 4 +%7 = OpTypeInt 32 0 +%8 = OpConstant %7 24 +%9 = OpTypeArray %6 %8 +%10 = OpTypePointer Output %9 +%11 = OpVariable %10 Output +%12 = OpVariable %10 Output +%13 = OpTypeBool +%14 = OpConstant %7 8 +%15 = OpTypeArray %13 %14 +%16 = OpTypePointer Output %15 +%17 = OpVariable %16 Output +%18 = OpTypeArray %7 %14 +%19 = OpTypePointer Output %18 +%20 = OpVariable %19 Output +%21 = OpVariable %19 Output +%22 = OpTypeArray %6 %14 +%23 = OpTypePointer Output %22 +%24 = OpVariable %23 Output +%25 = OpTypeVector %7 2 +%26 = OpTypeArray %25 %14 +%27 = OpTypePointer Output %26 +%28 = OpVariable %27 Output +%29 = OpConstant %7 64 +%30 = OpTypeArray %5 %29 +%31 = OpTypePointer Workgroup %30 +%32 = OpVariable %31 Workgroup +%33 = OpTypePointer Input %7 +%34 = OpVariable %33 Input +%36 = OpTypeStruct %5 +%37 = OpTypePointer TaskPayloadWorkgroupEXT %36 +%38 = OpVariable %37 TaskPayloadWorkgroupEXT +%40 = OpTypePointer Workgroup %5 +%42 = OpConstant %7 2 +%43 = OpConstant %7 264 +%45 = OpTypePointer Output %5 +%47 = OpConstant %7 0 +%49 = OpConstant %7 1 +%52 = OpConstant %7 3 +%56 = OpTypePointer TaskPayloadWorkgroupEXT %5 +%68 = OpTypePointer Output %25 +%72 = OpTypePointer Output %13 +%74 = OpTypePointer Output %7 +%3 = OpFunction %1 None %2 +%4 = OpLabel +OpBranch %84 +%84 = OpLabel +%35 = OpLoad %7 %34 +%39 = OpConvertUToF %5 %35 +%41 = OpAccessChain %40 %32 %35 +OpStore %41 %39 +OpControlBarrier %42 %42 %43 +OpSetMeshOutputsEXT %8 %14 +%44 = OpLoad %5 %41 +%46 = OpAccessChain %45 %11 %35 %47 +OpStore %46 %44 +%48 = OpAccessChain %45 %11 %35 %49 +OpStore %48 %44 +%50 = OpAccessChain %45 %11 %35 %42 +OpStore %50 %44 +%51 = OpAccessChain %45 %11 %35 %52 +OpStore %51 %44 +%53 = OpBitwiseXor %7 %35 %49 +%54 = OpAccessChain %40 %32 %53 +%55 = OpLoad %5 %54 +%57 = OpInBoundsAccessChain %56 %38 %47 +%58 = OpLoad %5 %57 +%59 = OpFAdd %5 %58 %55 +%60 = OpAccessChain %45 %12 %35 %47 +OpStore %60 %59 +%61 = OpAccessChain %45 %12 %35 %49 +OpStore %61 %59 +%62 = OpAccessChain %45 %12 %35 %42 +OpStore %62 %59 +%63 = OpAccessChain %45 %12 %35 %52 +OpStore %63 %59 +%64 = OpULessThan %13 %35 %14 +OpSelectionMerge %86 None +OpBranchConditional %64 %85 %86 +%85 = OpLabel +%65 = OpIMul %7 %35 %52 +%66 = OpIAdd %7 %65 %49 +%67 = OpCompositeConstruct %25 %65 %66 +%69 = OpAccessChain %68 %28 %35 +OpStore %69 %67 +%70 = OpBitwiseAnd %7 %35 %49 +%71 = OpINotEqual %13 %70 %47 +%73 = OpAccessChain %72 %17 %35 +OpStore %73 %71 +%75 = OpAccessChain %74 %21 %35 +OpStore %75 %35 +%76 = OpAccessChain %74 %20 %35 +OpStore %76 %35 +%77 = OpBitwiseXor %7 %35 %42 +%78 = OpAccessChain %40 %32 %77 +%79 = OpLoad %5 %78 +%80 = OpAccessChain %45 %24 %35 %47 +OpStore %80 %79 +%81 = OpAccessChain %45 %24 %35 %49 +OpStore %81 %79 +%82 = OpAccessChain %45 %24 %35 %42 +OpStore %82 %79 +%83 = OpAccessChain %45 %24 %35 %52 +OpStore %83 %79 +OpBranch %86 +%86 = OpLabel +OpReturn +OpFunctionEnd +#endif diff --git a/reference/shaders/stages/mesh-basic.mesh b/reference/shaders/stages/mesh-basic.mesh new file mode 100644 index 0000000..bcd6b20 --- /dev/null +++ b/reference/shaders/stages/mesh-basic.mesh @@ -0,0 +1,198 @@ +#version 460 +#extension GL_EXT_mesh_shader : require +layout(local_size_x = 2, local_size_y = 3, local_size_z = 4) in; +layout(max_vertices = 24, max_primitives = 8, triangles) out; + +struct _36 +{ + float _m0; +}; + +layout(location = 1) out vec4 B[24]; +layout(location = 3) perprimitiveEXT out vec4 C[8]; +shared float _32[64]; +taskPayloadSharedEXT _36 _38; + +void main() +{ + _32[gl_LocalInvocationIndex] = float(gl_LocalInvocationIndex); + barrier(); + SetMeshOutputsEXT(24u, 8u); + gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.x = _32[gl_LocalInvocationIndex]; + gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.y = _32[gl_LocalInvocationIndex]; + gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.z = _32[gl_LocalInvocationIndex]; + gl_MeshVerticesEXT[gl_LocalInvocationIndex].gl_Position.w = _32[gl_LocalInvocationIndex]; + float _59 = _38._m0 + _32[gl_LocalInvocationIndex ^ 1u]; + B[gl_LocalInvocationIndex].x = _59; + B[gl_LocalInvocationIndex].y = _59; + B[gl_LocalInvocationIndex].z = _59; + B[gl_LocalInvocationIndex].w = _59; + if (gl_LocalInvocationIndex < 8u) + { + uint _65 = gl_LocalInvocationIndex * 3u; + gl_PrimitiveTriangleIndicesEXT[gl_LocalInvocationIndex] = uvec3(_65, _65 + 1u, _65 + 2u); + gl_MeshPrimitivesEXT[gl_LocalInvocationIndex].gl_CullPrimitiveEXT = (gl_LocalInvocationIndex & 1u) != 0u; + gl_MeshPrimitivesEXT[gl_LocalInvocationIndex].gl_PrimitiveID = int(gl_LocalInvocationIndex); + gl_MeshPrimitivesEXT[gl_LocalInvocationIndex].gl_Layer = int(gl_LocalInvocationIndex); + uint _78 = gl_LocalInvocationIndex ^ 2u; + C[gl_LocalInvocationIndex].x = _32[_78]; + C[gl_LocalInvocationIndex].y = _32[_78]; + C[gl_LocalInvocationIndex].z = _32[_78]; + C[gl_LocalInvocationIndex].w = _32[_78]; + } +} + + +#if 0 +// SPIR-V disassembly +; SPIR-V +; Version: 1.4 +; Generator: Unknown(30017); 21022 +; Bound: 89 +; Schema: 0 +OpCapability Shader +OpCapability Geometry +OpCapability ShaderViewportIndexLayerEXT +OpCapability MeshShadingEXT +OpExtension "SPV_EXT_mesh_shader" +OpExtension "SPV_EXT_shader_viewport_index_layer" +OpMemoryModel Logical GLSL450 +OpEntryPoint MeshEXT %3 "main" %11 %12 %17 %20 %21 %24 %28 %32 %34 %38 +OpExecutionMode %3 OutputVertices 24 +OpExecutionMode %3 OutputPrimitivesNV 8 +OpExecutionMode %3 OutputTrianglesNV +OpExecutionMode %3 LocalSize 2 3 4 +OpName %3 "main" +OpName %11 "SV_Position" +OpName %12 "B" +OpName %17 "SV_CullPrimitive" +OpName %20 "SV_RenderTargetArrayIndex" +OpName %21 "SV_PrimitiveID" +OpName %24 "C" +OpName %28 "indices" +OpName %36 "" +OpDecorate %11 BuiltIn Position +OpDecorate %12 Location 1 +OpDecorate %17 BuiltIn CullPrimitiveEXT +OpDecorate %17 PerPrimitiveNV +OpDecorate %20 BuiltIn Layer +OpDecorate %20 PerPrimitiveNV +OpDecorate %21 BuiltIn PrimitiveId +OpDecorate %21 PerPrimitiveNV +OpDecorate %24 Location 3 +OpDecorate %24 PerPrimitiveNV +OpDecorate %28 BuiltIn PrimitiveTriangleIndicesEXT +OpDecorate %34 BuiltIn LocalInvocationIndex +%1 = OpTypeVoid +%2 = OpTypeFunction %1 +%5 = OpTypeFloat 32 +%6 = OpTypeVector %5 4 +%7 = OpTypeInt 32 0 +%8 = OpConstant %7 24 +%9 = OpTypeArray %6 %8 +%10 = OpTypePointer Output %9 +%11 = OpVariable %10 Output +%12 = OpVariable %10 Output +%13 = OpTypeBool +%14 = OpConstant %7 8 +%15 = OpTypeArray %13 %14 +%16 = OpTypePointer Output %15 +%17 = OpVariable %16 Output +%18 = OpTypeArray %7 %14 +%19 = OpTypePointer Output %18 +%20 = OpVariable %19 Output +%21 = OpVariable %19 Output +%22 = OpTypeArray %6 %14 +%23 = OpTypePointer Output %22 +%24 = OpVariable %23 Output +%25 = OpTypeVector %7 3 +%26 = OpTypeArray %25 %14 +%27 = OpTypePointer Output %26 +%28 = OpVariable %27 Output +%29 = OpConstant %7 64 +%30 = OpTypeArray %5 %29 +%31 = OpTypePointer Workgroup %30 +%32 = OpVariable %31 Workgroup +%33 = OpTypePointer Input %7 +%34 = OpVariable %33 Input +%36 = OpTypeStruct %5 +%37 = OpTypePointer TaskPayloadWorkgroupEXT %36 +%38 = OpVariable %37 TaskPayloadWorkgroupEXT +%40 = OpTypePointer Workgroup %5 +%42 = OpConstant %7 2 +%43 = OpConstant %7 264 +%45 = OpTypePointer Output %5 +%47 = OpConstant %7 0 +%49 = OpConstant %7 1 +%52 = OpConstant %7 3 +%56 = OpTypePointer TaskPayloadWorkgroupEXT %5 +%69 = OpTypePointer Output %25 +%73 = OpTypePointer Output %13 +%75 = OpTypePointer Output %7 +%3 = OpFunction %1 None %2 +%4 = OpLabel +OpBranch %85 +%85 = OpLabel +%35 = OpLoad %7 %34 +%39 = OpConvertUToF %5 %35 +%41 = OpAccessChain %40 %32 %35 +OpStore %41 %39 +OpControlBarrier %42 %42 %43 +OpSetMeshOutputsEXT %8 %14 +%44 = OpLoad %5 %41 +%46 = OpAccessChain %45 %11 %35 %47 +OpStore %46 %44 +%48 = OpAccessChain %45 %11 %35 %49 +OpStore %48 %44 +%50 = OpAccessChain %45 %11 %35 %42 +OpStore %50 %44 +%51 = OpAccessChain %45 %11 %35 %52 +OpStore %51 %44 +%53 = OpBitwiseXor %7 %35 %49 +%54 = OpAccessChain %40 %32 %53 +%55 = OpLoad %5 %54 +%57 = OpInBoundsAccessChain %56 %38 %47 +%58 = OpLoad %5 %57 +%59 = OpFAdd %5 %58 %55 +%60 = OpAccessChain %45 %12 %35 %47 +OpStore %60 %59 +%61 = OpAccessChain %45 %12 %35 %49 +OpStore %61 %59 +%62 = OpAccessChain %45 %12 %35 %42 +OpStore %62 %59 +%63 = OpAccessChain %45 %12 %35 %52 +OpStore %63 %59 +%64 = OpULessThan %13 %35 %14 +OpSelectionMerge %87 None +OpBranchConditional %64 %86 %87 +%86 = OpLabel +%65 = OpIMul %7 %35 %52 +%66 = OpIAdd %7 %65 %49 +%67 = OpIAdd %7 %65 %42 +%68 = OpCompositeConstruct %25 %65 %66 %67 +%70 = OpAccessChain %69 %28 %35 +OpStore %70 %68 +%71 = OpBitwiseAnd %7 %35 %49 +%72 = OpINotEqual %13 %71 %47 +%74 = OpAccessChain %73 %17 %35 +OpStore %74 %72 +%76 = OpAccessChain %75 %21 %35 +OpStore %76 %35 +%77 = OpAccessChain %75 %20 %35 +OpStore %77 %35 +%78 = OpBitwiseXor %7 %35 %42 +%79 = OpAccessChain %40 %32 %78 +%80 = OpLoad %5 %79 +%81 = OpAccessChain %45 %24 %35 %47 +OpStore %81 %80 +%82 = OpAccessChain %45 %24 %35 %49 +OpStore %82 %80 +%83 = OpAccessChain %45 %24 %35 %42 +OpStore %83 %80 +%84 = OpAccessChain %45 %24 %35 %52 +OpStore %84 %80 +OpBranch %87 +%87 = OpLabel +OpReturn +OpFunctionEnd +#endif diff --git a/roundtrip_shaders.py b/roundtrip_shaders.py index 6aea71f..4499e97 100755 --- a/roundtrip_shaders.py +++ b/roundtrip_shaders.py @@ -71,6 +71,8 @@ def convert_shaders(args): results.append(pool.apply_async(convert_spirv, args = (in_path, out_path, args, 'rchit'))) results.append(pool.apply_async(convert_spirv, args = (in_path, out_path, args, 'rmiss'))) results.append(pool.apply_async(convert_spirv, args = (in_path, out_path, args, 'rcall'))) + results.append(pool.apply_async(convert_spirv, args = (in_path, out_path, args, 'mesh'))) + results.append(pool.apply_async(convert_spirv, args = (in_path, out_path, args, 'task'))) for res in results: res.get() diff --git a/shaders/stages/mesh-basic-line.mesh b/shaders/stages/mesh-basic-line.mesh new file mode 100644 index 0000000..8602031 --- /dev/null +++ b/shaders/stages/mesh-basic-line.mesh @@ -0,0 +1,43 @@ +struct VOut +{ + float4 pos : SV_Position; + float4 b : B; +}; + +struct PrimOut +{ + bool cull : SV_CullPrimitive; + uint layer : SV_RenderTargetArrayIndex; + uint primid : SV_PrimitiveID; + float4 c : C; +}; + +groupshared float foo[64]; + +struct Payload +{ + float p; +}; + +[numthreads(2, 3, 4)] +[outputtopology("line")] +void main(uint tid : SV_GroupIndex, + in payload Payload p, + out vertices VOut vout[24], + out indices uint2 ind[8], + out primitives PrimOut prim[8]) +{ + foo[tid] = float(tid); + GroupMemoryBarrierWithGroupSync(); + SetMeshOutputCounts(24, 8); + vout[tid].pos = foo[tid].xxxx; + vout[tid].b = foo[tid ^ 1].xxxx + p.p; + if (tid < 8) + { + ind[tid] = 3 * tid + uint2(0, 1); + prim[tid].cull = bool(tid & 1); + prim[tid].primid = tid; + prim[tid].layer = tid; + prim[tid].c = foo[tid ^ 2].xxxx; + } +} diff --git a/shaders/stages/mesh-basic.mesh b/shaders/stages/mesh-basic.mesh new file mode 100644 index 0000000..cf23bc2 --- /dev/null +++ b/shaders/stages/mesh-basic.mesh @@ -0,0 +1,43 @@ +struct VOut +{ + float4 pos : SV_Position; + float4 b : B; +}; + +struct PrimOut +{ + bool cull : SV_CullPrimitive; + uint layer : SV_RenderTargetArrayIndex; + uint primid : SV_PrimitiveID; + float4 c : C; +}; + +groupshared float foo[64]; + +struct Payload +{ + float p; +}; + +[numthreads(2, 3, 4)] +[outputtopology("triangle")] +void main(uint tid : SV_GroupIndex, + in payload Payload p, + out vertices VOut vout[24], + out indices uint3 ind[8], + out primitives PrimOut prim[8]) +{ + foo[tid] = float(tid); + GroupMemoryBarrierWithGroupSync(); + SetMeshOutputCounts(24, 8); + vout[tid].pos = foo[tid].xxxx; + vout[tid].b = foo[tid ^ 1].xxxx + p.p; + if (tid < 8) + { + ind[tid] = 3 * tid + uint3(0, 1, 2); + prim[tid].cull = bool(tid & 1); + prim[tid].primid = tid; + prim[tid].layer = tid; + prim[tid].c = foo[tid ^ 2].xxxx; + } +} diff --git a/test_shaders.py b/test_shaders.py index 521bc8c..d435ef9 100755 --- a/test_shaders.py +++ b/test_shaders.py @@ -56,6 +56,7 @@ def create_temporary(suff = ''): def get_sm(shader, version_minor): minor_version = '_{}'.format(version_minor) lib_version = 'lib_6_{}'.format(5 if version_minor <= 5 else 6) + mesh_version = '_{}'.format(5 if version_minor <= 5 else version_minor) _, ext = os.path.splitext(shader) if ext == '.vert': return 'vs_6' + minor_version @@ -69,6 +70,10 @@ def get_sm(shader, version_minor): return 'ds_6' + minor_version elif ext == '.geom': return 'gs_6' + minor_version + elif ext == '.mesh': + return 'ms_6' + mesh_version + elif ext == '.task': + return 'as_6' + mesh_version elif ext == '.rmiss': return lib_version elif ext == '.rint': |