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