aboutsummaryrefslogtreecommitdiffstats
path: root/api-test/dx12-command-buffer.cpp
diff options
context:
space:
mode:
authorQuentin LADEVIE <qladevie@wanadev.fr>2025-01-26 22:27:10 +0100
committerQuentin LADEVIE <qladevie@wanadev.fr>2025-01-26 22:27:10 +0100
commitc29105b461135f3909cca0308fb05715cee45763 (patch)
tree49c6c41bb88377f6af73ebdf39821038b88b05cf /api-test/dx12-command-buffer.cpp
parent3490db941ea16e67da72f60ebda75ec0f8bb8051 (diff)
DX12 command buffers and resourcesapi-proto
Diffstat (limited to 'api-test/dx12-command-buffer.cpp')
-rw-r--r--api-test/dx12-command-buffer.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/api-test/dx12-command-buffer.cpp b/api-test/dx12-command-buffer.cpp
new file mode 100644
index 0000000..0310dfd
--- /dev/null
+++ b/api-test/dx12-command-buffer.cpp
@@ -0,0 +1,47 @@
+#include "dx12-command-buffer.hpp"
+
+#include "dx12-device.hpp"
+
+namespace dx12 {
+ void command_buffer::start() const {
+ HRESULT hr = command_allocator->Reset();
+ assert(hr == S_OK);
+
+ hr = dx12_command_buffer->Reset(command_allocator, nullptr);
+ assert(hr == S_OK);
+
+ auto& device = dx12::device::get_render_device();
+ dx12_command_buffer->SetDescriptorHeaps(2U, dx12::device::get_bindless_model().get_heaps());
+ }
+
+ void command_buffer::stop() const {
+ HRESULT hr = dx12_command_buffer->Close();
+ assert(hr == S_OK);
+ }
+
+ void command_buffer::copy(handle<device_buffer> src_buffer, handle<device_texture> dst_texture, uint64_t offset) const {
+ auto& dst = device::get_render_device().get_texture(dst_texture);
+ D3D12_TEXTURE_COPY_LOCATION dst_copy_location {
+ .pResource = dst.resource,
+ .Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
+ .SubresourceIndex = 0U,
+ };
+
+ auto& src = device::get_render_device().get_buffer(src_buffer);
+ D3D12_TEXTURE_COPY_LOCATION src_copy_location {
+ .pResource = src.resource,
+ .Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
+ .PlacedFootprint = {
+ .Offset = offset,
+ .Footprint = {
+ .Format = dst.format,
+ .Width = dst.width,
+ .Height = dst.height,
+ .Depth = dst.depth,
+ .RowPitch = static_cast<UINT>(dst.row_pitch),
+ },
+ },
+ };
+ dx12_command_buffer->CopyTextureRegion(&dst_copy_location, 0U, 0U, 0U, &src_copy_location, nullptr);
+ }
+}