diff options
author | grm <grm@eyesin.space> | 2025-01-03 02:14:17 +0200 |
---|---|---|
committer | grm <grm@eyesin.space> | 2025-01-03 02:14:17 +0200 |
commit | 67eec36945ed1706f23d0fe6d3017a09516dc42b (patch) | |
tree | f1cb425c31aee5d30a813a6fdf6e0df82394c9d5 /src | |
parent | bbcc41762f335e90dc850dd9d4a6cc5e51631c7c (diff) | |
download | cgame-67eec36945ed1706f23d0fe6d3017a09516dc42b.tar.gz cgame-67eec36945ed1706f23d0fe6d3017a09516dc42b.tar.bz2 cgame-67eec36945ed1706f23d0fe6d3017a09516dc42b.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/render.c | 53 | ||||
-rw-r--r-- | src/shader.frag | 4 | ||||
-rw-r--r-- | src/vksetup.h | 11 |
3 files changed, 46 insertions, 22 deletions
diff --git a/src/render.c b/src/render.c index 1ff2e13..5e9202b 100644 --- a/src/render.c +++ b/src/render.c @@ -618,6 +618,19 @@ recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) // TODO Make polygon mode dynamic //vkCmdSetPolygonModeEXT(commandBuffer, s.polygon_mode); + + + /* vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, s.vk_compute_pipeline); */ + /* vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, s.vk_compute_pipeline_layout, 0, 1, &s.frames[imageIndex].vk_compute_descriptor_set, 0, 0); */ + + /* vkCmdDispatch(commandBuffer, PARTICLE_COUNT / 256, 1, 1); */ + + + + + + + vks_transition_image_layout_info transition_info = { 0 }; transition_info.image = s.vk.swapchain.images[imageIndex]; @@ -862,9 +875,11 @@ void vulkan_create_descriptor_sets() { VkDescriptorSetLayout layouts[MAX_FRAMES_IN_FLIGHT] = {0}; + /* VkDescriptorSetLayout compute_layouts[MAX_FRAMES_IN_FLIGHT] = {0}; */ for (int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { layouts[i] = s.vk_descriptor_set_layout; + /* compute_layouts[i] = s.vk_compute_descriptor_set_layout; */ } // TODO Find a way to group allocation @@ -876,15 +891,23 @@ vulkan_create_descriptor_sets() allocInfo.pSetLayouts = layouts; VK_CHECK(vkAllocateDescriptorSets(s.vk.device, &allocInfo, &s.frames[i].vk_descriptor_set)); + + /* allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; */ + /* allocInfo.descriptorPool = s.vk_descriptor_pool; */ + /* allocInfo.descriptorSetCount = 1; */ + /* allocInfo.pSetLayouts = compute_layouts; */ + + /* VK_CHECK(vkAllocateDescriptorSets(s.vk.device, &allocInfo, &s.frames[i].vk_compute_descriptor_set)); */ } for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { + VkWriteDescriptorSet descriptorWrites[2] = {0}; + VkDescriptorBufferInfo bufferInfo = {0}; bufferInfo.buffer = s.frames[i].uniform_buffer.handle; bufferInfo.offset = 0; bufferInfo.range = sizeof(UniformBufferObject); - VkWriteDescriptorSet descriptorWrites[2] = {0}; descriptorWrites[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; descriptorWrites[0].dstSet = s.frames[i].vk_descriptor_set; descriptorWrites[0].dstBinding = 0; @@ -907,7 +930,7 @@ vulkan_create_descriptor_sets() descriptorWrites[1].pImageInfo = &imageInfo; /* VkDescriptorBufferInfo storageBufferInfoLastFrame = {0}; */ - /* storageBufferInfoLastFrame.buffer = s.frames[(i - 1) % MAX_FRAMES_IN_FLIGHT].vk_shader_storage_buffer; */ + /* storageBufferInfoLastFrame.buffer = s.frames[(i - 1) % MAX_FRAMES_IN_FLIGHT].shader_storage_buffer.handle; */ /* storageBufferInfoLastFrame.offset = 0; */ /* storageBufferInfoLastFrame.range = sizeof(Particle) * PARTICLE_COUNT; */ @@ -920,7 +943,7 @@ vulkan_create_descriptor_sets() /* descriptorWrites[2].pBufferInfo = &storageBufferInfoLastFrame; */ /* VkDescriptorBufferInfo storageBufferInfoCurrentFrame = {0}; */ - /* storageBufferInfoCurrentFrame.buffer = s.frames[i].vk_shader_storage_buffer; */ + /* storageBufferInfoCurrentFrame.buffer = s.frames[i].shader_storage_buffer.handle; */ /* storageBufferInfoCurrentFrame.offset = 0; */ /* storageBufferInfoCurrentFrame.range = sizeof(Particle) * PARTICLE_COUNT; */ @@ -932,7 +955,6 @@ vulkan_create_descriptor_sets() /* descriptorWrites[3].descriptorCount = 1; */ /* descriptorWrites[3].pBufferInfo = &storageBufferInfoCurrentFrame; */ - vkUpdateDescriptorSets(s.vk.device, VK_ARRAY_LEN(descriptorWrites), descriptorWrites, 0, NULL); } } @@ -1406,9 +1428,9 @@ void vulkan_create_compute_stuff() vkUnmapMemory(s.vk.device, stagingBuffer.memory); for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) { - // vks_create_buffer(s.vk, bufferSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, &s.frames[i].shader_storage_buffer); - // Copy data from the staging buffer (host) to the shader storage buffer (GPU) - // vks_copy_buffer(s.vk, stagingBuffer.handle, s.frames[i].shader_storage_buffer.handle, bufferSize); + vks_create_buffer(s.vk, bufferSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, &s.frames[i].shader_storage_buffer); + // Copy data from the staging buffer (host) to the shader storage buffer (GPU) + vks_copy_buffer(s.vk, stagingBuffer.handle, s.frames[i].shader_storage_buffer.handle, bufferSize); } VkDescriptorSetLayoutBinding layoutBindings[3]; @@ -1434,23 +1456,20 @@ void vulkan_create_compute_stuff() layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; layoutInfo.bindingCount = 3; layoutInfo.pBindings = layoutBindings; - VK_CHECK(vkCreateDescriptorSetLayout(s.vk.device, &layoutInfo, NULL, &s.vk_compute_descriptor_set_layout)); - VkComputePipelineCreateInfo pipelineInfo = {0}; - pipelineInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; - pipelineInfo.layout = s.vk_compute_pipeline_layout; - pipelineInfo.stage = computeShaderStageInfo; - - VK_CHECK(vkCreateComputePipelines(s.vk.device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, &s.vk_compute_pipeline)); - VkPipelineLayoutCreateInfo pipelineLayoutInfo = {0}; pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutInfo.setLayoutCount = 1; pipelineLayoutInfo.pSetLayouts = &s.vk_compute_descriptor_set_layout; - VK_CHECK(vkCreatePipelineLayout(s.vk.device, &pipelineLayoutInfo, NULL, &s.vk_compute_pipeline_layout)); + VkComputePipelineCreateInfo pipelineInfo = {0}; + pipelineInfo.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + pipelineInfo.layout = s.vk_compute_pipeline_layout; + pipelineInfo.stage = computeShaderStageInfo; + VK_CHECK(vkCreateComputePipelines(s.vk.device, VK_NULL_HANDLE, 1, &pipelineInfo, NULL, &s.vk_compute_pipeline)); + if (s.prev_comp_result != comp_result) { shaderc_result_release(comp_result); } @@ -1470,7 +1489,7 @@ init_vulkan() vulkan_create_descriptor_set_layout(); vulkan_create_graphics_pipeline(s.polygon_mode); - //vulkan_create_compute_stuff(); + vulkan_create_compute_stuff(); vulkan_create_texture_image(); vulkan_create_texture_sampler(); diff --git a/src/shader.frag b/src/shader.frag index fc16ceb..6f5abb6 100644 --- a/src/shader.frag +++ b/src/shader.frag @@ -18,8 +18,8 @@ layout(binding = 0) uniform UniformBufferObject { void main() { float pulse = sin(ubo.time * 20) * .5 + .5; - outColor = vec4(fragColor * texture(texSampler, fragTexCoord).rgb * pulse, 1.0); - // outColor = texture(texSampler, fragTexCoord); + outColor = vec4(fragColor * texture(texSampler, fragTexCoord).rgb , 1.0); + //outColor = texture(texSampler, fragTexCoord); //outColor = vec4(fragColor, 1); // float repeat = 10; // float f = zmod(ubo.time, repeat); diff --git a/src/vksetup.h b/src/vksetup.h index daa9148..923083b 100644 --- a/src/vksetup.h +++ b/src/vksetup.h @@ -213,8 +213,8 @@ typedef struct vks_frame_data { VkDescriptorSet vk_descriptor_set; /* compute stuff */ - /* VkDescriptorSet vk_compute_descriptor_set; */ - /* vks_buffer shader_storage_buffer; */ + VkDescriptorSet vk_compute_descriptor_set; + vks_buffer shader_storage_buffer; } vks_frame_data; /* Info structs */ @@ -1335,7 +1335,12 @@ vks_create_buffer(const vks_context vk, allocInfo.usage = VMA_MEMORY_USAGE_AUTO; allocInfo.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT; - vmaCreateBuffer(vk.allocator, &bufferInfo, &allocInfo, &buffer->handle, &buffer->allocation, NULL); + VK_CHECK(vmaCreateBuffer(vk.allocator, &bufferInfo, &allocInfo, &buffer->handle, &buffer->allocation, NULL)); + + VmaAllocationInfo info = {0}; + + vmaGetAllocationInfo(vk.allocator, buffer->allocation, &info); + buffer->memory = info.deviceMemory; } #endif /* VKSETUP_IMPLEMENTATION */ |