Skip to content

Commit 7ff03de

Browse files
Merge pull request #426 from FlyAndNotDown/master
2 parents ebf3377 + 32494b2 commit 7ff03de

27 files changed

Lines changed: 660 additions & 59 deletions

File tree

CMake/Target.cmake

Lines changed: 123 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,95 @@ function(exp_gather_target_runtime_dependencies_recurse)
8686
set(${arg_OUT_DEP_TARGET} ${result_dep_target} PARENT_SCOPE)
8787
endfunction()
8888

89+
# Every runtime file lands in the single shared per-sub-project Binaries directory. To keep the copies generator-agnostic
90+
# and race-free, each destination is owned by exactly one copy step rather than being re-copied by every consumer:
91+
# - files referenced through a target ($<TARGET_FILE:...>) get a per-file owner created in the consumer's scope, so the
92+
# generator expression resolves where the target is visible (imported third-party targets such as Qt are
93+
# directory-scoped and would be invisible in a global aggregate target). A first-party owner additionally waits on its
94+
# producing target; merging these into one target is impossible because a build tool such as MirrorTool consumes a dll
95+
# while another dll's producer transitively depends on the tool, which would close a build cycle;
96+
# - prebuilt third-party files given as plain paths, plus resources, carry no target and are batched (deduplicated) into
97+
# one per-sub-project assets target whose copies run sequentially (see exp_finalize_dist_assets).
98+
function(exp_add_runtime_dep_copy)
99+
set(options "")
100+
set(singleValueArgs KEY SRC PRODUCER OUTPUT_TARGET)
101+
set(multiValueArgs "")
102+
cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN})
103+
104+
string(MAKE_C_IDENTIFIER "${arg_KEY}" key_id)
105+
set(registry_property EXP_RUNTIME_DEP_COPY_${SUB_PROJECT_NAME}_${key_id})
106+
107+
get_property(copy_target GLOBAL PROPERTY ${registry_property})
108+
if (NOT copy_target)
109+
exp_get_runtime_output_dir(OUTPUT out_dir)
110+
set(copy_target ${SUB_PROJECT_NAME}.CopyDll.${key_id})
111+
add_custom_target(
112+
${copy_target}
113+
COMMAND ${CMAKE_COMMAND} -E make_directory ${out_dir}
114+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${arg_SRC} ${out_dir}
115+
)
116+
set_target_properties(${copy_target} PROPERTIES FOLDER ${AUX_TARGETS_FOLDER})
117+
if (arg_PRODUCER)
118+
add_dependencies(${copy_target} ${arg_PRODUCER})
119+
endif ()
120+
set_property(GLOBAL PROPERTY ${registry_property} ${copy_target})
121+
endif ()
122+
123+
set(${arg_OUTPUT_TARGET} ${copy_target} PARENT_SCOPE)
124+
endfunction()
125+
126+
function(exp_schedule_dist_assets_finalize)
127+
get_property(scheduled GLOBAL PROPERTY EXP_DIST_ASSETS_SCHEDULED_${SUB_PROJECT_NAME})
128+
if (NOT scheduled)
129+
set_property(GLOBAL PROPERTY EXP_DIST_ASSETS_SCHEDULED_${SUB_PROJECT_NAME} TRUE)
130+
cmake_language(DEFER DIRECTORY ${CMAKE_SOURCE_DIR} CALL exp_finalize_dist_assets "${SUB_PROJECT_NAME}")
131+
endif ()
132+
endfunction()
133+
134+
function(exp_finalize_dist_assets sub_project)
135+
get_property(asset_files GLOBAL PROPERTY EXP_DIST_ASSET_FILES_${sub_project})
136+
get_property(asset_resources GLOBAL PROPERTY EXP_DIST_ASSET_RESOURCES_${sub_project})
137+
get_property(consumers GLOBAL PROPERTY EXP_DIST_ASSET_CONSUMERS_${sub_project})
138+
139+
if (NOT asset_files AND NOT asset_resources)
140+
return()
141+
endif ()
142+
143+
if (with_multi_config_generator)
144+
set(out_dir ${CMAKE_BINARY_DIR}/Dist/$<CONFIG>/${sub_project}/Binaries)
145+
else ()
146+
set(out_dir ${CMAKE_BINARY_DIR}/Dist/${sub_project}/Binaries)
147+
endif ()
148+
149+
set(copy_commands COMMAND ${CMAKE_COMMAND} -E make_directory ${out_dir})
150+
if (asset_files)
151+
list(REMOVE_DUPLICATES asset_files)
152+
foreach (f ${asset_files})
153+
list(APPEND copy_commands COMMAND ${CMAKE_COMMAND} -E copy_if_different ${f} ${out_dir})
154+
endforeach ()
155+
endif ()
156+
if (asset_resources)
157+
list(REMOVE_DUPLICATES asset_resources)
158+
foreach (entry ${asset_resources})
159+
string(REPLACE "->" ";" pair "${entry}")
160+
list(GET pair 0 src)
161+
list(GET pair 1 dst)
162+
list(APPEND copy_commands COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${out_dir}/${dst})
163+
endforeach ()
164+
endif ()
165+
166+
set(copy_target ${sub_project}.CopyDistAssets)
167+
add_custom_target(${copy_target} ${copy_commands})
168+
set_target_properties(${copy_target} PROPERTIES FOLDER ${sub_project}/Aux)
169+
170+
if (consumers)
171+
list(REMOVE_DUPLICATES consumers)
172+
foreach (consumer ${consumers})
173+
add_dependencies(${consumer} ${copy_target})
174+
endforeach ()
175+
endif ()
176+
endfunction()
177+
89178
function(exp_process_runtime_dependencies)
90179
set(options NOT_INSTALL)
91180
set(singleValueArgs NAME)
@@ -105,28 +194,41 @@ function(exp_process_runtime_dependencies)
105194
OUT_DEP_TARGET dep_dep_targets
106195
)
107196
list(APPEND runtime_deps ${dep_target_runtime_deps})
108-
list(APPEND dep_targets ${dep_dep_targets})
109197
endforeach ()
110198

111-
set(copy_commands COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:${arg_NAME}>)
112-
foreach(r ${runtime_deps})
113-
list(APPEND copy_commands COMMAND ${CMAKE_COMMAND} -E copy_if_different ${r} $<TARGET_FILE_DIR:${arg_NAME}>)
114-
endforeach()
115-
if (NOT "${copy_commands}" STREQUAL "")
116-
set(custom_target_name ${arg_NAME}.CopyRuntimeDeps)
117-
add_custom_target(
118-
${custom_target_name}
119-
${copy_commands}
120-
)
199+
if (runtime_deps)
200+
list(REMOVE_DUPLICATES runtime_deps)
201+
endif ()
121202

122-
add_dependencies(${arg_NAME} ${custom_target_name})
123-
foreach (t ${dep_targets})
124-
add_dependencies(${custom_target_name} ${t})
125-
endforeach ()
203+
foreach (r ${runtime_deps})
204+
set(referenced "")
205+
if ("${r}" MATCHES "^\\$<TARGET_FILE:(.+)>$")
206+
set(referenced ${CMAKE_MATCH_1})
207+
endif ()
126208

127-
set_target_properties(${custom_target_name} PROPERTIES FOLDER ${AUX_TARGETS_FOLDER})
128-
endif ()
129-
if (NOT arg_NOT_INSTALL AND NOT "${runtime_deps}" STREQUAL "")
209+
if (referenced AND TARGET ${referenced})
210+
set(producer "")
211+
get_target_property(referenced_imported ${referenced} IMPORTED)
212+
if (NOT referenced_imported)
213+
set(producer ${referenced})
214+
endif ()
215+
216+
exp_add_runtime_dep_copy(
217+
KEY ${r}
218+
SRC ${r}
219+
PRODUCER ${producer}
220+
OUTPUT_TARGET copy_target
221+
)
222+
add_dependencies(${arg_NAME} ${copy_target})
223+
else ()
224+
set_property(GLOBAL APPEND PROPERTY EXP_DIST_ASSET_FILES_${SUB_PROJECT_NAME} ${r})
225+
endif ()
226+
endforeach ()
227+
228+
set_property(GLOBAL APPEND PROPERTY EXP_DIST_ASSET_CONSUMERS_${SUB_PROJECT_NAME} ${arg_NAME})
229+
exp_schedule_dist_assets_finalize()
230+
231+
if (NOT arg_NOT_INSTALL AND runtime_deps)
130232
install(
131233
FILES ${runtime_deps} DESTINATION ${SUB_PROJECT_NAME}/Binaries
132234
)
@@ -160,7 +262,7 @@ function(exp_add_resources_copy_command)
160262
OUTPUT_DST dst
161263
)
162264

163-
list(APPEND copy_commands COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} $<TARGET_FILE_DIR:${arg_NAME}>/${dst})
265+
set_property(GLOBAL APPEND PROPERTY EXP_DIST_ASSET_RESOURCES_${SUB_PROJECT_NAME} "${src}->${dst}")
164266

165267
cmake_path(SET dst_path NORMALIZE "${SUB_PROJECT_NAME}/Binaries/${dst}")
166268
cmake_path(GET dst_path PARENT_PATH dst_dir)
@@ -169,13 +271,8 @@ function(exp_add_resources_copy_command)
169271
endif ()
170272
endforeach()
171273

172-
set(copy_res_target_name ${arg_NAME}.CopyRes)
173-
add_custom_target(
174-
${copy_res_target_name}
175-
${copy_commands}
176-
)
177-
set_target_properties(${copy_res_target_name} PROPERTIES FOLDER ${AUX_TARGETS_FOLDER})
178-
add_dependencies(${arg_NAME} ${copy_res_target_name})
274+
set_property(GLOBAL APPEND PROPERTY EXP_DIST_ASSET_CONSUMERS_${SUB_PROJECT_NAME} ${arg_NAME})
275+
exp_schedule_dist_assets_finalize()
179276
endfunction()
180277

181278
function(exp_gather_target_libs)

Engine/Source/RHI-DirectX12/Include/RHI/DirectX12/CommandRecorder.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace RHI::DirectX12 {
2020
~DX12CommandRecorder() override;
2121

2222
void ResourceBarrier(const Barrier& inBarrier) override;
23+
void BeginMarker(const std::string& inLabel) override;
24+
void EndMarker() override;
2325
Common::UniquePtr<CopyPassCommandRecorder> BeginCopyPass() override;
2426
Common::UniquePtr<ComputePassCommandRecorder> BeginComputePass() override;
2527
Common::UniquePtr<RasterPassCommandRecorder> BeginRasterPass(const RasterPassBeginInfo& inBeginInfo) override;
@@ -38,6 +40,8 @@ namespace RHI::DirectX12 {
3840

3941
// CommonCommandRecorder
4042
void ResourceBarrier(const Barrier& inBarrier) override;
43+
void BeginMarker(const std::string& inLabel) override;
44+
void EndMarker() override;
4145

4246
// CopyPassCommandRecorder
4347
void CopyBufferToBuffer(Buffer* src, Buffer* dst, const BufferCopyInfo& copyInfo) override;
@@ -60,6 +64,8 @@ namespace RHI::DirectX12 {
6064

6165
// CommonCommandRecorder
6266
void ResourceBarrier(const Barrier& inBarrier) override;
67+
void BeginMarker(const std::string& inLabel) override;
68+
void EndMarker() override;
6369

6470
// ComputePassCommandRecorder
6571
void SetPipeline(ComputePipeline* inPipeline) override;
@@ -82,6 +88,8 @@ namespace RHI::DirectX12 {
8288

8389
// CommonCommandRecorder
8490
void ResourceBarrier(const Barrier& inBarrier) override;
91+
void BeginMarker(const std::string& inLabel) override;
92+
void EndMarker() override;
8593

8694
// RasterPassCommandRecorder
8795
void SetPipeline(RasterPipeline* inPipeline) override;
@@ -95,6 +103,10 @@ namespace RHI::DirectX12 {
95103
void SetPrimitiveTopology(PrimitiveTopology inPrimitiveTopology) override;
96104
void SetBlendConstant(const float* inConstants) override;
97105
void SetStencilReference(uint32_t inReference) override;
106+
void DrawIndirect(Buffer* inIndirectBuffer, size_t inOffset) override;
107+
void DrawIndexedIndirect(Buffer* inIndirectBuffer, size_t inOffset) override;
108+
void MultiDrawIndirect(Buffer* inIndirectBuffer, size_t inOffset, size_t inDrawCount) override;
109+
void MultiDrawIndexedIndirect(Buffer* inIndirectBuffer, size_t inOffset, size_t inDrawCount) override;
98110
void EndPass() override;
99111

100112
private:

Engine/Source/RHI-DirectX12/Include/RHI/DirectX12/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ namespace RHI::DirectX12 {
252252
ECIMPL_ITEM(BufferState::shaderReadOnly, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE)
253253
ECIMPL_ITEM(BufferState::storage, D3D12_RESOURCE_STATE_COMMON)
254254
ECIMPL_ITEM(BufferState::rwStorage, D3D12_RESOURCE_STATE_UNORDERED_ACCESS)
255+
ECIMPL_ITEM(BufferState::indirect, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT)
255256
ECIMPL_END(D3D12_RESOURCE_STATES)
256257

257258
ECIMPL_BEGIN(TextureDimension, D3D12_RESOURCE_DIMENSION)

Engine/Source/RHI-DirectX12/Include/RHI/DirectX12/Device.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ namespace RHI::DirectX12 {
9595
TextureSubResourceCopyFootprint GetTextureSubResourceCopyFootprint(const Texture& texture, const TextureSubResourceInfo& subResourceInfo) override;
9696

9797
ID3D12Device* GetNative() const;
98+
ID3D12CommandSignature* GetDrawIndirectCommandSignature() const;
99+
ID3D12CommandSignature* GetDrawIndexedIndirectCommandSignature() const;
98100
Common::UniquePtr<DescriptorAllocation> AllocateRtvDescriptor() const;
99101
Common::UniquePtr<DescriptorAllocation> AllocateCbvSrvUavDescriptor() const;
100102
Common::UniquePtr<DescriptorAllocation> AllocateSamplerDescriptor() const;
@@ -105,6 +107,7 @@ namespace RHI::DirectX12 {
105107
void CreateNativeQueues(const DeviceCreateInfo& inCreateInfo);
106108
void QueryNativeDescriptorSize();
107109
void CreateDescriptorPools();
110+
void CreateDrawIndirectCommandSignatures();
108111
#if BUILD_CONFIG_DEBUG
109112
void RegisterNativeDebugLayerExceptionHandler();
110113
void UnregisterNativeDebugLayerExceptionHandler();
@@ -122,5 +125,7 @@ namespace RHI::DirectX12 {
122125
Common::UniquePtr<DescriptorPool> samplerDescriptorPool;
123126
Common::UniquePtr<DescriptorPool> dsvDescriptorPool;
124127
ComPtr<ID3D12Device> nativeDevice;
128+
ComPtr<ID3D12CommandSignature> drawIndirectCommandSignature;
129+
ComPtr<ID3D12CommandSignature> drawIndexedIndirectCommandSignature;
125130
};
126131
}

Engine/Source/RHI-DirectX12/Include/RHI/DirectX12/Gpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace RHI::DirectX12 {
2020
~DX12Gpu() override;
2121

2222
GpuProperty GetProperty() override;
23+
FeatureFlags GetFeatures() override;
24+
GpuLimits GetLimits() override;
2325
Common::UniquePtr<Device> RequestDevice(const DeviceCreateInfo& inCreateInfo) override;
2426
DX12Instance& GetInstance() const override;
2527

Engine/Source/RHI-DirectX12/Src/Buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace RHI::DirectX12 {
8080
void* data;
8181
const CD3DX12_RANGE range(inOffset, inOffset + inLength);
8282
Assert(SUCCEEDED(nativeResource->Map(0, &range, &data)));
83-
return data;
83+
return static_cast<uint8_t*>(data) + inOffset;
8484
}
8585

8686
void DX12Buffer::Unmap()

0 commit comments

Comments
 (0)