Example #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]);
     }
 }
Example #2
0
        private void ActivateResourceSet(uint slot, D3D11ResourceSet d3d11RS, bool graphics)
        {
            int cbBase      = GetConstantBufferBase(slot, graphics);
            int uaBase      = GetUnorderedAccessBase(slot, graphics);
            int textureBase = GetTextureBase(slot, graphics);
            int samplerBase = GetSamplerBase(slot, graphics);

            D3D11ResourceLayout layout = d3d11RS.Layout;

            BindableResource[] resources = d3d11RS.Resources;
            for (int i = 0; i < resources.Length; i++)
            {
                BindableResource resource = resources[i];
                D3D11ResourceLayout.ResourceBindingInfo rbi = layout.GetDeviceSlotIndex(i);
                switch (rbi.Kind)
                {
                case ResourceKind.UniformBuffer:
                    D3D11Buffer uniformBuffer = Util.AssertSubtype <BindableResource, D3D11Buffer>(resource);
                    BindUniformBuffer(uniformBuffer, cbBase + rbi.Slot, rbi.Stages);
                    break;

                case ResourceKind.StructuredBufferReadOnly:
                    D3D11Buffer storageBufferRO = Util.AssertSubtype <BindableResource, D3D11Buffer>(resource);
                    BindStorageBufferView(storageBufferRO, textureBase + rbi.Slot, rbi.Stages);
                    break;

                case ResourceKind.StructuredBufferReadWrite:
                    D3D11Buffer storageBuffer = Util.AssertSubtype <BindableResource, D3D11Buffer>(resource);
                    BindUnorderedAccessView(null, storageBuffer.UnorderedAccessView, uaBase + rbi.Slot, rbi.Stages, slot);
                    break;

                case ResourceKind.TextureReadOnly:
                    D3D11TextureView texView = Util.AssertSubtype <BindableResource, D3D11TextureView>(resource);
                    UnbindUAVTexture(texView.Target);
                    BindTextureView(texView, textureBase + rbi.Slot, rbi.Stages, slot);
                    break;

                case ResourceKind.TextureReadWrite:
                    D3D11TextureView rwTexView = Util.AssertSubtype <BindableResource, D3D11TextureView>(resource);
                    UnbindSRVTexture(rwTexView.Target);
                    BindUnorderedAccessView(rwTexView.Target, rwTexView.UnorderedAccessView, uaBase + rbi.Slot, rbi.Stages, slot);
                    break;

                case ResourceKind.Sampler:
                    D3D11Sampler sampler = Util.AssertSubtype <BindableResource, D3D11Sampler>(resource);
                    BindSampler(sampler, samplerBase + rbi.Slot, rbi.Stages);
                    break;

                default: throw Illegal.Value <ResourceKind>();
                }
            }
        }
Example #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>();
            }
        }