Skip to content

Commit f7d23a3

Browse files
committed
New denoiser, more async
1 parent 79c4c80 commit f7d23a3

File tree

79 files changed

+2068
-681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2068
-681
lines changed

sources/Core/Math/Constants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace Math
6666
return AlignUpWithMask(value, alignment - 1);
6767
}
6868

69-
template <typename T> __forceinline T roundUp(T a, size_t b) { return (1 + (a - 1) / b) * b; }
69+
template <typename T> __forceinline T roundUp(T num, size_t factor) { return num + factor - 1 - (num + factor - 1) % factor; }
7070

7171
template <typename T> __forceinline T AlignDown(T value, size_t alignment)
7272
{

sources/DirectXFramework/DX12/CommandList.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ namespace DX12
267267
list->OMSetRenderTargets(c, &rt.cpu, true, h.is_valid() ? &h.cpu : nullptr);
268268
}
269269

270-
270+
void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
271+
{
272+
set_rtv(place_rtv(rt), h);
273+
}
271274
void GraphicsContext::flush_binds(bool force)
272275
{
273276
base.flush_heaps(force);

sources/DirectXFramework/DX12/CommandList.h

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,10 +1126,11 @@ namespace DX12
11261126
void set_viewports(std::vector<Viewport> viewports);
11271127

11281128

1129+
void set_rtv(std::initializer_list<Handle> rt, Handle h);
11291130

11301131
void set_rtv(const HandleTable&, Handle);
11311132
void set_rtv(int c, Handle rt, Handle h);
1132-
1133+
11331134
void set_rtv(const HandleTableLight&, Handle);
11341135

11351136
void draw(D3D12_DRAW_INDEXED_ARGUMENTS args)
@@ -1174,13 +1175,29 @@ namespace DX12
11741175
set_rtvs_internal(t, h);
11751176
set_rtvs_internal(t + 1, list...);
11761177
}
1177-
1178+
template<class T, size_t N>
1179+
constexpr size_t size(T(&)[N]) { return N; }
1180+
11781181
template<class ...Handles>
1179-
void set_rtvs(const Handle& h, Handles... list)
1182+
void set_rtvs(const Handle& h, Handles... rtvlist)
11801183
{
1181-
D3D12_CPU_DESCRIPTOR_HANDLE handles[sizeof...(Handles)];
1182-
set_rtvs_internal(handles, list...);
1183-
list->OMSetRenderTargets(sizeof...(Handles), handles, false, h.is_valid() ? &h.cpu : nullptr);
1184+
1185+
auto f = [&](Handle h) {
1186+
get_base().transition_rtv(h.resource_info);
1187+
};
1188+
1189+
(f(std::forward<Handles>(rtvlist)), ...);
1190+
1191+
1192+
if (h.is_valid())
1193+
get_base().transition_dsv(h.resource_info);
1194+
1195+
get_base().flush_transitions();
1196+
1197+
1198+
1199+
CD3DX12_CPU_DESCRIPTOR_HANDLE ar[] = { (rtvlist.cpu)... };
1200+
list->OMSetRenderTargets(size(ar), ar, false, h.is_valid() ? &h.cpu : nullptr);
11841201
}
11851202

11861203

sources/DirectXFramework/DX12/ResourceViews.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace DX12
126126
class TextureView :public ResourceView
127127
{
128128
HandleTableLight hlsl;
129-
//HandleTableLight rtv;
129+
HandleTableLight rtv;
130130
public:
131131

132132

@@ -139,6 +139,7 @@ namespace DX12
139139
HLSL::TextureCube<> textureÑube;
140140
HLSL::Texture2DArray<> texture2DArray;
141141

142+
Handle renderTarget;
142143
public:
143144
template<class F>
144145
void init(F& frame)
@@ -170,15 +171,15 @@ namespace DX12
170171

171172
place_uav(hlsl[1]);
172173
}
173-
/*
174+
174175
if (desc.Flags & D3D12_RESOURCE_FLAGS::D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) {
175176

176-
rtv = frame.rtv_cpu.place(1);
177+
rtv = frame.get_cpu_heap(DescriptorHeapType::RTV).place(1);
177178

178179
renderTarget = rtv[0];
179-
place_uav(renderTarget);
180+
place_rtv(renderTarget);
180181
}
181-
*/
182+
182183
}
183184
TextureView() = default;
184185

sources/DirectXFramework/DX12/States.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,32 @@ namespace DX12
120120
};
121121

122122

123-
//mutable SpinLock states_lock;
124-
123+
125124
mutable std::array<SubResourcesCPU, 128> cpu_state;
126125

126+
mutable SpinLock states_lock;
127+
mutable std::map<int, SubResourcesCPU> cpu_state_map;
128+
127129
SubResourcesCPU& get_state(int id) const
128130
{
131+
if(id<128)
129132
return cpu_state[id];
130-
/*
133+
134+
131135
std::lock_guard<SpinLock> guard(states_lock);
132136

133-
auto it = cpu_state[id];
137+
auto it = cpu_state_map.find(id);
134138

135-
if (it == cpu_state.end())
139+
if (it == cpu_state_map.end())
136140
{
137-
auto & state = cpu_state[id];
141+
auto & state = cpu_state_map[id];
138142
state.subres.resize(gpu_state.subres.size());
139143

140144
return state;
141145
}
142146

143147
return it->second;
144-
*/
148+
145149
}
146150

147151

sources/FileSystem/FileSystem/FileSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct file
3535
std::shared_ptr<istream> get_new_stream()
3636
{
3737
std::filesystem::path full_path(std::filesystem::current_path());
38-
Log::get() << "Current path is : " << full_path.generic_string() << Log::endl;
38+
// Log::get() << "Current path is : " << full_path.generic_string() << Log::endl;
3939

4040
return provider->create_stream(file_name);
4141
}

sources/FlowGraph/FrameGraph.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,11 @@ void TaskBuilder::create_resources()
774774
flags |= D3D12_RESOURCE_FLAGS::D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
775775
}
776776

777+
if (check(info->flags & ResourceFlags::Counted))
778+
{
779+
//info->heap_type = Render::HeapType::READBACK;
780+
}
781+
777782
info->d3ddesc = CD3DX12_RESOURCE_DESC::Buffer(desc.size, flags);
778783
}
779784
/*

sources/FlowGraph/FrameGraph.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@ enum class ResourceType :int {
1010

1111
enum class ResourceFlags :int {
1212
None = 0,
13-
PixelRead = 1,
14-
ComputeRead = 2,
15-
DSRead = 1024,
13+
PixelRead = (1<<1),
14+
ComputeRead = (1 << 2),
15+
DSRead = (1 << 3),
1616

17-
UnorderedAccess = 4,
18-
RenderTarget = 8,
19-
DepthStencil = 16,
17+
UnorderedAccess = (1 << 4),
18+
RenderTarget = (1 << 5),
19+
DepthStencil = (1 << 6),
2020

2121

22-
GenCPU = 32,
23-
ReadCPU = 64,
22+
GenCPU = (1 << 7),
23+
ReadCPU = (1 << 8),
2424

2525
Temporal = 0,
26-
Static = 128,
27-
Required = 256,
26+
Static = (1 << 9),
27+
Required = (1 << 10),
2828

29-
Cube = 512,
30-
Changed = 1024
29+
Cube = (1 << 11),
30+
Counted = (1 << 12),
31+
Changed = (1 << 13)
3132

3233
, GENERATE_OPS
3334
};

sources/RenderSystem/Assets/MeshAsset.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ bool MeshAssetInstance::update_transforms()
389389
{
390390
bool res = scene_object::update_transforms();
391391

392-
if (res)
392+
if (res|| need_update_mats)
393393
{
394394

395395
// node_buffer.data().clear();
@@ -407,21 +407,23 @@ bool MeshAssetInstance::update_transforms()
407407
if (!info.primitive_global)
408408
info.primitive_global = std::make_shared<AABB>();
409409

410-
411-
mat4x4 mat = nodes[index].asset_node->mesh_matrix*global_transform;
412-
info.primitive_global->apply_transform(p, mat);
410+
mat4x4 prev_mat = info.global_mat;
411+
info.global_mat = nodes[index].asset_node->mesh_matrix*global_transform;
412+
info.primitive_global->apply_transform(p, info.global_mat);
413413

414414
auto &my_node = gpu_nodes[info.mesh_info.GetNode_offset() - nodes_handle.get_offset()];
415-
my_node.node_global_matrix = mat;
416-
my_node.node_inverse_matrix = mat;
415+
my_node.node_global_matrix = info.global_mat;
416+
my_node.node_global_matrix_prev = prev_mat;
417+
418+
my_node.node_inverse_matrix = info.global_mat;
417419
my_node.node_inverse_matrix.inverse();
418420

419421

420422
my_node.aabb.min = info.primitive->get_min();
421423
my_node.aabb.max = info.primitive->get_max();
422424

423425

424-
426+
need_update_mats = prev_mat != info.global_mat;
425427

426428
}
427429

@@ -579,9 +581,11 @@ nodes.emplace_back(node);
579581

580582
info.primitive_global = std::make_shared<AABB>();
581583

582-
mat4x4 mat = nodes.back().asset_node->mesh_matrix * global_transform;
583584

584-
info.primitive_global->apply_transform(info.primitive, mat);
585+
586+
info.global_mat = nodes.back().asset_node->mesh_matrix * global_transform;
587+
588+
info.primitive_global->apply_transform(info.primitive, info.global_mat);
585589

586590

587591
// node_buffer[node->index] = mat;
@@ -591,11 +595,12 @@ nodes.emplace_back(node);
591595
info.mesh_info.GetVertex_offset() = UINT(mesh_asset->vertex_handle.get_offset() + mesh_asset->meshes[m].vertex_offset) ;
592596

593597
auto &my_node = gpu_nodes[UINT(info.mesh_info.GetNode_offset() - nodes_handle.get_offset())];
594-
my_node.node_global_matrix = mat;
595-
my_node.node_inverse_matrix = mat;
598+
my_node.node_global_matrix = info.global_mat;
599+
my_node.node_inverse_matrix = info.global_mat;
596600
my_node.node_inverse_matrix.inverse();
597601

598-
602+
my_node.node_global_matrix_prev = info.global_mat;
603+
599604
my_node.aabb.min = info.primitive->get_min();
600605
my_node.aabb.max = info.primitive->get_max();
601606

sources/RenderSystem/Assets/MeshAsset.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ class MeshAssetInstance : public scene_object, public material_holder, public As
259259

260260
size_t nodes_count;
261261
size_t rendering_count;
262+
263+
bool need_update_mats = false;
262264
public:
263265
MESH_TYPE type= MESH_TYPE::STATIC;
264266
MeshAsset::ref mesh_asset;
@@ -287,7 +289,8 @@ class MeshAssetInstance : public scene_object, public material_holder, public As
287289
MaterialAsset* material;
288290

289291
UINT node_id;
290-
292+
mat4x4 global_mat;
293+
291294
//compiled
292295
Slots::MeshInfo::Compiled compiled_mesh_info;
293296

0 commit comments

Comments
 (0)