예제 #1
0
        /// <summary>
        /// Creates a new <see cref="PipelineState"/> instance with the specified parameters
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice"/> to use</param>
        /// <param name="rootSignature">The <see cref="ID3D12RootSignature"/> value for the current shader</param>
        /// <param name="computeShader">The bytecode for the compute shader to run</param>
        public PipelineState(GraphicsDevice device, ID3D12RootSignature rootSignature, ShaderBytecode computeShader)
        {
            RootSignature = rootSignature;
            ComputeShader = computeShader;

            NativePipelineState = device.NativeDevice.CreateComputePipelineState(this);
        }
예제 #2
0
        public async Task <PipelineState> CreateGraphicsPipelineStateAsync()
        {
            if (MaterialDescriptor is null)
            {
                throw new InvalidOperationException("The current material descriptor cannot be null when creating a pipeline state.");
            }

            InputElementDescription[] inputElements = new[]
            {
                new InputElementDescription("Position", 0, (Format)PixelFormat.R32G32B32_Float, 0),
                new InputElementDescription("Normal", 0, (Format)PixelFormat.R32G32B32_Float, 1),
                new InputElementDescription("Tangent", 0, (Format)PixelFormat.R32G32B32A32_Float, 2),
                new InputElementDescription("TexCoord", 0, (Format)PixelFormat.R32G32_Float, 3)
            };

            CompiledShader compiledShader = new CompiledShader();

            string shaderCachePath = Path.Combine("Log", "ShaderCache");

            string filePath = Path.Combine(shaderCachePath, $"Shader_{MaterialDescriptor.Id}");

            if (!await Content.ExistsAsync(filePath))
            {
                ShaderGenerator       shaderGenerator = new ShaderGenerator(MaterialDescriptor.Attributes);
                ShaderGeneratorResult result          = shaderGenerator.GenerateShader();

                CompiledShaderAsset shaderAsset = new CompiledShaderAsset();

                foreach (var entryPoint in result.EntryPoints)
                {
                    compiledShader.Shaders[entryPoint.Key]    = ShaderCompiler.Compile(GetShaderStage(entryPoint.Key), result.ShaderSource, entryPoint.Value);
                    shaderAsset.ShaderSources[entryPoint.Key] = Path.Combine(shaderCachePath, $"{entryPoint.Key}_{MaterialDescriptor.Id}.cso");

                    using Stream stream = await Content.FileProvider.OpenStreamAsync(shaderAsset.ShaderSources[entryPoint.Key], FileMode.Create, FileAccess.ReadWrite);

                    await stream.WriteAsync(compiledShader.Shaders[entryPoint.Key], 0, compiledShader.Shaders[entryPoint.Key].Length);
                }

                await Content.SaveAsync(filePath, shaderAsset);
            }
            else
            {
                compiledShader = await Content.LoadAsync <CompiledShader>(filePath);
            }

            ID3D12RootSignature rootSignature = CreateRootSignature();

            return(new PipelineState(GraphicsDevice, inputElements, rootSignature,
                                     compiledShader.Shaders["vertex"],
                                     compiledShader.Shaders["pixel"],
                                     compiledShader.Shaders.ContainsKey("geometry") ? compiledShader.Shaders["geometry"] : null,
                                     compiledShader.Shaders.ContainsKey("hull") ? compiledShader.Shaders["hull"] : null,
                                     compiledShader.Shaders.ContainsKey("domain") ? compiledShader.Shaders["domain"] : null));
        }
        public async Task <PipelineState> CreateGraphicsPipelineStateAsync()
        {
            if (MaterialDescriptor is null)
            {
                throw new InvalidOperationException("The current material descriptor cannot be null when creating a pipeline state.");
            }

            InputElementDescription[] inputElements = new[]
            {
                new InputElementDescription("Position", 0, (Format)PixelFormat.R32G32B32_Float, 0),
                new InputElementDescription("Normal", 0, (Format)PixelFormat.R32G32B32_Float, 1),
                new InputElementDescription("Tangent", 0, (Format)PixelFormat.R32G32B32A32_Float, 2),
                new InputElementDescription("TexCoord", 0, (Format)PixelFormat.R32G32_Float, 3)
            };

            CompiledShader compiledShader = new CompiledShader();

            string fileName = $"Shader_{MaterialDescriptor.Id}";

            if (!await Content.ExistsAsync(fileName))
            {
                ShaderGenerator       shaderGenerator = new ShaderGenerator(MaterialDescriptor.Attributes);
                ShaderGeneratorResult result          = shaderGenerator.GenerateShader();

                CompiledShaderAsset shaderAsset = new CompiledShaderAsset();

                foreach (var entryPoint in result.EntryPoints)
                {
                    compiledShader.Shaders[entryPoint.Key]    = ShaderCompiler.Compile(GetShaderStage(entryPoint.Key), result.ShaderSource, entryPoint.Value);
                    shaderAsset.ShaderSources[entryPoint.Key] = $"{entryPoint.Key}_{MaterialDescriptor.Id}.cso";
                    await FileIO.WriteBytesAsync(await Content.RootFolder !.CreateFileAsync(shaderAsset.ShaderSources[entryPoint.Key], CreationCollisionOption.ReplaceExisting), compiledShader.Shaders[entryPoint.Key]);
                }

                await Content.SaveAsync(fileName, shaderAsset);
            }
            else
            {
                compiledShader = await Content.LoadAsync <CompiledShader>(fileName);
            }

            ID3D12RootSignature rootSignature = CreateRootSignature();

            return(new PipelineState(GraphicsDevice, inputElements, rootSignature,
                                     compiledShader.Shaders["vertex"],
                                     compiledShader.Shaders["pixel"],
                                     compiledShader.Shaders.ContainsKey("geometry") ? compiledShader.Shaders["geometry"] : null,
                                     compiledShader.Shaders.ContainsKey("hull") ? compiledShader.Shaders["hull"] : null,
                                     compiledShader.Shaders.ContainsKey("domain") ? compiledShader.Shaders["domain"] : null));
        }
예제 #4
0
 public void Dispose()
 {
     rootSignature?.Release();
     rootSignature = null;
 }
예제 #5
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);
        }
예제 #6
0
        public ID3D12CommandSignature CreateCommandSignature(CommandSignatureDescription description, ID3D12RootSignature rootSignature)
        {
            Guard.NotNull(rootSignature, nameof(rootSignature));

            return(CreateCommandSignature(ref description, rootSignature, typeof(ID3D12CommandSignature).GUID));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GlobalRootSignature"/> struct.
 /// </summary>
 /// <param name="rootSignature"></param>
 public GlobalRootSignature(ID3D12RootSignature rootSignature)
 {
     RootSignature = rootSignature;
 }
예제 #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);
        }
 public PipelineStateSubObjectTypeRootSignature(ID3D12RootSignature rootSignature)
 {
     Type          = PipelineStateSubObjectType.RootSignature;
     RootSignature = rootSignature.NativePointer;
 }
예제 #10
0
 public PipelineState(GraphicsDevice device, InputElementDescription[] inputElements, ID3D12RootSignature rootSignature, byte[] vertexShader, byte[] pixelShader, byte[]?geometryShader = default, byte[]?hullShader = default, byte[]?domainShader = default)
     : this(device, CreateGraphicsPipelineStateDescription(device, inputElements, rootSignature, vertexShader, pixelShader, geometryShader, hullShader, domainShader))
 {
 }
        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);
        }
예제 #12
0
        private void CreateRootSignature()
        {
            //RootDescriptorTable table = new RootDescriptorTable()
            //{
            //Ranges = new DescriptorRange()
            //    {

            //   }
            //}

            //RootParameter rootParameter = new RootParameter(RootDescriptorTable)
            //{
            //    DescriptorTable = new RootDescriptorTable
            //}


            DescriptorRange Ranges = new DescriptorRange()
            {
                BaseShaderRegister = 0,
                NumDescriptors     = 1,
                OffsetInDescriptorsFromTableStart = 0,
                RangeType     = DescriptorRangeType.ShaderResourceView,
                RegisterSpace = 0,
            };

            RootParameter[] slotRootParameters = new RootParameter[]
            {
                //new RootParameter(new roo
                //new RootParameter(RootParameterType.ConstantBufferView, new RootDescriptor(0, 0), ShaderVisibility.All),
                //new RootParameter(RootParameterType.ConstantBufferView, new RootDescriptor(1, 0), ShaderVisibility.All),
                //new RootParameter(RootParameterType.ShaderResourceView, new RootDescriptor(1, 0), ShaderVisibility.All),
                //new RootParameter(new RootDescriptorTable(new DescriptorRange[]{ Ranges }), ShaderVisibility.All)
            };



            RootSignatureDescription SignatureDesc = new RootSignatureDescription()
            {
                Flags = RootSignatureFlags.AllowInputAssemblerInputLayout,
                //Parameters = slotRootParameters,
                //StaticSamplers = new StaticSamplerDescription[]
                //{
                //    new StaticSamplerDescription()
                //    {

                //        ShaderRegister = 0,
                //        RegisterSpace = 0,
                //        ShaderVisibility = ShaderVisibility.Pixel,

                //        Filter = Filter.MinMagMipPoint,
                //        AddressU = TextureAddressMode.Border,
                //        AddressV = TextureAddressMode.Border,
                //        AddressW = TextureAddressMode.Border,
                //        MipLODBias = 0,
                //        MaxAnisotropy = 0,
                //        ComparisonFunction = ComparisonFunction.Never,
                //        BorderColor = StaticBorderColor.TransparentBlack,
                //        MinLOD = 0.0f,
                //        MaxLOD =  int.MaxValue,
                //    }
                //},
            };


            RootSignature = GraphicsDevice.NativeDevice.CreateRootSignature <ID3D12RootSignature>(0, SignatureDesc, RootSignatureVersion.Version10);
            //RootSignature.
        }
예제 #13
0
        private static GraphicsPipelineStateDescription CreateGraphicsPipelineStateDescription(GraphicsDevice device, InputElementDescription[] inputElements, ID3D12RootSignature rootSignature, ShaderBytecode vertexShader, ShaderBytecode pixelShader, ShaderBytecode geometryShader, ShaderBytecode hullShader, ShaderBytecode domainShader)
        {
            RasterizerDescription rasterizerDescription = RasterizerDescription.CullNone;

            rasterizerDescription.FrontCounterClockwise = true;

            BlendDescription blendDescription = BlendDescription.AlphaBlend;

            GraphicsPipelineStateDescription pipelineStateDescription = new GraphicsPipelineStateDescription
            {
                InputLayout           = new InputLayoutDescription(inputElements),
                RootSignature         = rootSignature,
                VertexShader          = vertexShader,
                PixelShader           = pixelShader,
                GeometryShader        = geometryShader,
                HullShader            = hullShader,
                DomainShader          = domainShader,
                RasterizerState       = rasterizerDescription,
                BlendState            = blendDescription,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                StreamOutput          = new StreamOutputDescription()
            };

            Texture?depthStencilBuffer = device.CommandList.DepthStencilBuffer;

            if (depthStencilBuffer != null)
            {
                pipelineStateDescription.DepthStencilFormat = (Format)depthStencilBuffer.Description.Format;
            }

            Format[] renderTargetFormats = new Format[device.CommandList.RenderTargets.Length];

            for (int i = 0; i < renderTargetFormats.Length; i++)
            {
                renderTargetFormats[i] = (Format)((Texture)device.CommandList.RenderTargets[i]).Description.Format;
            }

            pipelineStateDescription.RenderTargetFormats = renderTargetFormats;

            return(pipelineStateDescription);
        }
예제 #14
0
 private static ComputePipelineStateDescription CreateComputePipelineStateDescription(ID3D12RootSignature rootSignature, ShaderBytecode computeShader)
 {
     return(new ComputePipelineStateDescription
     {
         RootSignature = rootSignature,
         ComputeShader = computeShader
     });
 }
예제 #15
0
        internal void Sign1(GraphicsDevice graphicsDevice, int registerSpace = 0)
        {
            //static samplers
            StaticSamplerDescription[] samplerDescription = null;
            if (flags != RootSignatureFlags.LocalRootSignature)
            {
                samplerDescription    = new StaticSamplerDescription[4];
                samplerDescription[0] = new StaticSamplerDescription()
                {
                    AddressU           = TextureAddressMode.Clamp,
                    AddressV           = TextureAddressMode.Clamp,
                    AddressW           = TextureAddressMode.Clamp,
                    BorderColor        = StaticBorderColor.OpaqueBlack,
                    ComparisonFunction = ComparisonFunction.Never,
                    Filter             = Filter.MinMagMipLinear,
                    MipLODBias         = 0,
                    MaxAnisotropy      = 0,
                    MinLOD             = 0,
                    MaxLOD             = float.MaxValue,
                    ShaderVisibility   = ShaderVisibility.All,
                    RegisterSpace      = 0,
                    ShaderRegister     = 0,
                };
                samplerDescription[1]          = samplerDescription[0];
                samplerDescription[1].AddressU = TextureAddressMode.Wrap;
                samplerDescription[1].AddressV = TextureAddressMode.Wrap;
                samplerDescription[1].AddressW = TextureAddressMode.Wrap;
                samplerDescription[2]          = samplerDescription[0];
                samplerDescription[3]          = samplerDescription[0];

                samplerDescription[1].ShaderRegister     = 1;
                samplerDescription[2].ShaderRegister     = 2;
                samplerDescription[3].ShaderRegister     = 3;
                samplerDescription[1].MaxAnisotropy      = 16;
                samplerDescription[1].Filter             = Filter.Anisotropic;
                samplerDescription[2].ComparisonFunction = ComparisonFunction.Less;
                samplerDescription[2].Filter             = Filter.ComparisonMinMagMipLinear;
                samplerDescription[3].Filter             = Filter.MinMagMipPoint;
            }

            RootParameter1[] rootParameters = new RootParameter1[descs.Length];

            int cbvCount = 0;
            int srvCount = 0;
            int uavCount = 0;

            cbv.Clear();
            srv.Clear();
            uav.Clear();

            for (int i = 0; i < descs.Length; i++)
            {
                ResourceAccessType t = descs[i];
                switch (t)
                {
                case ResourceAccessType.CBV:
                    rootParameters[i] = new RootParameter1(RootParameterType.ConstantBufferView, new RootDescriptor1(cbvCount, registerSpace), ShaderVisibility.All);
                    cbv[cbvCount]     = i;
                    cbvCount++;
                    break;

                case ResourceAccessType.SRV:
                    rootParameters[i] = new RootParameter1(RootParameterType.ShaderResourceView, new RootDescriptor1(srvCount, registerSpace), ShaderVisibility.All);
                    srv[srvCount]     = i;
                    srvCount++;
                    break;

                case ResourceAccessType.UAV:
                    rootParameters[i] = new RootParameter1(RootParameterType.UnorderedAccessView, new RootDescriptor1(uavCount, registerSpace), ShaderVisibility.All);
                    uav[uavCount]     = i;
                    uavCount++;
                    break;

                case ResourceAccessType.CBVTable:
                    rootParameters[i] = new RootParameter1(new RootDescriptorTable1(new DescriptorRange1(DescriptorRangeType.ConstantBufferView, 1, cbvCount, registerSpace)), ShaderVisibility.All);
                    cbv[cbvCount]     = i;
                    cbvCount++;
                    break;

                case ResourceAccessType.SRVTable:
                    rootParameters[i] = new RootParameter1(new RootDescriptorTable1(new DescriptorRange1(DescriptorRangeType.ShaderResourceView, 1, srvCount, registerSpace)), ShaderVisibility.All);
                    srv[srvCount]     = i;
                    srvCount++;
                    break;

                case ResourceAccessType.UAVTable:
                    rootParameters[i] = new RootParameter1(new RootDescriptorTable1(new DescriptorRange1(DescriptorRangeType.UnorderedAccessView, 1, uavCount, registerSpace)), ShaderVisibility.All);
                    uav[uavCount]     = i;
                    uavCount++;
                    break;
                }
            }

            RootSignatureDescription1 rootSignatureDescription = new RootSignatureDescription1();

            rootSignatureDescription.StaticSamplers = samplerDescription;
            rootSignatureDescription.Flags          = flags;
            rootSignatureDescription.Parameters     = rootParameters;

            rootSignature?.Release();
            rootSignature = graphicsDevice.device.CreateRootSignature <ID3D12RootSignature>(0, rootSignatureDescription);
        }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LocalRootSignature"/> struct.
 /// </summary>
 /// <param name="rootSignature"></param>
 public LocalRootSignature(ID3D12RootSignature rootSignature)
 {
     RootSignature = rootSignature;
 }
예제 #17
0
 public PipelineState(GraphicsDevice device, ID3D12RootSignature rootSignature, byte[] computeShader)
     : this(device, CreateComputePipelineStateDescription(rootSignature, computeShader))
 {
 }