Skip to content

Commit

Permalink
use setHashOverride - add m_overrideHash & wasHashOverridden method
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxor4d committed Nov 1, 2024
1 parent c344e99 commit 2b8d288
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/d3d9/d3d9_rtx_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 8 additions & 6 deletions src/dxvk/rtx_render/rtx_materials.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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();
}
}

Expand All @@ -1485,6 +1486,7 @@ struct LegacyMaterialData {
uint32_t colorTextureSlot[kMaxSupportedTextures] = { kInvalidResourceSlot };

XXH64_hash_t m_cachedHash = kEmptyHash;
bool m_overrideHash = false;
};

struct MaterialData {
Expand Down
2 changes: 1 addition & 1 deletion src/dxvk/rtx_render/rtx_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down

0 comments on commit 2b8d288

Please sign in to comment.