diff --git a/implementations/Crafter.Graphics-RenderingElement3DVulkan.cpp b/implementations/Crafter.Graphics-RenderingElement3DVulkan.cpp index 43d3b4f..7b58118 100644 --- a/implementations/Crafter.Graphics-RenderingElement3DVulkan.cpp +++ b/implementations/Crafter.Graphics-RenderingElement3DVulkan.cpp @@ -27,7 +27,7 @@ using namespace Crafter; std::vector RenderingElement3DVulkan::elements; -RenderingElement3DVulkan::RenderingElement3DVulkan(Mesh& mesh) { +RenderingElement3DVulkan::RenderingElement3DVulkan(Mesh& mesh, std::uint32_t customIndex, std::uint32_t mask, std::uint32_t shaderOffset) { VkAccelerationStructureDeviceAddressInfoKHR addrInfo { .sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR, .accelerationStructure = mesh.accelerationStructure @@ -35,10 +35,10 @@ RenderingElement3DVulkan::RenderingElement3DVulkan(Mesh& mesh) { VkDeviceAddress blasDeviceAddr = VulkanDevice::vkGetAccelerationStructureDeviceAddressKHR(VulkanDevice::device, &addrInfo); instance = { - .instanceCustomIndex = 0, - .mask = 0xFF, - .instanceShaderBindingTableRecordOffset = 0, - .flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR | VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR, + .instanceCustomIndex = customIndex, + .mask = mask, + .instanceShaderBindingTableRecordOffset = shaderOffset, + .flags = VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR, .accelerationStructureReference = blasDeviceAddr }; } diff --git a/implementations/Crafter.Graphics-VulkanDevice.cpp b/implementations/Crafter.Graphics-VulkanDevice.cpp index c8158b5..c17971f 100644 --- a/implementations/Crafter.Graphics-VulkanDevice.cpp +++ b/implementations/Crafter.Graphics-VulkanDevice.cpp @@ -221,9 +221,16 @@ void VulkanDevice::CreateDevice() { queueCreateInfo.queueCount = 1; queueCreateInfo.pQueuePriorities = &priority; + VkPhysicalDeviceVulkan12Features features12 { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, + .runtimeDescriptorArray = VK_TRUE, + .bufferDeviceAddress = VK_TRUE + }; + VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR vkPhysicalDeviceRayTracingPositionFetchFeatures { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR, - .rayTracingPositionFetch = VK_TRUE, + .pNext = &features12, + .rayTracingPositionFetch = VK_TRUE }; VkPhysicalDeviceRayTracingPipelineFeaturesKHR physicalDeviceRayTracingPipelineFeatures{ @@ -232,15 +239,9 @@ void VulkanDevice::CreateDevice() { .rayTracingPipeline = VK_TRUE }; - VkPhysicalDeviceBufferDeviceAddressFeatures deviceBufferDeviceAddressFeature = { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES, - .pNext = &physicalDeviceRayTracingPipelineFeatures, - .bufferDeviceAddress = VK_TRUE - }; - VkPhysicalDeviceAccelerationStructureFeaturesKHR deviceAccelerationStructureFeature = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR, - .pNext = &deviceBufferDeviceAddressFeature, + .pNext = &physicalDeviceRayTracingPipelineFeatures, .accelerationStructure = VK_TRUE }; diff --git a/interfaces/Crafter.Graphics-DescriptorPoolVulkan.cppm b/interfaces/Crafter.Graphics-DescriptorPoolVulkan.cppm index ad8e2ef..51d7761 100644 --- a/interfaces/Crafter.Graphics-DescriptorPoolVulkan.cppm +++ b/interfaces/Crafter.Graphics-DescriptorPoolVulkan.cppm @@ -78,7 +78,7 @@ export namespace Crafter { bool found = false; for(VkDescriptorPoolSize& type : types) { if(type.type == binding.descriptorType && type.descriptorCount != 12345) { - type.descriptorCount += 1; + type.descriptorCount += binding.descriptorCount; found = true; } } @@ -86,7 +86,7 @@ export namespace Crafter { for(std::uint32_t i = 0; i < GetUniqueDiscriptorCount(); i++){ if(types[i].descriptorCount == 12345) { types[i].type = binding.descriptorType; - types[i].descriptorCount = 1; + types[i].descriptorCount = binding.descriptorCount; break; } } diff --git a/interfaces/Crafter.Graphics-ImageVulkan.cppm b/interfaces/Crafter.Graphics-ImageVulkan.cppm index 0208399..2f64308 100644 --- a/interfaces/Crafter.Graphics-ImageVulkan.cppm +++ b/interfaces/Crafter.Graphics-ImageVulkan.cppm @@ -14,7 +14,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0215-1301 USA */ module; @@ -40,7 +40,10 @@ export namespace Crafter { VkImageView imageView; VkDescriptorImageInfo descriptor; - ImageVulkan(std::uint32_t width, std::uint32_t height, VkCommandBuffer cmd, VkFormat format) : width(width), height(height) { + void Create(std::uint32_t width, std::uint32_t height, VkCommandBuffer cmd, VkFormat format) { + this->width = width; + this->height = height; + buffer.Create(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, width * height); VkImageCreateInfo imageInfo = {}; @@ -49,7 +52,7 @@ export namespace Crafter { imageInfo.extent.width = width; imageInfo.extent.height = height; imageInfo.extent.depth = 1; - imageInfo.mipLevels = 10; + imageInfo.mipLevels = 5; imageInfo.arrayLayers = 1; imageInfo.format = format; imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; @@ -78,20 +81,20 @@ export namespace Crafter { viewInfo.format = format; viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; viewInfo.subresourceRange.baseMipLevel = 0; - viewInfo.subresourceRange.levelCount = 10; + viewInfo.subresourceRange.levelCount = 5; viewInfo.subresourceRange.baseArrayLayer = 0; viewInfo.subresourceRange.layerCount = 1; VulkanDevice::CheckVkResult(vkCreateImageView(VulkanDevice::device, &viewInfo, nullptr, &imageView)); // Final transition to shader read-only layout - TransitionImageLayout(cmd, image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, 10); + TransitionImageLayout(cmd, image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, 5); } void Update(const PixelType* bufferdata, VkCommandBuffer cmd) { std::memcpy(buffer.value, bufferdata, height*width*sizeof(PixelType)); buffer.FlushDevice(cmd, VK_ACCESS_MEMORY_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); - TransitionImageLayout(cmd, image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 10); + TransitionImageLayout(cmd, image, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 5); VkBufferImageCopy region{}; region.bufferOffset = 0; @@ -116,7 +119,7 @@ export namespace Crafter { TransitionImageLayout(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 0, 1); // Mipmap generation (now includes the correct layout and offset management) - for (std::uint32_t i = 1; i < 10; ++i) { + for (std::uint32_t i = 1; i < 5; ++i) { std::uint32_t mipWidth = std::max(1u, width >> i); std::uint32_t mipHeight = std::max(1u, height >> i); @@ -144,7 +147,7 @@ export namespace Crafter { TransitionImageLayout(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, i, 1); } - TransitionImageLayout(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, 10); + TransitionImageLayout(cmd, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, 5); } private: diff --git a/interfaces/Crafter.Graphics-RenderingElement3DVulkan.cppm b/interfaces/Crafter.Graphics-RenderingElement3DVulkan.cppm index eee103c..6b25a2b 100644 --- a/interfaces/Crafter.Graphics-RenderingElement3DVulkan.cppm +++ b/interfaces/Crafter.Graphics-RenderingElement3DVulkan.cppm @@ -43,7 +43,7 @@ export namespace Crafter { static std::vector elements; inline static VulkanBuffer scratchBuffer; inline static std::vector tlases; - RenderingElement3DVulkan(Mesh& mesh); + RenderingElement3DVulkan(Mesh& mesh, std::uint32_t customIndex, std::uint32_t mask, std::uint32_t shaderOffset); static void BuildTLAS(VkCommandBuffer cmd, std::uint32_t index); }; }