Skip to content

Commit 1cb8658

Browse files
committed
small refactor
1 parent 252cbe5 commit 1cb8658

File tree

103 files changed

+1562
-662
lines changed

Some content is hidden

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

103 files changed

+1562
-662
lines changed

sources/Core/Allocators/Allocators.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,13 @@ class DataProvider
385385
template<class T>
386386
class TypedHandle
387387
{
388-
//: public AllocatorHanle
389-
390388
DataProvider<T>* provider = nullptr;
391389
public:
392390

393391
AllocatorHanle handle;
394392

395393
TypedHandle() = default;
396-
TypedHandle(AllocatorHanle& handle, DataProvider<T>* provider) :handle(handle), provider(provider)
394+
TypedHandle(AllocatorHanle& handle, DataProvider<T>* provider) : handle(handle), provider(provider)
397395
{
398396
//assert(handle.get_size());
399397
}
@@ -406,6 +404,12 @@ class TypedHandle
406404
{
407405
return handle.get_offset();
408406
}
407+
408+
size_t get_size()
409+
{
410+
return handle.get_size();
411+
}
412+
409413
std::span<T> aquire()
410414
{
411415
return provider->aquire(handle.get_offset(), handle.get_size());
@@ -464,9 +468,11 @@ class DataAllocator : private AllocatorType, public DataProvider<T>
464468
return Handle(handle, this);
465469
}
466470

467-
void Free(TypedHandle<T>& handle)
471+
void Free(Handle& handle)
468472
{
469473
std::lock_guard<std::mutex> g(m);
474+
475+
on_free(handle.get_offset(), handle.get_offset()+ handle.get_size());
470476
handle.handle.Free();
471477
}
472478

@@ -479,6 +485,8 @@ class DataAllocator : private AllocatorType, public DataProvider<T>
479485

480486
}
481487

488+
virtual void on_free(size_t from, size_t to) {
482489

490+
}
483491

484492
};

sources/Core/Log/Log.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,11 @@ class ClassLogger: public Singleton<ClassLogger<T>>
236236
template<class T>
237237
LogBlock operator<<(const T& smth)
238238
{
239-
return LogBlock(Log::get(), logging_level) << smth;
239+
240+
auto block = LogBlock(Log::get(), logging_level);
241+
block << smth;
242+
243+
return block;
240244
}
241245
};
242246

sources/Core/patterns/Singleton.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
template <typename T>
33
Singleton<T>::~Singleton()
44
{
5-
if (!std::is_same<T, Log>::value)
5+
/*if (!std::is_same<T, Log>::value)
66
if (!std::is_same<T, ClassLogger<singleton_system>>::value)
77
ClassLogger<singleton_system>::get() << Log::LEVEL_DEBUG << "Singleton deleting " << typeid(T).name() << Log::endl;
88
else
9-
OutputDebugStringA((string("Singleton deleting ") + typeid(T).name() + "\n").c_str());
9+
OutputDebugStringA((string("Singleton deleting ") + typeid(T).name() + "\n").c_str());*/
1010
}
1111

1212
template <typename T>
1313
Singleton<T>::Singleton()
1414
{
15-
if (!std::is_same<T, Log>::value)
15+
/*if (!std::is_same<T, Log>::value)
1616
if (!std::is_same<T, ClassLogger<singleton_system>>::value)
1717
ClassLogger<singleton_system>::get() << Log::LEVEL_DEBUG << "Singleton creating " << typeid(T).name() << Log::endl;
1818
else
19-
OutputDebugStringA((string("Singleton creating ") + typeid(T).name() + "\n").c_str());
19+
OutputDebugStringA((string("Singleton creating ") + typeid(T).name() + "\n").c_str());*/
2020
}

sources/Core/pch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ using namespace std;
5656
#pragma warning(disable:4512)
5757
#pragma warning(disable:4100)
5858
#pragma warning(disable:4310)
59+
5960
#include <magic_enum.hpp>
6061

6162
#include <boost/predef/other/endian.h>

sources/DirectXFramework/DX12/Buffer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ namespace DX12
359359
auto list = Device::get().get_upload_list();
360360
set_data(list, offset, v);
361361
list->end();
362-
list->execute();
362+
list->execute_and_wait();
363363
}
364364

365365

@@ -527,7 +527,7 @@ namespace DX12
527527
data.resize(size);
528528
}
529529

530-
update_data(size_t offset, std::vector<T>&& v) :offset(offset), data(std::move(v))
530+
update_data(size_t offset, std::vector<T>& v) :offset(offset), data(v)
531531
{
532532
size = data.size();
533533
}
@@ -554,7 +554,7 @@ namespace DX12
554554

555555
virtual void write(size_t offset, std::vector<T>& v) override {
556556
std::lock_guard<std::mutex> g(m);
557-
update_list.emplace_back(offset, std::move(v));
557+
update_list.emplace_back(offset, v);
558558
}
559559

560560

sources/DirectXFramework/DX12/CommandList.cpp

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,19 @@ namespace DX12
114114

115115
void GraphicsContext::begin()
116116
{
117+
reset();
117118
topology = D3D_PRIMITIVE_TOPOLOGY::D3D_PRIMITIVE_TOPOLOGY_UNDEFINED;
118119
reset_tables();
119120
index = IndexBufferView();
120121
}
121122
void GraphicsContext::end()
122123
{
123-
current_root_signature = nullptr;
124+
//current_root_signature = nullptr;
124125
}
125126

126127
void ComputeContext::begin()
127128
{
129+
reset();
128130
reset_tables();
129131
}
130132
void ComputeContext::end()
@@ -193,14 +195,9 @@ namespace DX12
193195
});
194196
}
195197

196-
void GraphicsContext::set_signature(const RootSignature::ptr& s)
198+
void GraphicsContext::on_set_signature(const RootSignature::ptr& s)
197199
{
198-
assert(s);
199-
if (current_root_signature != s)
200-
{
201-
list->SetGraphicsRootSignature(s->get_native().Get());
202-
current_root_signature = s;
203-
}
200+
list->SetGraphicsRootSignature(s->get_native().Get());
204201
}
205202

206203
void GraphicsContext::set_heaps(DescriptorHeap::ptr& a, DescriptorHeap::ptr& b)
@@ -478,13 +475,13 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
478475

479476
base.create_transition_point(false);
480477
}
481-
478+
/*
482479
void GraphicsContext::set_pipeline(PipelineState::ptr state)
483480
{
484481
set_signature(state->desc.root_signature);
485482
base.set_pipeline_internal(state.get());
486483
}
487-
484+
*/
488485
void GraphicsContext::set_layout(Layouts layout)
489486
{
490487
set_signature(get_Signature(layout));
@@ -626,7 +623,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
626623
void Transitions::create_transition_point(bool end)
627624
{
628625
auto prev_point = transition_points.empty()?nullptr: &transition_points.back();
629-
auto point = &transition_points.emplace_back();
626+
auto point = &transition_points.emplace_back(type);
630627

631628
if(prev_point) prev_point->next_point = point;
632629
point->prev_point = prev_point;
@@ -637,9 +634,9 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
637634
{
638635
assert(point->prev_point->start);
639636
}
640-
compiler.func([point](ID3D12GraphicsCommandList4* list)
637+
compiler.func([point,this](ID3D12GraphicsCommandList4* list)
641638
{
642-
Barriers transitions;
639+
Barriers transitions(type);
643640

644641
for (auto uav : point->uav_transitions)
645642
{
@@ -721,7 +718,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
721718
{
722719
PROFILE(L"fix_pretransitions");
723720

724-
Barriers result;
721+
Barriers result(CommandListType::DIRECT);
725722
std::vector<Resource*> discards;
726723

727724

@@ -955,20 +952,16 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
955952
}
956953

957954

958-
void ComputeContext::set_signature(const RootSignature::ptr& s)
955+
void ComputeContext::on_set_signature(const RootSignature::ptr& s)
959956
{
960-
if (s != current_compute_root_signature)
961-
{
962-
current_compute_root_signature = s;
963-
list->SetComputeRootSignature(s->get_native().Get());
964-
}
957+
list->SetComputeRootSignature(s->get_native().Get());
965958
}
959+
966960
void ComputeContext::dispach(int x, int y, int z)
967961
{
968-
PROFILE_GPU(L"Dispatch");
969-
base.setup_debug(this);
970-
962+
PROFILE_GPU(L"Dispatch");
971963
base.create_transition_point();
964+
base.setup_debug(this);
972965
commit_tables();
973966
flush_binds();
974967

@@ -999,7 +992,8 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
999992
{
1000993
list->SetComputeRootDescriptorTable(i, table.gpu);
1001994
}
1002-
995+
996+
/*
1003997
void ComputeContext::set_pipeline(ComputePipelineState::ptr state)
1004998
{
1005999
if (state->desc.root_signature)
@@ -1009,7 +1003,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
10091003
10101004
base.track_object(*state);
10111005
}
1012-
1006+
*/
10131007
void ComputeContext::set_pso(std::shared_ptr<StateObject>& pso)
10141008
{
10151009
base.set_pipeline_internal(nullptr);
@@ -1160,10 +1154,10 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
11601154
void GraphicsContext::execute_indirect(IndirectCommand& command_types, UINT max_commands, Resource* command_buffer, UINT64 command_offset, Resource* counter_buffer, UINT64 counter_offset)
11611155
{
11621156
PROFILE_GPU(L"execute_indirect");
1163-
base.setup_debug(this);
11641157
base.create_transition_point();
11651158

1166-
1159+
base.setup_debug(this);
1160+
11671161
if (command_buffer) get_base().transition(command_buffer, ResourceState::INDIRECT_ARGUMENT);
11681162
if (counter_buffer) get_base().transition(counter_buffer, ResourceState::INDIRECT_ARGUMENT);
11691163

@@ -1320,4 +1314,40 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
13201314
{
13211315
return m_commandList;
13221316
}
1317+
1318+
1319+
void SignatureDataSetter::set_pipeline(std::shared_ptr<PipelineStateBase> pipeline)
1320+
{
1321+
/*
1322+
{
1323+
for (auto& s : used_slots.slots_usage)
1324+
{
1325+
auto slot_id = get_slot_id(s);
1326+
auto& slot = slots[slot_id];
1327+
1328+
auto& used_tables = *slot.tables;
1329+
1330+
for (auto& id : used_tables)
1331+
{
1332+
auto& table = tables[id].table;
1333+
1334+
for (UINT i = 0; i < (UINT)table.get_count(); ++i)
1335+
{
1336+
const auto& h = table[i];
1337+
1338+
base.stop_using(h.resource_info);
1339+
1340+
}
1341+
}
1342+
}
1343+
}
1344+
*/
1345+
if (pipeline->root_signature)
1346+
set_signature(pipeline->root_signature);
1347+
1348+
base.set_pipeline_internal(pipeline.get());
1349+
1350+
1351+
used_slots = pipeline->slots;
1352+
}
13231353
}

0 commit comments

Comments
 (0)