Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GL_NV_displacement_micromap. #3324

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions SPIRV/GLSL.ext.NV.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,7 @@ const char* const E_SPV_NV_shader_sm_builtins = "SPV_NV_shader_sm_builtins";
//SPV_NV_shader_execution_reorder
const char* const E_SPV_NV_shader_invocation_reorder = "SPV_NV_shader_invocation_reorder";

//SPV_NV_displacement_micromap
const char* const E_SPV_NV_displacement_micromap = "SPV_NV_displacement_micromap";

#endif // #ifndef GLSLextNV_H
46 changes: 45 additions & 1 deletion SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,22 @@ spv::BuiltIn TGlslangToSpvTraverser::TranslateBuiltInDecoration(glslang::TBuiltI
builder.addExtension(spv::E_SPV_NV_ray_tracing_motion_blur);
builder.addCapability(spv::CapabilityRayTracingMotionBlurNV);
return spv::BuiltInCurrentRayTimeNV;
case glslang::EbvMicroTrianglePositionNV:
builder.addCapability(spv::CapabilityRayTracingDisplacementMicromapNV);
builder.addExtension("SPV_NV_displacement_micromap");
return spv::BuiltInHitMicroTriangleVertexPositionsNV;
case glslang::EbvMicroTriangleBaryNV:
builder.addCapability(spv::CapabilityRayTracingDisplacementMicromapNV);
builder.addExtension("SPV_NV_displacement_micromap");
return spv::BuiltInHitMicroTriangleVertexBarycentricsNV;
case glslang::EbvHitKindFrontFacingMicroTriangleNV:
builder.addCapability(spv::CapabilityRayTracingDisplacementMicromapNV);
builder.addExtension("SPV_NV_displacement_micromap");
return spv::BuiltInHitKindFrontFacingMicroTriangleNV;
case glslang::EbvHitKindBackFacingMicroTriangleNV:
builder.addCapability(spv::CapabilityRayTracingDisplacementMicromapNV);
builder.addExtension("SPV_NV_displacement_micromap");
return spv::BuiltInHitKindBackFacingMicroTriangleNV;

// barycentrics
case glslang::EbvBaryCoordNV:
Expand Down Expand Up @@ -3292,6 +3308,12 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
builder.addExtension(spv::E_SPV_QCOM_image_processing);
break;

case glslang::EOpFetchMicroTriangleVertexPositionNV:
case glslang::EOpFetchMicroTriangleVertexBarycentricNV:
builder.addExtension(spv::E_SPV_NV_displacement_micromap);
builder.addCapability(spv::CapabilityDisplacementMicromapNV);
break;

case glslang::EOpDebugPrintf:
noReturnValue = true;
break;
Expand Down Expand Up @@ -3656,7 +3678,10 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
spv::Id typeId = builder.makeArrayType(builder.makeVectorType(builder.makeFloatType(32), 3),
builder.makeUintConstant(3), 0);
// do the op
spv::Id result = builder.createOp(spv::OpRayQueryGetIntersectionTriangleVertexPositionsKHR, typeId, idImmOps);

spv::Op spvOp = spv::OpRayQueryGetIntersectionTriangleVertexPositionsKHR;

spv::Id result = builder.createOp(spvOp, typeId, idImmOps);
// store the result to the pointer (out param 'm')
builder.createStore(result, operands[2]);
result = 0;
Expand Down Expand Up @@ -7177,6 +7202,14 @@ spv::Id TGlslangToSpvTraverser::createUnaryOperation(glslang::TOperator op, OpDe
unaryOp = spv::OpHitObjectGetShaderRecordBufferHandleNV;
break;

case glslang::EOpFetchMicroTriangleVertexPositionNV:
unaryOp = spv::OpFetchMicroTriangleVertexPositionNV;
break;

case glslang::EOpFetchMicroTriangleVertexBarycentricNV:
unaryOp = spv::OpFetchMicroTriangleVertexBarycentricNV;
break;

case glslang::EOpCopyObject:
unaryOp = spv::OpCopyObject;
break;
Expand Down Expand Up @@ -9061,6 +9094,17 @@ spv::Id TGlslangToSpvTraverser::createMiscOperation(glslang::TOperator op, spv::
addImageProcessingQCOMDecoration(operands[0], spv::DecorationBlockMatchTextureQCOM);
addImageProcessingQCOMDecoration(operands[2], spv::DecorationBlockMatchTextureQCOM);
break;

case glslang::EOpFetchMicroTriangleVertexBarycentricNV:
typeId = builder.makeVectorType(builder.makeFloatType(32), 2);
opCode = spv::OpFetchMicroTriangleVertexBarycentricNV;
break;

case glslang::EOpFetchMicroTriangleVertexPositionNV:
typeId = builder.makeVectorType(builder.makeFloatType(32), 3);
opCode = spv::OpFetchMicroTriangleVertexPositionNV;
break;

default:
return 0;
}
Expand Down
25 changes: 24 additions & 1 deletion SPIRV/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ const char* BuiltInString(int builtIn)
case BuiltInRayTmaxKHR: return "RayTmaxKHR";
case BuiltInCullMaskKHR: return "CullMaskKHR";
case BuiltInHitTriangleVertexPositionsKHR: return "HitTriangleVertexPositionsKHR";
case BuiltInHitMicroTriangleVertexPositionsNV: return "HitMicroTriangleVertexPositionsNV";
case BuiltInHitMicroTriangleVertexBarycentricsNV: return "HitMicroTriangleVertexBarycentricsNV";
case BuiltInHitKindFrontFacingMicroTriangleNV: return "HitKindFrontFacingMicroTriangleNV";
case BuiltInHitKindBackFacingMicroTriangleNV: return "HitKindBackFacingMicroTriangleNV";
case BuiltInInstanceCustomIndexKHR: return "InstanceCustomIndexKHR";
case BuiltInRayGeometryIndexKHR: return "RayGeometryIndexKHR";
case BuiltInObjectToWorldKHR: return "ObjectToWorldKHR";
Expand Down Expand Up @@ -977,6 +981,8 @@ const char* CapabilityString(int info)
case CapabilityRayTracingProvisionalKHR: return "RayTracingProvisionalKHR";
case CapabilityRayTraversalPrimitiveCullingKHR: return "RayTraversalPrimitiveCullingKHR";
case CapabilityRayTracingPositionFetchKHR: return "RayTracingPositionFetchKHR";
case CapabilityDisplacementMicromapNV: return "DisplacementMicromapNV";
case CapabilityRayTracingDisplacementMicromapNV: return "CapabilityRayTracingDisplacementMicromapNV";
case CapabilityRayQueryPositionFetchKHR: return "RayQueryPositionFetchKHR";
case CapabilityComputeDerivativeGroupQuadsNV: return "ComputeDerivativeGroupQuadsNV";
case CapabilityComputeDerivativeGroupLinearNV: return "ComputeDerivativeGroupLinearNV";
Expand Down Expand Up @@ -1542,6 +1548,9 @@ const char* OpcodeString(int op)
case OpHitObjectGetShaderBindingTableRecordIndexNV: return "OpHitObjectGetShaderBindingTableRecordIndexNV";
case OpHitObjectGetShaderRecordBufferHandleNV: return "OpHitObjectGetShaderRecordBufferHandleNV";

case OpFetchMicroTriangleVertexBarycentricNV: return "OpFetchMicroTriangleVertexBarycentricNV";
case OpFetchMicroTriangleVertexPositionNV: return "OpFetchMicroTriangleVertexPositionNV";

case OpColorAttachmentReadEXT: return "OpColorAttachmentReadEXT";
case OpDepthAttachmentReadEXT: return "OpDepthAttachmentReadEXT";
case OpStencilAttachmentReadEXT: return "OpStencilAttachmentReadEXT";
Expand Down Expand Up @@ -3082,7 +3091,7 @@ void Parameterize()

InstructionDesc[OpRayQueryGetIntersectionTriangleVertexPositionsKHR].operands.push(OperandId, "'RayQuery'");
InstructionDesc[OpRayQueryGetIntersectionTriangleVertexPositionsKHR].operands.push(OperandId, "'Committed'");
InstructionDesc[OpRayQueryGetIntersectionWorldToObjectKHR].setResultAndType(true, true);
InstructionDesc[OpRayQueryGetIntersectionTriangleVertexPositionsKHR].setResultAndType(true, true);

InstructionDesc[OpImageSampleFootprintNV].operands.push(OperandId, "'Sampled Image'");
InstructionDesc[OpImageSampleFootprintNV].operands.push(OperandId, "'Coordinate'");
Expand Down Expand Up @@ -3348,6 +3357,20 @@ void Parameterize()
InstructionDesc[OpHitObjectTraceRayMotionNV].operands.push(OperandId, "'Payload'");
InstructionDesc[OpHitObjectTraceRayMotionNV].setResultAndType(false, false);

InstructionDesc[OpFetchMicroTriangleVertexBarycentricNV].operands.push(OperandId, "'Acceleration Structure'");
InstructionDesc[OpFetchMicroTriangleVertexBarycentricNV].operands.push(OperandId, "'Instance ID'");
InstructionDesc[OpFetchMicroTriangleVertexBarycentricNV].operands.push(OperandId, "'Geometry Index'");
InstructionDesc[OpFetchMicroTriangleVertexBarycentricNV].operands.push(OperandId, "'Primitive Index'");
InstructionDesc[OpFetchMicroTriangleVertexBarycentricNV].operands.push(OperandId, "'Barycentrics'");
InstructionDesc[OpFetchMicroTriangleVertexBarycentricNV].setResultAndType(true, true);

InstructionDesc[OpFetchMicroTriangleVertexPositionNV].operands.push(OperandId, "'Acceleration Structure'");
InstructionDesc[OpFetchMicroTriangleVertexPositionNV].operands.push(OperandId, "'Instance ID'");
InstructionDesc[OpFetchMicroTriangleVertexPositionNV].operands.push(OperandId, "'Geometry Index'");
InstructionDesc[OpFetchMicroTriangleVertexPositionNV].operands.push(OperandId, "'Primitive Index'");
InstructionDesc[OpFetchMicroTriangleVertexPositionNV].operands.push(OperandId, "'Barycentrics'");
InstructionDesc[OpFetchMicroTriangleVertexPositionNV].setResultAndType(true, true);

InstructionDesc[OpColorAttachmentReadEXT].operands.push(OperandId, "'Attachment'");
InstructionDesc[OpColorAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
InstructionDesc[OpStencilAttachmentReadEXT].operands.push(OperandId, "'Sample'", true);
Expand Down
8 changes: 8 additions & 0 deletions SPIRV/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,10 @@ enum BuiltIn {
BuiltInHitKindNV = 5333,
BuiltInCurrentRayTimeNV = 5334,
BuiltInHitTriangleVertexPositionsKHR = 5335,
BuiltInHitMicroTriangleVertexPositionsNV = 5337,
BuiltInHitMicroTriangleVertexBarycentricsNV = 5344,
BuiltInHitKindFrontFacingMicroTriangleNV = 5405,
BuiltInHitKindBackFacingMicroTriangleNV = 5406,
BuiltInIncomingRayFlagsKHR = 5351,
BuiltInIncomingRayFlagsNV = 5351,
BuiltInRayGeometryIndexKHR = 5352,
Expand Down Expand Up @@ -1094,6 +1098,8 @@ enum Capability {
CapabilityFragmentShaderPixelInterlockEXT = 5378,
CapabilityDemoteToHelperInvocation = 5379,
CapabilityDemoteToHelperInvocationEXT = 5379,
CapabilityDisplacementMicromapNV = 5380,
CapabilityRayTracingDisplacementMicromapNV = 5409,
CapabilityRayTracingOpacityMicromapEXT = 5381,
CapabilityShaderInvocationReorderNV = 5383,
CapabilityBindlessTextureNV = 5390,
Expand Down Expand Up @@ -1736,6 +1742,8 @@ enum Op {
OpSetMeshOutputsEXT = 5295,
OpGroupNonUniformPartitionNV = 5296,
OpWritePackedPrimitiveIndices4x8NV = 5299,
OpFetchMicroTriangleVertexPositionNV = 5300,
OpFetchMicroTriangleVertexBarycentricNV = 5301,
OpReportIntersectionKHR = 5334,
OpReportIntersectionNV = 5334,
OpIgnoreIntersectionNV = 5335,
Expand Down
96 changes: 96 additions & 0 deletions Test/baseResults/spv.nv.dmm-allops.comp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
spv.nv.dmm-allops.comp
// Module Version 10400
// Generated by (magic number): 8000b
// Id's are bound by 59

Capability Shader
Capability RayQueryKHR
Capability DisplacementMicromapNV
Extension "SPV_KHR_ray_query"
Extension "SPV_NV_displacement_micromap"
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main" 11 16
ExecutionMode 4 LocalSize 16 1 1
Source GLSL 460
SourceExtension "GL_EXT_ray_query"
SourceExtension "GL_NV_displacement_micromap"
Name 4 "main"
Name 9 "block"
MemberName 9(block) 0 "op_pos"
MemberName 9(block) 1 "op_bary"
Name 11 ""
Name 16 "as"
MemberDecorate 9(block) 0 Offset 0
MemberDecorate 9(block) 1 Offset 16
Decorate 9(block) Block
Decorate 11 DescriptorSet 0
Decorate 11 Binding 0
Decorate 16(as) DescriptorSet 0
Decorate 16(as) Binding 1
Decorate 58 BuiltIn WorkgroupSize
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 3
8: TypeVector 6(float) 2
9(block): TypeStruct 7(fvec3) 8(fvec2)
10: TypePointer StorageBuffer 9(block)
11: 10(ptr) Variable StorageBuffer
12: TypeInt 32 1
13: 12(int) Constant 0
14: TypeAccelerationStructureKHR
15: TypePointer UniformConstant 14
16(as): 15(ptr) Variable UniformConstant
18: 12(int) Constant 1
19: TypeVector 12(int) 2
20: 19(ivec2) ConstantComposite 13 13
22: TypePointer StorageBuffer 7(fvec3)
25: 19(ivec2) ConstantComposite 13 18
32: 19(ivec2) ConstantComposite 18 13
40: TypePointer StorageBuffer 8(fvec2)
54: TypeInt 32 0
55: TypeVector 54(int) 3
56: 54(int) Constant 16
57: 54(int) Constant 1
58: 55(ivec3) ConstantComposite 56 57 57
4(main): 2 Function None 3
5: Label
17: 14 Load 16(as)
21: 7(fvec3) FetchMicroTriangleVertexPositionNV 17 18 18 18 20
23: 22(ptr) AccessChain 11 13
Store 23 21
24: 14 Load 16(as)
26: 7(fvec3) FetchMicroTriangleVertexPositionNV 24 18 18 18 25
27: 22(ptr) AccessChain 11 13
28: 7(fvec3) Load 27
29: 7(fvec3) FAdd 28 26
30: 22(ptr) AccessChain 11 13
Store 30 29
31: 14 Load 16(as)
33: 7(fvec3) FetchMicroTriangleVertexPositionNV 31 18 18 18 32
34: 22(ptr) AccessChain 11 13
35: 7(fvec3) Load 34
36: 7(fvec3) FAdd 35 33
37: 22(ptr) AccessChain 11 13
Store 37 36
38: 14 Load 16(as)
39: 8(fvec2) FetchMicroTriangleVertexBarycentricNV 38 18 18 18 20
41: 40(ptr) AccessChain 11 18
Store 41 39
42: 14 Load 16(as)
43: 8(fvec2) FetchMicroTriangleVertexBarycentricNV 42 18 18 18 25
44: 40(ptr) AccessChain 11 18
45: 8(fvec2) Load 44
46: 8(fvec2) FAdd 45 43
47: 40(ptr) AccessChain 11 18
Store 47 46
48: 14 Load 16(as)
49: 8(fvec2) FetchMicroTriangleVertexBarycentricNV 48 18 18 18 32
50: 40(ptr) AccessChain 11 18
51: 8(fvec2) Load 50
52: 8(fvec2) FAdd 51 49
53: 40(ptr) AccessChain 11 18
Store 53 52
Return
FunctionEnd