Commit 1d7be50a by Jamie Madill Committed by Commit Bot

Vulkan: Upgrade RGB8 textures to RGBA8.

It's unlikely any real hardware supports this format. Hack in a fixed fallback format for RGB8. We could consider implementing conditional support by checking the VkPhysicalDevice properties. This extends the Vulkan format support info in the RendererVk class to distinguish between a Buffer and Texture format. This is closely related to how Vulkan has separate format support bits for Linear Textures, Optimal Textures, and Buffers. We probably won't need to keep separate caps for Linear/Optimal, but it makes sense for Buffers to eventually use the same format tables. BUG=angleproject:2207 Change-Id: I8d427a99db15b314b13dd99f31aa1ac5055f0881 Reviewed-on: https://chromium-review.googlesource.com/742376 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent 7b62cf97
...@@ -38,7 +38,7 @@ gl::ErrorOrResult<const gl::InternalFormat *> GetReadAttachmentInfo( ...@@ -38,7 +38,7 @@ gl::ErrorOrResult<const gl::InternalFormat *> GetReadAttachmentInfo(
RenderTargetVk *renderTarget = nullptr; RenderTargetVk *renderTarget = nullptr;
ANGLE_TRY(readAttachment->getRenderTarget(context, &renderTarget)); ANGLE_TRY(readAttachment->getRenderTarget(context, &renderTarget));
GLenum implFormat = renderTarget->format->format().fboImplementationInternalFormat; GLenum implFormat = renderTarget->format->textureFormat().fboImplementationInternalFormat;
return &gl::GetSizedInternalFormatInfo(implFormat); return &gl::GetSizedInternalFormatInfo(implFormat);
} }
...@@ -316,7 +316,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context, ...@@ -316,7 +316,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
ANGLE_TRY( ANGLE_TRY(
stagingImage.getDeviceMemory().map(device, 0, stagingImage.getSize(), 0, &mapPointer)); stagingImage.getDeviceMemory().map(device, 0, stagingImage.getSize(), 0, &mapPointer));
const auto &angleFormat = renderTarget->format->format(); const auto &angleFormat = renderTarget->format->textureFormat();
// TODO(jmadill): Use pixel bytes from the ANGLE format directly. // TODO(jmadill): Use pixel bytes from the ANGLE format directly.
const auto &glFormat = gl::GetSizedInternalFormatInfo(angleFormat.glInternalFormat); const auto &glFormat = gl::GetSizedInternalFormatInfo(angleFormat.glInternalFormat);
...@@ -395,7 +395,7 @@ gl::ErrorOrResult<vk::RenderPass *> FramebufferVk::getRenderPass(const gl::Conte ...@@ -395,7 +395,7 @@ gl::ErrorOrResult<vk::RenderPass *> FramebufferVk::getRenderPass(const gl::Conte
// TODO(jmadill): We would only need this flag for duplicated attachments. // TODO(jmadill): We would only need this flag for duplicated attachments.
colorDesc.flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT; colorDesc.flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT;
colorDesc.format = renderTarget->format->native; colorDesc.format = renderTarget->format->vkTextureFormat;
colorDesc.samples = ConvertSamples(colorAttachment.getSamples()); colorDesc.samples = ConvertSamples(colorAttachment.getSamples());
// The load op controls the prior existing depth/color attachment data. // The load op controls the prior existing depth/color attachment data.
...@@ -429,7 +429,7 @@ gl::ErrorOrResult<vk::RenderPass *> FramebufferVk::getRenderPass(const gl::Conte ...@@ -429,7 +429,7 @@ gl::ErrorOrResult<vk::RenderPass *> FramebufferVk::getRenderPass(const gl::Conte
ANGLE_TRY(depthStencilAttachment->getRenderTarget(context, &renderTarget)); ANGLE_TRY(depthStencilAttachment->getRenderTarget(context, &renderTarget));
depthStencilDesc.flags = 0; depthStencilDesc.flags = 0;
depthStencilDesc.format = renderTarget->format->native; depthStencilDesc.format = renderTarget->format->vkTextureFormat;
depthStencilDesc.samples = ConvertSamples(depthStencilAttachment->getSamples()); depthStencilDesc.samples = ConvertSamples(depthStencilAttachment->getSamples());
depthStencilDesc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; depthStencilDesc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthStencilDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE; depthStencilDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
......
...@@ -775,7 +775,7 @@ vk::Error RendererVk::createStagingImage(TextureDimension dimension, ...@@ -775,7 +775,7 @@ vk::Error RendererVk::createStagingImage(TextureDimension dimension,
vk::StagingImage *imageOut) vk::StagingImage *imageOut)
{ {
ANGLE_TRY(imageOut->init(mDevice, mCurrentQueueFamilyIndex, mMemoryProperties, dimension, ANGLE_TRY(imageOut->init(mDevice, mCurrentQueueFamilyIndex, mMemoryProperties, dimension,
format.native, extent, usage)); format.vkTextureFormat, extent, usage));
return vk::NoError(); return vk::NoError();
} }
......
...@@ -301,8 +301,8 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer) ...@@ -301,8 +301,8 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount, ANGLE_VK_TRY(vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, mSurface, &surfaceFormatCount,
surfaceFormats.data())); surfaceFormats.data()));
mRenderTarget.format = &GetVkFormatFromConfig(renderer, *mState.config); mRenderTarget.format = &GetVkFormatFromConfig(renderer, *mState.config);
auto nativeFormat = mRenderTarget.format->native; VkFormat nativeFormat = mRenderTarget.format->vkTextureFormat;
if (surfaceFormatCount == 1u && surfaceFormats[0].format == VK_FORMAT_UNDEFINED) if (surfaceFormatCount == 1u && surfaceFormats[0].format == VK_FORMAT_UNDEFINED)
{ {
......
...@@ -86,7 +86,7 @@ gl::Error TextureVk::setImage(const gl::Context *context, ...@@ -86,7 +86,7 @@ gl::Error TextureVk::setImage(const gl::Context *context,
imageInfo.pNext = nullptr; imageInfo.pNext = nullptr;
imageInfo.flags = 0; imageInfo.flags = 0;
imageInfo.imageType = VK_IMAGE_TYPE_2D; imageInfo.imageType = VK_IMAGE_TYPE_2D;
imageInfo.format = vkFormat.native; imageInfo.format = vkFormat.vkTextureFormat;
imageInfo.extent.width = size.width; imageInfo.extent.width = size.width;
imageInfo.extent.height = size.height; imageInfo.extent.height = size.height;
imageInfo.extent.depth = size.depth; imageInfo.extent.depth = size.depth;
...@@ -128,7 +128,7 @@ gl::Error TextureVk::setImage(const gl::Context *context, ...@@ -128,7 +128,7 @@ gl::Error TextureVk::setImage(const gl::Context *context,
viewInfo.flags = 0; viewInfo.flags = 0;
viewInfo.image = mImage.getHandle(); viewInfo.image = mImage.getHandle();
viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D; viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
viewInfo.format = vkFormat.native; viewInfo.format = vkFormat.vkTextureFormat;
viewInfo.components.r = VK_COMPONENT_SWIZZLE_R; viewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
viewInfo.components.g = VK_COMPONENT_SWIZZLE_G; viewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
viewInfo.components.b = VK_COMPONENT_SWIZZLE_B; viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
......
...@@ -19,16 +19,23 @@ namespace vk ...@@ -19,16 +19,23 @@ namespace vk
Format::Format() Format::Format()
: internalFormat(GL_NONE), : internalFormat(GL_NONE),
formatID(angle::Format::ID::NONE), textureFormatID(angle::Format::ID::NONE),
native(VK_FORMAT_UNDEFINED), vkTextureFormat(VK_FORMAT_UNDEFINED),
bufferFormatID(angle::Format::ID::NONE),
vkBufferFormat(VK_FORMAT_UNDEFINED),
dataInitializerFunction(nullptr), dataInitializerFunction(nullptr),
loadFunctions() loadFunctions()
{ {
} }
const angle::Format &Format::format() const const angle::Format &Format::textureFormat() const
{ {
return angle::Format::Get(formatID); return angle::Format::Get(textureFormatID);
}
const angle::Format &Format::bufferFormat() const
{
return angle::Format::Get(bufferFormatID);
} }
FormatTable::FormatTable() FormatTable::FormatTable()
...@@ -47,8 +54,8 @@ void FormatTable::initialize(VkPhysicalDevice physicalDevice, gl::TextureCapsMap ...@@ -47,8 +54,8 @@ void FormatTable::initialize(VkPhysicalDevice physicalDevice, gl::TextureCapsMap
const angle::Format &angleFormat = angle::Format::Get(formatID); const angle::Format &angleFormat = angle::Format::Get(formatID);
mFormatData[formatIndex].initialize(physicalDevice, angleFormat); mFormatData[formatIndex].initialize(physicalDevice, angleFormat);
mFormatData[formatIndex].loadFunctions = mFormatData[formatIndex].loadFunctions = GetLoadFunctionsMap(
GetLoadFunctionsMap(mFormatData[formatIndex].internalFormat, formatID); mFormatData[formatIndex].internalFormat, mFormatData[formatIndex].textureFormatID);
} }
} }
......
...@@ -35,11 +35,14 @@ struct Format final : private angle::NonCopyable ...@@ -35,11 +35,14 @@ struct Format final : private angle::NonCopyable
// This is an auto-generated method in vk_format_table_autogen.cpp. // This is an auto-generated method in vk_format_table_autogen.cpp.
void initialize(VkPhysicalDevice physicalDevice, const angle::Format &angleFormat); void initialize(VkPhysicalDevice physicalDevice, const angle::Format &angleFormat);
const angle::Format &format() const; const angle::Format &textureFormat() const;
const angle::Format &bufferFormat() const;
GLenum internalFormat; GLenum internalFormat;
angle::Format::ID formatID; angle::Format::ID textureFormatID;
VkFormat native; VkFormat vkTextureFormat;
angle::Format::ID bufferFormatID;
VkFormat vkBufferFormat;
InitializeTextureDataFunction dataInitializerFunction; InitializeTextureDataFunction dataInitializerFunction;
LoadFunctionMap loadFunctions; LoadFunctionMap loadFunctions;
}; };
......
...@@ -57,16 +57,18 @@ void Format::initialize(VkPhysicalDevice physicalDevice, const angle::Format &an ...@@ -57,16 +57,18 @@ void Format::initialize(VkPhysicalDevice physicalDevice, const angle::Format &an
}} // namespace rx }} // namespace rx
""" """
empty_format_entry_template = """{space}case angle::Format::ID::{formatName}: empty_format_entry_template = """{space}case angle::Format::ID::{format_id}:
{space} // This format is not implemented in Vulkan. {space} // This format is not implemented in Vulkan.
{space} break; {space} break;
""" """
format_entry_template = """{space}case angle::Format::ID::{formatName}: format_entry_template = """{space}case angle::Format::ID::{format_id}:
{space}{{ {space}{{
{space} internalFormat = {internalFormat}; {space} internalFormat = {internal_format};
{space} formatID = angle::Format::ID::{formatName}; {space} textureFormatID = angle::Format::ID::{texture_format_id};
{space} native = {vkFormat}; {space} vkTextureFormat = {vk_texture_format};
{space} bufferFormatID = angle::Format::ID::{buffer_format_id};
{space} vkBufferFormat = {vk_buffer_format};
{space} dataInitializerFunction = {initializer}; {space} dataInitializerFunction = {initializer};
{space} break; {space} break;
{space}}} {space}}}
...@@ -77,17 +79,44 @@ def gen_format_case(angle, internal_format, vk_map): ...@@ -77,17 +79,44 @@ def gen_format_case(angle, internal_format, vk_map):
if angle not in vk_map or angle == 'NONE': if angle not in vk_map or angle == 'NONE':
return empty_format_entry_template.format( return empty_format_entry_template.format(
space = ' ', space = ' ',
formatName = angle) format_id = angle)
texture_format_id = angle
buffer_format_id = angle
vk_format_name = vk_map[angle] vk_format_name = vk_map[angle]
vk_buffer_format = vk_format_name
vk_texture_format = vk_format_name
if isinstance(vk_format_name, dict):
info = vk_format_name
vk_format_name = info["native"]
if "buffer" in info:
buffer_format_id = info["buffer"]
vk_buffer_format = vk_map[buffer_format_id]
assert(not isinstance(vk_buffer_format, dict))
else:
vk_buffer_format = vk_format_name
if "texture" in info:
texture_format_id = info["texture"]
vk_texture_format = vk_map[texture_format_id]
assert(not isinstance(vk_texture_format, dict))
else:
vk_texture_format = vk_format_name
initializer = angle_format.get_internal_format_initializer( initializer = angle_format.get_internal_format_initializer(
internal_format, vk_format_name) internal_format, texture_format_id)
return format_entry_template.format( return format_entry_template.format(
space = ' ', space = ' ',
internalFormat = internal_format, internal_format = internal_format,
formatName = angle, format_id = angle,
vkFormat = vk_format_name, texture_format_id = texture_format_id,
buffer_format_id = buffer_format_id,
vk_buffer_format = vk_buffer_format,
vk_texture_format = vk_texture_format,
initializer = initializer) initializer = initializer)
input_file_name = 'vk_format_map.json' input_file_name = 'vk_format_map.json'
......
...@@ -17,7 +17,10 @@ ...@@ -17,7 +17,10 @@
"R8G8_UINT": "VK_FORMAT_R8G8_UINT", "R8G8_UINT": "VK_FORMAT_R8G8_UINT",
"R8G8_SINT": "VK_FORMAT_R8G8_SINT", "R8G8_SINT": "VK_FORMAT_R8G8_SINT",
"R8G8_SRGB": "VK_FORMAT_R8G8_SRGB", "R8G8_SRGB": "VK_FORMAT_R8G8_SRGB",
"R8G8B8_UNORM": "VK_FORMAT_R8G8B8_UNORM", "R8G8B8_UNORM": {
"native": "VK_FORMAT_R8G8B8_UNORM",
"texture": "R8G8B8A8_UNORM"
},
"R8G8B8_SNORM": "VK_FORMAT_R8G8B8_SNORM", "R8G8B8_SNORM": "VK_FORMAT_R8G8B8_SNORM",
"R8G8B8_UINT": "VK_FORMAT_R8G8B8_UINT", "R8G8B8_UINT": "VK_FORMAT_R8G8B8_UINT",
"R8G8B8_SINT": "VK_FORMAT_R8G8B8_SINT", "R8G8B8_SINT": "VK_FORMAT_R8G8B8_SINT",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment