Keep track of current texture layouts
* Fixes a few compute pipeline validation errors
This commit is contained in:
parent
1c52c348ed
commit
d999485325
3 changed files with 81 additions and 63 deletions
|
@ -377,6 +377,8 @@ GFXTexture* GFXVulkan::create_texture(const GFXTextureCreateInfo& info) {
|
|||
if(check_flag(info.usage, GFXTextureUsage::Storage))
|
||||
imageUsage |= VK_IMAGE_USAGE_STORAGE_BIT;
|
||||
|
||||
texture->usage = info.usage;
|
||||
|
||||
VkImageAspectFlagBits imageAspect;
|
||||
if (info.format == GFXPixelFormat::DEPTH_32F)
|
||||
imageAspect = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
|
@ -431,6 +433,8 @@ GFXTexture* GFXVulkan::create_texture(const GFXTextureCreateInfo& info) {
|
|||
texture->layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
}
|
||||
|
||||
texture->current_layout = texture->layout;
|
||||
|
||||
// allocate memory
|
||||
VkMemoryRequirements memRequirements;
|
||||
vkGetImageMemoryRequirements(device, texture->handle, &memRequirements);
|
||||
|
@ -950,8 +954,10 @@ GFXPipeline* GFXVulkan::create_graphics_pipeline(const GFXGraphicsPipelineCreate
|
|||
case GFXBindingType::StorageBuffer:
|
||||
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
|
||||
break;
|
||||
case GFXBindingType::Texture:
|
||||
case GFXBindingType::Texture: {
|
||||
descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
pipeline->bindings_marked_as_normal_images.push_back(binding.binding);
|
||||
}
|
||||
break;
|
||||
case GFXBindingType::StorageImage:
|
||||
{
|
||||
|
@ -1083,8 +1089,10 @@ GFXPipeline* GFXVulkan::create_compute_pipeline(const GFXComputePipelineCreateIn
|
|||
case GFXBindingType::StorageBuffer:
|
||||
descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
|
||||
break;
|
||||
case GFXBindingType::Texture:
|
||||
case GFXBindingType::Texture: {
|
||||
descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
pipeline->bindings_marked_as_normal_images.push_back(binding.binding);
|
||||
}
|
||||
break;
|
||||
case GFXBindingType::StorageImage:
|
||||
{
|
||||
|
@ -1388,8 +1396,10 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
|
|||
break;
|
||||
case GFXCommandType::Draw:
|
||||
{
|
||||
if(try_bind_descriptor())
|
||||
vkCmdDraw(cmd, command.data.draw.vertex_count, command.data.draw.instance_count, command.data.draw.vertex_offset, command.data.draw.base_instance);
|
||||
if(try_bind_descriptor()) {
|
||||
vkCmdDraw(cmd, command.data.draw.vertex_count, command.data.draw.instance_count,
|
||||
command.data.draw.vertex_offset, command.data.draw.base_instance);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GFXCommandType::DrawIndexed:
|
||||
|
@ -1467,8 +1477,27 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
|
|||
break;
|
||||
case GFXCommandType::Dispatch:
|
||||
{
|
||||
if(try_bind_descriptor())
|
||||
vkCmdDispatch(cmd, command.data.dispatch.group_count_x, command.data.dispatch.group_count_y, command.data.dispatch.group_count_z);
|
||||
if(try_bind_descriptor()) {
|
||||
for(auto binding : currentPipeline->bindings_marked_as_storage_images) {
|
||||
auto tex = (GFXVulkanTexture*)boundTextures[binding];
|
||||
inlineTransitionImageLayout(cmd, tex->handle, tex->format, tex->aspect, tex->range, tex->current_layout, VK_IMAGE_LAYOUT_GENERAL);
|
||||
}
|
||||
|
||||
vkCmdDispatch(cmd, command.data.dispatch.group_count_x, command.data.dispatch.group_count_y,
|
||||
command.data.dispatch.group_count_z);
|
||||
|
||||
for(auto binding : currentPipeline->bindings_marked_as_storage_images) {
|
||||
auto tex = (GFXVulkanTexture*)boundTextures[binding];
|
||||
|
||||
VkImageLayout next_layout = tex->layout;
|
||||
if((tex->usage & GFXTextureUsage::Sampled) == GFXTextureUsage::Sampled)
|
||||
next_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
|
||||
inlineTransitionImageLayout(cmd, tex->handle, tex->format, tex->aspect, tex->range, VK_IMAGE_LAYOUT_GENERAL, next_layout);
|
||||
|
||||
tex->current_layout = next_layout;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GFXCommandType::PushGroup:
|
||||
|
@ -2002,8 +2031,7 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe
|
|||
return;
|
||||
|
||||
// update set
|
||||
int i = 0;
|
||||
for (auto& buffer : boundShaderBuffers) {
|
||||
for (auto [i, buffer] : utility::enumerate(boundShaderBuffers)) {
|
||||
if (buffer.buffer != nullptr) {
|
||||
GFXVulkanBuffer* vulkanBuffer = (GFXVulkanBuffer*)buffer.buffer;
|
||||
|
||||
|
@ -2022,17 +2050,10 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe
|
|||
|
||||
vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0, nullptr);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (auto& texture : boundTextures) {
|
||||
if (texture == nullptr) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (auto [i, texture] : utility::enumerate(boundTextures)) {
|
||||
if (texture != nullptr) {
|
||||
GFXVulkanTexture* vulkanTexture = (GFXVulkanTexture*) texture;
|
||||
|
||||
VkDescriptorImageInfo imageInfo = {};
|
||||
|
@ -2058,17 +2079,11 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe
|
|||
descriptorWrite.pImageInfo = &imageInfo;
|
||||
|
||||
vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0, nullptr);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for (auto& sampler : boundSamplers) {
|
||||
if (sampler == nullptr) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& [i, sampler] : utility::enumerate(boundSamplers)) {
|
||||
if (sampler != nullptr) {
|
||||
GFXVulkanSampler* vulkanSampler = (GFXVulkanSampler*) sampler;
|
||||
|
||||
VkDescriptorImageInfo imageInfo = {};
|
||||
|
@ -2083,8 +2098,7 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe
|
|||
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
|
||||
|
||||
vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0, nullptr);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
pipeline->cachedDescriptorSets[hash] = descriptorSet;
|
||||
|
|
|
@ -15,6 +15,7 @@ public:
|
|||
|
||||
VkDescriptorSetLayout descriptorLayout;
|
||||
|
||||
std::vector<int> bindings_marked_as_normal_images;
|
||||
std::vector<int> bindings_marked_as_storage_images;
|
||||
std::vector<int> bindings_marked_as_sampled_images;
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ public:
|
|||
|
||||
VkFormat format;
|
||||
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
VkImageLayout current_layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
VkImageAspectFlagBits aspect;
|
||||
VkImageSubresourceRange range;
|
||||
|
||||
GFXTextureUsage usage;
|
||||
};
|
||||
|
|
Reference in a new issue