diff --git a/include/fwk/gfx/shader_compiler.h b/include/fwk/gfx/shader_compiler.h index b75db051..316f18ed 100644 --- a/include/fwk/gfx/shader_compiler.h +++ b/include/fwk/gfx/shader_compiler.h @@ -14,8 +14,7 @@ struct ShaderCompilerSetup { vector source_dirs; Maybe spirv_cache_dir; VulkanVersion vulkan_version = {1, 2, 0}; - Maybe glsl_version = 4.5; - Maybe spirv_version = 1.3; + Maybe spirv_version = 1.5; bool debug_info = false; bool generate_assembly = false; }; diff --git a/include/fwk/vulkan/vulkan_internal.h b/include/fwk/vulkan/vulkan_internal.h index cbaa7db4..618bc2ad 100644 --- a/include/fwk/vulkan/vulkan_internal.h +++ b/include/fwk/vulkan/vulkan_internal.h @@ -16,6 +16,7 @@ inline auto toVk(VDescriptorType type) { return type == VDescriptorType::accel_struct ? VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR : VkDescriptorType(type); } + inline auto toVk(VDescriptorPoolFlags flags) { return VkDescriptorPoolCreateFlagBits(flags.bits); } inline auto toVk(VPrimitiveTopology type) { return VkPrimitiveTopology(type); } inline auto toVk(VImageUsageFlags usage) { return VkImageUsageFlags{usage.bits}; } diff --git a/include/fwk/vulkan/vulkan_ray_tracing.h b/include/fwk/vulkan/vulkan_ray_tracing.h index 7be28ecc..aa1b5122 100644 --- a/include/fwk/vulkan/vulkan_ray_tracing.h +++ b/include/fwk/vulkan/vulkan_ray_tracing.h @@ -23,6 +23,7 @@ class VulkanAccelStruct : public VulkanObjectBase { ~VulkanAccelStruct(); PVBuffer m_buffer; + PVBuffer m_scratch_buffer; }; } diff --git a/include/fwk/vulkan_base.h b/include/fwk/vulkan_base.h index 6062b439..001051b1 100644 --- a/include/fwk/vulkan_base.h +++ b/include/fwk/vulkan_base.h @@ -91,7 +91,7 @@ DEFINE_ENUM(VBindPoint, graphics, compute); DEFINE_ENUM(VBufferUsage, transfer_src, transfer_dst, uniform_texel_buffer, storage_texel_buffer, uniform_buffer, storage_buffer, index_buffer, vertex_buffer, indirect_buffer, - device_address, accel_struct_build_input, accel_struct_storage); + device_address, accel_struct_build_input_read_only, accel_struct_storage); using VBufferUsageFlags = EnumFlags; DEFINE_ENUM(VImageUsage, transfer_src, transfer_dst, sampled, storage, color_att, depth_stencil_att, diff --git a/src/gfx/shader_compiler.cpp b/src/gfx/shader_compiler.cpp index 2e0031a2..098e4ae0 100644 --- a/src/gfx/shader_compiler.cpp +++ b/src/gfx/shader_compiler.cpp @@ -182,9 +182,7 @@ ShaderCompiler::ShaderCompiler(ShaderCompilerSetup setup) { } uint vk_version = (setup.vulkan_version.major << 22) | (setup.vulkan_version.minor << 12); shaderc_compile_options_set_target_env(opts, shaderc_target_env_vulkan, vk_version); - if(setup.glsl_version) - shaderc_compile_options_set_forced_version_profile(opts, int(*setup.glsl_version * 100), - shaderc_profile_none); + if(setup.spirv_version) { int version = int(*setup.spirv_version * 10); int major = version / 10; diff --git a/src/vulkan/vulkan_device.cpp b/src/vulkan/vulkan_device.cpp index 18bbfae5..84b23c70 100644 --- a/src/vulkan/vulkan_device.cpp +++ b/src/vulkan/vulkan_device.cpp @@ -186,9 +186,9 @@ Ex VulkanDevice::initialize(const VDeviceSetup &setup) { m_features |= VDeviceFeature::shader_clock; } - vector raytracing_exts{{VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, - VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME, - VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME}}; + vector raytracing_exts{ + {VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME, + VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME, VK_KHR_RAY_QUERY_EXTENSION_NAME}}; if(allOf(raytracing_exts, [&](const string &ext) { return anyOf(phys_info.extensions, ext); })) { insertBack(exts, raytracing_exts); diff --git a/src/vulkan/vulkan_pipeline.cpp b/src/vulkan/vulkan_pipeline.cpp index 7bd722a9..e8d20371 100644 --- a/src/vulkan/vulkan_pipeline.cpp +++ b/src/vulkan/vulkan_pipeline.cpp @@ -180,7 +180,7 @@ void VDescriptorSet::set(int index, PVAccelStruct as) { write.dstSet = handle; write.dstBinding = index; write.dstArrayElement = 0; - write.descriptorType = toVk(VDescriptorType::storage_image); + write.descriptorType = toVk(VDescriptorType::accel_struct); write.pNext = &as_info; vkUpdateDescriptorSets(device->handle(), 1, &write, 0, nullptr); } diff --git a/src/vulkan/vulkan_ray_tracing.cpp b/src/vulkan/vulkan_ray_tracing.cpp index f35e056c..439ff51b 100644 --- a/src/vulkan/vulkan_ray_tracing.cpp +++ b/src/vulkan/vulkan_ray_tracing.cpp @@ -28,7 +28,7 @@ Ex VulkanAccelStruct::create(VulkanDevice &device, VAccelStructTy VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR}; create_info.buffer = buffer.buffer().handle(); create_info.offset = buffer.byteOffset(); - create_info.size = buffer.byteOffset(); + create_info.size = buffer.byteSize(); create_info.type = VkAccelerationStructureTypeKHR(type); VkAccelerationStructureKHR handle = 0; @@ -37,14 +37,21 @@ Ex VulkanAccelStruct::create(VulkanDevice &device, VAccelStructTy return device.createObject(handle, buffer.buffer()); } -template static u64 getAddress(VulkanDevice &device, VBufferSpan buffer) { +static u64 getAddress(VulkanDevice &device, const VulkanBuffer &buffer) { VkBufferDeviceAddressInfo info = {VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO}; - info.buffer = buffer.buffer().handle(); - return vkGetBufferDeviceAddress(device.handle(), &info) + buffer.byteOffset(); + info.buffer = buffer.handle(); + return vkGetBufferDeviceAddress(device.handle(), &info); +} + +template static u64 getAddress(VulkanDevice &device, VBufferSpan buffer) { + return getAddress(device, *buffer.buffer()) + buffer.byteOffset(); } Ex VulkanAccelStruct::build(VulkanDevice &device, VBufferSpan vertices, VBufferSpan indices) { + DASSERT(vertices.buffer()->usage() & VBufferUsage::accel_struct_build_input_read_only); + DASSERT(indices.buffer()->usage() & VBufferUsage::accel_struct_build_input_read_only); + VkAccelerationStructureGeometryTrianglesDataKHR triangles{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR}; triangles.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; @@ -61,11 +68,12 @@ Ex VulkanAccelStruct::build(VulkanDevice &device, VBufferSpan VulkanAccelStruct::build(VulkanDevice &device, VBufferSpanm_scratch_buffer = + EX_PASS(VulkanBuffer::create(device, size_info.buildScratchSize, + VBufferUsage::device_address | VBufferUsage::storage_buffer)); + build_info.scratchData.deviceAddress = getAddress(device, *accel->m_scratch_buffer); + build_info.srcAccelerationStructure = accel->handle(); build_info.dstAccelerationStructure = accel->handle(); - auto *offsets = &offset; - - auto result = - vkBuildAccelerationStructuresKHR(device.handle(), nullptr, 1, &build_info, &offsets); + auto &cmds = device.cmdQueue(); + auto cmd_handle = cmds.bufferHandle(); + vkCmdBuildAccelerationStructuresKHR(cmd_handle, 1, &build_info, &build_range_infos); + // TODO: barriers here in case of multiple builds + // TODO: compacting + // TODO: clear scratch buffer once building is done return accel; } diff --git a/src/vulkan/vulkan_shader.cpp b/src/vulkan/vulkan_shader.cpp index ec69988d..7ce439e0 100644 --- a/src/vulkan/vulkan_shader.cpp +++ b/src/vulkan/vulkan_shader.cpp @@ -27,11 +27,14 @@ Ex> getBindings(CSpan bytecode, VShaderStag for(int i : intRange(reflection->descriptor_binding_count)) { auto &binding = reflection->descriptor_bindings[i]; - uint desc_type = uint(binding.descriptor_type); - if(desc_type > count) - return ERROR("Unsupported descriptor type: %", desc_type); - out.emplace_back(VDescriptorType(desc_type), flag(stage), binding.binding, binding.count, - binding.set); + VDescriptorType desc_type; + if(binding.descriptor_type <= SPV_REFLECT_DESCRIPTOR_TYPE_INPUT_ATTACHMENT) + desc_type = VDescriptorType(binding.descriptor_type); + else if(binding.descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR) + desc_type = VDescriptorType::accel_struct; + else + return ERROR("Unsupported descriptor type: %", binding.descriptor_type); + out.emplace_back(desc_type, flag(stage), binding.binding, binding.count, binding.set); } // TODO: is this needed? diff --git a/todo.txt b/todo.txt index 8ec4d1b0..7d7b413f 100644 --- a/todo.txt +++ b/todo.txt @@ -12,6 +12,7 @@ CAŁY CZAS TO ROBISZ :( Problemy: +- natstepfilter - remove min_size from Span<> - disable/remove backtraces? - drobny błąd przy wyświetlaniu perfanalyzera: jak sie zmniejszy okno, to ostatnia linia moze byc czasami