From 4ae9a520d97dcaf69f4a0cd044a4fc3fe689924d Mon Sep 17 00:00:00 2001 From: ladevieq Date: Mon, 7 Feb 2022 21:53:14 +0100 Subject: Compute shader render pass api --- src/compute-renderpass.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/compute-renderpass.cpp (limited to 'src/compute-renderpass.cpp') diff --git a/src/compute-renderpass.cpp b/src/compute-renderpass.cpp new file mode 100644 index 0000000..fe772bf --- /dev/null +++ b/src/compute-renderpass.cpp @@ -0,0 +1,32 @@ +#include "compute-renderpass.hpp" + +#include "vk-api.hpp" + +#include "vk-renderer.hpp" + +void ComputeRenderpass::set_ouput_texture(Texture* output_texture) { + this->output_texture = output_texture; + + // TODO: Remove hardcoded offset + memcpy(constants.data() + 56, &output_texture->device_image.bindless_storage_index, 4); +} + +void ComputeRenderpass::set_dispatch_size(size_t count_x, size_t count_y, size_t count_z) { + group_count_x = count_x; + group_count_y = count_y; + group_count_z = count_z; +} + +void ComputeRenderpass::set_constant(off_t offset, uint64_t* constant) { + memcpy(constants.data() + offset, constant, sizeof(uint64_t)); +} + +void ComputeRenderpass::set_constant(off_t offset, Texture* texture) { + memcpy(constants.data() + offset, (void*)&texture->device_image.bindless_sampled_index, 4); +} + +void ComputeRenderpass::execute(VkCommandBuffer command_buffer) { + vkCmdPushConstants(command_buffer, api.bindless_descriptor.pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, 64, (void*)&constants); + + api.run_compute_pipeline(command_buffer, pipeline, group_count_x, group_count_y, group_count_z); +} -- cgit v1.3