From c29105b461135f3909cca0308fb05715cee45763 Mon Sep 17 00:00:00 2001 From: Quentin LADEVIE Date: Sun, 26 Jan 2025 22:27:10 +0100 Subject: DX12 command buffers and resources --- api-test/dx12-command-buffer.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 api-test/dx12-command-buffer.cpp (limited to 'api-test/dx12-command-buffer.cpp') 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 src_buffer, handle 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(dst.row_pitch), + }, + }, + }; + dx12_command_buffer->CopyTextureRegion(&dst_copy_location, 0U, 0U, 0U, &src_copy_location, nullptr); + } +} -- cgit v1.3