From dafe81d108dc693026c8c264174639a930542530 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Mon, 10 Mar 2025 18:44:26 +0100 Subject: [PATCH] Fixed bugs: - Assign colorOutput texture to output - Texture event passes texture IDs after all, so translate those to ID3D12Resource pointers - Assign texture in End event, perform clear in Begin event. Fixes inputColor texture entry getting cleared. --- FSR3UnityPlugin.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/FSR3UnityPlugin.cpp b/FSR3UnityPlugin.cpp index 6c0af06..1788fa1 100644 --- a/FSR3UnityPlugin.cpp +++ b/FSR3UnityPlugin.cpp @@ -242,7 +242,7 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data) 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.colorInput, FFX_API_RESOURCE_STATE_PIXEL_COMPUTE_READ); // TODO: shouldn't this be FFX_API_RESOURCE_STATE_UNORDERED_ACCESS? + 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.jitterOffset.y = params->jitterOffsetY; @@ -303,6 +303,9 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data) static void UNITY_INTERFACE_API OnSetTextureEvent(int eventID, void* data) { + if (s_GraphicsD3D12 == nullptr) + return; + auto* params = (UnityRenderingExtTextureUpdateParamsV2*)data; uint32_t featureSlot = (params->userData >> 16) & 0xFFFF; @@ -313,23 +316,23 @@ static void UNITY_INTERFACE_API OnSetTextureEvent(int eventID, void* data) return; auto& feature = s_Features[featureSlot]; - if (clearTextureTable) - { - memset(&feature.textureTable, 0, sizeof(FSR3TextureTable)); - } // User rendering code switch (eventID) { case kUnityRenderingExtEventUpdateTextureBeginV2: { - // 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) = params->textureID; + if (clearTextureTable) + { + memset(&feature.textureTable, 0, sizeof(FSR3TextureTable)); + } break; } case kUnityRenderingExtEventUpdateTextureEndV2: { + // 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); break; } }