Esempio n. 1
0
 public D3D11Pipeline(D3D11ResourceCache cache, ref ComputePipelineDescription description)
     : base(ref description)
 {
     IsComputePipeline = true;
     ComputeShader     = (ComputeShader)((D3D11Shader)description.ComputeShader).DeviceShader;
     ResourceLayout[] genericLayouts = description.ResourceLayouts;
     ResourceLayouts = new D3D11ResourceLayout[genericLayouts.Length];
     for (int i = 0; i < ResourceLayouts.Length; i++)
     {
         ResourceLayouts[i] = Util.AssertSubtype <ResourceLayout, D3D11ResourceLayout>(genericLayouts[i]);
     }
 }
 public D3D11ResourceFactory(D3D11GraphicsDevice gd)
 {
     _gd     = gd;
     _device = gd.Device;
     _cache  = new D3D11ResourceCache(_device);
 }
Esempio n. 3
0
        public D3D11Pipeline(D3D11ResourceCache cache, ref GraphicsPipelineDescription description)
            : base(ref description)
        {
            BlendState        = cache.GetBlendState(ref description.BlendState);
            DepthStencilState = cache.GetDepthStencilState(ref description.DepthStencilState);
            StencilReference  = description.DepthStencilState.StencilReference;
            RasterizerState   = cache.GetRasterizerState(
                ref description.RasterizerState,
                description.Outputs.SampleCount != TextureSampleCount.Count1);
            PrimitiveTopology = D3D11Formats.ToD3D11PrimitiveTopology(description.PrimitiveTopology);

            byte[]   vsBytecode = null;
            Shader[] stages     = description.ShaderSet.Shaders;
            for (int i = 0; i < description.ShaderSet.Shaders.Length; i++)
            {
                if (stages[i].Stage == ShaderStages.Vertex)
                {
                    D3D11Shader d3d11VertexShader = ((D3D11Shader)stages[i]);
                    VertexShader = (VertexShader)d3d11VertexShader.DeviceShader;
                    vsBytecode   = d3d11VertexShader.Bytecode;
                }
                if (stages[i].Stage == ShaderStages.Geometry)
                {
                    GeometryShader = (GeometryShader)((D3D11Shader)stages[i]).DeviceShader;
                }
                if (stages[i].Stage == ShaderStages.TessellationControl)
                {
                    HullShader = (HullShader)((D3D11Shader)stages[i]).DeviceShader;
                }
                if (stages[i].Stage == ShaderStages.TessellationEvaluation)
                {
                    DomainShader = (DomainShader)((D3D11Shader)stages[i]).DeviceShader;
                }
                if (stages[i].Stage == ShaderStages.Fragment)
                {
                    PixelShader = (PixelShader)((D3D11Shader)stages[i]).DeviceShader;
                }
                if (stages[i].Stage == ShaderStages.Compute)
                {
                    ComputeShader = (ComputeShader)((D3D11Shader)stages[i]).DeviceShader;
                }
            }

            ResourceLayout[] genericLayouts = description.ResourceLayouts;
            ResourceLayouts = new D3D11ResourceLayout[genericLayouts.Length];
            for (int i = 0; i < ResourceLayouts.Length; i++)
            {
                ResourceLayouts[i] = Util.AssertSubtype <ResourceLayout, D3D11ResourceLayout>(genericLayouts[i]);
            }

            Debug.Assert(vsBytecode != null || ComputeShader != null);
            if (vsBytecode != null && description.ShaderSet.VertexLayouts.Length > 0)
            {
                InputLayout = cache.GetInputLayout(description.ShaderSet.VertexLayouts, vsBytecode);
                int numVertexBuffers = description.ShaderSet.VertexLayouts.Length;
                VertexStrides = new int[numVertexBuffers];
                for (int i = 0; i < numVertexBuffers; i++)
                {
                    VertexStrides[i] = (int)description.ShaderSet.VertexLayouts[i].Stride;
                }
            }
            else
            {
                VertexStrides = Array.Empty <int>();
            }
        }