private void BuildShadersAndInputLayout()
        {
            ShaderMacro[] defines =
            {
                new ShaderMacro("FOG", "1")
            };

            ShaderMacro[] alphaTestDefines =
            {
                new ShaderMacro("FOG",        "1"),
                new ShaderMacro("ALPHA_TEST", "1")
            };

            ShaderMacro[] waveDefines =
            {
                new ShaderMacro("DISPLACEMENT_MAP", "1")
            };

            _shaders["standardVS"]     = D3DUtil.CompileShader("Shaders\\Default.hlsl", "VS", "vs_5_0");
            _shaders["wavesVS"]        = D3DUtil.CompileShader("Shaders\\Default.hlsl", "VS", "vs_5_0", waveDefines);
            _shaders["opaquePS"]       = D3DUtil.CompileShader("Shaders\\Default.hlsl", "PS", "ps_5_0", defines);
            _shaders["alphaTestedPS"]  = D3DUtil.CompileShader("Shaders\\Default.hlsl", "PS", "ps_5_0", alphaTestDefines);
            _shaders["wavesUpdateCS"]  = D3DUtil.CompileShader("Shaders\\WaveSim.hlsl", "UpdateWavesCS", "cs_5_0");
            _shaders["wavesDisturbCS"] = D3DUtil.CompileShader("Shaders\\WaveSim.hlsl", "DisturbWavesCS", "cs_5_0");
            _shaders["compositeVS"]    = D3DUtil.CompileShader("Shaders\\composite.hlsl", "VS", "vs_5_0");
            _shaders["compositePS"]    = D3DUtil.CompileShader("Shaders\\composite.hlsl", "PS", "ps_5_0");
            _shaders["sobelCS"]        = D3DUtil.CompileShader("Shaders\\Sobel.hlsl", "SobelCS", "cs_5_0");

            _inputLayout = new InputLayoutDescription(new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 24, 0)
            });
        }
Пример #2
0
        private void BuildShadersAndInputLayout()
        {
            ShaderMacro[] defines =
            {
                new ShaderMacro("FOG", "1")
            };

            ShaderMacro[] alphaTestDefines =
            {
                new ShaderMacro("FOG",        "1"),
                new ShaderMacro("ALPHA_TEST", "1")
            };

            _shaders["standardVS"]    = D3DUtil.CompileShader("Shaders\\Default.hlsl", "VS", "vs_5_0");
            _shaders["opaquePS"]      = D3DUtil.CompileShader("Shaders\\Default.hlsl", "PS", "ps_5_0", defines);
            _shaders["alphaTestedPS"] = D3DUtil.CompileShader("Shaders\\Default.hlsl", "PS", "ps_5_0", alphaTestDefines);
            _shaders["horzBlurCS"]    = D3DUtil.CompileShader("Shaders\\Blur.hlsl", "HorzBlurCS", "cs_5_0");
            _shaders["vertBlurCS"]    = D3DUtil.CompileShader("Shaders\\Blur.hlsl", "VertBlurCS", "cs_5_0");

            _inputLayout = new InputLayoutDescription(new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 24, 0)
            });
        }
        private void BuildShadersAndInputLayout()
        {
            ShaderMacro[] alphaTestDefines =
            {
                new ShaderMacro("ALPHA_TEST", "1")
            };

            _shaders["standardVS"] = D3DUtil.CompileShader("Shaders\\Default.hlsl", "VS", "vs_5_1");
            _shaders["opaquePS"]   = D3DUtil.CompileShader("Shaders\\Default.hlsl", "PS", "ps_5_1");

            _shaders["shadowVS"]            = D3DUtil.CompileShader("Shaders\\Shadows.hlsl", "VS", "vs_5_1");
            _shaders["shadowOpaquePS"]      = D3DUtil.CompileShader("Shaders\\Shadows.hlsl", "PS", "ps_5_1");
            _shaders["shadowAlphaTestedPS"] = D3DUtil.CompileShader("Shaders\\Shadows.hlsl", "PS", "ps_5_1", alphaTestDefines);

            _shaders["debugVS"] = D3DUtil.CompileShader("Shaders\\ShadowDebug.hlsl", "VS", "vs_5_1");
            _shaders["debugPS"] = D3DUtil.CompileShader("Shaders\\ShadowDebug.hlsl", "PS", "ps_5_1");

            _shaders["skyVS"] = D3DUtil.CompileShader("Shaders\\Sky.hlsl", "VS", "vs_5_1");
            _shaders["skyPS"] = D3DUtil.CompileShader("Shaders\\Sky.hlsl", "PS", "ps_5_1");

            _inputLayout = new InputLayoutDescription(new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 24, 0),
                new InputElement("TANGENT", 0, Format.R32G32B32_Float, 32, 0)
            });
        }
Пример #4
0
 /// <summary>
 /// Registers the input layout.
 /// </summary>
 /// <param name="description">The description.</param>
 /// <returns></returns>
 public InputLayoutProxy RegisterInputLayout(InputLayoutDescription description)
 {
     if (description == null)
     {
         return(null);
     }
     return(layoutPool.TryCreateOrGet(description.ShaderByteCode, description, out var inputLayout) ? inputLayout : null);
 }
        private void BuildShadersAndInputLayout()
        {
            _shaders["standardVS"] = D3DUtil.CompileShader("Shaders\\Default.hlsl", "VS", "vs_5_0");
            _shaders["opaquePS"]   = D3DUtil.CompileShader("Shaders\\Default.hlsl", "PS", "ps_5_0");

            _inputLayout = new InputLayoutDescription(new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0)
            });
        }
Пример #6
0
        private void BuildShadersAndInputLayout()
        {
            _mvsByteCode = D3DUtil.CompileShader("Shaders\\Color.hlsl", "VS", "vs_5_0");
            _mpsByteCode = D3DUtil.CompileShader("Shaders\\Color.hlsl", "PS", "ps_5_0");

            _inputLayout = new InputLayoutDescription(new [] // TODO: API suggestion: Add params overload
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 12, 0)
            });
        }
        private void BuildShadersAndInputLayout()
        {
            _shaders["tessVS"] = D3DUtil.CompileShader("Shaders\\BezierTessellation.hlsl", "VS", "vs_5_0");
            _shaders["tessHS"] = D3DUtil.CompileShader("Shaders\\BezierTessellation.hlsl", "HS", "hs_5_0");
            _shaders["tessDS"] = D3DUtil.CompileShader("Shaders\\BezierTessellation.hlsl", "DS", "ds_5_0");
            _shaders["tessPS"] = D3DUtil.CompileShader("Shaders\\BezierTessellation.hlsl", "PS", "ps_5_0");

            _inputLayout = new InputLayoutDescription(new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0)
            });
        }
Пример #8
0
        private static GraphicsPipelineStateDescription CreateGraphicsPipelineStateDescription(GraphicsDevice device, RootSignature rootSignature, InputElementDescription[] inputElements, byte[] vertexShader, byte[] pixelShader, byte[]?geometryShader, byte[]?hullShader, byte[]?domainShader)
        {
            RasterizerDescription rasterizerDescription = RasterizerDescription.CullNone;

            rasterizerDescription.FrontCounterClockwise = true;

            BlendDescription       blendDescription       = BlendDescription.AlphaBlend;
            InputLayoutDescription inputLayoutDescription = new InputLayoutDescription(inputElements.Select(i => Unsafe.As <InputElementDescription, Vortice.Direct3D12.InputElementDescription>(ref i)).ToArray());

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

            DepthStencilView?depthStencilBuffer = device.CommandList.DepthStencilBuffer;

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

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

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

            pipelineStateDescription.RenderTargetFormats = renderTargetFormats;

            return(pipelineStateDescription);
        }
        void CreateInputLayout()
        {
            // @TODO - need to modify input element description from H1VertexStream

            // platform-specific implementation
            List <InputElement> inputElements = new List <InputElement>();

            foreach (var stream in m_InputElements)
            {
                InputElement element = new InputElement();
                element.SemanticName  = stream.SemanticName;
                element.SemanticIndex = stream.SemanticIndex;
                element.Format        = H1RHIDefinitionHelper.ConvertToFormat(stream.Format);

                // watch out - I use multiple vertex buffer instead of big vertex buffer indicating by alignbyteoffset
                element.Slot = stream.InputSlot;
                inputElements.Add(element);
            }

            // create input layout based on the resultant list of input elements
            m_InputLayoutDesc = new InputLayoutDescription(inputElements.ToArray());
        }
Пример #10
0
        /// <summary>
        /// Setup resources for rendering
        /// </summary>
        void LoadAssets()
        {
            // Create the main command list
            commandList = Collect(device.CreateCommandList(CommandListType.Direct, commandListAllocator, pipelineState));

            // Create the descriptor heap for the render target view
            descriptorHeapRT = Collect(device.CreateDescriptorHeap(new DescriptorHeapDescription()
            {
                Type            = DescriptorHeapType.RenderTargetView,
                DescriptorCount = 1
            }));
#if USE_DEPTH
            descriptorHeapDS = Collect(device.CreateDescriptorHeap(new DescriptorHeapDescription()
            {
                Type            = DescriptorHeapType.DepthStencilView,
                DescriptorCount = 1
            }));
#endif
#if USE_TEXTURE
            descriptorHeapCB = Collect(device.CreateDescriptorHeap(new DescriptorHeapDescription()
            {
                Type            = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView,
                DescriptorCount = 2,
                Flags           = DescriptorHeapFlags.ShaderVisible,
            }));
            descriptorHeapS = Collect(device.CreateDescriptorHeap(new DescriptorHeapDescription()
            {
                Type            = DescriptorHeapType.Sampler,
                DescriptorCount = 1,
                Flags           = DescriptorHeapFlags.ShaderVisible,
            }));
            descriptorsHeaps[0] = descriptorHeapCB;
            descriptorsHeaps[1] = descriptorHeapS;
#else
            descriptorHeapCB = Collect(device.CreateDescriptorHeap(new DescriptorHeapDescription()
            {
                Type            = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView,
                DescriptorCount = 1,
                Flags           = DescriptorHeapFlags.ShaderVisible,
            }));
            descriptorsHeaps[0] = descriptorHeapCB;
#endif
#if true // root signature in code
            var rsparams = new RootParameter[]
            {
                new RootParameter(ShaderVisibility.Vertex, new RootDescriptor(), RootParameterType.ConstantBufferView),
                new RootParameter(ShaderVisibility.Vertex,
                                  new DescriptorRange
                {
                    RangeType          = DescriptorRangeType.ConstantBufferView,
                    BaseShaderRegister = 1,
                    DescriptorCount    = 1,
                }),
#if USE_TEXTURE
                new RootParameter(ShaderVisibility.Pixel,
                                  new DescriptorRange
                {
                    RangeType          = DescriptorRangeType.ShaderResourceView,
                    BaseShaderRegister = 0,
                    DescriptorCount    = 1,
                }),
                new RootParameter(ShaderVisibility.Pixel,
                                  new DescriptorRange
                {
                    RangeType          = DescriptorRangeType.Sampler,
                    BaseShaderRegister = 0,
                    DescriptorCount    = 1,
                }),
#endif
            };
            var rs = new RootSignatureDescription(RootSignatureFlags.AllowInputAssemblerInputLayout, rsparams);
            rootSignature = Collect(device.CreateRootSignature(rs.Serialize()));
#else
            var rootSignatureByteCode = Utilities.ReadStream(assembly.GetManifestResourceStream("Shaders.Cube" + shaderNameSuffix + ".rs"));
            using (var bufferRootSignature = DataBuffer.Create(rootSignatureByteCode))
                rootSignature = Collect(device.CreateRootSignature(bufferRootSignature));
#endif
            byte[] vertexShaderByteCode = GetResourceBytes("Cube" + shaderNameSuffix + ".vso");
            byte[] pixelShaderByteCode  = GetResourceBytes("Cube" + shaderNameSuffix + ".pso");

            var layout = new InputLayoutDescription(new InputElement[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0),
                new InputElement("NORMAL", 0, Format.R32G32B32_Float, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 0),
#if USE_INSTANCES
                new InputElement("OFFSET", 0, Format.R32G32B32_Float, 0, 1, InputClassification.PerInstanceData, 1),
#endif
            });

            #region pipeline state
            var psd = new GraphicsPipelineStateDescription
            {
                InputLayout           = layout,
                VertexShader          = vertexShaderByteCode,
                PixelShader           = pixelShaderByteCode,
                RootSignature         = rootSignature,
                DepthStencilState     = DepthStencilStateDescription.Default(),
                DepthStencilFormat    = Format.Unknown,
                BlendState            = BlendStateDescription.Default(),
                RasterizerState       = RasterizerStateDescription.Default(),
                SampleDescription     = new SampleDescription(1, 0),
                RenderTargetCount     = 1,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                SampleMask            = -1,
                StreamOutput          = new StreamOutputDescription()
            };
            psd.RenderTargetFormats[0] = Format.R8G8B8A8_UNorm;
#if USE_DEPTH
            psd.DepthStencilFormat = Format.D32_Float;
#else
            psd.DepthStencilState.IsDepthEnabled = false;
#endif
            //psd.RasterizerState.CullMode = CullMode.None;
            pipelineState = Collect(device.CreateGraphicsPipelineState(psd));
            #endregion pipeline state

            #region vertices
            var vertices = new[]
            {
                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                       // Front
                -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,

                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                        // BACK
                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                        // BACK
                1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,

                -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                        // Top
                -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                        // Top
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,

                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                       // Bottom
                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                       // Bottom
                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,

                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                       // Left
                -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                       // Left
                -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
                -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,

                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                        // Right
                1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f,                        // Right
                1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
                1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
            };
            #endregion vertices
            #region vertex buffer
            // Instantiate Vertex buiffer from vertex data
            int sizeOfFloat = sizeof(float);
            int sizeInBytes = vertices.Length * sizeOfFloat;
            vertexBuffer = Collect(device.CreateCommittedResource(
                                       new HeapProperties(HeapType.Upload),
                                       HeapFlags.None,
                                       new ResourceDescription(ResourceDimension.Buffer, 0, sizeInBytes, 1, 1, 1, Format.Unknown, 1, 0, TextureLayout.RowMajor, ResourceFlags.None),
                                       ResourceStates.GenericRead));
            vertexBufferView = new[]
            {
                new VertexBufferView
                {
                    BufferLocation = vertexBuffer.GPUVirtualAddress,
                    SizeInBytes    = sizeInBytes,
                    StrideInBytes  = sizeOfFloat * 8,
                }
            };
            var ptr = vertexBuffer.Map(0);
            Utilities.Write(ptr, vertices, 0, vertices.Length);
            vertexBuffer.Unmap(0);
            #endregion vertex buffer
            #region instances
#if USE_INSTANCES
            int instanceSizeInBytes = sizeOfFloat * instances.Length;
            instancesBuffer = Collect(device.CreateCommittedResource(
                                          new HeapProperties(HeapType.Upload),
                                          HeapFlags.None,
                                          new ResourceDescription(ResourceDimension.Buffer, 0, instanceSizeInBytes, 1, 1, 1, Format.Unknown, 1, 0, TextureLayout.RowMajor, ResourceFlags.None),
                                          ResourceStates.GenericRead));
            instancesBufferView = new[]
            {
                new VertexBufferView
                {
                    BufferLocation = instancesBuffer.GPUVirtualAddress,
                    SizeInBytes    = instanceSizeInBytes,
                    StrideInBytes  = sizeOfFloat * 3,
                }
            };
            ptr = instancesBuffer.Map(0);
            Utilities.Write(ptr, instances, 0, instances.Length);
            instancesBuffer.Unmap(0);
#endif
            #endregion instances

            #region indices
#if USE_INDICES
            var indexData = new[]
            {
                0, 1, 2, 3, 4,
                5, 6, 7, 8, 9, 10,
                11, 12, 13, 14, 15, 16,
                17, 18, 19, 20, 21, 22,
                23, 24, 25, 26, 27, 28,
                29, 30, 31, 32, 33
            };
            sizeInBytes = indexData.Length * sizeof(int);
            indexBuffer = Collect(device.CreateCommittedResource(
                                      new HeapProperties(HeapType.Upload),
                                      HeapFlags.None,
                                      new ResourceDescription(ResourceDimension.Buffer, 0, sizeInBytes, 1, 1, 1, Format.Unknown, 1, 0, TextureLayout.RowMajor, ResourceFlags.None),
                                      ResourceStates.GenericRead));
            ptr = indexBuffer.Map(0);
            Utilities.Write(ptr, indexData, 0, indexData.Length);
            indexBuffer.Unmap(0);
            indexBufferView = new IndexBufferView
            {
                BufferLocation = indexBuffer.GPUVirtualAddress,
                SizeInBytes    = sizeInBytes,
                Format         = Format.R32_UInt
            };
#endif
            #endregion indices

            #region transform
            transWorld = Collect(device.CreateCommittedResource(
                                     new HeapProperties(HeapType.Upload),
                                     HeapFlags.None,
                                     new ResourceDescription(ResourceDimension.Buffer, 0, 16 * sizeOfMatrix, 1, 1, 1, Format.Unknown, 1, 0, TextureLayout.RowMajor, ResourceFlags.None),
                                     ResourceStates.GenericRead));
            transWorldPtr = transWorld.Map(0);
            transViewProj = Collect(device.CreateCommittedResource(
                                        new HeapProperties(HeapType.Upload),
                                        HeapFlags.None,
                                        new ResourceDescription(ResourceDimension.Buffer, 0, sizeOfMatrix, 1, 1, 1, Format.Unknown, 1, 0, TextureLayout.RowMajor, ResourceFlags.None),
                                        ResourceStates.GenericRead));
            device.CreateConstantBufferView(new ConstantBufferViewDescription
            {
                BufferLocation = transViewProj.GPUVirtualAddress,
                SizeInBytes    = sizeOfMatrix,
            }, descriptorHeapCB.CPUDescriptorHandleForHeapStart);

            var view = Matrix.LookAtLH(new Vector3(5, 5, -5), Vector3.Zero, Vector3.UnitY);
            var proj = Matrix.PerspectiveFovLH(MathUtil.Pi / 4, (float)width / height, 0.1f, 100);
            var vpT  = view * proj;
            vpT.Transpose();
            ptr = transViewProj.Map(0);
            Utilities.Write(ptr, ref vpT);
            transViewProj.Unmap(0);
            #endregion transform

#if USE_TEXTURE
            #region texture
            Resource buf;
            using (var tl = new TextureLoader("GeneticaMortarlessBlocks.jpg"))
            {
                int w = tl.Width, h = tl.Height;
                var descrs = new[]
                {
                    new ResourceDescription(ResourceDimension.Texture2D,
                                            0, w, h, 1, 1,
                                            Format.B8G8R8A8_UNorm, 1, 0,
                                            TextureLayout.Unknown,
                                            ResourceFlags.None),
                };
                texture = Collect(device.CreateCommittedResource(
                                      new HeapProperties(HeapType.Default),
                                      HeapFlags.None,
                                      descrs[0],
                                      ResourceStates.CopyDestination)
                                  );
                var resAllocInfo = device.GetResourceAllocationInfo(1, 1, descrs);
                buf = device.CreateCommittedResource(
                    new HeapProperties(HeapType.Upload),
                    HeapFlags.None,
                    new ResourceDescription(
                        ResourceDimension.Buffer,
                        0,
                        resAllocInfo.SizeInBytes,
                        1, 1, 1,
                        Format.Unknown,
                        1, 0,
                        TextureLayout.RowMajor,
                        ResourceFlags.None),
                    ResourceStates.GenericRead);

                var ptrBuf   = buf.Map(0);
                int rowPitch = tl.CopyImageData(ptrBuf);
                buf.Unmap(0);

                var src = new TextureCopyLocation(buf,
                                                  new PlacedSubResourceFootprint
                {
                    Offset    = 0,
                    Footprint = new SubResourceFootprint
                    {
                        Format   = Format.B8G8R8A8_UNorm_SRgb,
                        Width    = w,
                        Height   = h,
                        Depth    = 1,
                        RowPitch = rowPitch
                    }
                }
                                                  );
                var dst = new TextureCopyLocation(texture, 0);
                // record copy
                commandList.CopyTextureRegion(dst, 0, 0, 0, src, null);

                commandList.ResourceBarrierTransition(texture, ResourceStates.CopyDestination, ResourceStates.GenericRead);
            }
            descrOffsetCB = device.GetDescriptorHandleIncrementSize(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);
            device.CreateShaderResourceView(texture, null, descriptorHeapCB.CPUDescriptorHandleForHeapStart + descrOffsetCB);
            #endregion texture

            #region sampler
            device.CreateSampler(new SamplerStateDescription
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter   = Filter.MaximumMinMagMipLinear,
            }, descriptorHeapS.CPUDescriptorHandleForHeapStart);
            #endregion sampler
#endif
            // Get the backbuffer and creates the render target view
            renderTarget = Collect(swapChain.GetBackBuffer <Resource>(0));
            device.CreateRenderTargetView(renderTarget, null, descriptorHeapRT.CPUDescriptorHandleForHeapStart);

#if USE_DEPTH
            depthBuffer = Collect(device.CreateCommittedResource(
                                      new HeapProperties(HeapType.Default),
                                      HeapFlags.None,
                                      new ResourceDescription(ResourceDimension.Texture2D, 0, width, height, 1, 1, Format.D32_Float, 1, 0, TextureLayout.Unknown, ResourceFlags.AllowDepthStencil),
                                      ResourceStates.Present,
                                      new ClearValue
            {
                Format       = Format.D32_Float,
                DepthStencil = new DepthStencilValue
                {
                    Depth   = 1,
                    Stencil = 0,
                }
            }));
            device.CreateDepthStencilView(depthBuffer, null, descriptorHeapDS.CPUDescriptorHandleForHeapStart);
#endif

            // Create the viewport
            viewPort = new ViewportF(0, 0, width, height);

            // Create the scissor
            scissorRectangle = new Rectangle(0, 0, width, height);

            // Create a fence to wait for next frame
            fence        = Collect(device.CreateFence(0, FenceFlags.None));
            currentFence = 1;

            // Close command list
            commandList.Close();
            commandQueue.ExecuteCommandList(commandList);

            // Create an event handle use for VTBL
            CreateWaitEvent();

            // Wait the command list to complete
            WaitForPrevFrame();
#if USE_TEXTURE
            buf.Dispose();
#endif
        }
Пример #11
0
 /// <summary>
 /// Registers the input layout.
 /// </summary>
 /// <param name="description">The description.</param>
 /// <returns></returns>
 public InputLayout RegisterInputLayout(InputLayoutDescription description)
 {
     return(description == null ? null : layoutPool.Register(description.Description));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TechniqueDescription"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="inputLayout">The input layout.</param>
 /// <param name="shaderPasses">The shader passes.</param>
 public TechniqueDescription(string name, InputLayoutDescription inputLayout, IList <ShaderPassDescription> shaderPasses)
     : this(name, inputLayout)
 {
     PassDescriptions = shaderPasses;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TechniqueDescription"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="inputLayout">The input layout.</param>
 public TechniqueDescription(string name, InputLayoutDescription inputLayout)
     : this(name)
 {
     InputLayoutDescription = inputLayout;
 }
Пример #14
0
        public ID3D12PipelineState GetState(GraphicsDevice device, PSODesc desc, RootSignature rootSignature)
        {
            foreach (var psoCombind in PSOCombinds)
            {
                if (psoCombind.PSODesc == desc && psoCombind.rootSignature == rootSignature)
                {
                    if (psoCombind.pipelineState == null)
                    {
                        throw new Exception("pipeline state error");
                    }
                    return(psoCombind.pipelineState);
                }
            }
            InputLayoutDescription inputLayoutDescription;

            if (device.inputLayouts.TryGetValue(desc.InputLayout, out inputLayoutDescription))
            {
            }
            else
            {
                inputLayoutDescription = new InputLayoutDescription(new InputElementDescription("POSITION", 0, Format.R32G32B32_Float, 0));
            }

            GraphicsPipelineStateDescription graphicsPipelineStateDescription = new GraphicsPipelineStateDescription();

            graphicsPipelineStateDescription.RootSignature         = rootSignature.rootSignature;
            graphicsPipelineStateDescription.VertexShader          = vertexShader;
            graphicsPipelineStateDescription.GeometryShader        = geometryShader;
            graphicsPipelineStateDescription.PixelShader           = pixelShader;
            graphicsPipelineStateDescription.PrimitiveTopologyType = PrimitiveTopologyType.Triangle;
            graphicsPipelineStateDescription.InputLayout           = inputLayoutDescription;
            graphicsPipelineStateDescription.DepthStencilFormat    = desc.DepthStencilFormat;
            graphicsPipelineStateDescription.RenderTargetFormats   = new Format[desc.RenderTargetCount];
            Array.Fill(graphicsPipelineStateDescription.RenderTargetFormats, desc.RenderTargetFormat);

            if (desc.BlendState == "Alpha")
            {
                graphicsPipelineStateDescription.BlendState = blendStateAlpha();
            }
            else if (desc.BlendState == "Add")
            {
                graphicsPipelineStateDescription.BlendState = BlendDescription.Additive;
            }
            else
            {
                graphicsPipelineStateDescription.BlendState = BlendDescription.Opaque;
            }


            graphicsPipelineStateDescription.DepthStencilState = new DepthStencilDescription(desc.DepthStencilFormat != Format.Unknown, desc.DepthStencilFormat != Format.Unknown);
            graphicsPipelineStateDescription.SampleMask        = uint.MaxValue;
            var RasterizerState = new RasterizerDescription(CullMode.None, FillMode.Solid);

            RasterizerState.DepthBias                        = desc.DepthBias;
            RasterizerState.SlopeScaledDepthBias             = desc.SlopeScaledDepthBias;
            graphicsPipelineStateDescription.RasterizerState = RasterizerState;

            var pipelineState = device.device.CreateGraphicsPipelineState <ID3D12PipelineState>(graphicsPipelineStateDescription);

            if (pipelineState == null)
            {
                throw new Exception("pipeline state error");
            }
            PSOCombinds.Add(new PSOCombind {
                PSODesc = desc, pipelineState = pipelineState, rootSignature = rootSignature
            });
            return(pipelineState);
        }