update
This commit is contained in:
parent
15f1f77344
commit
75c9ae5087
5 changed files with 28 additions and 24 deletions
|
|
@ -27,7 +27,7 @@ using namespace Crafter;
|
||||||
|
|
||||||
std::vector<RenderingElement3DVulkan> RenderingElement3DVulkan::elements;
|
std::vector<RenderingElement3DVulkan> RenderingElement3DVulkan::elements;
|
||||||
|
|
||||||
RenderingElement3DVulkan::RenderingElement3DVulkan(Mesh& mesh) {
|
RenderingElement3DVulkan::RenderingElement3DVulkan(Mesh& mesh, std::uint32_t customIndex, std::uint32_t mask, std::uint32_t shaderOffset) {
|
||||||
VkAccelerationStructureDeviceAddressInfoKHR addrInfo {
|
VkAccelerationStructureDeviceAddressInfoKHR addrInfo {
|
||||||
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR,
|
.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR,
|
||||||
.accelerationStructure = mesh.accelerationStructure
|
.accelerationStructure = mesh.accelerationStructure
|
||||||
|
|
@ -35,10 +35,10 @@ RenderingElement3DVulkan::RenderingElement3DVulkan(Mesh& mesh) {
|
||||||
VkDeviceAddress blasDeviceAddr = VulkanDevice::vkGetAccelerationStructureDeviceAddressKHR(VulkanDevice::device, &addrInfo);
|
VkDeviceAddress blasDeviceAddr = VulkanDevice::vkGetAccelerationStructureDeviceAddressKHR(VulkanDevice::device, &addrInfo);
|
||||||
|
|
||||||
instance = {
|
instance = {
|
||||||
.instanceCustomIndex = 0,
|
.instanceCustomIndex = customIndex,
|
||||||
.mask = 0xFF,
|
.mask = mask,
|
||||||
.instanceShaderBindingTableRecordOffset = 0,
|
.instanceShaderBindingTableRecordOffset = shaderOffset,
|
||||||
.flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR | VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR,
|
.flags = VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR,
|
||||||
.accelerationStructureReference = blasDeviceAddr
|
.accelerationStructureReference = blasDeviceAddr
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -221,9 +221,16 @@ void VulkanDevice::CreateDevice() {
|
||||||
queueCreateInfo.queueCount = 1;
|
queueCreateInfo.queueCount = 1;
|
||||||
queueCreateInfo.pQueuePriorities = &priority;
|
queueCreateInfo.pQueuePriorities = &priority;
|
||||||
|
|
||||||
|
VkPhysicalDeviceVulkan12Features features12 {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES,
|
||||||
|
.runtimeDescriptorArray = VK_TRUE,
|
||||||
|
.bufferDeviceAddress = VK_TRUE
|
||||||
|
};
|
||||||
|
|
||||||
VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR vkPhysicalDeviceRayTracingPositionFetchFeatures {
|
VkPhysicalDeviceRayTracingPositionFetchFeaturesKHR vkPhysicalDeviceRayTracingPositionFetchFeatures {
|
||||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR,
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_POSITION_FETCH_FEATURES_KHR,
|
||||||
.rayTracingPositionFetch = VK_TRUE,
|
.pNext = &features12,
|
||||||
|
.rayTracingPositionFetch = VK_TRUE
|
||||||
};
|
};
|
||||||
|
|
||||||
VkPhysicalDeviceRayTracingPipelineFeaturesKHR physicalDeviceRayTracingPipelineFeatures{
|
VkPhysicalDeviceRayTracingPipelineFeaturesKHR physicalDeviceRayTracingPipelineFeatures{
|
||||||
|
|
@ -232,15 +239,9 @@ void VulkanDevice::CreateDevice() {
|
||||||
.rayTracingPipeline = VK_TRUE
|
.rayTracingPipeline = VK_TRUE
|
||||||
};
|
};
|
||||||
|
|
||||||
VkPhysicalDeviceBufferDeviceAddressFeatures deviceBufferDeviceAddressFeature = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES,
|
|
||||||
.pNext = &physicalDeviceRayTracingPipelineFeatures,
|
|
||||||
.bufferDeviceAddress = VK_TRUE
|
|
||||||
};
|
|
||||||
|
|
||||||
VkPhysicalDeviceAccelerationStructureFeaturesKHR deviceAccelerationStructureFeature = {
|
VkPhysicalDeviceAccelerationStructureFeaturesKHR deviceAccelerationStructureFeature = {
|
||||||
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR,
|
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR,
|
||||||
.pNext = &deviceBufferDeviceAddressFeature,
|
.pNext = &physicalDeviceRayTracingPipelineFeatures,
|
||||||
.accelerationStructure = VK_TRUE
|
.accelerationStructure = VK_TRUE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ export namespace Crafter {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for(VkDescriptorPoolSize& type : types) {
|
for(VkDescriptorPoolSize& type : types) {
|
||||||
if(type.type == binding.descriptorType && type.descriptorCount != 12345) {
|
if(type.type == binding.descriptorType && type.descriptorCount != 12345) {
|
||||||
type.descriptorCount += 1;
|
type.descriptorCount += binding.descriptorCount;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +86,7 @@ export namespace Crafter {
|
||||||
for(std::uint32_t i = 0; i < GetUniqueDiscriptorCount<Shaders...>(); i++){
|
for(std::uint32_t i = 0; i < GetUniqueDiscriptorCount<Shaders...>(); i++){
|
||||||
if(types[i].descriptorCount == 12345) {
|
if(types[i].descriptorCount == 12345) {
|
||||||
types[i].type = binding.descriptorType;
|
types[i].type = binding.descriptorType;
|
||||||
types[i].descriptorCount = 1;
|
types[i].descriptorCount = binding.descriptorCount;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ Lesser General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
You should have received a copy of the GNU Lesser General Public
|
||||||
License along with this library; if not, write to the Free Software
|
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;
|
module;
|
||||||
|
|
@ -40,7 +40,10 @@ export namespace Crafter {
|
||||||
VkImageView imageView;
|
VkImageView imageView;
|
||||||
VkDescriptorImageInfo descriptor;
|
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);
|
buffer.Create(VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, width * height);
|
||||||
|
|
||||||
VkImageCreateInfo imageInfo = {};
|
VkImageCreateInfo imageInfo = {};
|
||||||
|
|
@ -49,7 +52,7 @@ export namespace Crafter {
|
||||||
imageInfo.extent.width = width;
|
imageInfo.extent.width = width;
|
||||||
imageInfo.extent.height = height;
|
imageInfo.extent.height = height;
|
||||||
imageInfo.extent.depth = 1;
|
imageInfo.extent.depth = 1;
|
||||||
imageInfo.mipLevels = 10;
|
imageInfo.mipLevels = 5;
|
||||||
imageInfo.arrayLayers = 1;
|
imageInfo.arrayLayers = 1;
|
||||||
imageInfo.format = format;
|
imageInfo.format = format;
|
||||||
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
|
|
@ -78,20 +81,20 @@ export namespace Crafter {
|
||||||
viewInfo.format = format;
|
viewInfo.format = format;
|
||||||
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
viewInfo.subresourceRange.baseMipLevel = 0;
|
viewInfo.subresourceRange.baseMipLevel = 0;
|
||||||
viewInfo.subresourceRange.levelCount = 10;
|
viewInfo.subresourceRange.levelCount = 5;
|
||||||
viewInfo.subresourceRange.baseArrayLayer = 0;
|
viewInfo.subresourceRange.baseArrayLayer = 0;
|
||||||
viewInfo.subresourceRange.layerCount = 1;
|
viewInfo.subresourceRange.layerCount = 1;
|
||||||
|
|
||||||
VulkanDevice::CheckVkResult(vkCreateImageView(VulkanDevice::device, &viewInfo, nullptr, &imageView));
|
VulkanDevice::CheckVkResult(vkCreateImageView(VulkanDevice::device, &viewInfo, nullptr, &imageView));
|
||||||
|
|
||||||
// Final transition to shader read-only layout
|
// 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) {
|
void Update(const PixelType* bufferdata, VkCommandBuffer cmd) {
|
||||||
std::memcpy(buffer.value, bufferdata, height*width*sizeof(PixelType));
|
std::memcpy(buffer.value, bufferdata, height*width*sizeof(PixelType));
|
||||||
buffer.FlushDevice(cmd, VK_ACCESS_MEMORY_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
|
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{};
|
VkBufferImageCopy region{};
|
||||||
region.bufferOffset = 0;
|
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);
|
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)
|
// 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 mipWidth = std::max(1u, width >> i);
|
||||||
std::uint32_t mipHeight = std::max(1u, height >> 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_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:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ export namespace Crafter {
|
||||||
static std::vector<RenderingElement3DVulkan> elements;
|
static std::vector<RenderingElement3DVulkan> elements;
|
||||||
inline static VulkanBuffer<char, false, true, false> scratchBuffer;
|
inline static VulkanBuffer<char, false, true, false> scratchBuffer;
|
||||||
inline static std::vector<TlasWithBuffer> tlases;
|
inline static std::vector<TlasWithBuffer> 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);
|
static void BuildTLAS(VkCommandBuffer cmd, std::uint32_t index);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue