Skip to content

Commit c344e99

Browse files
committed
Usage of unused render states for special game scenarios
- use unused RenderState 42 to assign a remix texture category for the next surface - use unused RenderState 150 to set a custom material hash for the next surface - add hidden remix option 'useUnusedRenderstates' (default: false) to enable usage of unused render states review changes
1 parent 912a164 commit c344e99

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/d3d9/d3d9_rtx_utils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ namespace dxvk {
176176

177177
materialData.alphaBlendEnabled = d3d9State.renderStates[D3DRS_ALPHABLENDENABLE] != FALSE;
178178

179+
if (RtxOptions::Get()->useUnusedRenderstates()) {
180+
materialData.remixTextureCategoryFlagsFromD3D = d3d9State.renderStates[42] != 0xfefefefe ? d3d9State.renderStates[42] : 0u; // D3DRENDERSTATETYPE index 42 is not in use - unused values are set to 0xfefefefe
181+
materialData.remixHashFromD3D = d3d9State.renderStates[150] != 0xfefefefe ? d3d9State.renderStates[150] : 0u; // D3DRENDERSTATETYPE index 150 is not in use - unused values are set to 0xfefefefe
182+
}
183+
179184
if (materialData.alphaBlendEnabled) {
180185
D3D9BlendState color;
181186
color.Src = D3DBLEND(d3d9State.renderStates[D3DRS_SRCBLEND]);

src/dxvk/rtx_render/rtx_materials.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,8 @@ struct LegacyMaterialData {
14511451
uint32_t tFactor = 0xffffffff; // Value for D3DRS_TEXTUREFACTOR, default value of is opaque white
14521452
D3DMATERIAL9 d3dMaterial = {};
14531453
bool isTextureFactorBlend = false;
1454+
uint32_t remixTextureCategoryFlagsFromD3D = 0u;
1455+
XXH64_hash_t remixHashFromD3D = 0;
14541456

14551457
void setHashOverride(XXH64_hash_t hash) {
14561458
m_cachedHash = hash;
@@ -1469,6 +1471,11 @@ struct LegacyMaterialData {
14691471
// plain data hash used by the RtSurfaceMaterial for storage in map-like data structures, but rather
14701472
// one used to identify a material and compare to user-provided hashes.
14711473
m_cachedHash = colorTextures[0].getImageHash();
1474+
1475+
// Custom hash set via unused D3D RenderState
1476+
if (remixHashFromD3D) {
1477+
m_cachedHash = remixHashFromD3D;
1478+
}
14721479
}
14731480

14741481
const static uint32_t kMaxSupportedTextures = 2;

src/dxvk/rtx_render/rtx_options.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,9 @@ namespace dxvk {
989989
RTX_OPTION("rtx", float, effectLightRadius, 5.f, "");
990990
RTX_OPTION("rtx", bool, effectLightPlasmaBall, false, "");
991991

992+
RTX_OPTION("rtx", bool, useUnusedRenderstates, false, "Enable usage of unused D3D renderstates to aid with special game scenarios whilst having game code access.\n"
993+
"(RS 42) Setting the remix texture category for the next surface. (RS 150) Setting a user defined material hash for the next surface.");
994+
992995
RTX_OPTION("rtx", bool, useObsoleteHashOnTextureUpload, false,
993996
"Whether or not to use slower XXH64 hash on texture upload.\n"
994997
"New projects should not enable this option as this solely exists for compatibility with older hashing schemes.");

src/dxvk/rtx_render/rtx_types.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ namespace dxvk {
133133
// than doing N lookups per texture hash for each category.
134134
const XXH64_hash_t& textureHash = materialData.getColorTexture().getImageHash();
135135

136+
if (RtxOptions::Get()->useUnusedRenderstates()) {
137+
categories = CategoryFlags(materialData.remixTextureCategoryFlagsFromD3D);
138+
}
139+
136140
setCategory(InstanceCategories::WorldUI, lookupHash(RtxOptions::worldSpaceUiTextures(), textureHash));
137141
setCategory(InstanceCategories::WorldMatte, lookupHash(RtxOptions::worldSpaceUiBackgroundTextures(), textureHash));
138142

@@ -297,9 +301,12 @@ namespace dxvk {
297301
return true;
298302
}
299303

300-
// NOTE: we use color texture hash for sky detection, however the replacement is hashed with
301-
// the whole legacy material hash (which, as of 12/9/2022, equals to color texture hash). Adding a check just in case.
302-
assert(drawCallState.getMaterialData().getColorTexture().getImageHash() == drawCallState.getMaterialData().getHash() && "Texture or material hash method changed!");
304+
// NOTE: disable assert if material is using a custom hash that was set via an unused D3D RenderState
305+
if (!drawCallState.getMaterialData().remixHashFromD3D) {
306+
// NOTE: we use color texture hash for sky detection, however the replacement is hashed with
307+
// the whole legacy material hash (which, as of 12/9/2022, equals to color texture hash). Adding a check just in case.
308+
assert(drawCallState.getMaterialData().getColorTexture().getImageHash() == drawCallState.getMaterialData().getHash() && "Texture or material hash method changed!");
309+
}
303310

304311
if (drawCallState.getMaterialData().usesTexture()) {
305312
if (lookupHash(RtxOptions::skyBoxTextures(), drawCallState.getMaterialData().getHash())) {

0 commit comments

Comments
 (0)