diff options
| -rw-r--r-- | include/vk-api.hpp | 8 | ||||
| -rw-r--r-- | src/compute-renderpass.cpp | 6 | ||||
| -rw-r--r-- | src/main.cpp | 20 | ||||
| -rw-r--r-- | src/vk-api.cpp | 4 |
4 files changed, 20 insertions, 18 deletions
diff --git a/include/vk-api.hpp b/include/vk-api.hpp index cc0188d..de19a7d 100644 --- a/include/vk-api.hpp +++ b/include/vk-api.hpp @@ -21,6 +21,8 @@ struct pipeline { VkPipelineBindPoint bind_point; }; +using bindless_index = uint32_t; + struct image { VkImage handle; VkImageView view; @@ -29,8 +31,8 @@ struct image { VkImageSubresourceRange subresource_range; VkFormat format; VkExtent3D size; - uint32_t bindless_storage_index; - uint32_t bindless_sampled_index; + bindless_index bindless_storage_index; + bindless_index bindless_sampled_index; VkImageLayout previous_layout = VK_IMAGE_LAYOUT_UNDEFINED; VkPipelineStageFlags previous_stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; @@ -47,7 +49,7 @@ struct swapchain { struct sampler { VkSampler handle; - uint32_t bindless_index; + bindless_index bindless_index; }; struct global_descriptor { diff --git a/src/compute-renderpass.cpp b/src/compute-renderpass.cpp index d801b11..87a2810 100644 --- a/src/compute-renderpass.cpp +++ b/src/compute-renderpass.cpp @@ -12,7 +12,7 @@ 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); + memcpy(constants.data() + 56, &output_texture->device_image.bindless_storage_index, sizeof(bindless_index)); } void ComputeRenderpass::set_dispatch_size(size_t count_x, size_t count_y, size_t count_z) { @@ -26,14 +26,14 @@ void ComputeRenderpass::set_constant(off_t offset, uint64_t* constant) { } void ComputeRenderpass::set_constant(off_t offset, Texture* texture) { - memcpy(constants.data() + offset, (void*)&texture->device_image.bindless_storage_index, 4); + memcpy(constants.data() + offset, (void*)&texture->device_image.bindless_storage_index, sizeof(bindless_index)); input_textures.push_back(texture); } void ComputeRenderpass::set_constant(off_t offset, Buffer* buffer) { auto address = buffer->device_address(); - memcpy(constants.data() + offset, (void*)&address, 8); + memcpy(constants.data() + offset, (void*)&address, sizeof(VkDeviceAddress)); } void ComputeRenderpass::execute(VkCommandBuffer command_buffer) { diff --git a/src/main.cpp b/src/main.cpp index 197c794..45e30a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -116,14 +116,14 @@ int main() { can_render = true; renderer.recreate_swapchain(); main_scene.meta.cam.set_aspect_ratio((float)event.width / (float)event.height); - main_scene.meta.sample_index = 0; + main_scene.meta.sample_index = 1; accumulation_texture = renderer.create_2d_texture(width, height, VK_FORMAT_R32G32B32A32_SFLOAT); output_texture = renderer.create_2d_texture(width, height, VK_FORMAT_R32G32B32A32_SFLOAT); raytracing_pass->set_dispatch_size(event.width / 8 + 1, event.height / 8 + 1, 1); } - main_scene.meta.sample_index = 0; + main_scene.meta.sample_index = 1; break; } @@ -154,12 +154,12 @@ int main() { } case KEYS::E: { main_scene.meta.cam.rotate_y(0.001f * delta_time); - main_scene.meta.sample_index = 0; + main_scene.meta.sample_index = 1; break; } case KEYS::Q: { main_scene.meta.cam.rotate_y(-0.001f * delta_time); - main_scene.meta.sample_index = 0; + main_scene.meta.sample_index = 1; break; } case KEYS::SPACE: { @@ -177,7 +177,7 @@ int main() { main_scene.meta.cam.move(move_vec); if (!move_vec.near_zero()) { - main_scene.meta.sample_index = 0; + main_scene.meta.sample_index = 1; } break; @@ -226,17 +226,17 @@ int main() { ImGui::Text("frame count %u\n", main_scene.meta.sample_index); if (ImGui::Checkbox("depth of field", (bool*)&main_scene.meta.enable_dof)) { - main_scene.meta.sample_index = 0; + main_scene.meta.sample_index = 1; } ImGui::SliderInt("max bounces", (int32_t*)&main_scene.meta.max_bounce, 1, 250); ImGui::SliderInt("min bounces", (int32_t*)&main_scene.meta.min_bounce, 1, main_scene.meta.max_bounce); if (ImGui::SliderInt("downscale factor", (int32_t*)&main_scene.meta.downscale_factor, 1, 32)) { - main_scene.meta.sample_index = 0; + main_scene.meta.sample_index = 1; } if (ImGui::Checkbox("debug bvh", (bool*)&main_scene.meta.debug_bvh)) { - main_scene.meta.sample_index = 0; + main_scene.meta.sample_index = 1; } ImGui::End(); @@ -259,10 +259,10 @@ int main() { raytracing_pass->set_constant(60, accumulation_texture); - main_scene.meta.sample_index++; - renderer.render(); + main_scene.meta.sample_index++; + std::swap(output_texture, accumulation_texture); } diff --git a/src/vk-api.cpp b/src/vk-api.cpp index a5f6435..6ce7312 100644 --- a/src/vk-api.cpp +++ b/src/vk-api.cpp @@ -830,8 +830,8 @@ swapchain vkapi::create_swapchain(VkSurfaceKHR surface, size_t min_image_count, create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; create_info.preTransform = caps.currentTransform; create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - // create_info.presentMode = VK_PRESENT_MODE_FIFO_KHR; - create_info.presentMode = VK_PRESENT_MODE_MAILBOX_KHR; + create_info.presentMode = VK_PRESENT_MODE_FIFO_KHR; + // create_info.presentMode = VK_PRESENT_MODE_MAILBOX_KHR; create_info.clipped = VK_TRUE; create_info.oldSwapchain = old_swapchain; |
