コード例 #1
0
    /// <summary>
    /// Creates a <see cref="ID3D12StateObject"/>.
    /// </summary>
    /// <param name="description">The description of the state object to create.</param>
    /// <param name="stateObject">An instance of <see cref="ID3D12StateObject"/>.</param>
    /// <returns>The result of operation.</returns>
    public Result CreateStateObject <T>(StateObjectDescription description, out T?stateObject) where T : ID3D12StateObject
    {
        Result result = CreateStateObject(description, typeof(T).GUID, out IntPtr nativePtr);

        if (result.Failure)
        {
            stateObject = default;
            return(result);
        }

        stateObject = MarshallingHelpers.FromPointer <T>(nativePtr);
        return(result);
    }
コード例 #2
0
    public Result AddToStateObject <T>(StateObjectDescription addition, ID3D12StateObject stateObjectToGrowFrom, out T?newStateObject) where T : ID3D12StateObject
    {
        Result result = AddToStateObject(addition, stateObjectToGrowFrom, typeof(T).GUID, out IntPtr nativePtr);

        if (result.Failure)
        {
            newStateObject = default;
            return(result);
        }

        newStateObject = MarshallingHelpers.FromPointer <T>(nativePtr);
        return(result);
    }
コード例 #3
0
 public T AddToStateObject <T>(StateObjectDescription addition, ID3D12StateObject stateObjectToGrowFrom) where T : ID3D12StateObject
 {
     AddToStateObject(addition, stateObjectToGrowFrom, typeof(T).GUID, out IntPtr nativePtr).CheckError();
     return(MarshallingHelpers.FromPointer <T>(nativePtr));
 }
コード例 #4
0
        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);
        }
コード例 #5
0
 public StateObject CreateStateObject(StateObjectDescription description)
 {
     return(CreateStateObject(description, Utilities.GetGuidFromType(typeof(StateObject))));
 }
コード例 #6
0
 public ID3D12StateObject AddToStateObject(StateObjectDescription addition, ID3D12StateObject stateObjectToGrowFrom)
 {
     return(AddToStateObject(addition, stateObjectToGrowFrom, typeof(ID3D12StateObject).GUID));
 }
コード例 #7
0
 /// <summary>
 /// Creates a <see cref="ID3D12StateObject"/>.
 /// </summary>
 /// <param name="description">The description of the state object to create.</param>
 /// <returns>An instance of <see cref="ID3D12StateObject"/>.</returns>
 public ID3D12StateObject CreateStateObject(StateObjectDescription description)
 {
     return(CreateStateObject(description, typeof(ID3D12StateObject).GUID));
 }
コード例 #8
0
        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);
        }
        private void CreateRtPipelineState()
        {
            List <StateSubObject> subObjects = new List <StateSubObject>();

            // Create the DXIL library
            DxilLibrary library = CreateDxilLibrary();

            subObjects.Add(library.stateSubObject); // 0 Library

            // Create the triangle HitProgram
            HitProgram triHitProgram = new HitProgram(null, TriangleClosestHitShader, HitGroupTri);

            subObjects.Add(triHitProgram.subObject); // 1 Triangle Hit Group

            // Create the plane HitProgram
            HitProgram planeHitProgram = new HitProgram(null, PlaneClosestHitShader, HitGroupPlane);

            subObjects.Add(planeHitProgram.subObject); // 2 Plane Hit Group

            // Create the shadow-ray hit group
            HitProgram shadowHitProgram = new HitProgram(null, ShadowChsShader, ShadowHitGroup);

            subObjects.Add(shadowHitProgram.subObject); // 3 Shadow Hit Group

            // Create the ray-gen root-signature and association
            MyLocalRootSignature rgsRootSignature = new MyLocalRootSignature(device, CreateRayGenRootDesc());

            subObjects.Add(rgsRootSignature.subObject); // 4 Ray Gen Root Sig

            int rgsRootIndex = subObjects.Count - 1;    // 4
            ExportAssociation rgsRootAssociation = new ExportAssociation(new string[] { RayGenShader }, subObjects[rgsRootIndex]);

            subObjects.Add(rgsRootAssociation.SubObject); // 5 Associate Root Sig to RGS

            // Create the tri hit root-signature and association
            MyLocalRootSignature triHitRootSignature = new MyLocalRootSignature(device, CreateTriangleHitRootDesc());

            subObjects.Add(triHitRootSignature.subObject); // 6 Triangle Hit Root Sig

            int triHitRootIndex = subObjects.Count - 1;    // 6
            ExportAssociation triHitRootAssociation = new ExportAssociation(new string[] { TriangleClosestHitShader }, subObjects[triHitRootIndex]);

            subObjects.Add(triHitRootAssociation.SubObject); // 7 Associate Triangle Root Sig to Triangle Hit Group

            // Create the plane hit root-signature and association
            MyLocalRootSignature planeHitRootSignature = new MyLocalRootSignature(device, CreatePlaneHitRootDesc());

            subObjects.Add(planeHitRootSignature.subObject); // 8 Plane Hit Root Sig

            int planeHitRootIndex = subObjects.Count - 1;    // 8
            ExportAssociation planeHitRootAssociation = new ExportAssociation(new string[] { HitGroupPlane }, subObjects[planeHitRootIndex]);

            subObjects.Add(planeHitRootAssociation.SubObject); // 9 Associate Plane Hit Root Sig to Plane Hit Group

            // Create the empty root-signature and associate it with the primary miss-shader and the shadow programs
            MyLocalRootSignature emptyRootSignature = new MyLocalRootSignature(device, new RootSignatureDescription(RootSignatureFlags.LocalRootSignature));

            subObjects.Add(emptyRootSignature.subObject); // 10 Empty Root Sig for Plane Hit Group and Miss

            int emptyRootIndex = subObjects.Count - 1;    // 10
            ExportAssociation emptyRootAssociation = new ExportAssociation(new string[] { MissShader, ShadowChsShader, ShadowMissShader },
                                                                           subObjects[emptyRootIndex]);

            subObjects.Add(emptyRootAssociation.SubObject); // 11 Associate empty root sig to Plane Hit Group and Miss shader

            // Bind the payload size to all programs
            ShaderConfig primaryShaderConfig = new ShaderConfig(Unsafe.SizeOf <float>() * 2, Unsafe.SizeOf <float>() * 3);

            subObjects.Add(primaryShaderConfig.subObject); // 12

            int primaryShaderConfigIndex = subObjects.Count - 1;
            ExportAssociation primaryConfigAssociation = new ExportAssociation(
                new string[] { RayGenShader, MissShader, TriangleClosestHitShader, PlaneClosestHitShader, ShadowMissShader, ShadowChsShader },
                subObjects[primaryShaderConfigIndex]);

            subObjects.Add(primaryConfigAssociation.SubObject); // 13 Associate shader config to all programs

            // Create the pipeline config
            PipelineConfig pconfig = new PipelineConfig(2); // maxRecursionDepth - 1 TraceRay() from the ray-gen, 1 TraceRay() from the primary hit-shader

            subObjects.Add(pconfig.SubObject);              // 14

            // Create the global root signature and store the empty signature
            MyGlobalRootSignature root = new MyGlobalRootSignature(device, new RootSignatureDescription());

            emptyRootSig = root.rootSig.RootSignature;
            subObjects.Add(root.subObject); // 15

            // Create the state
            StateObjectDescription desc = new StateObjectDescription(StateObjectType.RaytracingPipeline, subObjects.ToArray());

            pipelineState = device.CreateStateObject(desc);
        }
コード例 #10
0
 /// <summary>
 /// Creates a <see cref="ID3D12StateObject"/>.
 /// </summary>
 /// <param name="description">The description of the state object to create.</param>
 /// <returns>An instance of <see cref="ID3D12StateObject"/>.</returns>
 public T CreateStateObject <T>(StateObjectDescription description) where T : ID3D12StateObject
 {
     CreateStateObject(description, typeof(T).GUID, out IntPtr nativePtr).CheckError();
     return(MarshallingHelpers.FromPointer <T>(nativePtr));
 }