mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
AbstractTexture: Add support for depth textures/formats
This commit is contained in:
@ -112,6 +112,21 @@ VkFormat GetVkFormatForHostTextureFormat(AbstractTextureFormat format)
|
||||
case AbstractTextureFormat::BGRA8:
|
||||
return VK_FORMAT_B8G8R8A8_UNORM;
|
||||
|
||||
case AbstractTextureFormat::R16:
|
||||
return VK_FORMAT_R16_UNORM;
|
||||
|
||||
case AbstractTextureFormat::D16:
|
||||
return VK_FORMAT_D16_UNORM;
|
||||
|
||||
case AbstractTextureFormat::R32F:
|
||||
return VK_FORMAT_R32_SFLOAT;
|
||||
|
||||
case AbstractTextureFormat::D32F:
|
||||
return VK_FORMAT_D32_SFLOAT;
|
||||
|
||||
case AbstractTextureFormat::D32F_S8:
|
||||
return VK_FORMAT_D32_SFLOAT_S8_UINT;
|
||||
|
||||
default:
|
||||
PanicAlert("Unhandled texture format.");
|
||||
return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
|
@ -79,14 +79,29 @@ std::unique_ptr<VKTexture> VKTexture::Create(const TextureConfig& tex_config)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Clear render targets before use to prevent reading uninitialized memory.
|
||||
VkClearColorValue clear_value = {{0.0f, 0.0f, 0.0f, 1.0f}};
|
||||
VkImageSubresourceRange clear_range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, tex_config.levels, 0,
|
||||
tex_config.layers};
|
||||
texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentInitCommandBuffer(),
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
vkCmdClearColorImage(g_command_buffer_mgr->GetCurrentInitCommandBuffer(), texture->GetImage(),
|
||||
texture->GetLayout(), &clear_value, 1, &clear_range);
|
||||
if (!IsDepthFormat(tex_config.format))
|
||||
{
|
||||
// Clear render targets before use to prevent reading uninitialized memory.
|
||||
VkClearColorValue clear_value = {{0.0f, 0.0f, 0.0f, 1.0f}};
|
||||
VkImageSubresourceRange clear_range = {VK_IMAGE_ASPECT_COLOR_BIT, 0, tex_config.levels, 0,
|
||||
tex_config.layers};
|
||||
texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentInitCommandBuffer(),
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
vkCmdClearColorImage(g_command_buffer_mgr->GetCurrentInitCommandBuffer(), texture->GetImage(),
|
||||
texture->GetLayout(), &clear_value, 1, &clear_range);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Clear render targets before use to prevent reading uninitialized memory.
|
||||
VkClearDepthStencilValue clear_value = {0.0f, 0};
|
||||
VkImageSubresourceRange clear_range = {VK_IMAGE_ASPECT_DEPTH_BIT, 0, tex_config.levels, 0,
|
||||
tex_config.layers};
|
||||
texture->TransitionToLayout(g_command_buffer_mgr->GetCurrentInitCommandBuffer(),
|
||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
vkCmdClearDepthStencilImage(g_command_buffer_mgr->GetCurrentInitCommandBuffer(),
|
||||
texture->GetImage(), texture->GetLayout(), &clear_value, 1,
|
||||
&clear_range);
|
||||
}
|
||||
}
|
||||
|
||||
return std::unique_ptr<VKTexture>(new VKTexture(tex_config, std::move(texture), framebuffer));
|
||||
|
Reference in New Issue
Block a user