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 hit-program root-signature (root-signature and the subobject association) // 2 for miss-shader root-signature (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[12]; 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; // 2 RayGen Root Sig 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 hit root-signature and association Structs.LocalRootSignature hitRootSignature = new Structs.LocalRootSignature(mpDevice, rtpipeline.CreateHitRootDesc()); subobjects[index] = hitRootSignature.subobject; // 4 Hit Root Sig int hitRootIndex = index++; // 4 ExportAssociation hitRootAssociation = new ExportAssociation(new string[] { RTPipeline.kClosestHitShader }, subobjects[hitRootIndex]); // 5 Associate Hit Root Sig to Hit Group subobjects[index++] = hitRootAssociation.subobject; // 6 Associate Hit Root Sig to Hit Group // Create the miss root-signature and association RootSignatureDescription emptyDesc = new RootSignatureDescription(RootSignatureFlags.LocalRootSignature); Structs.LocalRootSignature missRootSignature = new Structs.LocalRootSignature(mpDevice, emptyDesc); subobjects[index] = missRootSignature.subobject; // 6 Miss Root Sig int missRootIndex = index++; // 6 ExportAssociation missRootAssociation = new ExportAssociation(new string[] { RTPipeline.kMissShader }, subobjects[missRootIndex]); subobjects[index++] = missRootAssociation.subobject; // 7 Associate Miss Root Sig to Miss Shader // Bind the payload size to the programs ShaderConfig shaderConfig = new ShaderConfig(sizeof(float) * 2, sizeof(float) * 4); subobjects[index] = shaderConfig.subObject; // 8 Shader Config; int shaderConfigIndex = index++; // 8 string[] shaderExports = new string[] { RTPipeline.kMissShader, RTPipeline.kClosestHitShader, RTPipeline.kRayGenShader }; ExportAssociation configAssociation = new ExportAssociation(shaderExports, subobjects[shaderConfigIndex]); subobjects[index++] = configAssociation.subobject; // 9 Associate Shader Config to Miss, CHS, RGS // Create the pipeline config PipelineConfig config = new PipelineConfig(1); subobjects[index++] = config.suboject; // 10 // Create the global root signature and store the empty signature Structs.GlobalRootSignature root = new Structs.GlobalRootSignature(mpDevice, new RootSignatureDescription()); mpEmptyRootSig = root.pRootSig.RootSignature; subobjects[index++] = root.suboject; // 11 // Create the state StateObjectDescription desc = new StateObjectDescription(StateObjectType.RaytracingPipeline, subobjects); mpPipelineState = mpDevice.CreateStateObject(desc); }
public void CreateRtPipelineState() { var rtpipeline = new RTPipeline(); // Need 10 subobjects: // 1 for the DXIL library // 1 for hit-group // 2 for the hit-groups (triangle hit group, plane hit-group) // 2 for RayGen root-signature (root-signature and the subobject association) // 2 for triangle hit-program root-signature (root-signature and the subobject association) // 2 for plane hit-program and miss-shader root-signature (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[13]; int index = 0; // Create the DXIL library DxilLibrary dxilLib = rtpipeline.CreateDxilLibrary(); subobjects[index++] = dxilLib.stateSubObject; // 0 Library // Create the triangle HitProgram HitProgram triHitProgram = new HitProgram(null, RTPipeline.kTriangleChs, RTPipeline.kTriHitGroup); subobjects[index++] = triHitProgram.subObject; // 1 Triangle Hit Group // Create the plane HitProgram HitProgram planeHitProgram = new HitProgram(null, RTPipeline.kPlaneChs, RTPipeline.kPlaneHitGroup); subobjects[index++] = planeHitProgram.subObject; // 2 Plane Hit Group // Create the ray-gen root-signature and association Structs.LocalRootSignature rgsRootSignature = new Structs.LocalRootSignature(mpDevice, rtpipeline.CreateRayGenRootDesc()); subobjects[index] = rgsRootSignature.subobject; // 3 RayGen Root Sig int rgsRootIndex = index++; // 3 ExportAssociation rgsRootAssociation = new ExportAssociation(new string[] { RTPipeline.kRayGenShader }, subobjects[rgsRootIndex]); subobjects[index++] = rgsRootAssociation.subobject; // 4 Associate Root Sig to RGS // Create the tri hit root-signature and association Structs.LocalRootSignature triHitRootSignature = new Structs.LocalRootSignature(mpDevice, rtpipeline.CreateTriangleHitRootDesc()); subobjects[index] = triHitRootSignature.subobject; // 5 Triangle Hit Root Sig int triHitRootIndex = index++; // 5 ExportAssociation triHitRootAssociation = new ExportAssociation(new string[] { RTPipeline.kTriangleChs }, subobjects[triHitRootIndex]); // 5 Associate Hit Root Sig to Hit Group subobjects[index++] = triHitRootAssociation.subobject; // 6 Associate Hit Root Sig to Hit Group // Create the empty root-signature and association it with the plane hit-program and miss-shader RootSignatureDescription emptyDesc = new RootSignatureDescription(RootSignatureFlags.LocalRootSignature); Structs.LocalRootSignature emptyRootSignature = new Structs.LocalRootSignature(mpDevice, emptyDesc); subobjects[index] = emptyRootSignature.subobject; // 7 Miss Root Sig for Plane Hit Group and Miss int emptyRootIndex = index++; // 7 ExportAssociation emptyRootAssociation = new ExportAssociation(new string[] { RTPipeline.kPlaneChs, RTPipeline.kMissShader }, subobjects[emptyRootIndex]); subobjects[index++] = emptyRootAssociation.subobject; // 8 Associate empty Root Sig to Plane Hit Group and Miss Shader // Bind the payload size to the programs ShaderConfig shaderConfig = new ShaderConfig(sizeof(float) * 2, sizeof(float) * 3); subobjects[index] = shaderConfig.subObject; // 9 Shader Config; int shaderConfigIndex = index++; // 9 string[] shaderExports = new string[] { RTPipeline.kMissShader, RTPipeline.kTriangleChs, RTPipeline.kPlaneChs, RTPipeline.kRayGenShader }; ExportAssociation configAssociation = new ExportAssociation(shaderExports, subobjects[shaderConfigIndex]); subobjects[index++] = configAssociation.subobject; // 10 Associate Shader Config to all shaders and hit groups // Create the pipeline config PipelineConfig config = new PipelineConfig(1); subobjects[index++] = config.suboject; // 11 // Create the global root signature and store the empty signature Structs.GlobalRootSignature root = new Structs.GlobalRootSignature(mpDevice, new RootSignatureDescription()); mpEmptyRootSig = root.pRootSig.RootSignature; subobjects[index++] = root.suboject; // 12 // Create the state StateObjectDescription desc = new StateObjectDescription(StateObjectType.RaytracingPipeline, subobjects); mpPipelineState = mpDevice.CreateStateObject(desc); }