From f53321bd43ce67e251b2b6d988096942bbe2d3fd Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Mon, 10 Mar 2025 19:11:28 +0100 Subject: [PATCH] Use ID3D12Resource pointers in the texture table, to remove some unnecessary casts --- FSR3UnityPlugin.cpp | 20 ++++++++++---------- FSR3UnityTypes.h | 16 ++++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/FSR3UnityPlugin.cpp b/FSR3UnityPlugin.cpp index 1788fa1..3e2a797 100644 --- a/FSR3UnityPlugin.cpp +++ b/FSR3UnityPlugin.cpp @@ -236,15 +236,15 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data) ffx::DispatchDescUpscale dispatchUpscale{}; dispatchUpscale.commandList = state.commandList; - dispatchUpscale.color = ffxApiGetResourceDX12((ID3D12Resource*)feature.textureTable.colorInput, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); - dispatchUpscale.depth = ffxApiGetResourceDX12((ID3D12Resource*)feature.textureTable.depth, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); - dispatchUpscale.motionVectors = ffxApiGetResourceDX12((ID3D12Resource*)feature.textureTable.motionVectors, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); - dispatchUpscale.exposure = ffxApiGetResourceDX12((ID3D12Resource*)feature.textureTable.exposureTexture, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); - dispatchUpscale.reactive = ffxApiGetResourceDX12((ID3D12Resource*)feature.textureTable.reactiveMask, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); - dispatchUpscale.transparencyAndComposition = ffxApiGetResourceDX12((ID3D12Resource*)feature.textureTable.transparencyMask, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); - dispatchUpscale.output = ffxApiGetResourceDX12((ID3D12Resource*)feature.textureTable.colorOutput, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); // TODO: shouldn't this be FFX_API_RESOURCE_STATE_UNORDERED_ACCESS? - - dispatchUpscale.jitterOffset.x = params->jitterOffsetX; // TODO: might need to negate these + dispatchUpscale.color = ffxApiGetResourceDX12(feature.textureTable.colorInput, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); + dispatchUpscale.depth = ffxApiGetResourceDX12(feature.textureTable.depth, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); + dispatchUpscale.motionVectors = ffxApiGetResourceDX12(feature.textureTable.motionVectors, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); + dispatchUpscale.exposure = ffxApiGetResourceDX12(feature.textureTable.exposureTexture, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); + dispatchUpscale.reactive = ffxApiGetResourceDX12(feature.textureTable.reactiveMask, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); + dispatchUpscale.transparencyAndComposition = ffxApiGetResourceDX12(feature.textureTable.transparencyMask, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); + dispatchUpscale.output = ffxApiGetResourceDX12(feature.textureTable.colorOutput, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); // TODO: shouldn't this be FFX_API_RESOURCE_STATE_UNORDERED_ACCESS? + + dispatchUpscale.jitterOffset.x = params->jitterOffsetX; dispatchUpscale.jitterOffset.y = params->jitterOffsetY; dispatchUpscale.motionVectorScale.x = params->MVScaleX; dispatchUpscale.motionVectorScale.y = params->MVScaleY; @@ -332,7 +332,7 @@ static void UNITY_INTERFACE_API OnSetTextureEvent(int eventID, void* data) { // We organized the texture table struct to be ordered the same as the texture slot enum // This way we can use the texture slot value simply as a pointer offset into the texture table - *(((intptr_t*)&feature.textureTable) + textureSlot) = (intptr_t)s_GraphicsD3D12->TextureFromNativeTexture((UnityTextureID)params->textureID); + *(((ID3D12Resource**)&feature.textureTable) + textureSlot) = s_GraphicsD3D12->TextureFromNativeTexture((UnityTextureID)params->textureID); break; } } diff --git a/FSR3UnityTypes.h b/FSR3UnityTypes.h index 3219108..7621894 100644 --- a/FSR3UnityTypes.h +++ b/FSR3UnityTypes.h @@ -59,12 +59,12 @@ struct FSR3CommandExecutionData struct FSR3TextureTable { - intptr_t colorInput; - intptr_t colorOutput; - intptr_t depth; - intptr_t motionVectors; - intptr_t transparencyMask; - intptr_t exposureTexture; - intptr_t reactiveMask; - intptr_t biasColorMask; + ID3D12Resource* colorInput; + ID3D12Resource* colorOutput; + ID3D12Resource* depth; + ID3D12Resource* motionVectors; + ID3D12Resource* transparencyMask; + ID3D12Resource* exposureTexture; + ID3D12Resource* reactiveMask; + ID3D12Resource* biasColorMask; };