private void BindSampler(D3D11Sampler sampler, int slot, ShaderStages stages) { if ((stages & ShaderStages.Vertex) == ShaderStages.Vertex) { bool bind = false; if (slot < MaxCachedSamplers) { if (_vertexBoundSamplers[slot] != sampler) { _vertexBoundSamplers[slot] = sampler; bind = true; } } else { bind = true; } if (bind) { _context.VertexShader.SetSampler(slot, sampler.DeviceSampler); } } if ((stages & ShaderStages.Geometry) == ShaderStages.Geometry) { _context.GeometryShader.SetSampler(slot, sampler.DeviceSampler); } if ((stages & ShaderStages.TessellationControl) == ShaderStages.TessellationControl) { _context.HullShader.SetSampler(slot, sampler.DeviceSampler); } if ((stages & ShaderStages.TessellationEvaluation) == ShaderStages.TessellationEvaluation) { _context.DomainShader.SetSampler(slot, sampler.DeviceSampler); } if ((stages & ShaderStages.Fragment) == ShaderStages.Fragment) { bool bind = false; if (slot < MaxCachedSamplers) { if (_fragmentBoundSamplers[slot] != sampler) { _fragmentBoundSamplers[slot] = sampler; bind = true; } } else { bind = true; } if (bind) { _context.PixelShader.SetSampler(slot, sampler.DeviceSampler); } } }
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>(); } } }