public GlobalRootSignature(ID3D12Device5 pDevice, RootSignatureDescription desc) { pRootSig = new Vortice.Direct3D12.GlobalRootSignature(); pRootSig.RootSignature = pDevice.CreateRootSignature(desc, RootSignatureVersion.Version1); suboject = new StateSubObject(pRootSig); }
public void CreateRtPipelineState() { var rtpipeline = new RTPipeline(); // Need 10 subobjects: // 1 for the DXIL library // 1 for hit-group // 2 for RayGen root-signature (root-signature and the subobject association) // 2 for the root-signature shared between miss and hit shaders (signature and association) // 2 for shader config (shared between all programs. 1 for the config, 1 for association) // 1 for pipeline config // 1 for the global root signature StateSubObject[] subobjects = new StateSubObject[10]; int index = 0; // Create the DXIL library DxilLibrary dxilLib = rtpipeline.CreateDxilLibrary(); subobjects[index++] = dxilLib.stateSubObject; // 0 Library HitProgram hitProgram = new HitProgram(null, RTPipeline.kClosestHitShader, RTPipeline.kHitGroup); subobjects[index++] = hitProgram.subObject; // 1 Hit Group // Create the ray-gen root-signature and association Structs.LocalRootSignature rgsRootSignature = new Structs.LocalRootSignature(mpDevice, rtpipeline.CreateRayGenRootDesc()); subobjects[index] = rgsRootSignature.subobject; int rgsRootIndex = index++; // 2 ExportAssociation rgsRootAssociation = new ExportAssociation(new string[] { RTPipeline.kRayGenShader }, subobjects[rgsRootIndex]); subobjects[index++] = rgsRootAssociation.subobject; // 3 Associate Root Sig to RGS // Create the miss- and hit-programs root-signature and association RootSignatureDescription emptyDesc = new RootSignatureDescription(RootSignatureFlags.LocalRootSignature); Structs.LocalRootSignature hitMissRootSignature = new Structs.LocalRootSignature(mpDevice, emptyDesc); subobjects[index] = hitMissRootSignature.subobject; // 4 Root Sig to be shared between Miss and CHS int hitMissRootIndex = index++; // 4 string[] missHitExportName = new string[] { RTPipeline.kMissShader, RTPipeline.kClosestHitShader }; ExportAssociation missHitRootAssociation = new ExportAssociation(missHitExportName, subobjects[hitMissRootIndex]); subobjects[index++] = missHitRootAssociation.subobject; // 5 Associate Root Sig to Miss and CHS // Bind the payload size to the programs ShaderConfig shaderConfig = new ShaderConfig(sizeof(float) * 2, sizeof(float) * 1); subobjects[index] = shaderConfig.subObject; // 6 Shader Config; int shaderConfigIndex = index++; // 6 string[] shaderExports = new string[] { RTPipeline.kMissShader, RTPipeline.kClosestHitShader, RTPipeline.kRayGenShader }; ExportAssociation configAssociation = new ExportAssociation(shaderExports, subobjects[shaderConfigIndex]); subobjects[index++] = configAssociation.subobject; // 7 Associate Shader Config to Miss, CHS, RGS // Create the pipeline config PipelineConfig config = new PipelineConfig(0); subobjects[index++] = config.suboject; // 8 // Create the global root signature and store the empty signature Structs.GlobalRootSignature root = new Structs.GlobalRootSignature(mpDevice, new RootSignatureDescription()); mpEmptyRootSig = root.pRootSig; subobjects[index++] = root.suboject; // 9 // Create the state StateObjectDescription desc = new StateObjectDescription(StateObjectType.RaytracingPipeline, subobjects); mpPipelineState = mpDevice.CreateStateObject(desc); }