Skip to content

Commit

Permalink
Implement some missing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Sep 28, 2024
1 parent 30c3ff0 commit dab5731
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ void kope_d3d12_command_list_set_render_pipeline(kope_g5_command_list *list, kop
list->d3d12.list->SetGraphicsRootSignature(pipeline->root_signature);
}

void kope_d3d12_command_list_draw(kope_g5_command_list *list, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance) {
list->d3d12.list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
list->d3d12.list->DrawInstanced(vertex_count, instance_count, first_vertex, first_instance);
}

void kope_d3d12_command_list_draw_indexed(kope_g5_command_list *list, uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t base_vertex,
uint32_t first_instance) {
list->d3d12.list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
Expand Down Expand Up @@ -218,6 +223,39 @@ void kope_d3d12_command_list_set_root_constants(kope_g5_command_list *list, uint
}
}

void kope_d3d12_command_list_copy_buffer_to_buffer(kope_g5_command_list *list, kope_g5_buffer *source, uint64_t source_offset, kope_g5_buffer *destination,
uint64_t destination_offset, uint64_t size) {
if (source->d3d12.resource_state != D3D12_RESOURCE_STATE_COPY_SOURCE && source->d3d12.resource_state != D3D12_RESOURCE_STATE_GENERIC_READ) {
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;
}

list->d3d12.list->CopyBufferRegion(destination->d3d12.resource, destination_offset, source->d3d12.resource, source_offset, size);
}

void kope_d3d12_command_list_copy_buffer_to_texture(kope_g5_command_list *list, const kope_g5_image_copy_buffer *source,
const kope_g5_image_copy_texture *destination, uint32_t width, uint32_t height,
uint32_t depth_or_array_layers) {
Expand Down Expand Up @@ -417,6 +455,12 @@ void kope_d3d12_command_list_copy_texture_to_texture(kope_g5_command_list *list,
list->d3d12.list->CopyTextureRegion(&dst, destination->origin_x, destination->origin_y, destination->origin_z, &src, &source_box);
}

void kope_d3d12_command_list_clear_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer, size_t offset, uint64_t size) {
UINT values[4] = {0};
// TODO
// list->d3d12.list->ClearUnorderedAccessViewUint(a, b, buffer->d3d12.resource, values, 0, 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 Expand Up @@ -555,3 +599,36 @@ void kope_d3d12_command_list_trace_rays(kope_g5_command_list *list, uint32_t wid

list->d3d12.list->DispatchRays(&desc);
}

void kope_d3d12_command_list_set_viewport(kope_g5_command_list *list, float x, float y, float width, float height, float min_depth, float max_depth) {
D3D12_VIEWPORT viewport = {0};
viewport.TopLeftX = x;
viewport.TopLeftY = y;
viewport.Width = width;
viewport.Height = height;
viewport.MinDepth = min_depth;
viewport.MaxDepth = max_depth;
list->d3d12.list->RSSetViewports(1, &viewport);
}

void kope_d3d12_command_list_set_scissor_rect(kope_g5_command_list *list, uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
D3D12_RECT rect = {0};
rect.left = x;
rect.right = rect.left + width;
rect.top = y;
rect.bottom = rect.top + height;
list->d3d12.list->RSSetScissorRects(1, &rect);
}

void kope_d3d12_command_list_set_blend_constant(kope_g5_command_list *list, kope_g5_color color) {
float color_array[4] = {0};
color_array[0] = color.r;
color_array[1] = color.g;
color_array[2] = color.b;
color_array[3] = color.a;
list->d3d12.list->OMSetBlendFactor(color_array);
}

void kope_d3d12_command_list_set_stencil_reference(kope_g5_command_list *list, uint32_t reference) {
list->d3d12.list->OMSetStencilRef(reference);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
extern "C" {
#endif

void kope_d3d12_command_list_copy_buffer_to_buffer(kope_g5_command_list *list, kope_g5_buffer *source, uint64_t source_offset, kope_g5_buffer *destination,
uint64_t destination_offset, uint64_t size);

void kope_d3d12_command_list_copy_buffer_to_texture(kope_g5_command_list *list, const kope_g5_image_copy_buffer *source,
const kope_g5_image_copy_texture *destination, uint32_t width, uint32_t height,
uint32_t depth_or_array_layers);
Expand All @@ -22,12 +25,22 @@ void kope_d3d12_command_list_copy_texture_to_texture(kope_g5_command_list *list,
const kope_g5_image_copy_texture *destination, uint32_t width, uint32_t height,
uint32_t depth_or_array_layers);

void kope_d3d12_command_list_clear_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer, size_t offset, uint64_t 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);

void kope_d3d12_command_list_present(kope_g5_command_list *list);

void kope_d3d12_command_list_set_viewport(kope_g5_command_list *list, float x, float y, float width, float height, float min_depth, float max_depth);

void kope_d3d12_command_list_set_scissor_rect(kope_g5_command_list *list, uint32_t x, uint32_t y, uint32_t width, uint32_t height);

void kope_d3d12_command_list_set_blend_constant(kope_g5_command_list *list, kope_g5_color color);

void kope_d3d12_command_list_set_stencil_reference(kope_g5_command_list *list, uint32_t reference);

void kope_d3d12_command_list_set_index_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer, kope_g5_index_format index_format, uint64_t offset,
uint64_t size);

Expand All @@ -36,6 +49,8 @@ void kope_d3d12_command_list_set_vertex_buffer(kope_g5_command_list *list, uint3

void kope_d3d12_command_list_set_render_pipeline(kope_g5_command_list *list, kope_d3d12_render_pipeline *pipeline);

void kope_d3d12_command_list_draw(kope_g5_command_list *list, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance);

void kope_d3d12_command_list_draw_indexed(kope_g5_command_list *list, uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t base_vertex,
uint32_t first_instance);

Expand Down
2 changes: 2 additions & 0 deletions Sources/kope/graphics5/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ typedef enum kope_g5_api { KOPE_G5_API_DIRECT3D12, KOPE_G5_API_VULKAN } kope_g5_
#define KOPE_G5_CALL4(name, arg0, arg1, arg2, arg3) kope_d3d12_##name(arg0, arg1, arg2, arg3)
#define KOPE_G5_CALL5(name, arg0, arg1, arg2, arg3, arg4) kope_d3d12_##name(arg0, arg1, arg2, arg3, arg4)
#define KOPE_G5_CALL6(name, arg0, arg1, arg2, arg3, arg4, arg5) kope_d3d12_##name(arg0, arg1, arg2, arg3, arg4, arg5)
#define KOPE_G5_CALL7(name, arg0, arg1, arg2, arg3, arg4, arg5, arg6) kope_d3d12_##name(arg0, arg1, arg2, arg3, arg4, arg5, arg6)

#endif

Expand All @@ -91,6 +92,7 @@ typedef enum kope_g5_api { KOPE_G5_API_DIRECT3D12, KOPE_G5_API_VULKAN } kope_g5_
#define KOPE_G5_CALL4(name, arg0, arg1, arg2, arg3) kope_vulkan_##name(arg0, arg1, arg2, arg3)
#define KOPE_G5_CALL5(name, arg0, arg1, arg2, arg3, arg4) kope_vulkan_##name(arg0, arg1, arg2, arg3, arg4)
#define KOPE_G5_CALL6(name, arg0, arg1, arg2, arg3, arg4, arg5) kope_vulkan_##name(arg0, arg1, arg2, arg3, arg4, arg5)
#define KOPE_G5_CALL7(name, arg0, arg1, arg2, arg3, arg4, arg5, arg6) kope_vulkan_##name(arg0, arg1, arg2, arg3, arg4, arg5, arg6)

#endif

Expand Down
29 changes: 29 additions & 0 deletions Sources/kope/graphics5/commandlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

#include <assert.h>

void kope_g5_command_list_copy_buffer_to_buffer(kope_g5_command_list *list, kope_g5_buffer *source, uint64_t source_offset, kope_g5_buffer *destination,
uint64_t destination_offset, uint64_t size) {
KOPE_G5_CALL6(command_list_copy_buffer_to_buffer, list, source, source_offset, destination, destination_offset, size);
}

void kope_g5_command_list_copy_buffer_to_texture(kope_g5_command_list *list, const kope_g5_image_copy_buffer *source,
const kope_g5_image_copy_texture *destination, uint32_t width, uint32_t height,
uint32_t depth_or_array_layers) {
Expand All @@ -31,6 +36,10 @@ void kope_g5_command_list_copy_texture_to_texture(kope_g5_command_list *list, co
KOPE_G5_CALL6(command_list_copy_texture_to_texture, list, source, destination, width, height, depth_or_array_layers);
}

void kope_g5_command_list_clear_buffer(kope_g5_command_list *list, kope_g5_buffer *buffer, size_t offset, uint64_t size) {
KOPE_G5_CALL4(command_list_clear_buffer, list, buffer, offset, 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 All @@ -48,6 +57,10 @@ void kope_g5_command_list_set_index_buffer(kope_g5_command_list *list, kope_g5_b
KOPE_G5_CALL5(command_list_set_index_buffer, list, buffer, index_format, offset, size);
}

void kope_g5_command_list_draw(kope_g5_command_list *list, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance) {
KOPE_G5_CALL5(command_list_draw, list, vertex_count, instance_count, first_vertex, first_instance);
}

void kope_g5_command_list_draw_indexed(kope_g5_command_list *list, uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t base_vertex,
uint32_t first_instance) {
KOPE_G5_CALL6(command_list_draw_indexed, list, index_count, instance_count, first_index, base_vertex, first_instance);
Expand All @@ -72,3 +85,19 @@ void kope_g5_command_list_update_raytracing_hierarchy(kope_g5_command_list *list
void kope_g5_command_list_trace_rays(kope_g5_command_list *list, uint32_t width, uint32_t height, uint32_t depth) {
KOPE_G5_CALL4(command_list_trace_rays, list, width, height, depth);
}

void kope_g5_command_list_set_viewport(kope_g5_command_list *list, float x, float y, float width, float height, float min_depth, float max_depth) {
KOPE_G5_CALL7(command_list_set_viewport, list, x, y, width, height, min_depth, max_depth);
}

void kope_g5_command_list_set_scissor_rect(kope_g5_command_list *list, uint32_t x, uint32_t y, uint32_t width, uint32_t height) {
KOPE_G5_CALL5(command_list_set_scissor_rect, list, x, y, width, height);
}

void kope_g5_command_list_set_blend_constant(kope_g5_command_list *list, kope_g5_color color) {
KOPE_G5_CALL2(command_list_set_blend_constant, list, color);
}

void kope_g5_command_list_set_stencil_reference(kope_g5_command_list *list, uint32_t reference) {
KOPE_G5_CALL2(command_list_set_stencil_reference, list, reference);
}

0 comments on commit dab5731

Please sign in to comment.