Beispiel #1
0
        internal virtual void RCQUpdateResources(RenderCommandQueue commandQueue, ShaderResourcePackage shaderResources)
        {
            for (int i = 0; i < ConstantBufferBindings.Length; i++)
            {
                commandQueue.QueueCommand(RenderCommand.DiscardWriteShaderConstantBuffer(
                                              ConstantBufferBindings[i], shaderResources.GetValue(ConstantBufferBindings[i])
                                              ));
            }

            if (TextureSamplerBindings.Length > 0)
            {
                if (texSamplerValueDict == null)
                {
                    texSamplerValueDict = new FastClearList <KVP <TextureSamplerBinding, TextureSampler> >();
                }
                texSamplerValueDict.Clear();
                for (int i = 0; i < TextureSamplerBindings.Length; ++i)
                {
                    var tsb = TextureSamplerBindings[i];
                    texSamplerValueDict.Add(new KVP <TextureSamplerBinding, TextureSampler>(tsb, shaderResources.GetValue(tsb)));
                }
                commandQueue.QueueCommand(RenderCommand.SetShaderTextureSamplers(this, texSamplerValueDict));
            }

            if (ResourceViewBindings.Length > 0)
            {
                if (resViewValueDict == null)
                {
                    resViewValueDict = new FastClearList <KVP <ResourceViewBinding, IResourceView> >();
                }
                resViewValueDict.Clear();
                for (int i = 0; i < ResourceViewBindings.Length; ++i)
                {
                    var rvb = ResourceViewBindings[i];
                    resViewValueDict.Add(new KVP <ResourceViewBinding, IResourceView>(rvb, shaderResources.GetValue(rvb)));
                    Assure.False(
                        ((BaseResourceView)shaderResources.GetValue(ResourceViewBindings[i])) != null &&
                        ((BaseResourceView)shaderResources.GetValue(ResourceViewBindings[i])).Resource.PermittedBindings == GPUBindings.None,
                        "Underlying resource has no permitted GPU bindings."
                        );
                }
                commandQueue.QueueCommand(RenderCommand.SetShaderResourceViews(this, resViewValueDict));
            }
        }
Beispiel #2
0
        internal virtual void RCQUpdateResources(RenderCommandQueue commandQueue)
        {
            for (int i = 0; i < ConstantBufferBindings.Length; i++)
            {
                commandQueue.QueueCommand(RenderCommand.DiscardWriteShaderConstantBuffer(
                                              ConstantBufferBindings[i], ConstantBufferBindings[i].CurValuePtr
                                              ));
            }

            if (TextureSamplerBindings.Length > 0)
            {
                if (texSamplerValueDict == null)
                {
                    texSamplerValueDict = new FastClearList <KVP <TextureSamplerBinding, TextureSampler> >();
                }
                texSamplerValueDict.Clear();
                for (int i = 0; i < TextureSamplerBindings.Length; ++i)
                {
                    texSamplerValueDict.Add(new KVP <TextureSamplerBinding, TextureSampler>(TextureSamplerBindings[i], TextureSamplerBindings[i].GetBoundResource()));
                }
                commandQueue.QueueCommand(RenderCommand.SetShaderTextureSamplers(this, texSamplerValueDict));
            }

            if (ResourceViewBindings.Length > 0)
            {
                if (resViewValueDict == null)
                {
                    resViewValueDict = new FastClearList <KVP <ResourceViewBinding, IResourceView> >();
                }
                resViewValueDict.Clear();
                for (int i = 0; i < ResourceViewBindings.Length; ++i)
                {
                    resViewValueDict.Add(new KVP <ResourceViewBinding, IResourceView>(ResourceViewBindings[i], ResourceViewBindings[i].GetBoundResourceAsBaseResourceView()));
                    Assure.False(ResourceViewBindings[i].GetBoundResourceAsBaseResourceView().Resource.PermittedBindings == GPUBindings.None, "Underlying resource has no permitted GPU bindings.");
                }
                commandQueue.QueueCommand(RenderCommand.SetShaderResourceViews(this, resViewValueDict));
            }
        }
        public unsafe void TestSetShaderTextureSamplers()
        {
            TextureSampler ts0 = new TextureSampler(TextureFilterType.Anisotropic, TextureWrapMode.Border, AnisotropicFilteringLevel.EightTimes);
            TextureSampler ts2 = new TextureSampler(TextureFilterType.Anisotropic, TextureWrapMode.Border, AnisotropicFilteringLevel.EightTimes);

            Shader shader = new FragmentShader(
                @"Tests\SimpleFS.cso",
                new TextureSamplerBinding(0U, "TS0"),
                new TextureSamplerBinding(1U, "TS1"),
                new TextureSamplerBinding(2U, "TS2")
                );

            Dictionary <TextureSamplerBinding, TextureSampler> tsDict = new Dictionary <TextureSamplerBinding, TextureSampler>();

            tsDict[shader.TextureSamplerBindings[0]] = ts0;
            tsDict[shader.TextureSamplerBindings[2]] = ts2;

            RenderCommand testCommand = RenderCommand.SetShaderTextureSamplers(shader, tsDict);

            Assert.AreEqual(RenderCommandInstruction.FSSetSamplers, testCommand.Instruction);
            ResourceHandle *resHandleArray = (ResourceHandle *)new IntPtr(UnsafeUtils.Reinterpret <RenderCommandArgument, long>(testCommand.Arg1, sizeof(long)));

            Assert.AreEqual(ts0.ResourceHandle, resHandleArray[0]);
            Assert.AreEqual(ResourceHandle.NULL, resHandleArray[1]);
            Assert.AreEqual(ts2.ResourceHandle, resHandleArray[2]);
            Assert.AreEqual((RenderCommandArgument)3U, testCommand.Arg2);

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.SetShaderTextureSamplers(null, tsDict);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }

            try {
                RenderCommand.SetShaderTextureSamplers(shader, null);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            ts0.Dispose();
            ts2.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.SetShaderTextureSamplers(shader, tsDict);
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif

            shader.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                RenderCommand.SetShaderTextureSamplers(shader, new Dictionary <TextureSamplerBinding, TextureSampler>());
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif
        }