浏览代码

Fix bug in emitting correct capability for LSS built-in functions. (#3968)

* Fix bug in emitting correct capability for LSS built-in functions.

* Add unit test.
alelenv 3 月之前
父节点
当前提交
fc060af481

+ 12 - 14
SPIRV/GlslangToSpv.cpp

@@ -3515,20 +3515,6 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
         noReturnValue = true;
         break;
 
-    case glslang::EOpHitObjectGetSpherePositionNV:
-    case glslang::EOpHitObjectGetSphereRadiusNV:
-    case glslang::EOpHitObjectIsSphereHitNV:
-        builder.addExtension(spv::E_SPV_NV_linear_swept_spheres);
-        builder.addCapability(spv::Capability::ShaderInvocationReorderNV);
-        builder.addCapability(spv::Capability::RayTracingSpheresGeometryNV);
-        break;
-
-    case glslang::EOpHitObjectIsLSSHitNV:
-        builder.addExtension(spv::E_SPV_NV_linear_swept_spheres);
-        builder.addCapability(spv::Capability::ShaderInvocationReorderNV);
-        builder.addCapability(spv::Capability::RayTracingLinearSweptSpheresGeometryNV);
-        break;
-
     case glslang::EOpRayQueryGetIntersectionLSSPositionsNV:
     case glslang::EOpRayQueryGetIntersectionLSSRadiiNV:
         builder.addExtension(spv::E_SPV_NV_linear_swept_spheres);
@@ -7989,18 +7975,30 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, OpDe
 
     case glslang::EOpHitObjectGetSpherePositionNV:
         unaryOp = spv::Op::OpHitObjectGetSpherePositionNV;
+        builder.addExtension(spv::E_SPV_NV_linear_swept_spheres);
+        builder.addCapability(spv::Capability::ShaderInvocationReorderNV);
+        builder.addCapability(spv::Capability::RayTracingSpheresGeometryNV);
         break;
 
     case glslang::EOpHitObjectGetSphereRadiusNV:
         unaryOp = spv::Op::OpHitObjectGetSphereRadiusNV;
+        builder.addExtension(spv::E_SPV_NV_linear_swept_spheres);
+        builder.addCapability(spv::Capability::ShaderInvocationReorderNV);
+        builder.addCapability(spv::Capability::RayTracingSpheresGeometryNV);
         break;
 
     case glslang::EOpHitObjectIsSphereHitNV:
         unaryOp = spv::Op::OpHitObjectIsSphereHitNV;
+        builder.addExtension(spv::E_SPV_NV_linear_swept_spheres);
+        builder.addCapability(spv::Capability::ShaderInvocationReorderNV);
+        builder.addCapability(spv::Capability::RayTracingSpheresGeometryNV);
         break;
 
     case glslang::EOpHitObjectIsLSSHitNV:
         unaryOp = spv::Op::OpHitObjectIsLSSHitNV;
+        builder.addExtension(spv::E_SPV_NV_linear_swept_spheres);
+        builder.addCapability(spv::Capability::ShaderInvocationReorderNV);
+        builder.addCapability(spv::Capability::RayTracingLinearSweptSpheresGeometryNV);
         break;
 
     case glslang::EOpFetchMicroTriangleVertexPositionNV:

+ 34 - 0
Test/baseResults/spv.nv.lss-lssgeomcap.rgen.out

@@ -0,0 +1,34 @@
+spv.nv.lss-lssgeomcap.rgen
+// Module Version 10400
+// Generated by (magic number): 8000b
+// Id's are bound by 13
+
+                              Capability RayTracingKHR
+                              Capability ShaderInvocationReorderNV
+                              Capability RayTracingLinearSweptSpheresGeometryNV
+                              Extension  "SPV_KHR_ray_tracing"
+                              Extension  "SPV_NV_linear_swept_spheres"
+                              Extension  "SPV_NV_shader_invocation_reorder"
+               1:             ExtInstImport  "GLSL.std.450"
+                              MemoryModel Logical GLSL450
+                              EntryPoint RayGenerationKHR 4  "main" 11
+                              Source GLSL 460
+                              SourceExtension  "GL_NV_linear_swept_spheres"
+                              SourceExtension  "GL_NV_shader_invocation_reorder"
+                              Name 4  "main"
+                              Name 8  "temp"
+                              Name 11  "hObj"
+               2:             TypeVoid
+               3:             TypeFunction 2
+               6:             TypeBool
+               7:             TypePointer Function 6(bool)
+               9:             TypeHitObjectNV
+              10:             TypePointer Private 9
+        11(hObj):     10(ptr) Variable Private
+         4(main):           2 Function None 3
+               5:             Label
+         8(temp):      7(ptr) Variable Function
+              12:     6(bool) HitObjectIsLSSHitNV 11(hObj)
+                              Store 8(temp) 12
+                              Return
+                              FunctionEnd

+ 46 - 0
Test/baseResults/spv.nv.lss-spheregeomcap.rgen.out

@@ -0,0 +1,46 @@
+spv.nv.lss-spheregeomcap.rgen
+// Module Version 10400
+// Generated by (magic number): 8000b
+// Id's are bound by 21
+
+                              Capability RayTracingKHR
+                              Capability ShaderInvocationReorderNV
+                              Capability RayTracingSpheresGeometryNV
+                              Extension  "SPV_KHR_ray_tracing"
+                              Extension  "SPV_NV_linear_swept_spheres"
+                              Extension  "SPV_NV_shader_invocation_reorder"
+               1:             ExtInstImport  "GLSL.std.450"
+                              MemoryModel Logical GLSL450
+                              EntryPoint RayGenerationKHR 4  "main" 11
+                              Source GLSL 460
+                              SourceExtension  "GL_NV_linear_swept_spheres"
+                              SourceExtension  "GL_NV_shader_invocation_reorder"
+                              Name 4  "main"
+                              Name 8  "temp"
+                              Name 11  "hObj"
+                              Name 16  "pos"
+                              Name 19  "rad"
+               2:             TypeVoid
+               3:             TypeFunction 2
+               6:             TypeBool
+               7:             TypePointer Function 6(bool)
+               9:             TypeHitObjectNV
+              10:             TypePointer Private 9
+        11(hObj):     10(ptr) Variable Private
+              13:             TypeFloat 32
+              14:             TypeVector 13(float) 3
+              15:             TypePointer Function 14(fvec3)
+              18:             TypePointer Function 13(float)
+         4(main):           2 Function None 3
+               5:             Label
+         8(temp):      7(ptr) Variable Function
+         16(pos):     15(ptr) Variable Function
+         19(rad):     18(ptr) Variable Function
+              12:     6(bool) HitObjectIsSphereHitNV 11(hObj)
+                              Store 8(temp) 12
+              17:   14(fvec3) HitObjectGetSpherePositionNV 11(hObj)
+                              Store 16(pos) 17
+              20:   13(float) HitObjectGetSphereRadiusNV 11(hObj)
+                              Store 19(rad) 20
+                              Return
+                              FunctionEnd

+ 9 - 0
Test/spv.nv.lss-lssgeomcap.rgen

@@ -0,0 +1,9 @@
+#version 460
+#extension GL_NV_shader_invocation_reorder : enable
+#extension GL_NV_linear_swept_spheres : enable
+
+void main()
+{
+	hitObjectNV hObj;
+	bool temp = hitObjectIsLSSHitNV(hObj);
+}

+ 11 - 0
Test/spv.nv.lss-spheregeomcap.rgen

@@ -0,0 +1,11 @@
+#version 460
+#extension GL_NV_shader_invocation_reorder : enable
+#extension GL_NV_linear_swept_spheres : enable
+
+void main()
+{
+	hitObjectNV hObj;
+	bool temp = hitObjectIsSphereHitNV(hObj);
+	vec3 pos = hitObjectGetSpherePositionNV(hObj);
+	float rad = hitObjectGetSphereRadiusNV(hObj);
+}

+ 2 - 0
gtests/Spv.FromFile.cpp

@@ -770,6 +770,8 @@ INSTANTIATE_TEST_SUITE_P(
         "spv.nv.lss-allops.rchit",
         "spv.nv.lss-allops.rmiss",
         "spv.nv.lss-allops.frag",
+        "spv.nv.lss-spheregeomcap.rgen",
+        "spv.nv.lss-lssgeomcap.rgen",
 
     })),
     FileNameAsCustomTestSuffix