Пример #1
0
 private void BindTextureView(D3D11TextureView texView, int slot, ShaderStages stages)
 {
     if ((stages & ShaderStages.Vertex) == ShaderStages.Vertex)
     {
         bool bind = false;
         if (slot < MaxCachedUniformBuffers)
         {
             if (_vertexBoundTextureViews[slot] != texView)
             {
                 _vertexBoundTextureViews[slot] = texView;
                 bind = true;
             }
         }
         else
         {
             bind = true;
         }
         if (bind)
         {
             _context.VertexShader.SetShaderResource(slot, texView.ShaderResourceView);
         }
     }
     if ((stages & ShaderStages.Geometry) == ShaderStages.Geometry)
     {
         _context.GeometryShader.SetShaderResource(slot, texView.ShaderResourceView);
     }
     if ((stages & ShaderStages.TessellationControl) == ShaderStages.TessellationControl)
     {
         _context.HullShader.SetShaderResource(slot, texView.ShaderResourceView);
     }
     if ((stages & ShaderStages.TessellationEvaluation) == ShaderStages.TessellationEvaluation)
     {
         _context.DomainShader.SetShaderResource(slot, texView.ShaderResourceView);
     }
     if ((stages & ShaderStages.Fragment) == ShaderStages.Fragment)
     {
         bool bind = false;
         if (slot < MaxCachedUniformBuffers)
         {
             if (_fragmentBoundTextureViews[slot] != texView)
             {
                 _fragmentBoundTextureViews[slot] = texView;
                 bind = true;
             }
         }
         else
         {
             bind = true;
         }
         if (bind)
         {
             _context.PixelShader.SetShaderResource(slot, texView.ShaderResourceView);
         }
     }
 }
Пример #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>();
                }
            }
        }
Пример #3
0
        private void BindTextureView(D3D11TextureView texView, int slot, ShaderStages stages, uint resourceSet)
        {
            ShaderResourceView srv = texView?.ShaderResourceView ?? null;

            if (srv != null)
            {
                if (!_boundSRVs.TryGetValue(texView.Target, out List <BoundTextureInfo> list))
                {
                    list = GetNewOrCachedBoundTextureInfoList();
                    _boundSRVs.Add(texView.Target, list);
                }
                list.Add(new BoundTextureInfo {
                    Slot = slot, Stages = stages, ResourceSet = resourceSet
                });
            }

            if ((stages & ShaderStages.Vertex) == ShaderStages.Vertex)
            {
                bool bind = false;
                if (slot < MaxCachedUniformBuffers)
                {
                    if (_vertexBoundTextureViews[slot] != texView)
                    {
                        _vertexBoundTextureViews[slot] = texView;
                        bind = true;
                    }
                }
                else
                {
                    bind = true;
                }
                if (bind)
                {
                    _context.VertexShader.SetShaderResource(slot, srv);
                }
            }
            if ((stages & ShaderStages.Geometry) == ShaderStages.Geometry)
            {
                _context.GeometryShader.SetShaderResource(slot, srv);
            }
            if ((stages & ShaderStages.TessellationControl) == ShaderStages.TessellationControl)
            {
                _context.HullShader.SetShaderResource(slot, srv);
            }
            if ((stages & ShaderStages.TessellationEvaluation) == ShaderStages.TessellationEvaluation)
            {
                _context.DomainShader.SetShaderResource(slot, srv);
            }
            if ((stages & ShaderStages.Fragment) == ShaderStages.Fragment)
            {
                bool bind = false;
                if (slot < MaxCachedUniformBuffers)
                {
                    if (_fragmentBoundTextureViews[slot] != texView)
                    {
                        _fragmentBoundTextureViews[slot] = texView;
                        bind = true;
                    }
                }
                else
                {
                    bind = true;
                }
                if (bind)
                {
                    _context.PixelShader.SetShaderResource(slot, srv);
                }
            }
            if ((stages & ShaderStages.Compute) == ShaderStages.Compute)
            {
                _context.ComputeShader.SetShaderResource(slot, srv);
            }
        }