Skip to content

Commit

Permalink
Implement texture to texture copy
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 16, 2024
1 parent db6641c commit 8009020
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void kope_d3d12_command_list_set_descriptor_table(kope_g5_command_list *list, ui
}
}

void kope_g5_command_list_copy_buffer_to_texture(kope_g5_command_list *list, kope_g5_buffer *source, kope_g5_texture *destination, kope_uint3 size) {
void kope_d3d12_command_list_copy_buffer_to_texture(kope_g5_command_list *list, kope_g5_buffer *source, kope_g5_texture *destination, kope_uint3 size) {
if (source->d3d12.resource_state != D3D12_RESOURCE_STATE_COPY_SOURCE) {
D3D12_RESOURCE_BARRIER barrier;
barrier.Transition.pResource = source->d3d12.resource;
Expand Down Expand Up @@ -162,6 +162,48 @@ void kope_g5_command_list_copy_buffer_to_texture(kope_g5_command_list *list, kop
list->d3d12.list->CopyTextureRegion(&dst, 0, 0, 0, &src, NULL);
}

void kope_d3d12_command_list_copy_texture_to_texture(kope_g5_command_list *list, kope_g5_texture *source, kope_g5_texture *destination, kope_uint3 size) {
if (source->d3d12.resource_state != D3D12_RESOURCE_STATE_COPY_SOURCE) {
D3D12_RESOURCE_BARRIER barrier;
barrier.Transition.pResource = source->d3d12.resource;
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
barrier.Transition.StateBefore = (D3D12_RESOURCE_STATES)source->d3d12.resource_state;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE;
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;

list->d3d12.list->ResourceBarrier(1, &barrier);

source->d3d12.resource_state = D3D12_RESOURCE_STATE_COPY_SOURCE;
}

if (destination->d3d12.resource_state != D3D12_RESOURCE_STATE_COPY_DEST) {
D3D12_RESOURCE_BARRIER barrier;
barrier.Transition.pResource = destination->d3d12.resource;
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
barrier.Transition.StateBefore = (D3D12_RESOURCE_STATES)destination->d3d12.resource_state;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST;
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;

list->d3d12.list->ResourceBarrier(1, &barrier);

destination->d3d12.resource_state = D3D12_RESOURCE_STATE_COPY_DEST;
}

D3D12_TEXTURE_COPY_LOCATION dst;
dst.pResource = destination->d3d12.resource;
dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
dst.SubresourceIndex = 0;

D3D12_TEXTURE_COPY_LOCATION src;
src.pResource = source->d3d12.resource;
src.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
src.SubresourceIndex = 0;

list->d3d12.list->CopyTextureRegion(&dst, 0, 0, 0, &src, NULL);
}

void kope_d3d12_command_list_set_compute_pipeline(kope_g5_command_list *list, kope_d3d12_compute_pipeline *pipeline) {
list->d3d12.compute_pipeline_set = true;
list->d3d12.list->SetPipelineState(pipeline->pipe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
extern "C" {
#endif

void kope_d3d12_command_list_copy_buffer_to_texture(kope_g5_command_list *list, kope_g5_buffer *source, kope_g5_texture *destination, kope_uint3 size);

void kope_d3d12_command_list_copy_texture_to_texture(kope_g5_command_list *list, kope_g5_texture *source, kope_g5_texture *destination, kope_uint3 size);

void kope_d3d12_command_list_begin_render_pass(kope_g5_command_list *list, const kope_g5_render_pass_parameters *parameters);

void kope_d3d12_command_list_end_render_pass(kope_g5_command_list *list);
Expand Down
8 changes: 8 additions & 0 deletions Sources/kope/graphics5/commandlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
#include <kope/vulkan/commandlist_functions.h>
#endif

void kope_g5_command_list_copy_buffer_to_texture(kope_g5_command_list *list, kope_g5_buffer *source, kope_g5_texture *destination, kope_uint3 size) {
KOPE_G5_CALL4(command_list_copy_buffer_to_texture, list, source, destination, size);
}

void kope_g5_command_list_copy_texture_to_texture(kope_g5_command_list *list, kope_g5_texture *source, kope_g5_texture *destination, kope_uint3 size) {
KOPE_G5_CALL4(command_list_copy_texture_to_texture, list, source, destination, size);
}

void kope_g5_command_list_begin_render_pass(kope_g5_command_list *list, const kope_g5_render_pass_parameters *parameters) {
KOPE_G5_CALL2(command_list_begin_render_pass, list, parameters);
}
Expand Down

0 comments on commit 8009020

Please sign in to comment.