From 3578f00eb92103937f9b512afeb7a51b9812f19b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 10 May 2021 23:38:38 +0200 Subject: [PATCH] Fixed pixel shader dispatching with multiple textures --- .../Shaders/Extensions/ID3D12DeviceExtensions.cs | 10 ++++++++-- src/ComputeSharp/Shaders/ShaderRunner{T}.cs | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ComputeSharp/Shaders/Extensions/ID3D12DeviceExtensions.cs b/src/ComputeSharp/Shaders/Extensions/ID3D12DeviceExtensions.cs index c1fa6237..dedce974 100644 --- a/src/ComputeSharp/Shaders/Extensions/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp/Shaders/Extensions/ID3D12DeviceExtensions.cs @@ -1,7 +1,10 @@ using System; using ComputeSharp.Core.Extensions; using TerraFX.Interop; +using static TerraFX.Interop.D3D12_COMPARISON_FUNC; +using static TerraFX.Interop.D3D12_FILTER; using static TerraFX.Interop.D3D12_PIPELINE_STATE_FLAGS; +using static TerraFX.Interop.D3D12_TEXTURE_ADDRESS_MODE; using FX = TerraFX.Interop.Windows; namespace ComputeSharp.Shaders.Extensions @@ -52,8 +55,11 @@ namespace ComputeSharp.Shaders.Extensions D3D12_STATIC_SAMPLER_DESC.Init( out d3D12SamplerDescription, shaderRegister: 0, - filter: D3D12_FILTER.D3D12_FILTER_MIN_MAG_MIP_LINEAR, - comparisonFunc: D3D12_COMPARISON_FUNC.D3D12_COMPARISON_FUNC_NEVER); + filter: D3D12_FILTER_MIN_MAG_MIP_LINEAR, + addressU: D3D12_TEXTURE_ADDRESS_MODE_MIRROR, + addressV: D3D12_TEXTURE_ADDRESS_MODE_MIRROR, + addressW: D3D12_TEXTURE_ADDRESS_MODE_MIRROR, + comparisonFunc: D3D12_COMPARISON_FUNC_NEVER); } // Root signature description wrapping the packed collection of root parameters diff --git a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs index dc2e4ddc..220b2c2c 100644 --- a/src/ComputeSharp/Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp/Shaders/ShaderRunner{T}.cs @@ -241,9 +241,13 @@ namespace ComputeSharp.Shaders 1, ((GraphicsResourceHelper.IGraphicsResource)texture).ValidateAndGetGpuDescriptorHandle(device)); - ReadOnlySpan resources = dispatchData.Resources; + // Skip the last (missing) resource, as the internal counter is exceeding the number of explicit + // resources that the shader has actually captured (since it includes the target texture too). + // For the same reason, the target root descriptor table index is also offset by 2, as it needs + // to skip not only the constant buffer with capture values, but the implicit texture as well. + ReadOnlySpan resources = dispatchData.Resources[..^1]; - for (int i = 1; i < resources.Length; i++) + for (int i = 0; i < resources.Length; i++) { // Load the captured buffers commandList.D3D12GraphicsCommandList->SetComputeRootDescriptorTable((uint)i + 2, resources[i]);