diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist.cpp b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist.cpp index da62b4748..4bb7c0536 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist.cpp +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist.cpp @@ -5,6 +5,8 @@ #include #include +#include "pipeline_structs.h" + #include void kope_d3d12_command_list_begin_render_pass(kope_g5_command_list *list, const kope_g5_render_pass_parameters *parameters) { @@ -54,4 +56,26 @@ void kope_d3d12_command_list_set_index_buffer(kope_g5_command_list *list, kope_g view.Format = index_format == KOPE_G5_INDEX_FORMAT_UINT16 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; list->d3d12.list->IASetIndexBuffer(&view); -} \ No newline at end of file +} + +void kope_d3d12_command_list_set_vertex_buffer(kope_g5_command_list *list, uint32_t slot, kope_d3d12_buffer *buffer, uint64_t offset, uint64_t size, + uint64_t stride) { + D3D12_VERTEX_BUFFER_VIEW view = {0}; + + view.BufferLocation = buffer->resource->GetGPUVirtualAddress() + offset; + view.SizeInBytes = (UINT)size; + view.StrideInBytes = (UINT)stride; + + list->d3d12.list->IASetVertexBuffers(slot, 1, &view); +} + +void kope_d3d12_command_list_set_pipeline(kope_g5_command_list *list, kope_d3d12_pipeline *pipeline) { + list->d3d12.list->SetPipelineState(pipeline->pipe); + list->d3d12.list->SetGraphicsRootSignature(pipeline->root_signature); +} + +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); + list->d3d12.list->DrawIndexedInstanced(index_count, instance_count, first_index, base_vertex, first_instance); +} diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist_functions.h b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist_functions.h index 8a3662c98..5a3e55265 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist_functions.h +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/commandlist_functions.h @@ -3,6 +3,8 @@ #include +#include "pipeline_structs.h" + #ifdef __cplusplus extern "C" { #endif @@ -16,6 +18,14 @@ void kope_d3d12_command_list_present(kope_g5_command_list *list); 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); +void kope_d3d12_command_list_set_vertex_buffer(kope_g5_command_list *list, uint32_t slot, kope_d3d12_buffer *buffer, uint64_t offset, uint64_t size, + uint64_t stride); + +void kope_d3d12_command_list_set_pipeline(kope_g5_command_list *list, kope_d3d12_pipeline *pipeline); + +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); + #ifdef __cplusplus } #endif diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/pipeline.cpp b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/pipeline.cpp index b9a1a66a7..1937d2591 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/pipeline.cpp +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/pipeline.cpp @@ -332,30 +332,29 @@ void kope_d3d12_pipeline_init(kope_d3d12_device *device, kope_d3d12_pipeline *pi desc.RasterizerState.ForcedSampleCount = 0; desc.RasterizerState.ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF; - desc.BlendState.IndependentBlendEnable = FALSE; - bool independent_blend = false; - for (int i = 1; i < KOPE_D3D12_MAX_COLOR_TARGETS; ++i) { - if (parameters->fragment.targets[0].write_mask != parameters->fragment.targets[i].write_mask) { + for (int i = 1; i < parameters->fragment.targets_count; ++i) { + if (memcmp(¶meters->fragment.targets[0], ¶meters->fragment.targets[i], sizeof(kope_d3d12_color_target_state)) != 0) { independent_blend = true; break; } } + desc.BlendState.IndependentBlendEnable = independent_blend ? TRUE : FALSE; + set_blend_state(&desc.BlendState, ¶meters->fragment.targets[0], 0); if (independent_blend) { - desc.BlendState.IndependentBlendEnable = true; - for (int i = 1; i < KOPE_D3D12_MAX_COLOR_TARGETS; ++i) { + for (int i = 1; i < parameters->fragment.targets_count; ++i) { set_blend_state(&desc.BlendState, ¶meters->fragment.targets[i], i); } } desc.pRootSignature = NULL; - HRESULT result = device->device->CreateGraphicsPipelineState(&desc, IID_GRAPHICS_PPV_ARGS(&pipe->pipe)); - if (result != S_OK) { - kinc_log(KINC_LOG_LEVEL_WARNING, "Could not create pipeline."); - } + kinc_microsoft_affirm(device->device->CreateGraphicsPipelineState(&desc, IID_GRAPHICS_PPV_ARGS(&pipe->pipe))); + + kinc_microsoft_affirm( + device->device->CreateRootSignature(0, desc.VS.pShaderBytecode, desc.VS.BytecodeLength, IID_GRAPHICS_PPV_ARGS(&pipe->root_signature))); } void kope_d3d12_pipeline_destroy(kope_d3d12_pipeline *pipe) { diff --git a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/pipeline_structs.h b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/pipeline_structs.h index 0348a614c..9cbc60225 100644 --- a/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/pipeline_structs.h +++ b/Backends/Graphics5/Direct3D12/Sources/kope/direct3d12/pipeline_structs.h @@ -208,9 +208,11 @@ typedef struct kope_d3d12_pipeline_parameters { } kope_d3d12_pipeline_parameters; struct ID3D12PipelineState; +struct ID3D12RootSignature; typedef struct kope_d3d12_pipeline { struct ID3D12PipelineState *pipe; + struct ID3D12RootSignature *root_signature; } kope_d3d12_pipeline; #ifdef __cplusplus diff --git a/Sources/kope/graphics5/api.h b/Sources/kope/graphics5/api.h index a6982a13c..e1849874d 100644 --- a/Sources/kope/graphics5/api.h +++ b/Sources/kope/graphics5/api.h @@ -77,6 +77,7 @@ typedef enum kope_g5_api { KOPE_G5_API_DIRECT3D12, KOPE_G5_API_VULKAN } kope_g5_ #define KOPE_G5_CALL3(name, arg0, arg1, arg2) kope_d3d12_##name(arg0, arg1, arg2) #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) #endif @@ -89,6 +90,7 @@ typedef enum kope_g5_api { KOPE_G5_API_DIRECT3D12, KOPE_G5_API_VULKAN } kope_g5_ #define KOPE_G5_CALL3(name, arg0, arg1, arg2) kope_vulkan_##name(arg0, arg1, arg2) #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) #endif diff --git a/Sources/kope/graphics5/commandlist.c b/Sources/kope/graphics5/commandlist.c index 9e8ce1490..1354e6695 100644 --- a/Sources/kope/graphics5/commandlist.c +++ b/Sources/kope/graphics5/commandlist.c @@ -24,3 +24,8 @@ void kope_g5_command_list_set_index_buffer(kope_g5_command_list *list, kope_g5_b uint64_t size) { KOPE_G5_CALL5(command_list_set_index_buffer, list, buffer, index_format, offset, size); } + +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); +} \ No newline at end of file diff --git a/Sources/kope/graphics5/commandlist.h b/Sources/kope/graphics5/commandlist.h index 5a61908fd..590c97a88 100644 --- a/Sources/kope/graphics5/commandlist.h +++ b/Sources/kope/graphics5/commandlist.h @@ -92,15 +92,11 @@ KOPE_FUNC void kope_g5_command_list_clear_buffer(kope_g5_command_list *list, kop // KOPE_FUNC void kope_g5_command_list_resolve_query_set(kope_g5_command_list *list, GPUQuerySet querySet, uint32_t firstQuery, uint32_t queryCount, // kope_g5_buffer *destination, uint64_t destinationOffset); -KOPE_FUNC void kope_g5_command_list_set_pipeline(kope_g5_command_list *list, void *pipeline); - typedef enum kope_g5_index_format { KOPE_G5_INDEX_FORMAT_UINT16, KOPE_G5_INDEX_FORMAT_UINT32 } kope_g5_index_format; KOPE_FUNC void kope_g5_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); -KOPE_FUNC void kope_g5_command_list_set_vertex_buffer(kope_g5_command_list *list, uint32_t slot, kope_g5_buffer *buffer, uint64_t offset, uint64_t size); - KOPE_FUNC 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);