Skip to content

Commit f7a180f

Browse files
[REMIX-4725] convert components that use hashes to use tokens in OGN / USD
1 parent 4928a74 commit f7a180f

File tree

13 files changed

+166
-61
lines changed

13 files changed

+166
-61
lines changed

documentation/components/MeshHashChecker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Checks if a specific mesh hash was processed in the current frame\.
1313

1414
| Property | Display Name | Type | IO Type | Default Value | Optional |
1515
|----------|--------------|------|---------|---------------|----------|
16-
| meshHash | Mesh Hash | Uint64 | Input | 0 | No |
16+
| meshHash | Mesh Hash | Hash | Input | 0x0 | No |
1717

1818
### Mesh Hash
1919

documentation/components/TextureHashChecker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Checks if a specific texture hash was used for material replacement in the curre
1313

1414
| Property | Display Name | Type | IO Type | Default Value | Optional |
1515
|----------|--------------|------|---------|---------------|----------|
16-
| textureHash | Texture Hash | Uint64 | Input | 0 | No |
16+
| textureHash | Texture Hash | Hash | Input | 0x0 | No |
1717

1818
### Texture Hash
1919

src/dxvk/rtx_render/graph/components/mesh_hash_checker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace dxvk {
2929
namespace components {
3030

3131
#define LIST_INPUTS(X) \
32-
X(RtComponentPropertyType::Uint64, 0, meshHash, "Mesh Hash", "The mesh hash to check for usage in the current frame.")
32+
X(RtComponentPropertyType::Hash, 0x0, meshHash, "Mesh Hash", "The mesh hash to check for usage in the current frame.")
3333

3434
#define LIST_STATES(X)
3535

src/dxvk/rtx_render/graph/components/texture_hash_checker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace dxvk {
2929
namespace components {
3030

3131
#define LIST_INPUTS(X) \
32-
X(RtComponentPropertyType::Uint64, 0, textureHash, "Texture Hash", "The texture hash to check for usage in the current frame.")
32+
X(RtComponentPropertyType::Hash, 0x0, textureHash, "Texture Hash", "The texture hash to check for usage in the current frame.")
3333

3434
#define LIST_STATES(X)
3535

src/dxvk/rtx_render/graph/rtx_graph_md_writer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <cmath>
2727
#include <filesystem>
2828
#include <limits>
29+
#include <sstream>
30+
#include <iomanip>
2931
#include <unordered_map>
3032

3133
namespace dxvk {
@@ -138,6 +140,12 @@ std::string getValueAsString(const RtComponentPropertyValue& value, const RtComp
138140
return "\"" + escapeMarkdown(std::get<std::string>(value)) + "\"";
139141
case RtComponentPropertyType::AssetPath:
140142
return "\"" + escapeMarkdown(std::get<std::string>(value)) + "\"";
143+
case RtComponentPropertyType::Hash: {
144+
// Format hash as hex string with 0x prefix
145+
std::ostringstream ss;
146+
ss << "0x" << std::hex << std::get<uint64_t>(value);
147+
return ss.str();
148+
}
141149
case RtComponentPropertyType::Prim:
142150
// Prim references don't use the default value field,
143151
// as it isn't really applicable.

src/dxvk/rtx_render/graph/rtx_graph_ogn_writer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include "../util/util_env.h"
2525
#include "../util/util_filesys.h"
2626
#include <filesystem>
27+
#include <sstream>
28+
#include <iomanip>
2729

2830
namespace dxvk {
2931
namespace {
@@ -58,9 +60,10 @@ std::string propertyTypeToOgnType(RtComponentPropertyType type) {
5860
case RtComponentPropertyType::Int32: return "int";
5961
case RtComponentPropertyType::Uint32: return "uint";
6062
case RtComponentPropertyType::Uint64: return "uint64";
61-
case RtComponentPropertyType::Prim: return "target"; // USD Relationship to a prim
6263
case RtComponentPropertyType::String: return "token";
6364
case RtComponentPropertyType::AssetPath: return "token";
65+
case RtComponentPropertyType::Hash: return "token";
66+
case RtComponentPropertyType::Prim: return "target"; // USD Relationship to a prim
6467
}
6568
return "unknown";
6669
}
@@ -101,6 +104,12 @@ std::string getDefaultValueAsJson(const RtComponentPropertyValue& value, RtCompo
101104
return "\"" + escapeJsonString(std::get<std::string>(value)) + "\"";
102105
case RtComponentPropertyType::AssetPath:
103106
return "\"" + escapeJsonString(std::get<std::string>(value)) + "\"";
107+
case RtComponentPropertyType::Hash: {
108+
// Hash is stored as uint64_t but output as a hex string token in OGN
109+
std::ostringstream ss;
110+
ss << "\"0x" << std::hex << std::get<uint64_t>(value) << "\"";
111+
return ss.str();
112+
}
104113
case RtComponentPropertyType::Prim:
105114
// Target relationships don't typically have default values in OGN
106115
return "null";

src/dxvk/rtx_render/graph/rtx_graph_types.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,10 @@ std::ostream& operator << (std::ostream& os, RtComponentPropertyType type) {
219219
case RtComponentPropertyType::Int32: return os << "Int32";
220220
case RtComponentPropertyType::Uint32: return os << "Uint32";
221221
case RtComponentPropertyType::Uint64: return os << "Uint64";
222-
case RtComponentPropertyType::Prim: return os << "Prim";
223222
case RtComponentPropertyType::String: return os << "String";
224223
case RtComponentPropertyType::AssetPath: return os << "AssetPath";
224+
case RtComponentPropertyType::Hash: return os << "Hash";
225+
case RtComponentPropertyType::Prim: return os << "Prim";
225226
}
226227
return os << static_cast<int32_t>(type);
227228
}
@@ -257,12 +258,16 @@ RtComponentPropertyValue propertyValueFromString(const std::string& str, const R
257258
case RtComponentPropertyType::Uint64:
258259
// The `nullptr, 0` causes stoull to auto detect hex from `0x`
259260
return propertyValueForceType<uint64_t>(std::stoull(str, nullptr, 0));
260-
case RtComponentPropertyType::Prim:
261-
// Should never be reached (prim properties should be UsdRelationships, so they shouldn't ever have a string value). Just in case, return an invalid value.
262-
return kInvalidRtComponentPropertyValue;
263261
case RtComponentPropertyType::String:
264262
case RtComponentPropertyType::AssetPath:
265263
return str;
264+
case RtComponentPropertyType::Hash:
265+
// Hash is stored as uint64_t but represented as a token in USD/OGN
266+
// Parse as hex (base 16) - works with or without 0x prefix
267+
return propertyValueForceType<uint64_t>(std::stoull(str, nullptr, 16));
268+
case RtComponentPropertyType::Prim:
269+
// Should never be reached (prim properties should be UsdRelationships, so they shouldn't ever have a string value). Just in case, return an invalid value.
270+
return kInvalidRtComponentPropertyValue;
266271
}
267272
Logger::err(str::format("Unknown property type in propertyValueFromString. type: ", type, ", string: ", str));
268273
} catch (const std::invalid_argument& e) {
@@ -291,9 +296,10 @@ RtComponentPropertyVector propertyVectorFromType(const RtComponentPropertyType t
291296
case RtComponentPropertyType::Int32: return std::vector<RtComponentPropertyTypeToCppType<RtComponentPropertyType::Int32>>{};
292297
case RtComponentPropertyType::Uint32: return std::vector<RtComponentPropertyTypeToCppType<RtComponentPropertyType::Uint32>>{};
293298
case RtComponentPropertyType::Uint64: return std::vector<RtComponentPropertyTypeToCppType<RtComponentPropertyType::Uint64>>{};
294-
case RtComponentPropertyType::Prim: return std::vector<RtComponentPropertyTypeToCppType<RtComponentPropertyType::Prim>>{};
295299
case RtComponentPropertyType::String: return std::vector<std::string>{};
296300
case RtComponentPropertyType::AssetPath: return std::vector<std::string>{};
301+
case RtComponentPropertyType::Hash: return std::vector<RtComponentPropertyTypeToCppType<RtComponentPropertyType::Hash>>{};
302+
case RtComponentPropertyType::Prim: return std::vector<RtComponentPropertyTypeToCppType<RtComponentPropertyType::Prim>>{};
297303
}
298304
assert(false && "Unknown property type in propertyVectorFromType");
299305
return std::vector<RtComponentPropertyTypeToCppType<RtComponentPropertyType::Float>>{}; // fallback

src/dxvk/rtx_render/graph/rtx_graph_types.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ enum class RtComponentPropertyType {
5757
Uint64,
5858
String,
5959
AssetPath,
60+
Hash,
6061

6162
// Default Value is ignored for relationships. It's safe to just use 0.
6263
Prim,
6364

6465
// TODO should we support lists of any of the above types.
65-
// TODO should Hash be a separate type? it's just uint64_t under the hood, but could be displayed differently.
6666
// TODO support generic types (i.e. number, or numbersAndVectors)
6767

6868
// NOTE: Places to change when adding a new case:
@@ -89,9 +89,10 @@ template<> struct RtComponentPropertyTypeToCppTypeImpl<RtComponentPropertyType::
8989
template<> struct RtComponentPropertyTypeToCppTypeImpl<RtComponentPropertyType::Int32> { using Type = int32_t; };
9090
template<> struct RtComponentPropertyTypeToCppTypeImpl<RtComponentPropertyType::Uint32> { using Type = uint32_t; };
9191
template<> struct RtComponentPropertyTypeToCppTypeImpl<RtComponentPropertyType::Uint64> { using Type = uint64_t; };
92-
template<> struct RtComponentPropertyTypeToCppTypeImpl<RtComponentPropertyType::Prim> { using Type = uint32_t; };
9392
template<> struct RtComponentPropertyTypeToCppTypeImpl<RtComponentPropertyType::String> { using Type = std::string; };
9493
template<> struct RtComponentPropertyTypeToCppTypeImpl<RtComponentPropertyType::AssetPath> { using Type = std::string; };
94+
template<> struct RtComponentPropertyTypeToCppTypeImpl<RtComponentPropertyType::Hash> { using Type = uint64_t; };
95+
template<> struct RtComponentPropertyTypeToCppTypeImpl<RtComponentPropertyType::Prim> { using Type = uint32_t; };
9596

9697
template< RtComponentPropertyType propertyType >
9798
using RtComponentPropertyTypeToCppType = typename RtComponentPropertyTypeToCppTypeImpl<propertyType>::Type;

src/dxvk/rtx_render/graph/rtx_graph_usd_parser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ RtComponentPropertyValue GraphUsdParser::getPropertyValue(const pxr::UsdAttribut
436436
return spec.defaultValue;
437437
}
438438
return getPropertyValue<std::string>(value, spec);
439+
case RtComponentPropertyType::Hash:
440+
// Hash is stored as uint64_t but represented as a token in USD
441+
return getPropertyValue<uint64_t>(value, spec);
439442
case RtComponentPropertyType::Prim:
440443
throw DxvkError(str::format("Prim target properties should be UsdRelationships, not UsdAttributes."));
441444
return spec.defaultValue;

src/ogn/lightspeed.trex.logic/MeshHashChecker.ogn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"inputs": {
1010
"meshHash": {
1111
"description": ["The mesh hash to check for usage in the current frame."],
12-
"type": "uint64",
13-
"default": 0,
12+
"type": "token",
13+
"default": "0x0",
1414
"uiName": "Mesh Hash"
1515
}
1616
},

0 commit comments

Comments
 (0)