Esempio n. 1
0
        public override void SetResourceSet(uint slot, ResourceSet rs)
        {
            if (_resourceSets[slot] == rs)
            {
                return;
            }

            D3D11ResourceSet d3d11RS = Util.AssertSubtype <ResourceSet, D3D11ResourceSet>(rs);

            _resourceSets[slot] = d3d11RS;
            int cbBase      = GetConstantBufferBase(slot);
            int textureBase = GetTextureBase(slot);
            int samplerBase = GetSamplerBase(slot);

            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);
                if (resource is D3D11UniformBuffer ub)
                {
                    BindUniformBuffer(ub, cbBase + rbi.Slot, rbi.Stages);
                }
                else if (resource is D3D11TextureView texView)
                {
                    BindTextureView(texView, textureBase + rbi.Slot, rbi.Stages);
                }
                else if (resource is D3D11Sampler sampler)
                {
                    BindSampler(sampler, samplerBase + rbi.Slot, rbi.Stages);
                }
            }
        }
Esempio n. 2
0
 public D3D11Pipeline(D3D11ResourceCache cache, ref ComputePipelineDescription 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]);
     }
 }
Esempio n. 3
0
        public D3D11Pipeline(D3D11ResourceCache cache, ref PipelineDescription description)
        {
            BlendState        = cache.GetBlendState(ref description.BlendState);
            DepthStencilState = cache.GetDepthStencilState(ref description.DepthStencilState);
            RasterizerState   = cache.GetRasterizerState(ref description.RasterizerState);
            PrimitiveTopology = D3D11Formats.VdToD3D11PrimitiveTopology(description.PrimitiveTopology);

            byte[] vsBytecode = null;
            ShaderStageDescription[] stages = description.ShaderSet.ShaderStages;
            for (int i = 0; i < description.ShaderSet.ShaderStages.Length; i++)
            {
                if (stages[i].Stage == ShaderStages.Vertex)
                {
                    D3D11Shader d3d11VertexShader = ((D3D11Shader)stages[i].Shader);
                    VertexShader = (VertexShader)d3d11VertexShader.DeviceShader;
                    vsBytecode   = d3d11VertexShader.Bytecode;
                }
                if (stages[i].Stage == ShaderStages.Geometry)
                {
                    GeometryShader = (GeometryShader)((D3D11Shader)stages[i].Shader).DeviceShader;
                }
                if (stages[i].Stage == ShaderStages.TessellationControl)
                {
                    HullShader = (HullShader)((D3D11Shader)stages[i].Shader).DeviceShader;
                }
                if (stages[i].Stage == ShaderStages.TessellationEvaluation)
                {
                    DomainShader = (DomainShader)((D3D11Shader)stages[i].Shader).DeviceShader;
                }
                if (stages[i].Stage == ShaderStages.Fragment)
                {
                    PixelShader = (PixelShader)((D3D11Shader)stages[i].Shader).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);
            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;
            }
        }
Esempio n. 4
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>();
                }
            }
        }
Esempio n. 5
0
        public D3D11Pipeline(D3D11ResourceCache cache, ref GraphicsPipelineDescription description)
            : base(ref description)
        {
            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;
                }
            }

            cache.GetPipelineResources(
                ref description.BlendState,
                ref description.DepthStencilState,
                ref description.RasterizerState,
                description.Outputs.SampleCount != TextureSampleCount.Count1,
                description.ShaderSet.VertexLayouts,
                vsBytecode,
                out BlendState blendState,
                out DepthStencilState depthStencilState,
                out RasterizerState rasterizerState,
                out InputLayout inputLayout);

            BlendState = blendState;
            DepthStencilState = depthStencilState;
            StencilReference = description.DepthStencilState.StencilReference;
            RasterizerState = rasterizerState;
            PrimitiveTopology = D3D11Formats.VdToD3D11PrimitiveTopology(description.PrimitiveTopology);

            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 = inputLayout;
                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>();
            }
        }