Commit d9618bf4 by Frank Henigman Committed by Commit Bot

Vulkan: prepare for buffer format fallbacks.

Generate code for buffer fallbacks as well as texture fallbacks. No functional change. BUG=angleproject:2405 Change-Id: I9f30a2cbb3cd9ba1d18474f99cba434b030b0232 Reviewed-on: https://chromium-review.googlesource.com/1113026 Commit-Queue: Frank Henigman <fjhenigman@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent ecbaf666
...@@ -66,9 +66,9 @@ ...@@ -66,9 +66,9 @@
"Vulkan format:src/libANGLE/renderer/angle_format_map.json": "Vulkan format:src/libANGLE/renderer/angle_format_map.json":
"82d80c3be2cdfcc17aec07cf2223907f", "82d80c3be2cdfcc17aec07cf2223907f",
"Vulkan format:src/libANGLE/renderer/vulkan/gen_vk_format_table.py": "Vulkan format:src/libANGLE/renderer/vulkan/gen_vk_format_table.py":
"85a1e412d2dc8d3c06a8f3249e0aae48", "86aa4d78d3f1c82f938f1175237c86ce",
"Vulkan format:src/libANGLE/renderer/vulkan/vk_format_map.json": "Vulkan format:src/libANGLE/renderer/vulkan/vk_format_map.json":
"0ea1d6c72f5ffabecbf8d5d68a527dc7", "ad20bf1583747eb8e70b991135803c3c",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py": "Vulkan internal shader programs:src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py":
"c1cc895645db3fe1cd284352890c219e", "c1cc895645db3fe1cd284352890c219e",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/src/FullScreenQuad.vert": "Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/src/FullScreenQuad.vert":
......
...@@ -135,7 +135,7 @@ angle::Result PixelBuffer::stageSubresourceUpdate(ContextVk *contextVk, ...@@ -135,7 +135,7 @@ angle::Result PixelBuffer::stageSubresourceUpdate(ContextVk *contextVk,
const uint8_t *source = pixels + inputSkipBytes; const uint8_t *source = pixels + inputSkipBytes;
LoadImageFunctionInfo loadFunction = vkFormat.loadFunctions(type); LoadImageFunctionInfo loadFunction = vkFormat.textureLoadFunctions(type);
loadFunction.loadFunction(extents.width, extents.height, extents.depth, source, inputRowPitch, loadFunction.loadFunction(extents.width, extents.height, extents.depth, source, inputRowPitch,
inputDepthPitch, stagingPointer, outputRowPitch, outputDepthPitch); inputDepthPitch, stagingPointer, outputRowPitch, outputDepthPitch);
...@@ -190,7 +190,7 @@ angle::Result PixelBuffer::stageSubresourceUpdateFromFramebuffer( ...@@ -190,7 +190,7 @@ angle::Result PixelBuffer::stageSubresourceUpdateFromFramebuffer(
const vk::Format &vkFormat = renderer->getFormat(formatInfo.sizedInternalFormat); const vk::Format &vkFormat = renderer->getFormat(formatInfo.sizedInternalFormat);
const angle::Format &storageFormat = vkFormat.textureFormat(); const angle::Format &storageFormat = vkFormat.textureFormat();
LoadImageFunctionInfo loadFunction = vkFormat.loadFunctions(formatInfo.type); LoadImageFunctionInfo loadFunction = vkFormat.textureLoadFunctions(formatInfo.type);
size_t outputRowPitch = storageFormat.pixelBytes * clippedRectangle.width; size_t outputRowPitch = storageFormat.pixelBytes * clippedRectangle.width;
size_t outputDepthPitch = outputRowPitch * clippedRectangle.height; size_t outputDepthPitch = outputRowPitch * clippedRectangle.height;
...@@ -590,7 +590,7 @@ angle::Result TextureVk::copySubImageImpl(const gl::Context *context, ...@@ -590,7 +590,7 @@ angle::Result TextureVk::copySubImageImpl(const gl::Context *context,
const gl::Offset modifiedDestOffset(destOffset.x + sourceArea.x - sourceArea.x, const gl::Offset modifiedDestOffset(destOffset.x + sourceArea.x - sourceArea.x,
destOffset.y + sourceArea.y - sourceArea.y, 0); destOffset.y + sourceArea.y - sourceArea.y, 0);
ContextVk *contextVk = vk::GetImpl(context); ContextVk *contextVk = vk::GetImpl(context);
RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
FramebufferVk *framebufferVk = vk::GetImpl(source); FramebufferVk *framebufferVk = vk::GetImpl(source);
......
...@@ -57,92 +57,85 @@ void Format::initialize(VkPhysicalDevice physicalDevice, const angle::Format &an ...@@ -57,92 +57,85 @@ void Format::initialize(VkPhysicalDevice physicalDevice, const angle::Format &an
}} // namespace rx }} // namespace rx
""" """
empty_format_entry_template = """{space}case angle::Format::ID::{format_id}: empty_format_entry_template = """case angle::Format::ID::{format_id}:
{space} // This format is not implemented in Vulkan. // This format is not implemented in Vulkan.
{space} break; break;
""" """
format_entry_template = """{space}case angle::Format::ID::{format_id}: format_entry_template = """case angle::Format::ID::{format_id}:
{space}{{ internalFormat = {internal_format};
{space} internalFormat = {internal_format}; {texture_template}
{space} textureFormatID = angle::Format::ID::{texture}; {buffer_template}
{space} vkTextureFormat = {vk_texture_format}; break;
{space} bufferFormatID = angle::Format::ID::{buffer};
{space} vkBufferFormat = {vk_buffer_format};
{space} dataInitializerFunction = {initializer};
{space} break;
{space}}}
""" """
# This currently only handles texture fallback formats. texture_basic_template = """textureFormatID = angle::Format::ID::{texture};
fallback_format_entry_template = """{space}case angle::Format::ID::{format_id}: vkTextureFormat = {vk_texture_format};
{space}{{ textureInitializerFunction = {texture_initializer};"""
{space} internalFormat = {internal_format};
{space} if (!HasFullFormatSupport(physicalDevice, {vk_texture_format}))
{space} {{
{space} textureFormatID = angle::Format::ID::{fallback_texture};
{space} vkTextureFormat = {fallback_vk_texture_format};
{space} dataInitializerFunction = {fallback_initializer};
{space} ASSERT(HasFullFormatSupport(physicalDevice, {fallback_vk_texture_format}));
{space} }}
{space} else
{space} {{
{space} textureFormatID = angle::Format::ID::{texture};
{space} vkTextureFormat = {vk_texture_format};
{space} dataInitializerFunction = {initializer};
{space} }}
{space} bufferFormatID = angle::Format::ID::{buffer};
{space} vkBufferFormat = {vk_buffer_format};
{space} break;
{space}}}
"""
def gen_format_case(angle, internal_format, vk_json_data): texture_fallback_template = """initTextureFallback(physicalDevice,
angle::Format::ID::{texture},
{vk_texture_format},
{texture_initializer},
angle::Format::ID::{texture_fallback},
{vk_texture_format_fallback},
{texture_initializer_fallback});"""
buffer_basic_template = """bufferFormatID = angle::Format::ID::{buffer};
vkBufferFormat = {vk_buffer_format};"""
buffer_fallback_template = """initBufferFallback(physicalDevice,
angle::Format::ID::{buffer},
{vk_buffer_format},
angle::Format::ID::{buffer_fallback},
{vk_buffer_format_fallback});"""
def gen_format_case(angle, internal_format, vk_json_data):
vk_map = vk_json_data["map"] vk_map = vk_json_data["map"]
vk_overrides = vk_json_data["overrides"] vk_overrides = vk_json_data["overrides"]
vk_fallbacks = vk_json_data["fallbacks"] vk_fallbacks = vk_json_data["fallbacks"]
args = { "format_id" : angle }
args = {
"space": " ",
"format_id": angle,
"internal_format": internal_format
}
if ((angle not in vk_map) and (angle not in vk_overrides) and if ((angle not in vk_map) and (angle not in vk_overrides) and
(angle not in vk_fallbacks)) or angle == 'NONE': (angle not in vk_fallbacks)) or angle == 'NONE':
return empty_format_entry_template.format(**args) return empty_format_entry_template.format(**args)
template = format_entry_template def get_formats_and_template(format, type, basic_template, fallback_template):
format = vk_overrides.get(format, {}).get(type, format)
if angle in vk_map: fallback = vk_fallbacks.get(format, {}).get(type, "NONE")
args["buffer"] = angle if format not in vk_map:
args["texture"] = angle format = "NONE"
template = ""
if angle in vk_overrides: elif fallback == "NONE":
args.update(vk_overrides[angle]) template = basic_template
else:
if angle in vk_fallbacks: template = fallback_template
template = fallback_format_entry_template return format, fallback, template
fallback = vk_fallbacks[angle]
assert not "buffer" in fallback, "Buffer fallbacks not yet supported" texture_format, texture_fallback, texture_template = get_formats_and_template(
assert "texture" in fallback, "Fallback must have a texture fallback" angle, "texture", texture_basic_template, texture_fallback_template)
buffer_format, buffer_fallback, buffer_template = get_formats_and_template(
args["fallback_texture"] = fallback["texture"] angle, "buffer", buffer_basic_template, buffer_fallback_template)
args["fallback_vk_texture_format"] = vk_map[fallback["texture"]]
args["fallback_initializer"] = angle_format.get_internal_format_initializer( args.update(
internal_format, fallback["texture"]) internal_format=internal_format,
texture_template=texture_template,
assert "buffer" in args, "Missing buffer format for " + angle texture=texture_format,
assert "texture" in args, "Missing texture format for " + angle vk_texture_format=vk_map[texture_format],
texture_initializer=angle_format.get_internal_format_initializer(internal_format,
args["vk_buffer_format"] = vk_map[args["buffer"]] texture_format),
args["vk_texture_format"] = vk_map[args["texture"]] texture_fallback=texture_fallback,
vk_texture_format_fallback=vk_map[texture_fallback],
args["initializer"] = angle_format.get_internal_format_initializer( texture_initializer_fallback=angle_format.get_internal_format_initializer(internal_format,
internal_format, args["texture"]) texture_fallback),
buffer_template=buffer_template,
return template.format(**args) buffer=buffer_format,
vk_buffer_format=vk_map[buffer_format],
buffer_fallback=buffer_fallback,
vk_buffer_format_fallback=vk_map[buffer_fallback],
)
return format_entry_template.format(**args).format(**args)
input_file_name = 'vk_format_map.json' input_file_name = 'vk_format_map.json'
out_file_name = 'vk_format_table' out_file_name = 'vk_format_table'
......
...@@ -203,23 +203,18 @@ ...@@ -203,23 +203,18 @@
}, },
"overrides": { "overrides": {
"A8_UNORM": { "A8_UNORM": {
"buffer": "NONE",
"texture": "R8_UNORM" "texture": "R8_UNORM"
}, },
"L8_UNORM": { "L8_UNORM": {
"buffer": "NONE",
"texture": "R8_UNORM" "texture": "R8_UNORM"
}, },
"L8A8_UNORM": { "L8A8_UNORM": {
"buffer": "NONE",
"texture": "R8G8_UNORM" "texture": "R8G8_UNORM"
}, },
"R4G4B4A4_UNORM": { "R4G4B4A4_UNORM": {
"buffer": "NONE",
"texture": "R8G8B8A8_UNORM" "texture": "R8G8B8A8_UNORM"
}, },
"R5G5B5A1_UNORM": { "R5G5B5A1_UNORM": {
"buffer": "NONE",
"texture": "A1R5G5B5_UNORM" "texture": "A1R5G5B5_UNORM"
}, },
"R8G8B8_UNORM": { "R8G8B8_UNORM": {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -42,6 +42,20 @@ void FillTextureFormatCaps(const VkFormatProperties &formatProperties, ...@@ -42,6 +42,20 @@ void FillTextureFormatCaps(const VkFormatProperties &formatProperties,
outTextureCaps->renderbuffer = outTextureCaps->textureAttachment; outTextureCaps->renderbuffer = outTextureCaps->textureAttachment;
} }
bool HasFullTextureFormatSupport(VkPhysicalDevice physicalDevice, VkFormat vkFormat)
{
VkFormatProperties formatProperties;
vk::GetFormatProperties(physicalDevice, vkFormat, &formatProperties);
constexpr uint32_t kBitsColor =
(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
constexpr uint32_t kBitsDepth = (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
return HasFormatFeatureBits(kBitsColor, formatProperties) ||
HasFormatFeatureBits(kBitsDepth, formatProperties);
}
} // anonymous namespace } // anonymous namespace
namespace vk namespace vk
...@@ -70,20 +84,6 @@ void GetFormatProperties(VkPhysicalDevice physicalDevice, ...@@ -70,20 +84,6 @@ void GetFormatProperties(VkPhysicalDevice physicalDevice,
} }
} }
bool HasFullFormatSupport(VkPhysicalDevice physicalDevice, VkFormat vkFormat)
{
VkFormatProperties formatProperties;
GetFormatProperties(physicalDevice, vkFormat, &formatProperties);
constexpr uint32_t kBitsColor =
(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
constexpr uint32_t kBitsDepth = (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
return HasFormatFeatureBits(kBitsColor, formatProperties) ||
HasFormatFeatureBits(kBitsDepth, formatProperties);
}
// Format implementation. // Format implementation.
Format::Format() Format::Format()
: angleFormatID(angle::Format::ID::NONE), : angleFormatID(angle::Format::ID::NONE),
...@@ -92,9 +92,46 @@ Format::Format() ...@@ -92,9 +92,46 @@ Format::Format()
vkTextureFormat(VK_FORMAT_UNDEFINED), vkTextureFormat(VK_FORMAT_UNDEFINED),
bufferFormatID(angle::Format::ID::NONE), bufferFormatID(angle::Format::ID::NONE),
vkBufferFormat(VK_FORMAT_UNDEFINED), vkBufferFormat(VK_FORMAT_UNDEFINED),
dataInitializerFunction(nullptr), textureInitializerFunction(nullptr),
loadFunctions() textureLoadFunctions()
{
}
void Format::initTextureFallback(VkPhysicalDevice physicalDevice,
angle::Format::ID format,
VkFormat vkFormat,
InitializeTextureDataFunction initializer,
angle::Format::ID fallbackFormat,
VkFormat fallbackVkFormat,
InitializeTextureDataFunction fallbackInitializer)
{
ASSERT(format != angle::Format::ID::NONE);
ASSERT(fallbackFormat != angle::Format::ID::NONE);
if (HasFullTextureFormatSupport(physicalDevice, vkFormat))
{
textureFormatID = format;
vkTextureFormat = vkFormat;
textureInitializerFunction = initializer;
}
else
{
textureFormatID = fallbackFormat;
vkTextureFormat = fallbackVkFormat;
textureInitializerFunction = fallbackInitializer;
ASSERT(HasFullTextureFormatSupport(physicalDevice, vkTextureFormat));
}
}
void Format::initBufferFallback(VkPhysicalDevice physicalDevice,
angle::Format::ID format,
VkFormat vkFormat,
angle::Format::ID fallbackFormat,
VkFormat fallbackVkFormat)
{ {
ASSERT(format != angle::Format::ID::NONE);
ASSERT(fallbackFormat != angle::Format::ID::NONE);
UNIMPLEMENTED();
} }
const angle::Format &Format::textureFormat() const const angle::Format &Format::textureFormat() const
...@@ -141,7 +178,7 @@ void FormatTable::initialize(VkPhysicalDevice physicalDevice, ...@@ -141,7 +178,7 @@ void FormatTable::initialize(VkPhysicalDevice physicalDevice,
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);
const GLenum internalFormat = mFormatData[formatIndex].internalFormat; const GLenum internalFormat = mFormatData[formatIndex].internalFormat;
mFormatData[formatIndex].loadFunctions = mFormatData[formatIndex].textureLoadFunctions =
GetLoadFunctionsMap(internalFormat, mFormatData[formatIndex].textureFormatID); GetLoadFunctionsMap(internalFormat, mFormatData[formatIndex].textureFormatID);
mFormatData[formatIndex].angleFormatID = formatID; mFormatData[formatIndex].angleFormatID = formatID;
......
...@@ -41,6 +41,20 @@ struct Format final : private angle::NonCopyable ...@@ -41,6 +41,20 @@ 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);
void initTextureFallback(VkPhysicalDevice physicalDevice,
angle::Format::ID format,
VkFormat vkFormat,
InitializeTextureDataFunction initializer,
angle::Format::ID fallbackFormat,
VkFormat fallbackVkFormat,
InitializeTextureDataFunction fallbackInitializer);
void initBufferFallback(VkPhysicalDevice physicalDevice,
angle::Format::ID format,
VkFormat vkFormat,
angle::Format::ID fallbackFormat,
VkFormat fallbackVkFormat);
const angle::Format &textureFormat() const; const angle::Format &textureFormat() const;
const angle::Format &bufferFormat() const; const angle::Format &bufferFormat() const;
const angle::Format &angleFormat() const; const angle::Format &angleFormat() const;
...@@ -51,8 +65,8 @@ struct Format final : private angle::NonCopyable ...@@ -51,8 +65,8 @@ struct Format final : private angle::NonCopyable
VkFormat vkTextureFormat; VkFormat vkTextureFormat;
angle::Format::ID bufferFormatID; angle::Format::ID bufferFormatID;
VkFormat vkBufferFormat; VkFormat vkBufferFormat;
InitializeTextureDataFunction dataInitializerFunction; InitializeTextureDataFunction textureInitializerFunction;
LoadFunctionMap loadFunctions; LoadFunctionMap textureLoadFunctions;
}; };
bool operator==(const Format &lhs, const Format &rhs); bool operator==(const Format &lhs, const Format &rhs);
...@@ -83,8 +97,6 @@ class FormatTable final : angle::NonCopyable ...@@ -83,8 +97,6 @@ class FormatTable final : angle::NonCopyable
// initialized to 0. // initialized to 0.
const VkFormatProperties &GetMandatoryFormatSupport(VkFormat vkFormat); const VkFormatProperties &GetMandatoryFormatSupport(VkFormat vkFormat);
bool HasFullFormatSupport(VkPhysicalDevice physicalDevice, VkFormat vkFormat);
} // namespace vk } // namespace vk
} // namespace rx } // namespace rx
......
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