From 2b8d288eb4a13c458ebdc1bad1b5a0692c94468c Mon Sep 17 00:00:00 2001 From: #xoxor4d Date: Fri, 1 Nov 2024 22:41:44 +0100 Subject: [PATCH] use setHashOverride - add m_overrideHash & wasHashOverridden method --- src/d3d9/d3d9_rtx_utils.cpp | 5 ++++- src/dxvk/rtx_render/rtx_materials.h | 14 ++++++++------ src/dxvk/rtx_render/rtx_types.cpp | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/d3d9/d3d9_rtx_utils.cpp b/src/d3d9/d3d9_rtx_utils.cpp index 1b424a5a..97a35a5d 100644 --- a/src/d3d9/d3d9_rtx_utils.cpp +++ b/src/d3d9/d3d9_rtx_utils.cpp @@ -178,7 +178,10 @@ namespace dxvk { if (RtxOptions::Get()->useUnusedRenderstates()) { materialData.remixTextureCategoryFlagsFromD3D = d3d9State.renderStates[42] != 0xfefefefe ? d3d9State.renderStates[42] : 0u; // D3DRENDERSTATETYPE index 42 is not in use - unused values are set to 0xfefefefe - materialData.remixHashFromD3D = d3d9State.renderStates[150] != 0xfefefefe ? d3d9State.renderStates[150] : 0u; // D3DRENDERSTATETYPE index 150 is not in use - unused values are set to 0xfefefefe + + if (d3d9State.renderStates[150] != 0 && d3d9State.renderStates[150] != 0xfefefefe) { // D3DRENDERSTATETYPE index 150 is not in use - unused values are set to 0xfefefefe + materialData.setHashOverride(d3d9State.renderStates[150]); + } } if (materialData.alphaBlendEnabled) { diff --git a/src/dxvk/rtx_render/rtx_materials.h b/src/dxvk/rtx_render/rtx_materials.h index a637c80d..0f33de53 100644 --- a/src/dxvk/rtx_render/rtx_materials.h +++ b/src/dxvk/rtx_render/rtx_materials.h @@ -1452,10 +1452,14 @@ struct LegacyMaterialData { D3DMATERIAL9 d3dMaterial = {}; bool isTextureFactorBlend = false; uint32_t remixTextureCategoryFlagsFromD3D = 0u; - XXH64_hash_t remixHashFromD3D = 0; void setHashOverride(XXH64_hash_t hash) { m_cachedHash = hash; + m_overrideHash = true; + } + + bool wasHashOverridden() const { + return m_overrideHash; } private: @@ -1470,11 +1474,8 @@ struct LegacyMaterialData { // incorporate more textures used to identify a material uniquely. Note this is not the same as the // plain data hash used by the RtSurfaceMaterial for storage in map-like data structures, but rather // one used to identify a material and compare to user-provided hashes. - m_cachedHash = colorTextures[0].getImageHash(); - - // Custom hash set via unused D3D RenderState - if (remixHashFromD3D) { - m_cachedHash = remixHashFromD3D; + if (!m_overrideHash) { + m_cachedHash = colorTextures[0].getImageHash(); } } @@ -1485,6 +1486,7 @@ struct LegacyMaterialData { uint32_t colorTextureSlot[kMaxSupportedTextures] = { kInvalidResourceSlot }; XXH64_hash_t m_cachedHash = kEmptyHash; + bool m_overrideHash = false; }; struct MaterialData { diff --git a/src/dxvk/rtx_render/rtx_types.cpp b/src/dxvk/rtx_render/rtx_types.cpp index 0203299c..e0aa0bb3 100644 --- a/src/dxvk/rtx_render/rtx_types.cpp +++ b/src/dxvk/rtx_render/rtx_types.cpp @@ -302,7 +302,7 @@ namespace dxvk { } // NOTE: disable assert if material is using a custom hash that was set via an unused D3D RenderState - if (!drawCallState.getMaterialData().remixHashFromD3D) { + if (!drawCallState.getMaterialData().wasHashOverridden()) { // NOTE: we use color texture hash for sky detection, however the replacement is hashed with // the whole legacy material hash (which, as of 12/9/2022, equals to color texture hash). Adding a check just in case. assert(drawCallState.getMaterialData().getColorTexture().getImageHash() == drawCallState.getMaterialData().getHash() && "Texture or material hash method changed!");