Skip to content

Commit 23f3d36

Browse files
Merge branch 'NVIDIAGameWorks:main' into main
2 parents 1aa8380 + 217c5a9 commit 23f3d36

File tree

10 files changed

+399
-201
lines changed

10 files changed

+399
-201
lines changed

src/dxvk/imgui/dxvk_imgui_capture.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace dxvk {
5454
}
5555

5656
void ImGuiCapture::show(const Rc<DxvkContext>& ctx) {
57+
auto capturer = ctx->getCommonObjects()->capturer();
5758
const bool disableCapture =
5859
ctx->getCommonObjects()->getSceneManager().areReplacementsLoaded() &&
5960
RtxOptions::Get()->getEnableAnyReplacements();
@@ -68,6 +69,7 @@ namespace dxvk {
6869
showContinuousCapture(ctx);
6970
}
7071
ImGui::Separator();
72+
ImGui::Checkbox("Correct baked world transforms", &capturer->correctBakedTransformsRef());
7173
ImGui::Checkbox("Show menu on capture hotkey", &RtxOptions::Get()->m_captureShowMenuOnHotkey);
7274
if(RtxOptions::Get()->m_captureShowMenuOnHotkey) {
7375
ImGui::PushTextWrapPos(ImGui::GetCurrentWindow()->Size.x);

src/dxvk/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ dxvk_src = files([
215215
'rtx_render/rtx_game_capturer.cpp',
216216
'rtx_render/rtx_game_capturer.h',
217217
'rtx_render/rtx_game_capturer_paths.h',
218+
'rtx_render/rtx_game_capturer_utils.h',
218219
'rtx_render/rtx_geometry_utils.cpp',
219220
'rtx_render/rtx_geometry_utils.h',
220221
'rtx_render/rtx_hashing.cpp',

src/dxvk/rtx_render/rtx_game_capturer.cpp

Lines changed: 122 additions & 106 deletions
Large diffs are not rendered by default.

src/dxvk/rtx_render/rtx_game_capturer.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
#pragma once
2323

24+
#include "rtx_game_capturer_utils.h"
2425
#include "rtx_options.h"
2526

2627
#include "../../lssusd/game_exporter_types.h"
@@ -57,6 +58,13 @@ struct LegacyMaterialData;
5758
class GameCapturer : public RcObject
5859
{
5960
public:
61+
RW_RTX_OPTION("rtx.capture", bool, correctBakedTransforms, false,
62+
"Some games bake world transforms into mesh vertices. If individually captured\n"
63+
"meshes appear to be way off in the middle of nowhere OR instanced meshes appear\n"
64+
"to all have identity xform matrices, enabling will attempt to correct this and\n"
65+
"improve stage + mesh viewability in tools.\n"
66+
"Hashes are unaffected.");
67+
6068
GameCapturer(DxvkDevice* const pDevice, SceneManager& sceneManager, AssetExporter& exporter);
6169
~GameCapturer();
6270

@@ -125,10 +133,11 @@ class GameCapturer : public RcObject
125133
};
126134

127135
struct Mesh {
128-
lss::Mesh lssData;
129-
size_t instanceCount = 0;
130-
XXH64_hash_t matHash;
131-
MeshSync meshSync;
136+
lss::Mesh lssData;
137+
size_t instanceCount = 0;
138+
XXH64_hash_t matHash;
139+
MeshSync meshSync;
140+
AtomicOriginCalc originCalc;
132141
};
133142

134143
struct Instance {
@@ -280,7 +289,8 @@ class GameCapturer : public RcObject
280289
std::unordered_map<XXH64_hash_t, Material> materials;
281290
std::unordered_map<XXH64_hash_t, Instance> instances;
282291
std::unordered_map<XXH64_hash_t, uint8_t> instanceFlags;
283-
} m_cap;
292+
};
293+
std::unique_ptr<Capture> m_pCap;
284294
};
285295

286296
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*/
22+
#pragma once
23+
24+
#include "../../lssusd/usd_include_begin.h"
25+
#include <pxr/base/gf/vec3f.h>
26+
#include "../../lssusd/usd_include_end.h"
27+
28+
#include <atomic>
29+
30+
namespace dxvk {
31+
32+
struct AtomicOriginCalc; // Forward declare
33+
struct OriginCalc {
34+
inline void compareAndSwap(const pxr::GfVec3f& vec3) {
35+
replaceMin(&vec3[0]);
36+
replaceMax(&vec3[0]);
37+
}
38+
inline void compareAndSwap(const OriginCalc& other) {
39+
replaceMin(other.min);
40+
replaceMax(other.max);
41+
}
42+
inline pxr::GfVec3f calc() const {
43+
return (pxr::GfVec3f(&min[0]) + pxr::GfVec3f(&max[0])) / 2;
44+
}
45+
private:
46+
static constexpr float fMax = std::numeric_limits<float>::max();
47+
float min[3] = { fMax, fMax, fMax};
48+
float max[3] = {-fMax,-fMax,-fMax};
49+
inline void replaceMin(const float* const vec3) {
50+
min[0] = std::min(min[0],vec3[0]);
51+
min[1] = std::min(min[1],vec3[1]);
52+
min[2] = std::min(min[2],vec3[2]);
53+
}
54+
inline void replaceMax(const float* const vec3) {
55+
max[0] = std::max(max[0],vec3[0]);
56+
max[1] = std::max(max[1],vec3[1]);
57+
max[2] = std::max(max[2],vec3[2]);
58+
}
59+
friend AtomicOriginCalc;
60+
};
61+
62+
struct AtomicOriginCalc {
63+
inline void compareAndSwap(const pxr::GfVec3f& vec3) {
64+
replaceMin(&vec3[0]);
65+
replaceMax(&vec3[0]);
66+
}
67+
inline void compareAndSwap(const OriginCalc& other) {
68+
replaceMin(other.min);
69+
replaceMax(other.max);
70+
}
71+
inline pxr::GfVec3f calc() const {
72+
return (pxr::GfVec3f{min[0].load(),min[1].load(),min[2].load()} +
73+
pxr::GfVec3f{max[0].load(),max[1].load(),max[2].load()})
74+
/ 2;
75+
}
76+
inline void reset() {
77+
for(size_t i = 0; i < 3; ++i) {
78+
min[i].store(fMax);
79+
max[i].store(-fMax);
80+
}
81+
}
82+
private:
83+
static constexpr float fMax = std::numeric_limits<float>::max();
84+
std::atomic<float> min[3] = { fMax, fMax, fMax};
85+
std::atomic<float> max[3] = {-fMax,-fMax,-fMax};
86+
inline void replaceMin(const float* const vec3) {
87+
swapIfLess(min[0],vec3[0]);
88+
swapIfLess(min[1],vec3[1]);
89+
swapIfLess(min[2],vec3[2]);
90+
}
91+
inline void replaceMax(const float* const vec3) {
92+
swapIfGreater(max[0],vec3[0]);
93+
swapIfGreater(max[1],vec3[1]);
94+
swapIfGreater(max[2],vec3[2]);
95+
}
96+
static inline void swapIfLess(std::atomic<float>& atomic, const float other) {
97+
float val = fMax;
98+
do {
99+
val = atomic.load();
100+
} while(val > other && !atomic.compare_exchange_weak(val, other));
101+
}
102+
static void swapIfGreater(std::atomic<float>& atomic, const float other) {
103+
float val = -fMax;
104+
do {
105+
val = atomic.load();
106+
} while(val < other && !atomic.compare_exchange_weak(val, other));
107+
}
108+
};
109+
110+
}

src/dxvk/shaders/rtx/utility/gbuffer_helpers.slangh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ void polymorphicSurfaceMaterialInteractionWriteToGBuffer(
224224
uint16_t(polymorphicSurfaceMaterialInteraction.bdata1) // volumetricAnisotropy
225225
);
226226
}
227+
else
228+
{
229+
subsurfaceDataTexture[position] = uint4(0, 0, 0, 0);
230+
}
227231
}
228232
}
229233

0 commit comments

Comments
 (0)