diff --git a/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.h b/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.h index c921f5768..9ef264213 100644 --- a/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.h +++ b/Backends/Graphics5/Vulkan/Sources/kinc/backend/compute.h @@ -2,13 +2,12 @@ #include +#include "graphics5/MiniVulkan.h" + #ifdef __cplusplus extern "C" { #endif -struct ID3D12Buffer; -struct ID3D12PipelineState; - typedef struct { uint32_t offset; uint32_t size; @@ -35,8 +34,10 @@ typedef struct { kinc_internal_hash_index_t textures[64]; uint8_t *data; int length; - struct ID3D12Buffer *constantBuffer; - struct ID3D12PipelineState *pso; + + VkDescriptorSet descriptor_set; + VkPipelineLayout pipeline_layout; + VkPipeline pipeline; } kinc_compute_shader_impl_t; #ifdef __cplusplus diff --git a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h index 058770755..079147ffc 100644 --- a/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h +++ b/Backends/Graphics5/Vulkan/Sources/kinc/backend/graphics5/compute.c.h @@ -234,8 +234,7 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le pipeline_layout_info.setLayoutCount = 1; pipeline_layout_info.pSetLayouts = &descriptor_set_layout; - VkPipelineLayout compute_pipeline_layout; - if (vkCreatePipelineLayout(vk_ctx.device, &pipeline_layout_info, NULL, &compute_pipeline_layout) != VK_SUCCESS) { + if (vkCreatePipelineLayout(vk_ctx.device, &pipeline_layout_info, NULL, &shader->impl.pipeline_layout) != VK_SUCCESS) { kinc_log(KINC_LOG_LEVEL_WARNING, "Could not initialize compute shader."); return; } @@ -243,11 +242,10 @@ void kinc_compute_shader_init(kinc_compute_shader_t *shader, void *_data, int le VkComputePipelineCreateInfo pipeline_info = {0}; memset(&pipeline_info, 0, sizeof(pipeline_info)); pipeline_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; - pipeline_info.layout = compute_pipeline_layout; + pipeline_info.layout = shader->impl.pipeline_layout; pipeline_info.stage = compute_shader_stage_info; - VkPipeline compute_pipeline = {0}; - if (vkCreateComputePipelines(vk_ctx.device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &compute_pipeline) != VK_SUCCESS) { + if (vkCreateComputePipelines(vk_ctx.device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &shader->impl.pipeline) != VK_SUCCESS) { kinc_log(KINC_LOG_LEVEL_WARNING, "Could not initialize compute shader."); return; } @@ -403,10 +401,12 @@ void kinc_compute_set_texture3d_minification_filter(kinc_compute_texture_unit_t void kinc_compute_set_texture3d_mipmap_filter(kinc_compute_texture_unit_t unit, kinc_g4_mipmap_filter_t filter) {} void kinc_compute_set_shader(kinc_compute_shader_t *shader) { - /*ID3D12GraphicsCommandList *command_list = NULL; - command_list->SetPipelineState(shader->impl.pso);*/ + VkCommandBuffer command_buffer = {0}; + vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, shader->impl.pipeline); + vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, shader->impl.pipeline_layout, 0, 1, &shader->impl.descriptor_set, 0, 0); } void kinc_compute(int x, int y, int z) { - // ID3D12GraphicsCommandList *command_list = NULL; + VkCommandBuffer command_buffer = {0}; + vkCmdDispatch(command_buffer, x, y, z); }