Vulkan: Use angle::FormatID instead of VkFormat.

This change switches the internal enums we pass around from VkFormat
to FormatID. The end goal of the refactor is to allow the Vulkan
back-end to store packed tables indexed by FormatID. Because VkFormat
has large gaps in its enum space we'd otherwise need to use unordered
data structures like unordered_map.

The change removes the redundant VkFormat storage from vk::Format and
uses a new table query to return the VkFormat that 1:1 matches an
angle::FormatID. We also include a reverse mapping for use with native
Vulkan get functions for Android.

Also moves sRGB conversion functions into renderer_utils. A couple
sRGB formats that don't exist in GL are no longer handled by the sRGB
conversion functions. These formats should be extremely rare.

Bug: angleproject:5438
Change-Id: Id8b49773ca0c556f9f5a6a10fcf0d9762b93bbea
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2618204
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Ian Elliott <ianelliott@google.com>
This commit is contained in:
Jamie Madill 2021-01-08 17:29:42 -05:00 коммит произвёл Commit Bot
Родитель d21d682d03
Коммит 2e9706d80d
26 изменённых файлов: 1052 добавлений и 841 удалений

Просмотреть файл

@ -4,9 +4,9 @@
"src/libANGLE/renderer/angle_format_map.json":
"aa4a0d3463b76858a75787b9cdec8e98",
"src/libANGLE/renderer/vulkan/gen_vk_format_table.py":
"bf2279d1d8da7e3e271a352e101c8956",
"0bc8a6deefd856387da0bccf3817dde7",
"src/libANGLE/renderer/vulkan/vk_format_map.json":
"b62588b1e9f6d9fa98aeea886d8ed2bd",
"src/libANGLE/renderer/vulkan/vk_format_table_autogen.cpp":
"4dfb7525b4f45690091d6642e77481a3"
"ff081c37d8dfabdf87f46af9bf8e295a"
}

Просмотреть файл

@ -109,12 +109,12 @@ const TextureCaps &TextureCapsMap::get(GLenum internalFormat) const
const TextureCaps &TextureCapsMap::get(angle::FormatID formatID) const
{
return mFormatData[static_cast<size_t>(formatID)];
return mFormatData[formatID];
}
TextureCaps &TextureCapsMap::get(angle::FormatID formatID)
{
return mFormatData[static_cast<size_t>(formatID)];
return mFormatData[formatID];
}
void TextureCapsMap::set(angle::FormatID formatID, const TextureCaps &caps)

Просмотреть файл

@ -79,7 +79,7 @@ class TextureCapsMap final : angle::NonCopyable
TextureCaps &get(angle::FormatID formatID);
// Indexed by angle::FormatID
std::array<TextureCaps, angle::kNumANGLEFormats> mFormatData;
angle::FormatMap<TextureCaps> mFormatData;
};
void InitMinimumTextureCapsMap(const Version &clientVersion,

Просмотреть файл

@ -226,6 +226,9 @@ constexpr bool Format::isVertexTypeHalfFloat() const
return vertexAttribType == gl::VertexAttribType::HalfFloat;
}
template <typename T>
using FormatMap = PackedEnumMap<FormatID, T, kNumANGLEFormats>;
} // namespace angle
#endif // LIBANGLE_RENDERER_FORMAT_H_

Просмотреть файл

@ -1238,4 +1238,130 @@ ResetBaseVertexBaseInstance::~ResetBaseVertexBaseInstance()
}
}
angle::FormatID ConvertToSRGB(angle::FormatID formatID)
{
switch (formatID)
{
case angle::FormatID::R8_UNORM:
return angle::FormatID::R8_UNORM_SRGB;
case angle::FormatID::R8G8B8_UNORM:
return angle::FormatID::R8G8B8_UNORM_SRGB;
case angle::FormatID::R8G8B8A8_UNORM:
return angle::FormatID::R8G8B8A8_UNORM_SRGB;
case angle::FormatID::B8G8R8A8_UNORM:
return angle::FormatID::B8G8R8A8_UNORM_SRGB;
case angle::FormatID::BC1_RGB_UNORM_BLOCK:
return angle::FormatID::BC1_RGB_UNORM_SRGB_BLOCK;
case angle::FormatID::BC1_RGBA_UNORM_BLOCK:
return angle::FormatID::BC1_RGBA_UNORM_SRGB_BLOCK;
case angle::FormatID::BC2_RGBA_UNORM_BLOCK:
return angle::FormatID::BC2_RGBA_UNORM_SRGB_BLOCK;
case angle::FormatID::BC3_RGBA_UNORM_BLOCK:
return angle::FormatID::BC3_RGBA_UNORM_SRGB_BLOCK;
case angle::FormatID::BPTC_RGBA_UNORM_BLOCK:
return angle::FormatID::BPTC_SRGB_ALPHA_UNORM_BLOCK;
case angle::FormatID::ETC2_R8G8B8_UNORM_BLOCK:
return angle::FormatID::ETC2_R8G8B8_SRGB_BLOCK;
case angle::FormatID::ETC2_R8G8B8A1_UNORM_BLOCK:
return angle::FormatID::ETC2_R8G8B8A1_SRGB_BLOCK;
case angle::FormatID::ETC2_R8G8B8A8_UNORM_BLOCK:
return angle::FormatID::ETC2_R8G8B8A8_SRGB_BLOCK;
case angle::FormatID::ASTC_4x4_UNORM_BLOCK:
return angle::FormatID::ASTC_4x4_SRGB_BLOCK;
case angle::FormatID::ASTC_5x4_UNORM_BLOCK:
return angle::FormatID::ASTC_5x4_SRGB_BLOCK;
case angle::FormatID::ASTC_5x5_UNORM_BLOCK:
return angle::FormatID::ASTC_5x5_SRGB_BLOCK;
case angle::FormatID::ASTC_6x5_UNORM_BLOCK:
return angle::FormatID::ASTC_6x5_SRGB_BLOCK;
case angle::FormatID::ASTC_6x6_UNORM_BLOCK:
return angle::FormatID::ASTC_6x6_SRGB_BLOCK;
case angle::FormatID::ASTC_8x5_UNORM_BLOCK:
return angle::FormatID::ASTC_8x5_SRGB_BLOCK;
case angle::FormatID::ASTC_8x6_UNORM_BLOCK:
return angle::FormatID::ASTC_8x6_SRGB_BLOCK;
case angle::FormatID::ASTC_8x8_UNORM_BLOCK:
return angle::FormatID::ASTC_8x8_SRGB_BLOCK;
case angle::FormatID::ASTC_10x5_UNORM_BLOCK:
return angle::FormatID::ASTC_10x5_SRGB_BLOCK;
case angle::FormatID::ASTC_10x6_UNORM_BLOCK:
return angle::FormatID::ASTC_10x6_SRGB_BLOCK;
case angle::FormatID::ASTC_10x8_UNORM_BLOCK:
return angle::FormatID::ASTC_10x8_SRGB_BLOCK;
case angle::FormatID::ASTC_10x10_UNORM_BLOCK:
return angle::FormatID::ASTC_10x10_SRGB_BLOCK;
case angle::FormatID::ASTC_12x10_UNORM_BLOCK:
return angle::FormatID::ASTC_12x10_SRGB_BLOCK;
case angle::FormatID::ASTC_12x12_UNORM_BLOCK:
return angle::FormatID::ASTC_12x12_SRGB_BLOCK;
default:
return angle::FormatID::NONE;
}
}
angle::FormatID ConvertToLinear(angle::FormatID formatID)
{
switch (formatID)
{
case angle::FormatID::R8_UNORM_SRGB:
return angle::FormatID::R8_UNORM;
case angle::FormatID::R8G8B8_UNORM_SRGB:
return angle::FormatID::R8G8B8_UNORM;
case angle::FormatID::R8G8B8A8_UNORM_SRGB:
return angle::FormatID::R8G8B8A8_UNORM;
case angle::FormatID::B8G8R8A8_UNORM_SRGB:
return angle::FormatID::B8G8R8A8_UNORM;
case angle::FormatID::BC1_RGB_UNORM_SRGB_BLOCK:
return angle::FormatID::BC1_RGB_UNORM_BLOCK;
case angle::FormatID::BC1_RGBA_UNORM_SRGB_BLOCK:
return angle::FormatID::BC1_RGBA_UNORM_BLOCK;
case angle::FormatID::BC2_RGBA_UNORM_SRGB_BLOCK:
return angle::FormatID::BC2_RGBA_UNORM_BLOCK;
case angle::FormatID::BC3_RGBA_UNORM_SRGB_BLOCK:
return angle::FormatID::BC3_RGBA_UNORM_BLOCK;
case angle::FormatID::BPTC_SRGB_ALPHA_UNORM_BLOCK:
return angle::FormatID::BPTC_RGBA_UNORM_BLOCK;
case angle::FormatID::ETC2_R8G8B8_SRGB_BLOCK:
return angle::FormatID::ETC2_R8G8B8_UNORM_BLOCK;
case angle::FormatID::ETC2_R8G8B8A1_SRGB_BLOCK:
return angle::FormatID::ETC2_R8G8B8A1_UNORM_BLOCK;
case angle::FormatID::ETC2_R8G8B8A8_SRGB_BLOCK:
return angle::FormatID::ETC2_R8G8B8A8_UNORM_BLOCK;
case angle::FormatID::ASTC_4x4_SRGB_BLOCK:
return angle::FormatID::ASTC_4x4_UNORM_BLOCK;
case angle::FormatID::ASTC_5x4_SRGB_BLOCK:
return angle::FormatID::ASTC_5x4_UNORM_BLOCK;
case angle::FormatID::ASTC_5x5_SRGB_BLOCK:
return angle::FormatID::ASTC_5x5_UNORM_BLOCK;
case angle::FormatID::ASTC_6x5_SRGB_BLOCK:
return angle::FormatID::ASTC_6x5_UNORM_BLOCK;
case angle::FormatID::ASTC_6x6_SRGB_BLOCK:
return angle::FormatID::ASTC_6x6_UNORM_BLOCK;
case angle::FormatID::ASTC_8x5_SRGB_BLOCK:
return angle::FormatID::ASTC_8x5_UNORM_BLOCK;
case angle::FormatID::ASTC_8x6_SRGB_BLOCK:
return angle::FormatID::ASTC_8x6_UNORM_BLOCK;
case angle::FormatID::ASTC_8x8_SRGB_BLOCK:
return angle::FormatID::ASTC_8x8_UNORM_BLOCK;
case angle::FormatID::ASTC_10x5_SRGB_BLOCK:
return angle::FormatID::ASTC_10x5_UNORM_BLOCK;
case angle::FormatID::ASTC_10x6_SRGB_BLOCK:
return angle::FormatID::ASTC_10x6_UNORM_BLOCK;
case angle::FormatID::ASTC_10x8_SRGB_BLOCK:
return angle::FormatID::ASTC_10x8_UNORM_BLOCK;
case angle::FormatID::ASTC_10x10_SRGB_BLOCK:
return angle::FormatID::ASTC_10x10_UNORM_BLOCK;
case angle::FormatID::ASTC_12x10_SRGB_BLOCK:
return angle::FormatID::ASTC_12x10_UNORM_BLOCK;
case angle::FormatID::ASTC_12x12_SRGB_BLOCK:
return angle::FormatID::ASTC_12x12_UNORM_BLOCK;
default:
return angle::FormatID::NONE;
}
}
bool IsOverridableLinearFormat(angle::FormatID formatID)
{
return ConvertToSRGB(formatID) != angle::FormatID::NONE;
}
} // namespace rx

Просмотреть файл

@ -417,6 +417,9 @@ class ResetBaseVertexBaseInstance : angle::NonCopyable
bool mResetBaseInstance;
};
angle::FormatID ConvertToSRGB(angle::FormatID formatID);
angle::FormatID ConvertToLinear(angle::FormatID formatID);
bool IsOverridableLinearFormat(angle::FormatID formatID);
} // namespace rx
// MultiDraw macro patterns

Просмотреть файл

@ -49,13 +49,13 @@ constexpr unsigned int kEmulatedAlphaValue = 1;
bool HasSrcBlitFeature(RendererVk *renderer, RenderTargetVk *srcRenderTarget)
{
const VkFormat srcFormat = srcRenderTarget->getImageFormat().actualImageVkFormat;
angle::FormatID srcFormat = srcRenderTarget->getImageFormat().actualImageFormatID;
return renderer->hasImageFormatFeatureBits(srcFormat, VK_FORMAT_FEATURE_BLIT_SRC_BIT);
}
bool HasDstBlitFeature(RendererVk *renderer, RenderTargetVk *dstRenderTarget)
{
const VkFormat dstFormat = dstRenderTarget->getImageFormat().actualImageVkFormat;
angle::FormatID dstFormat = dstRenderTarget->getImageFormat().actualImageFormatID;
return renderer->hasImageFormatFeatureBits(dstFormat, VK_FORMAT_FEATURE_BLIT_DST_BIT);
}
@ -87,7 +87,7 @@ bool AreSrcAndDstFormatsIdentical(RenderTargetVk *srcRenderTarget, RenderTargetV
const vk::Format &srcFormat = srcRenderTarget->getImageFormat();
const vk::Format &dstFormat = dstRenderTarget->getImageFormat();
return srcFormat.actualImageVkFormat == dstFormat.actualImageVkFormat;
return srcFormat.actualImageFormatID == dstFormat.actualImageFormatID;
}
bool AreSrcAndDstDepthStencilChannelsBlitCompatible(RenderTargetVk *srcRenderTarget,

Просмотреть файл

@ -178,7 +178,7 @@ angle::Result MemoryObjectVk::createImage(ContextVk *contextVk,
// values constituting the bits of |usageFlags| are identical to their corresponding Vulkan
// value.
const VkImageUsageFlags imageUsageFlags =
vk::GetMaximalImageUsageFlags(renderer, vkFormat.actualImageVkFormat) & usageFlags;
vk::GetMaximalImageUsageFlags(renderer, vkFormat.actualImageFormatID) & usageFlags;
VkExternalMemoryImageCreateInfo externalMemoryImageCreateInfo = {};
externalMemoryImageCreateInfo.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO;

Просмотреть файл

@ -217,7 +217,7 @@ angle::Result OverlayVk::onPresent(ContextVk *contextVk,
// If the swapchain image doesn't support storage image, we can't output to it.
VkFormatFeatureFlags featureBits = renderer->getImageFormatFeatureBits(
imageToPresent->getFormat().actualImageVkFormat, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT);
imageToPresent->getFormat().actualImageFormatID, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT);
if ((featureBits & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) == 0)
{
return angle::Result::Continue;

Просмотреть файл

@ -45,9 +45,9 @@ angle::Result RenderbufferVk::setStorageImpl(const gl::Context *context,
GLsizei height,
gl::MultisamplingMode mode)
{
ContextVk *contextVk = vk::GetImpl(context);
RendererVk *renderer = contextVk->getRenderer();
const vk::Format &vkFormat = renderer->getFormat(internalformat);
ContextVk *contextVk = vk::GetImpl(context);
RendererVk *renderer = contextVk->getRenderer();
const vk::Format &format = renderer->getFormat(internalformat);
if (!mOwnsImage)
{
@ -82,10 +82,11 @@ angle::Result RenderbufferVk::setStorageImpl(const gl::Context *context,
// causing it to be interpreted in a different colorspace. Create the VkImage accordingly.
VkImageCreateFlags imageCreateFlags = vk::kVkImageCreateFlagsNone;
VkImageFormatListCreateInfoKHR *additionalCreateInfo = nullptr;
VkFormat vkImageFormat = vkFormat.actualImageVkFormat;
VkFormat vkImageListFormat = vkFormat.actualImageFormat().isSRGB
? vk::ConvertToLinear(vkImageFormat)
: vk::ConvertToSRGB(vkImageFormat);
angle::FormatID imageFormat = format.actualImageFormatID;
angle::FormatID imageListFormat = format.actualImageFormat().isSRGB
? ConvertToLinear(imageFormat)
: ConvertToSRGB(imageFormat);
VkFormat vkFormat = vk::GetVkFormatFromFormatID(imageListFormat);
VkImageFormatListCreateInfoKHR formatListInfo = {};
if (renderer->getFeatures().supportsImageFormatList.enabled)
@ -97,11 +98,11 @@ angle::Result RenderbufferVk::setStorageImpl(const gl::Context *context,
formatListInfo.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR;
formatListInfo.pNext = nullptr;
formatListInfo.viewFormatCount = 1;
formatListInfo.pViewFormats = &vkImageListFormat;
formatListInfo.pViewFormats = &vkFormat;
additionalCreateInfo = &formatListInfo;
}
const angle::Format &textureFormat = vkFormat.actualImageFormat();
const angle::Format &textureFormat = format.actualImageFormat();
const bool isDepthStencilFormat = textureFormat.hasDepthOrStencilBits();
ASSERT(textureFormat.redBits > 0 || isDepthStencilFormat);
@ -124,7 +125,7 @@ angle::Result RenderbufferVk::setStorageImpl(const gl::Context *context,
bool robustInit = contextVk->isRobustResourceInitEnabled();
VkExtent3D extents = {static_cast<uint32_t>(width), static_cast<uint32_t>(height), 1u};
ANGLE_TRY(mImage->initExternal(contextVk, gl::TextureType::_2D, extents, vkFormat, imageSamples,
ANGLE_TRY(mImage->initExternal(contextVk, gl::TextureType::_2D, extents, format, imageSamples,
usage, imageCreateFlags, vk::ImageLayout::Undefined,
additionalCreateInfo, gl::LevelIndex(0), gl::LevelIndex(0), 1, 1,
robustInit));

Просмотреть файл

@ -2244,36 +2244,36 @@ Serial RendererVk::issueShaderSerial()
// These functions look at the mandatory format for support, and fallback to querying the device (if
// necessary) to test the availability of the bits.
bool RendererVk::hasLinearImageFormatFeatureBits(VkFormat format,
bool RendererVk::hasLinearImageFormatFeatureBits(angle::FormatID formatID,
const VkFormatFeatureFlags featureBits) const
{
return hasFormatFeatureBits<&VkFormatProperties::linearTilingFeatures>(format, featureBits);
return hasFormatFeatureBits<&VkFormatProperties::linearTilingFeatures>(formatID, featureBits);
}
VkFormatFeatureFlags RendererVk::getLinearImageFormatFeatureBits(
VkFormat format,
angle::FormatID formatID,
const VkFormatFeatureFlags featureBits) const
{
return getFormatFeatureBits<&VkFormatProperties::linearTilingFeatures>(format, featureBits);
return getFormatFeatureBits<&VkFormatProperties::linearTilingFeatures>(formatID, featureBits);
}
VkFormatFeatureFlags RendererVk::getImageFormatFeatureBits(
VkFormat format,
angle::FormatID formatID,
const VkFormatFeatureFlags featureBits) const
{
return getFormatFeatureBits<&VkFormatProperties::optimalTilingFeatures>(format, featureBits);
return getFormatFeatureBits<&VkFormatProperties::optimalTilingFeatures>(formatID, featureBits);
}
bool RendererVk::hasImageFormatFeatureBits(VkFormat format,
bool RendererVk::hasImageFormatFeatureBits(angle::FormatID formatID,
const VkFormatFeatureFlags featureBits) const
{
return hasFormatFeatureBits<&VkFormatProperties::optimalTilingFeatures>(format, featureBits);
return hasFormatFeatureBits<&VkFormatProperties::optimalTilingFeatures>(formatID, featureBits);
}
bool RendererVk::hasBufferFormatFeatureBits(VkFormat format,
bool RendererVk::hasBufferFormatFeatureBits(angle::FormatID formatID,
const VkFormatFeatureFlags featureBits) const
{
return hasFormatFeatureBits<&VkFormatProperties::bufferFeatures>(format, featureBits);
return hasFormatFeatureBits<&VkFormatProperties::bufferFeatures>(formatID, featureBits);
}
void RendererVk::outputVmaStatString()
@ -2323,27 +2323,28 @@ angle::Result RendererVk::queueSubmitOneOff(vk::Context *context,
}
template <VkFormatFeatureFlags VkFormatProperties::*features>
VkFormatFeatureFlags RendererVk::getFormatFeatureBits(VkFormat format,
VkFormatFeatureFlags RendererVk::getFormatFeatureBits(angle::FormatID formatID,
const VkFormatFeatureFlags featureBits) const
{
ASSERT(static_cast<uint32_t>(format) < vk::kNumVkFormats);
VkFormatProperties &deviceProperties = mFormatProperties[format];
VkFormatProperties &deviceProperties = mFormatProperties[formatID];
if (deviceProperties.bufferFeatures == kInvalidFormatFeatureFlags)
{
VkFormat vkFormat = vk::GetVkFormatFromFormatID(formatID);
// If we don't have the actual device features, see if the requested features are mandatory.
// If so, there's no need to query the device.
const VkFormatProperties &mandatoryProperties = vk::GetMandatoryFormatSupport(format);
const VkFormatProperties &mandatoryProperties = vk::GetMandatoryFormatSupport(vkFormat);
if (IsMaskFlagSet(mandatoryProperties.*features, featureBits))
{
return featureBits;
}
// Otherwise query the format features and cache it.
vkGetPhysicalDeviceFormatProperties(mPhysicalDevice, format, &deviceProperties);
vkGetPhysicalDeviceFormatProperties(mPhysicalDevice, vkFormat, &deviceProperties);
// Workaround for some Android devices that don't indicate filtering
// support on D16_UNORM and they should.
if (mFeatures.forceD16TexFilter.enabled && format == VK_FORMAT_D16_UNORM)
if (mFeatures.forceD16TexFilter.enabled && vkFormat == VK_FORMAT_D16_UNORM)
{
deviceProperties.*features |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
}
@ -2353,14 +2354,16 @@ VkFormatFeatureFlags RendererVk::getFormatFeatureBits(VkFormat format,
}
template <VkFormatFeatureFlags VkFormatProperties::*features>
bool RendererVk::hasFormatFeatureBits(VkFormat format, const VkFormatFeatureFlags featureBits) const
bool RendererVk::hasFormatFeatureBits(angle::FormatID formatID,
const VkFormatFeatureFlags featureBits) const
{
return IsMaskFlagSet(getFormatFeatureBits<features>(format, featureBits), featureBits);
return IsMaskFlagSet(getFormatFeatureBits<features>(formatID, featureBits), featureBits);
}
bool RendererVk::haveSameFormatFeatureBits(VkFormat fmt1, VkFormat fmt2) const
bool RendererVk::haveSameFormatFeatureBits(angle::FormatID formatID1,
angle::FormatID formatID2) const
{
if (fmt1 == VK_FORMAT_UNDEFINED || fmt2 == VK_FORMAT_UNDEFINED)
if (formatID1 == angle::FormatID::NONE || formatID2 == angle::FormatID::NONE)
{
return false;
}
@ -2370,12 +2373,12 @@ bool RendererVk::haveSameFormatFeatureBits(VkFormat fmt1, VkFormat fmt2) const
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
VkFormatFeatureFlags fmt1LinearFeatureBits =
getLinearImageFormatFeatureBits(fmt1, kImageUsageFeatureBits);
getLinearImageFormatFeatureBits(formatID1, kImageUsageFeatureBits);
VkFormatFeatureFlags fmt1OptimalFeatureBits =
getImageFormatFeatureBits(fmt1, kImageUsageFeatureBits);
getImageFormatFeatureBits(formatID1, kImageUsageFeatureBits);
return hasLinearImageFormatFeatureBits(fmt2, fmt1LinearFeatureBits) &&
hasImageFormatFeatureBits(fmt2, fmt1OptimalFeatureBits);
return hasLinearImageFormatFeatureBits(formatID2, fmt1LinearFeatureBits) &&
hasImageFormatFeatureBits(formatID2, fmt1OptimalFeatureBits);
}
angle::Result RendererVk::cleanupGarbage(Serial lastCompletedQueueSerial)

Просмотреть файл

@ -184,15 +184,17 @@ class RendererVk : angle::NonCopyable
// Query the format properties for select bits (linearTilingFeatures, optimalTilingFeatures and
// bufferFeatures). Looks through mandatory features first, and falls back to querying the
// device (first time only).
bool hasLinearImageFormatFeatureBits(VkFormat format,
bool hasLinearImageFormatFeatureBits(angle::FormatID format,
const VkFormatFeatureFlags featureBits) const;
VkFormatFeatureFlags getLinearImageFormatFeatureBits(
VkFormat format,
angle::FormatID format,
const VkFormatFeatureFlags featureBits) const;
VkFormatFeatureFlags getImageFormatFeatureBits(VkFormat format,
VkFormatFeatureFlags getImageFormatFeatureBits(angle::FormatID format,
const VkFormatFeatureFlags featureBits) const;
bool hasImageFormatFeatureBits(VkFormat format, const VkFormatFeatureFlags featureBits) const;
bool hasBufferFormatFeatureBits(VkFormat format, const VkFormatFeatureFlags featureBits) const;
bool hasImageFormatFeatureBits(angle::FormatID format,
const VkFormatFeatureFlags featureBits) const;
bool hasBufferFormatFeatureBits(angle::FormatID format,
const VkFormatFeatureFlags featureBits) const;
ANGLE_INLINE egl::ContextPriority getDriverPriority(egl::ContextPriority priority)
{
@ -323,7 +325,7 @@ class RendererVk : angle::NonCopyable
void outputVmaStatString();
bool haveSameFormatFeatureBits(VkFormat fmt1, VkFormat fmt2) const;
bool haveSameFormatFeatureBits(angle::FormatID formatID1, angle::FormatID formatID2) const;
angle::Result cleanupGarbage(Serial lastCompletedQueueSerial);
@ -386,11 +388,12 @@ class RendererVk : angle::NonCopyable
bool *success);
template <VkFormatFeatureFlags VkFormatProperties::*features>
VkFormatFeatureFlags getFormatFeatureBits(VkFormat format,
VkFormatFeatureFlags getFormatFeatureBits(angle::FormatID formatID,
const VkFormatFeatureFlags featureBits) const;
template <VkFormatFeatureFlags VkFormatProperties::*features>
bool hasFormatFeatureBits(VkFormat format, const VkFormatFeatureFlags featureBits) const;
bool hasFormatFeatureBits(angle::FormatID formatID,
const VkFormatFeatureFlags featureBits) const;
egl::Display *mDisplay;
@ -453,7 +456,7 @@ class RendererVk : angle::NonCopyable
bool mPipelineCacheInitialized;
// A cache of VkFormatProperties as queried from the device over time.
mutable std::array<VkFormatProperties, vk::kNumVkFormats> mFormatProperties;
mutable angle::FormatMap<VkFormatProperties> mFormatProperties;
// Latest validation data for debug overlay.
std::string mLastValidationMessage;

Просмотреть файл

@ -136,10 +136,11 @@ angle::Result InitImageHelper(DisplayVk *displayVk,
// causing it to be interpreted in a different colorspace. Create the VkImage accordingly.
VkImageCreateFlags imageCreateFlags = vk::kVkImageCreateFlagsNone;
VkImageFormatListCreateInfoKHR *additionalCreateInfo = nullptr;
VkFormat vkImageFormat = vkFormat.actualImageVkFormat;
VkFormat vkImageListFormat = vkFormat.actualImageFormat().isSRGB
? vk::ConvertToLinear(vkImageFormat)
: vk::ConvertToSRGB(vkImageFormat);
angle::FormatID imageFormat = vkFormat.actualImageFormatID;
angle::FormatID imageListFormat = vkFormat.actualImageFormat().isSRGB
? ConvertToLinear(imageFormat)
: ConvertToSRGB(imageFormat);
VkFormat imageListVkFormat = vk::GetVkFormatFromFormatID(imageListFormat);
VkImageFormatListCreateInfoKHR formatListInfo = {};
if (renderer->getFeatures().supportsImageFormatList.enabled)
@ -151,7 +152,7 @@ angle::Result InitImageHelper(DisplayVk *displayVk,
formatListInfo.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR;
formatListInfo.pNext = nullptr;
formatListInfo.viewFormatCount = 1;
formatListInfo.pViewFormats = &vkImageListFormat;
formatListInfo.pViewFormats = &imageListVkFormat;
additionalCreateInfo = &formatListInfo;
}
@ -680,7 +681,7 @@ angle::Result WindowSurfaceVk::initializeImpl(DisplayVk *displayVk)
surfaceFormats.data()));
const vk::Format &format = renderer->getFormat(mState.config->renderTargetFormat);
VkFormat nativeFormat = format.actualImageVkFormat;
VkFormat nativeFormat = format.actualImageVkFormat();
if (surfaceFormatCount == 1u && surfaceFormats[0].format == VK_FORMAT_UNDEFINED)
{
@ -929,7 +930,7 @@ angle::Result WindowSurfaceVk::createSwapChain(vk::Context *context,
VkDevice device = renderer->getDevice();
const vk::Format &format = renderer->getFormat(mState.config->renderTargetFormat);
VkFormat nativeFormat = format.actualImageVkFormat;
VkFormat nativeFormat = format.actualImageVkFormat();
gl::Extents rotatedExtents = extents;
if (Is90DegreeRotation(getPreTransform()))

Просмотреть файл

@ -152,10 +152,10 @@ bool CanCopyWithDraw(RendererVk *renderer,
{
// Checks that the formats in copy by drawing have the appropriate feature bits
bool srcFormatHasNecessaryFeature =
vk::FormatHasNecessaryFeature(renderer, srcFormat.actualImageVkFormat, srcTilingMode,
vk::FormatHasNecessaryFeature(renderer, srcFormat.actualImageFormatID, srcTilingMode,
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
bool dstFormatHasNecessaryFeature =
vk::FormatHasNecessaryFeature(renderer, destFormat.actualImageVkFormat, destTilingMode,
vk::FormatHasNecessaryFeature(renderer, destFormat.actualImageFormatID, destTilingMode,
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
return srcFormatHasNecessaryFeature && dstFormatHasNecessaryFeature;
@ -180,7 +180,7 @@ bool CanGenerateMipmapWithCompute(RendererVk *renderer,
// Format must have STORAGE support.
const bool hasStorageSupport = renderer->hasImageFormatFeatureBits(
format.actualImageVkFormat, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT);
format.actualImageFormatID, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT);
// No support for sRGB formats yet.
const bool isSRGB = angleFormat.isSRGB;
@ -1436,13 +1436,13 @@ void TextureVk::initImageUsageFlags(ContextVk *contextVk, const vk::Format &form
{
// Work around a bug in the Mock ICD:
// https://github.com/KhronosGroup/Vulkan-Tools/issues/445
if (renderer->hasImageFormatFeatureBits(format.actualImageVkFormat,
if (renderer->hasImageFormatFeatureBits(format.actualImageFormatID,
VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
{
mImageUsageFlags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
}
else if (renderer->hasImageFormatFeatureBits(format.actualImageVkFormat,
else if (renderer->hasImageFormatFeatureBits(format.actualImageFormatID,
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
{
mImageUsageFlags |=
@ -1859,7 +1859,7 @@ angle::Result TextureVk::generateMipmap(const gl::Context *context)
return generateMipmapsWithCompute(contextVk);
}
else if (renderer->hasImageFormatFeatureBits(mImage->getFormat().actualImageVkFormat,
else if (renderer->hasImageFormatFeatureBits(mImage->getFormat().actualImageFormatID,
kBlitFeatureFlags))
{
// Otherwise, use blit if possible.
@ -2484,7 +2484,7 @@ bool TextureVk::shouldDecodeSRGB(ContextVk *contextVk,
bool decodeSRGB = format.actualImageFormat().isSRGB;
// If the SRGB override is enabled, we also decode SRGB.
if (isSRGBOverrideEnabled() && vk::IsOverridableLinearFormat(format.actualImageVkFormat))
if (isSRGBOverrideEnabled() && IsOverridableLinearFormat(format.actualImageFormatID))
{
decodeSRGB = true;
}
@ -2558,7 +2558,7 @@ const vk::ImageView &TextureVk::getCopyImageViewAndRecordUse(ContextVk *contextV
imageViews.retain(&contextVk->getResourceUseList());
ASSERT(mImage->getFormat().actualImageFormat().isSRGB ==
(vk::ConvertToLinear(mImage->getFormat().actualImageVkFormat) != VK_FORMAT_UNDEFINED));
(ConvertToLinear(mImage->getFormat().actualImageFormatID) != angle::FormatID::NONE));
if (mImage->getFormat().actualImageFormat().isSRGB)
{
return imageViews.getSRGBCopyImageView();
@ -2598,7 +2598,7 @@ angle::Result TextureVk::getStorageImageView(ContextVk *contextVk,
return getImageViews().getLevelLayerStorageImageView(
contextVk, *mImage, nativeLevelVk, nativeLayer,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, format.actualImageVkFormat,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, format.actualImageFormatID,
imageViewOut);
}
@ -2606,7 +2606,7 @@ angle::Result TextureVk::getStorageImageView(ContextVk *contextVk,
return getImageViews().getLevelStorageImageView(
contextVk, mState.getType(), *mImage, nativeLevelVk, nativeLayer,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, format.actualImageVkFormat,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT, format.actualImageFormatID,
imageViewOut);
}
@ -2648,13 +2648,15 @@ angle::Result TextureVk::initImage(ContextVk *contextVk,
// With the introduction of sRGB related GLES extensions any texture could be respecified
// causing it to be interpreted in a different colorspace. Create the VkImage accordingly.
VkImageFormatListCreateInfoKHR *additionalCreateInfo = nullptr;
VkFormat imageFormat = format.actualImageVkFormat;
VkFormat imageListFormat = format.actualImageFormat().isSRGB ? vk::ConvertToLinear(imageFormat)
: vk::ConvertToSRGB(imageFormat);
angle::FormatID imageFormat = format.actualImageFormatID;
angle::FormatID imageListFormat = format.actualImageFormat().isSRGB
? ConvertToLinear(imageFormat)
: ConvertToSRGB(imageFormat);
VkFormat vkFormat = vk::GetVkFormatFromFormatID(imageListFormat);
VkImageFormatListCreateInfoKHR formatListInfo = {};
if (renderer->getFeatures().supportsImageFormatList.enabled &&
renderer->haveSameFormatFeatureBits(imageFormat, imageListFormat))
renderer->haveSameFormatFeatureBits(format.actualImageFormatID, imageListFormat))
{
mRequiresMutableStorage = true;
@ -2665,7 +2667,7 @@ angle::Result TextureVk::initImage(ContextVk *contextVk,
formatListInfo.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR;
formatListInfo.pNext = nullptr;
formatListInfo.viewFormatCount = 1;
formatListInfo.pViewFormats = &imageListFormat;
formatListInfo.pViewFormats = &vkFormat;
additionalCreateInfo = &formatListInfo;
}

Просмотреть файл

@ -82,10 +82,14 @@ egl::Error HardwareBufferImageSiblingVkAndroid::ValidateHardwareBuffer(RendererV
<< bufferFormatProperties.externalFormat << " is unsupported ";
}
}
else if (!HasFullTextureFormatSupport(renderer, bufferFormatProperties.format))
else
{
return egl::EglBadParameter()
<< "AHardwareBuffer format does not support enough features to use as a texture.";
angle::FormatID formatID = vk::GetFormatIDFromVkFormat(bufferFormatProperties.format);
if (!HasFullTextureFormatSupport(renderer, formatID))
{
return egl::EglBadParameter() << "AHardwareBuffer format does not support enough "
"features to use as a texture.";
}
}
return egl::NoError();
@ -199,10 +203,11 @@ angle::Result HardwareBufferImageSiblingVkAndroid::initImpl(DisplayVk *displayVk
// With the introduction of sRGB related GLES extensions any texture could be respecified
// causing it to be interpreted in a different colorspace. Create the VkImage accordingly.
VkImageCreateFlags imageCreateFlags = vk::kVkImageCreateFlagsNone;
VkFormat vkImageFormat = vkFormat.actualImageVkFormat;
VkFormat vkImageListFormat = vkFormat.actualImageFormat().isSRGB
? vk::ConvertToLinear(vkImageFormat)
: vk::ConvertToSRGB(vkImageFormat);
angle::FormatID imageFormatID = vkFormat.actualImageFormatID;
angle::FormatID imageListFormatID = vkFormat.actualImageFormat().isSRGB
? ConvertToLinear(imageFormatID)
: ConvertToSRGB(imageFormatID);
VkFormat imageListVkFormat = vk::GetVkFormatFromFormatID(imageListFormatID);
VkImageFormatListCreateInfoKHR formatListInfo = {};
if (renderer->getFeatures().supportsImageFormatList.enabled)
@ -213,7 +218,7 @@ angle::Result HardwareBufferImageSiblingVkAndroid::initImpl(DisplayVk *displayVk
// There is just 1 additional format we might use to create a VkImageView for this VkImage
formatListInfo.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR;
formatListInfo.viewFormatCount = 1;
formatListInfo.pViewFormats = &vkImageListFormat;
formatListInfo.pViewFormats = &imageListVkFormat;
externalFormat.pNext = &formatListInfo;
}
@ -290,15 +295,15 @@ angle::Result HardwareBufferImageSiblingVkAndroid::initImpl(DisplayVk *displayVk
constexpr uint32_t kColorRenderableRequiredBits = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
constexpr uint32_t kDepthStencilRenderableRequiredBits = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
mRenderable = renderer->hasImageFormatFeatureBits(vkFormat.actualImageVkFormat,
mRenderable = renderer->hasImageFormatFeatureBits(vkFormat.actualImageFormatID,
kColorRenderableRequiredBits) ||
renderer->hasImageFormatFeatureBits(vkFormat.actualImageVkFormat,
renderer->hasImageFormatFeatureBits(vkFormat.actualImageFormatID,
kDepthStencilRenderableRequiredBits);
constexpr uint32_t kTextureableRequiredBits =
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
mTextureable =
renderer->hasImageFormatFeatureBits(vkFormat.actualImageVkFormat, kTextureableRequiredBits);
renderer->hasImageFormatFeatureBits(vkFormat.actualImageFormatID, kTextureableRequiredBits);
return angle::Result::Continue;
}

Просмотреть файл

@ -7,7 +7,6 @@
# Code generation for vk format map. See vk_format_map.json for data source.
# NOTE: don't run this script directly. Run scripts/run_code_generation.py.
from datetime import date
import json
import math
import pprint
@ -21,7 +20,7 @@ import angle_format
template_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {input_file_name}
//
// Copyright {copyright_year} The ANGLE Project Authors. All rights reserved.
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@ -38,7 +37,6 @@ using namespace angle;
namespace rx
{{
namespace vk
{{
@ -54,8 +52,25 @@ void Format::initialize(RendererVk *renderer,
}}
}}
}} // namespace vk
VkFormat GetVkFormatFromFormatID(angle::FormatID formatID)
{{
static constexpr angle::FormatMap<VkFormat> kMap = {{
{format_id_cases}
}};
return kMap[formatID];
}}
angle::FormatID GetFormatIDFromVkFormat(VkFormat vkFormat)
{{
switch (vkFormat)
{{
{vk_format_cases}
default:
return angle::FormatID::NONE;
}}
}}
}} // namespace vk
}} // namespace rx
"""
@ -72,10 +87,9 @@ break;
"""
image_basic_template = """actualImageFormatID = {image};
actualImageVkFormat = {vk_image_format};
imageInitializerFunction = {image_initializer};"""
image_struct_template = "{{{image}, {vk_image_format}, {image_initializer}}}"
image_struct_template = "{{{image}, {image_initializer}}}"
image_fallback_template = """{{
static constexpr ImageFormatInitInfo kInfo[] = {{{image_list}}};
@ -83,12 +97,11 @@ initImageFallback(renderer, kInfo, ArraySize(kInfo));
}}"""
buffer_basic_template = """actualBufferFormatID = {buffer};
actualBufferVkFormat = {vk_buffer_format};
vkBufferFormatIsPacked = {vk_buffer_format_is_packed};
vertexLoadFunction = {vertex_load_function};
vertexLoadRequiresConversion = {vertex_load_converts};"""
buffer_struct_template = """{{{buffer}, {vk_buffer_format}, {vk_buffer_format_is_packed},
buffer_struct_template = """{{{buffer}, {vk_buffer_format_is_packed},
{vertex_load_function}, {vertex_load_converts}}}"""
buffer_fallback_template = """{{
@ -170,7 +183,6 @@ def gen_format_case(angle, internal_format, vk_json_data):
def image_args(format):
return dict(
image="angle::FormatID::" + format,
vk_image_format=vk_map[format],
image_initializer=angle_format.get_internal_format_initializer(
internal_format, format))
@ -178,7 +190,6 @@ def gen_format_case(angle, internal_format, vk_json_data):
vk_buffer_format = vk_map[format]
return dict(
buffer="angle::FormatID::" + format,
vk_buffer_format=vk_buffer_format,
vk_buffer_format_is_packed=is_packed(vk_buffer_format),
vertex_load_function=get_vertex_copy_function(angle, format, vk_buffer_format),
vertex_load_converts='false' if angle == format else 'true',
@ -207,6 +218,17 @@ def gen_format_case(angle, internal_format, vk_json_data):
return format_entry_template.format(**args).format(**args)
def get_format_id_case(format_id, vk_format):
return "{angle::FormatID::%s, %s}" % (format_id, vk_format)
def get_vk_format_case(format_id, vk_format):
return """\
case %s:
return angle::FormatID::%s;
""" % (vk_format, format_id)
def main():
input_file_name = 'vk_format_map.json'
@ -232,13 +254,24 @@ def main():
if not verify_vk_map_keys(angle_to_gl, vk_json_data):
return 1
format_id_cases = [
get_format_id_case(format_id, vk_format)
for format_id, vk_format in vk_json_data["map"].iteritems()
]
vk_format_cases = [
get_vk_format_case(format_id, vk_format)
for format_id, vk_format in vk_json_data["map"].iteritems()
]
vk_cases = [
gen_format_case(angle, gl, vk_json_data) for angle, gl in sorted(angle_to_gl.iteritems())
]
output_cpp = template_table_autogen_cpp.format(
copyright_year=date.today().year,
format_case_data="\n".join(vk_cases),
format_id_cases=",\n".join(format_id_cases),
vk_format_cases="".join(vk_format_cases),
script_name=__file__,
out_file_name=out_file_name,
input_file_name=input_file_name)

Просмотреть файл

@ -155,7 +155,7 @@ void UnpackAttachmentDesc(VkAttachmentDescription *desc,
{
// We would only need this flag for duplicated attachments. Apply it conservatively.
desc->flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT;
desc->format = format.actualImageVkFormat;
desc->format = format.actualImageVkFormat();
desc->samples = gl_vk::GetSamples(samples);
desc->loadOp = static_cast<VkAttachmentLoadOp>(ops.loadOp);
desc->storeOp =
@ -179,7 +179,7 @@ void UnpackColorResolveAttachmentDesc(VkAttachmentDescription *desc,
// attachments simultaneously, so this flag can likely be removed without any issue if it incurs
// a performance penalty.
desc->flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT;
desc->format = format.actualImageVkFormat;
desc->format = format.actualImageVkFormat();
// This function is for color resolve attachments.
const angle::Format &angleFormat = format.actualImageFormat();
@ -212,7 +212,7 @@ void UnpackDepthStencilResolveAttachmentDesc(VkAttachmentDescription *desc,
// There cannot be simultaneous usages of the depth/stencil resolve image, as depth/stencil
// resolve currently only comes from depth/stencil renderbuffers.
desc->flags = 0;
desc->format = format.actualImageVkFormat;
desc->format = format.actualImageVkFormat();
// This function is for depth/stencil resolve attachment.
const angle::Format &angleFormat = format.intendedFormat();
@ -1712,8 +1712,7 @@ angle::Result GraphicsPipelineDesc::initializePipeline(
angle::FormatID formatID = static_cast<angle::FormatID>(packedAttrib.format);
const Format &format = contextVk->getRenderer()->getFormat(formatID);
const angle::Format &angleFormat = format.intendedFormat();
VkFormat vkFormat = packedAttrib.compressed ? format.actualCompressedBufferVkFormat
: format.actualBufferVkFormat;
VkFormat vkFormat = format.actualBufferVkFormat(packedAttrib.compressed);
gl::ComponentType attribType =
GetVertexAttributeComponentType(angleFormat.isPureInt(), angleFormat.vertexAttribType);

Просмотреть файл

@ -40,12 +40,12 @@ bool HasShaderImageAtomicsSupport(const RendererVk *rendererVk,
const Format &formatVk = rendererVk->getFormat(GL_R32F);
const bool hasImageAtomicSupport = rendererVk->hasImageFormatFeatureBits(
formatVk.actualImageVkFormat, VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT);
formatVk.actualImageFormatID, VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT);
bool hasBufferAtomicSupport = true;
if (supportedExtensions.textureBufferAny())
{
hasBufferAtomicSupport = rendererVk->hasBufferFormatFeatureBits(
formatVk.actualBufferVkFormat, VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT);
formatVk.actualBufferFormatID, VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT);
}
return hasImageAtomicSupport && hasBufferAtomicSupport;
@ -65,12 +65,19 @@ bool FormatReinterpretationSupported(const std::vector<GLenum> &optionalSizedFor
{
const Format &vkFormat = rendererVk->getFormat(glFormat);
VkFormat reinterpretedFormat = checkLinearColorspace
? ConvertToLinear(vkFormat.actualImageVkFormat)
: ConvertToSRGB(vkFormat.actualImageVkFormat);
angle::FormatID reinterpretedFormatID =
checkLinearColorspace ? ConvertToLinear(vkFormat.actualImageFormatID)
: ConvertToSRGB(vkFormat.actualImageFormatID);
if (!rendererVk->haveSameFormatFeatureBits(vkFormat.actualImageVkFormat,
reinterpretedFormat))
const Format &reinterpretedVkFormat = rendererVk->getFormat(reinterpretedFormatID);
if (reinterpretedVkFormat.actualImageFormatID != reinterpretedFormatID)
{
return false;
}
if (!rendererVk->haveSameFormatFeatureBits(vkFormat.actualImageFormatID,
reinterpretedFormatID))
{
return false;
}
@ -179,7 +186,7 @@ bool HasTexelBufferSupport(const RendererVk *rendererVk, GLenum formatGL)
const Format &formatVk = rendererVk->getFormat(formatGL);
return rendererVk->hasBufferFormatFeatureBits(
formatVk.actualBufferVkFormat,
formatVk.actualBufferFormatID,
VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT | VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT);
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -19,21 +19,23 @@ namespace rx
{
namespace
{
void FillTextureFormatCaps(RendererVk *renderer, VkFormat format, gl::TextureCaps *outTextureCaps)
void FillTextureFormatCaps(RendererVk *renderer,
angle::FormatID formatID,
gl::TextureCaps *outTextureCaps)
{
const VkPhysicalDeviceLimits &physicalDeviceLimits =
renderer->getPhysicalDeviceProperties().limits;
bool hasColorAttachmentFeatureBit =
renderer->hasImageFormatFeatureBits(format, VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
bool hasDepthAttachmentFeatureBit =
renderer->hasImageFormatFeatureBits(format, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
renderer->hasImageFormatFeatureBits(formatID, VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
bool hasDepthAttachmentFeatureBit = renderer->hasImageFormatFeatureBits(
formatID, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
outTextureCaps->texturable =
renderer->hasImageFormatFeatureBits(format, VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
renderer->hasImageFormatFeatureBits(formatID, VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
outTextureCaps->filterable = renderer->hasImageFormatFeatureBits(
format, VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT);
formatID, VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT);
outTextureCaps->blendable =
renderer->hasImageFormatFeatureBits(format, VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT);
renderer->hasImageFormatFeatureBits(formatID, VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT);
// For renderbuffer and texture attachments we require transfer and sampling for
// GLES 2.0 CopyTexImage support. Sampling is also required for other features like
@ -62,7 +64,7 @@ void FillTextureFormatCaps(RendererVk *renderer, VkFormat format, gl::TextureCap
}
}
bool HasFullBufferFormatSupport(RendererVk *renderer, VkFormat vkFormat)
bool HasFullBufferFormatSupport(RendererVk *renderer, angle::FormatID formatID)
{
// Note: GL_EXT_texture_buffer support uses the same vkBufferFormat that is determined by
// Format::initBufferFallback, which uses this function. That relies on the fact that formats
@ -70,10 +72,10 @@ bool HasFullBufferFormatSupport(RendererVk *renderer, VkFormat vkFormat)
// Vulkan. If this function is changed to test for more features in such a way that makes any
// of those formats use a fallback format, the implementation of GL_EXT_texture_buffer must be
// modified not to use vkBufferFormat.
return renderer->hasBufferFormatFeatureBits(vkFormat, VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT);
return renderer->hasBufferFormatFeatureBits(formatID, VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT);
}
using SupportTest = bool (*)(RendererVk *renderer, VkFormat vkFormat);
using SupportTest = bool (*)(RendererVk *renderer, angle::FormatID formatID);
template <class FormatInitInfo>
int FindSupportedFormat(RendererVk *renderer,
@ -88,36 +90,41 @@ int FindSupportedFormat(RendererVk *renderer,
for (int i = static_cast<int>(skip); i < last; ++i)
{
ASSERT(info[i].format != angle::FormatID::NONE);
if (hasSupport(renderer, info[i].vkFormat))
if (hasSupport(renderer, info[i].format))
return i;
}
if (skip > 0 && !hasSupport(renderer, info[last].vkFormat))
if (skip > 0 && !hasSupport(renderer, info[last].format))
{
// We couldn't find a valid fallback, try again without skip
return FindSupportedFormat(renderer, info, 0, numInfo, hasSupport);
}
ASSERT(info[last].format != angle::FormatID::NONE);
ASSERT(hasSupport(renderer, info[last].vkFormat));
ASSERT(hasSupport(renderer, info[last].format));
return last;
}
bool HasNonFilterableTextureFormatSupport(RendererVk *renderer, angle::FormatID formatID)
{
constexpr uint32_t kBitsColor =
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
constexpr uint32_t kBitsDepth = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
return renderer->hasImageFormatFeatureBits(formatID, kBitsColor) ||
renderer->hasImageFormatFeatureBits(formatID, kBitsDepth);
}
} // anonymous namespace
namespace vk
{
// Format implementation.
Format::Format()
: intendedFormatID(angle::FormatID::NONE),
intendedGLFormat(GL_NONE),
actualImageFormatID(angle::FormatID::NONE),
actualImageVkFormat(VK_FORMAT_UNDEFINED),
actualBufferFormatID(angle::FormatID::NONE),
actualBufferVkFormat(VK_FORMAT_UNDEFINED),
actualCompressedBufferFormatID(angle::FormatID::NONE),
actualCompressedBufferVkFormat(VK_FORMAT_UNDEFINED),
imageInitializerFunction(nullptr),
textureLoadFunctions(),
vertexLoadFunction(nullptr),
@ -152,7 +159,6 @@ void Format::initImageFallback(RendererVk *renderer, const ImageFormatInitInfo *
int i = FindSupportedFormat(renderer, info, skip, static_cast<uint32_t>(numInfo), testFunction);
actualImageFormatID = info[i].format;
actualImageVkFormat = info[i].vkFormat;
imageInitializerFunction = info[i].initializer;
}
@ -167,7 +173,6 @@ void Format::initBufferFallback(RendererVk *renderer,
HasFullBufferFormatSupport);
actualBufferFormatID = info[i].format;
actualBufferVkFormat = info[i].vkFormat;
vkBufferFormatIsPacked = info[i].vkFormatIsPacked;
vertexLoadFunction = info[i].vertexLoadFunction;
vertexLoadRequiresConversion = info[i].vertexLoadRequiresConversion;
@ -179,7 +184,6 @@ void Format::initBufferFallback(RendererVk *renderer,
HasFullBufferFormatSupport);
actualCompressedBufferFormatID = info[i].format;
actualCompressedBufferVkFormat = info[i].vkFormat;
vkCompressedBufferFormatIsPacked = info[i].vkFormatIsPacked;
compressedVertexLoadFunction = info[i].vertexLoadFunction;
compressedVertexLoadRequiresConversion = info[i].vertexLoadRequiresConversion;
@ -270,7 +274,7 @@ void FormatTable::initialize(RendererVk *renderer,
}
gl::TextureCaps textureCaps;
FillTextureFormatCaps(renderer, format.actualImageVkFormat, &textureCaps);
FillTextureFormatCaps(renderer, format.actualImageFormatID, &textureCaps);
outTextureCapsMap->set(formatID, textureCaps);
if (textureCaps.texturable)
@ -286,14 +290,14 @@ void FormatTable::initialize(RendererVk *renderer,
}
}
VkImageUsageFlags GetMaximalImageUsageFlags(RendererVk *renderer, VkFormat format)
VkImageUsageFlags GetMaximalImageUsageFlags(RendererVk *renderer, angle::FormatID formatID)
{
constexpr VkFormatFeatureFlags kImageUsageFeatureBits =
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT |
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT |
VK_FORMAT_FEATURE_TRANSFER_SRC_BIT | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
VkFormatFeatureFlags featureBits =
renderer->getImageFormatFeatureBits(format, kImageUsageFeatureBits);
renderer->getImageFormatFeatureBits(formatID, kImageUsageFeatureBits);
VkImageUsageFlags imageUsageFlags = 0;
if (featureBits & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
imageUsageFlags |= VK_IMAGE_USAGE_SAMPLED_BIT;
@ -310,10 +314,9 @@ VkImageUsageFlags GetMaximalImageUsageFlags(RendererVk *renderer, VkFormat forma
imageUsageFlags |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
return imageUsageFlags;
}
} // namespace vk
bool HasFullTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat)
bool HasFullTextureFormatSupport(RendererVk *renderer, angle::FormatID formatID)
{
constexpr uint32_t kBitsColor = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT |
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
@ -322,11 +325,11 @@ bool HasFullTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat)
// In OpenGL ES, all renderable formats except 32-bit floating-point support blending.
// 32-bit floating-point case validation is handled by ANGLE's frontend.
uint32_t kBitsColorFull = kBitsColor;
switch (vkFormat)
switch (formatID)
{
case VK_FORMAT_R32_SFLOAT:
case VK_FORMAT_R32G32_SFLOAT:
case VK_FORMAT_R32G32B32A32_SFLOAT:
case angle::FormatID::R32_FLOAT:
case angle::FormatID::R32G32_FLOAT:
case angle::FormatID::R32G32B32A32_FLOAT:
break;
default:
kBitsColorFull |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
@ -335,28 +338,18 @@ bool HasFullTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat)
constexpr uint32_t kBitsDepth = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
return renderer->hasImageFormatFeatureBits(vkFormat, kBitsColorFull) ||
renderer->hasImageFormatFeatureBits(vkFormat, kBitsDepth);
return renderer->hasImageFormatFeatureBits(formatID, kBitsColorFull) ||
renderer->hasImageFormatFeatureBits(formatID, kBitsDepth);
}
bool HasNonFilterableTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat)
{
constexpr uint32_t kBitsColor =
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
constexpr uint32_t kBitsDepth = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
return renderer->hasImageFormatFeatureBits(vkFormat, kBitsColor) ||
renderer->hasImageFormatFeatureBits(vkFormat, kBitsDepth);
}
bool HasNonRenderableTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat)
bool HasNonRenderableTextureFormatSupport(RendererVk *renderer, angle::FormatID formatID)
{
constexpr uint32_t kBitsColor =
VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
constexpr uint32_t kBitsDepth = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
return renderer->hasImageFormatFeatureBits(vkFormat, kBitsColor) ||
renderer->hasImageFormatFeatureBits(vkFormat, kBitsDepth);
return renderer->hasImageFormatFeatureBits(formatID, kBitsColor) ||
renderer->hasImageFormatFeatureBits(formatID, kBitsDepth);
}
size_t GetVertexInputAlignment(const vk::Format &format, bool compressed)

Просмотреть файл

@ -37,19 +37,20 @@ constexpr uint32_t kNumVkFormats = 185;
struct ImageFormatInitInfo final
{
angle::FormatID format;
VkFormat vkFormat;
InitializeTextureDataFunction initializer;
};
struct BufferFormatInitInfo final
{
angle::FormatID format;
VkFormat vkFormat;
bool vkFormatIsPacked;
VertexCopyFunction vertexLoadFunction;
bool vertexLoadRequiresConversion;
};
VkFormat GetVkFormatFromFormatID(angle::FormatID formatID);
angle::FormatID GetFormatIDFromVkFormat(VkFormat vkFormat);
// Describes a Vulkan format. For more information on formats in the Vulkan back-end please see
// https://chromium.googlesource.com/angle/angle/+/master/src/libANGLE/renderer/vulkan/doc/FormatTablesAndEmulation.md
struct Format final : private angle::NonCopyable
@ -69,6 +70,8 @@ struct Format final : private angle::NonCopyable
return angle::Format::Get(actualImageFormatID);
}
VkFormat actualImageVkFormat() const { return GetVkFormatFromFormatID(actualImageFormatID); }
// The actual Buffer format is used to implement the front-end format for Buffers. This format
// is used by vertex buffers as well as texture buffers. Note that all formats required for
// GL_EXT_texture_buffer have mandatory support for vertex buffers in Vulkan, so they won't be
@ -79,6 +82,12 @@ struct Format final : private angle::NonCopyable
: actualBufferFormatID);
}
VkFormat actualBufferVkFormat(bool compressed) const
{
return GetVkFormatFromFormatID(compressed ? actualCompressedBufferFormatID
: actualBufferFormatID);
}
VertexCopyFunction getVertexLoadFunction(bool compressed) const
{
return compressed ? compressedVertexLoadFunction : vertexLoadFunction;
@ -119,11 +128,8 @@ struct Format final : private angle::NonCopyable
angle::FormatID intendedFormatID;
GLenum intendedGLFormat;
angle::FormatID actualImageFormatID;
VkFormat actualImageVkFormat;
angle::FormatID actualBufferFormatID;
VkFormat actualBufferVkFormat;
angle::FormatID actualCompressedBufferFormatID;
VkFormat actualCompressedBufferVkFormat;
InitializeTextureDataFunction imageInitializerFunction;
LoadFunctionMap textureLoadFunctions;
@ -174,16 +180,14 @@ class FormatTable final : angle::NonCopyable
// initialized to 0.
const VkFormatProperties &GetMandatoryFormatSupport(VkFormat vkFormat);
VkImageUsageFlags GetMaximalImageUsageFlags(RendererVk *renderer, VkFormat format);
VkImageUsageFlags GetMaximalImageUsageFlags(RendererVk *renderer, angle::FormatID formatID);
} // namespace vk
// Checks if a vkFormat supports all the features needed to use it as a GL texture format
bool HasFullTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat);
// Checks if a vkFormat supports all the features except texture filtering
bool HasNonFilterableTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat);
// Checks if a vkFormat supports all the features except rendering
bool HasNonRenderableTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat);
// Checks if a Vulkan format supports all the features needed to use it as a GL texture format.
bool HasFullTextureFormatSupport(RendererVk *renderer, angle::FormatID formatID);
// Checks if a Vulkan format supports all the features except rendering.
bool HasNonRenderableTextureFormatSupport(RendererVk *renderer, angle::FormatID formatID);
// Returns the alignment for a buffer to be used with the vertex input stage in Vulkan. This
// calculation is listed in the Vulkan spec at the end of the section 'Vertex Input Description'.
@ -198,144 +202,6 @@ gl::SwizzleState GetFormatSwizzle(const ContextVk *contextVk,
gl::SwizzleState ApplySwizzle(const gl::SwizzleState &formatSwizzle,
const gl::SwizzleState &toApply);
namespace vk
{
ANGLE_INLINE VkFormat ConvertToSRGB(VkFormat format)
{
switch (format)
{
case VK_FORMAT_R8_UNORM:
return VK_FORMAT_R8_SRGB;
case VK_FORMAT_R8G8_UNORM:
return VK_FORMAT_R8G8_SRGB;
case VK_FORMAT_R8G8B8_UNORM:
return VK_FORMAT_R8G8B8_SRGB;
case VK_FORMAT_B8G8R8_UNORM:
return VK_FORMAT_B8G8R8_SRGB;
case VK_FORMAT_R8G8B8A8_UNORM:
return VK_FORMAT_R8G8B8A8_SRGB;
case VK_FORMAT_B8G8R8A8_UNORM:
return VK_FORMAT_B8G8R8A8_SRGB;
case VK_FORMAT_BC1_RGB_UNORM_BLOCK:
return VK_FORMAT_BC1_RGB_SRGB_BLOCK;
case VK_FORMAT_BC1_RGBA_UNORM_BLOCK:
return VK_FORMAT_BC1_RGBA_SRGB_BLOCK;
case VK_FORMAT_BC2_UNORM_BLOCK:
return VK_FORMAT_BC2_SRGB_BLOCK;
case VK_FORMAT_BC3_UNORM_BLOCK:
return VK_FORMAT_BC3_SRGB_BLOCK;
case VK_FORMAT_BC7_UNORM_BLOCK:
return VK_FORMAT_BC7_SRGB_BLOCK;
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
return VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK;
case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
return VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK;
case VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK:
return VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK;
case VK_FORMAT_ASTC_4x4_UNORM_BLOCK:
return VK_FORMAT_ASTC_4x4_SRGB_BLOCK;
case VK_FORMAT_ASTC_5x4_UNORM_BLOCK:
return VK_FORMAT_ASTC_5x4_SRGB_BLOCK;
case VK_FORMAT_ASTC_5x5_UNORM_BLOCK:
return VK_FORMAT_ASTC_5x5_SRGB_BLOCK;
case VK_FORMAT_ASTC_6x5_UNORM_BLOCK:
return VK_FORMAT_ASTC_6x5_SRGB_BLOCK;
case VK_FORMAT_ASTC_6x6_UNORM_BLOCK:
return VK_FORMAT_ASTC_6x6_SRGB_BLOCK;
case VK_FORMAT_ASTC_8x5_UNORM_BLOCK:
return VK_FORMAT_ASTC_8x5_SRGB_BLOCK;
case VK_FORMAT_ASTC_8x6_UNORM_BLOCK:
return VK_FORMAT_ASTC_8x6_SRGB_BLOCK;
case VK_FORMAT_ASTC_8x8_UNORM_BLOCK:
return VK_FORMAT_ASTC_8x8_SRGB_BLOCK;
case VK_FORMAT_ASTC_10x5_UNORM_BLOCK:
return VK_FORMAT_ASTC_10x5_SRGB_BLOCK;
case VK_FORMAT_ASTC_10x6_UNORM_BLOCK:
return VK_FORMAT_ASTC_10x6_SRGB_BLOCK;
case VK_FORMAT_ASTC_10x8_UNORM_BLOCK:
return VK_FORMAT_ASTC_10x8_SRGB_BLOCK;
case VK_FORMAT_ASTC_10x10_UNORM_BLOCK:
return VK_FORMAT_ASTC_10x10_SRGB_BLOCK;
case VK_FORMAT_ASTC_12x10_UNORM_BLOCK:
return VK_FORMAT_ASTC_12x10_SRGB_BLOCK;
case VK_FORMAT_ASTC_12x12_UNORM_BLOCK:
return VK_FORMAT_ASTC_12x12_SRGB_BLOCK;
default:
return VK_FORMAT_UNDEFINED;
}
}
ANGLE_INLINE VkFormat ConvertToLinear(VkFormat format)
{
switch (format)
{
case VK_FORMAT_R8_SRGB:
return VK_FORMAT_R8_UNORM;
case VK_FORMAT_R8G8_SRGB:
return VK_FORMAT_R8G8_UNORM;
case VK_FORMAT_R8G8B8_SRGB:
return VK_FORMAT_R8G8B8_UNORM;
case VK_FORMAT_B8G8R8_SRGB:
return VK_FORMAT_B8G8R8_UNORM;
case VK_FORMAT_R8G8B8A8_SRGB:
return VK_FORMAT_R8G8B8A8_UNORM;
case VK_FORMAT_B8G8R8A8_SRGB:
return VK_FORMAT_B8G8R8A8_UNORM;
case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
return VK_FORMAT_BC1_RGB_UNORM_BLOCK;
case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
return VK_FORMAT_BC1_RGBA_UNORM_BLOCK;
case VK_FORMAT_BC2_SRGB_BLOCK:
return VK_FORMAT_BC2_UNORM_BLOCK;
case VK_FORMAT_BC3_SRGB_BLOCK:
return VK_FORMAT_BC3_UNORM_BLOCK;
case VK_FORMAT_BC7_SRGB_BLOCK:
return VK_FORMAT_BC7_UNORM_BLOCK;
case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK;
case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
return VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
case VK_FORMAT_ASTC_5x4_SRGB_BLOCK:
return VK_FORMAT_ASTC_5x4_UNORM_BLOCK;
case VK_FORMAT_ASTC_5x5_SRGB_BLOCK:
return VK_FORMAT_ASTC_5x5_UNORM_BLOCK;
case VK_FORMAT_ASTC_6x5_SRGB_BLOCK:
return VK_FORMAT_ASTC_6x5_UNORM_BLOCK;
case VK_FORMAT_ASTC_6x6_SRGB_BLOCK:
return VK_FORMAT_ASTC_6x6_UNORM_BLOCK;
case VK_FORMAT_ASTC_8x5_SRGB_BLOCK:
return VK_FORMAT_ASTC_8x5_UNORM_BLOCK;
case VK_FORMAT_ASTC_8x6_SRGB_BLOCK:
return VK_FORMAT_ASTC_8x6_UNORM_BLOCK;
case VK_FORMAT_ASTC_8x8_SRGB_BLOCK:
return VK_FORMAT_ASTC_8x8_UNORM_BLOCK;
case VK_FORMAT_ASTC_10x5_SRGB_BLOCK:
return VK_FORMAT_ASTC_10x5_UNORM_BLOCK;
case VK_FORMAT_ASTC_10x6_SRGB_BLOCK:
return VK_FORMAT_ASTC_10x6_UNORM_BLOCK;
case VK_FORMAT_ASTC_10x8_SRGB_BLOCK:
return VK_FORMAT_ASTC_10x8_UNORM_BLOCK;
case VK_FORMAT_ASTC_10x10_SRGB_BLOCK:
return VK_FORMAT_ASTC_10x10_UNORM_BLOCK;
case VK_FORMAT_ASTC_12x10_SRGB_BLOCK:
return VK_FORMAT_ASTC_12x10_UNORM_BLOCK;
case VK_FORMAT_ASTC_12x12_SRGB_BLOCK:
return VK_FORMAT_ASTC_12x12_UNORM_BLOCK;
default:
return VK_FORMAT_UNDEFINED;
}
}
ANGLE_INLINE bool IsOverridableLinearFormat(VkFormat format)
{
return ConvertToSRGB(format) != VK_FORMAT_UNDEFINED;
}
} // namespace vk
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_VK_FORMAT_UTILS_H_

Просмотреть файл

@ -693,13 +693,13 @@ VkImageLayout ConvertImageLayoutToVkImageLayout(ImageLayout imageLayout)
}
bool FormatHasNecessaryFeature(RendererVk *renderer,
VkFormat format,
angle::FormatID formatID,
VkImageTiling tilingMode,
VkFormatFeatureFlags featureBits)
{
return (tilingMode == VK_IMAGE_TILING_OPTIMAL)
? renderer->hasImageFormatFeatureBits(format, featureBits)
: renderer->hasLinearImageFormatFeatureBits(format, featureBits);
? renderer->hasImageFormatFeatureBits(formatID, featureBits)
: renderer->hasLinearImageFormatFeatureBits(formatID, featureBits);
}
bool CanCopyWithTransfer(RendererVk *renderer,
@ -711,9 +711,9 @@ bool CanCopyWithTransfer(RendererVk *renderer,
// Checks that the formats in the copy transfer have the appropriate tiling and transfer bits
bool isTilingCompatible = srcTilingMode == destTilingMode;
bool srcFormatHasNecessaryFeature = FormatHasNecessaryFeature(
renderer, srcFormat.actualImageVkFormat, srcTilingMode, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
renderer, srcFormat.actualImageFormatID, srcTilingMode, VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
bool dstFormatHasNecessaryFeature =
FormatHasNecessaryFeature(renderer, destFormat.actualImageVkFormat, destTilingMode,
FormatHasNecessaryFeature(renderer, destFormat.actualImageFormatID, destTilingMode,
VK_FORMAT_FEATURE_TRANSFER_DST_BIT);
return isTilingCompatible && srcFormatHasNecessaryFeature && dstFormatHasNecessaryFeature;
@ -3626,7 +3626,7 @@ angle::Result ImageHelper::initExternal(Context *context,
imageInfo.pNext = externalImageCreateInfo;
imageInfo.flags = GetImageCreateFlags(textureType) | additionalCreateFlags;
imageInfo.imageType = mImageType;
imageInfo.format = format.actualImageVkFormat;
imageInfo.format = format.actualImageVkFormat();
imageInfo.extent = mExtents;
imageInfo.mipLevels = mipLevels;
imageInfo.arrayLayers = mLayerCount;
@ -3878,7 +3878,7 @@ angle::Result ImageHelper::initLayerImageView(Context *context,
{
return initLayerImageViewImpl(context, textureType, aspectMask, swizzleMap, imageViewOut,
baseMipLevelVk, levelCount, baseArrayLayer, layerCount,
mFormat->actualImageVkFormat, nullptr);
mFormat->actualImageVkFormat(), nullptr);
}
angle::Result ImageHelper::initLayerImageViewWithFormat(Context *context,
@ -3894,7 +3894,7 @@ angle::Result ImageHelper::initLayerImageViewWithFormat(Context *context,
{
return initLayerImageViewImpl(context, textureType, aspectMask, swizzleMap, imageViewOut,
baseMipLevelVk, levelCount, baseArrayLayer, layerCount,
format.actualImageVkFormat, nullptr);
format.actualImageVkFormat(), nullptr);
}
angle::Result ImageHelper::initLayerImageViewImpl(
@ -3969,7 +3969,7 @@ angle::Result ImageHelper::initReinterpretedLayerImageView(Context *context,
uint32_t baseArrayLayer,
uint32_t layerCount,
VkImageUsageFlags imageUsageFlags,
VkFormat imageViewFormat) const
angle::FormatID imageViewFormat) const
{
VkImageViewUsageCreateInfo imageViewUsageCreateInfo = {};
imageViewUsageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO;
@ -3978,7 +3978,8 @@ angle::Result ImageHelper::initReinterpretedLayerImageView(Context *context,
return initLayerImageViewImpl(context, textureType, aspectMask, swizzleMap, imageViewOut,
baseMipLevelVk, levelCount, baseArrayLayer, layerCount,
imageViewFormat, &imageViewUsageCreateInfo);
vk::GetVkFormatFromFormatID(imageViewFormat),
&imageViewUsageCreateInfo);
}
void ImageHelper::destroy(RendererVk *renderer)
@ -4045,7 +4046,7 @@ angle::Result ImageHelper::init2DStaging(Context *context,
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
imageInfo.flags = 0;
imageInfo.imageType = mImageType;
imageInfo.format = format.actualImageVkFormat;
imageInfo.format = format.actualImageVkFormat();
imageInfo.extent = mExtents;
imageInfo.mipLevels = 1;
imageInfo.arrayLayers = mLayerCount;
@ -5957,7 +5958,7 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk,
// per pixel which is sufficient to contain its depth aspect (no stencil aspect).
uint32_t pixelBytes = imageFormat.pixelBytes;
uint32_t depthBytesPerPixel = imageFormat.depthBits >> 3;
if (mFormat->actualImageVkFormat == VK_FORMAT_D24_UNORM_S8_UINT)
if (mFormat->actualImageVkFormat() == VK_FORMAT_D24_UNORM_S8_UINT)
{
pixelBytes = 5;
depthBytesPerPixel = 4;
@ -6725,18 +6726,18 @@ angle::Result ImageViewHelper::initSRGBReadViewsImpl(ContextVk *contextVk,
// When we select the linear/srgb counterpart formats, we must first make sure they're
// actually supported by the ICD. If they are not supported by the ICD, then we treat that as if
// there is no counterpart format. (In this case, the relevant extension should not be exposed)
VkFormat srgbOverrideFormat = ConvertToSRGB(image.getFormat().actualImageVkFormat);
ASSERT((srgbOverrideFormat == VK_FORMAT_UNDEFINED) ||
angle::FormatID srgbOverrideFormat = ConvertToSRGB(image.getFormat().actualImageFormatID);
ASSERT((srgbOverrideFormat == angle::FormatID::NONE) ||
(HasNonRenderableTextureFormatSupport(contextVk->getRenderer(), srgbOverrideFormat)));
VkFormat linearOverrideFormat = ConvertToLinear(image.getFormat().actualImageVkFormat);
ASSERT((linearOverrideFormat == VK_FORMAT_UNDEFINED) ||
angle::FormatID linearOverrideFormat = ConvertToLinear(image.getFormat().actualImageFormatID);
ASSERT((linearOverrideFormat == angle::FormatID::NONE) ||
(HasNonRenderableTextureFormatSupport(contextVk->getRenderer(), linearOverrideFormat)));
VkFormat linearFormat = (linearOverrideFormat != VK_FORMAT_UNDEFINED)
? linearOverrideFormat
: format.actualImageVkFormat;
ASSERT(linearFormat != VK_FORMAT_UNDEFINED);
angle::FormatID linearFormat = (linearOverrideFormat != angle::FormatID::NONE)
? linearOverrideFormat
: format.actualImageFormatID;
ASSERT(linearFormat != angle::FormatID::NONE);
const VkImageAspectFlags aspectFlags = GetFormatAspectFlags(format.intendedFormat());
@ -6747,7 +6748,7 @@ angle::Result ImageViewHelper::initSRGBReadViewsImpl(ContextVk *contextVk,
&mPerLevelLinearReadImageViews[mCurrentMaxLevel.get()], baseLevel, levelCount,
baseLayer, layerCount, imageUsageFlags, linearFormat));
}
if (srgbOverrideFormat != VK_FORMAT_UNDEFINED &&
if (srgbOverrideFormat != angle::FormatID::NONE &&
!mPerLevelSRGBReadImageViews[mCurrentMaxLevel.get()].valid())
{
ANGLE_TRY(image.initReinterpretedLayerImageView(
@ -6771,7 +6772,7 @@ angle::Result ImageViewHelper::initSRGBReadViewsImpl(ContextVk *contextVk,
&mPerLevelLinearFetchImageViews[mCurrentMaxLevel.get()], baseLevel, levelCount,
baseLayer, layerCount, imageUsageFlags, linearFormat));
}
if (srgbOverrideFormat != VK_FORMAT_UNDEFINED &&
if (srgbOverrideFormat != angle::FormatID::NONE &&
!mPerLevelSRGBFetchImageViews[mCurrentMaxLevel.get()].valid())
{
ANGLE_TRY(image.initReinterpretedLayerImageView(
@ -6788,7 +6789,7 @@ angle::Result ImageViewHelper::initSRGBReadViewsImpl(ContextVk *contextVk,
&mPerLevelLinearCopyImageViews[mCurrentMaxLevel.get()], baseLevel, levelCount,
baseLayer, layerCount, imageUsageFlags, linearFormat));
}
if (srgbOverrideFormat != VK_FORMAT_UNDEFINED &&
if (srgbOverrideFormat != angle::FormatID::NONE &&
!mPerLevelSRGBCopyImageViews[mCurrentMaxLevel.get()].valid())
{
ANGLE_TRY(image.initReinterpretedLayerImageView(
@ -6806,7 +6807,7 @@ angle::Result ImageViewHelper::getLevelStorageImageView(ContextVk *contextVk,
LevelIndex levelVk,
uint32_t layer,
VkImageUsageFlags imageUsageFlags,
VkFormat vkImageFormat,
angle::FormatID formatID,
const ImageView **imageViewOut)
{
ASSERT(mImageViewSerial.valid());
@ -6823,9 +6824,9 @@ angle::Result ImageViewHelper::getLevelStorageImageView(ContextVk *contextVk,
}
// Create the view. Note that storage images are not affected by swizzle parameters.
return image.initReinterpretedLayerImageView(
contextVk, viewType, image.getAspectFlags(), gl::SwizzleState(), imageView, levelVk, 1,
layer, image.getLayerCount(), imageUsageFlags, vkImageFormat);
return image.initReinterpretedLayerImageView(contextVk, viewType, image.getAspectFlags(),
gl::SwizzleState(), imageView, levelVk, 1, layer,
image.getLayerCount(), imageUsageFlags, formatID);
}
angle::Result ImageViewHelper::getLevelLayerStorageImageView(ContextVk *contextVk,
@ -6833,7 +6834,7 @@ angle::Result ImageViewHelper::getLevelLayerStorageImageView(ContextVk *contextV
LevelIndex levelVk,
uint32_t layer,
VkImageUsageFlags imageUsageFlags,
VkFormat vkImageFormat,
angle::FormatID formatID,
const ImageView **imageViewOut)
{
ASSERT(image.valid());
@ -6856,7 +6857,7 @@ angle::Result ImageViewHelper::getLevelLayerStorageImageView(ContextVk *contextV
gl::TextureType viewType = Get2DTextureType(1, image.getSamples());
return image.initReinterpretedLayerImageView(contextVk, viewType, image.getAspectFlags(),
gl::SwizzleState(), imageView, levelVk, 1, layer,
1, imageUsageFlags, vkImageFormat);
1, imageUsageFlags, formatID);
}
angle::Result ImageViewHelper::getLevelDrawImageView(ContextVk *contextVk,
@ -7018,7 +7019,9 @@ angle::Result BufferViewHelper::getView(ContextVk *contextVk,
{
ASSERT(format.valid());
auto iter = mViews.find(format.actualBufferVkFormat);
VkFormat viewVkFormat = format.actualBufferVkFormat(false);
auto iter = mViews.find(viewVkFormat);
if (iter != mViews.end())
{
*viewOut = &iter->second;
@ -7035,7 +7038,7 @@ angle::Result BufferViewHelper::getView(ContextVk *contextVk,
VkBufferViewCreateInfo viewCreateInfo = {};
viewCreateInfo.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
viewCreateInfo.buffer = buffer.getBuffer().getHandle();
viewCreateInfo.format = format.actualBufferVkFormat;
viewCreateInfo.format = viewVkFormat;
viewCreateInfo.offset = mOffset;
viewCreateInfo.range = size;
@ -7043,7 +7046,7 @@ angle::Result BufferViewHelper::getView(ContextVk *contextVk,
ANGLE_VK_TRY(contextVk, view.init(contextVk->getDevice(), viewCreateInfo));
// Cache the view
auto insertIter = mViews.insert({format.actualBufferVkFormat, std::move(view)});
auto insertIter = mViews.insert({viewVkFormat, std::move(view)});
*viewOut = &insertIter.first->second;
ASSERT(insertIter.second);

Просмотреть файл

@ -1302,7 +1302,7 @@ enum class ImageLayout
VkImageLayout ConvertImageLayoutToVkImageLayout(ImageLayout imageLayout);
bool FormatHasNecessaryFeature(RendererVk *renderer,
VkFormat format,
angle::FormatID formatID,
VkImageTiling tilingMode,
VkFormatFeatureFlags featureBits);
@ -1389,7 +1389,7 @@ class ImageHelper final : public Resource, public angle::Subject
uint32_t baseArrayLayer,
uint32_t layerCount,
VkImageUsageFlags imageUsageFlags,
VkFormat imageViewFormat) const;
angle::FormatID imageViewFormat) const;
angle::Result initImageView(Context *context,
gl::TextureType textureType,
VkImageAspectFlags aspectMask,
@ -2089,7 +2089,7 @@ class ImageViewHelper final : public Resource
LevelIndex levelVk,
uint32_t layer,
VkImageUsageFlags imageUsageFlags,
VkFormat vkImageFormat,
angle::FormatID formatID,
const ImageView **imageViewOut);
// Creates a storage view with a single layer of the level.
@ -2098,7 +2098,7 @@ class ImageViewHelper final : public Resource
LevelIndex levelVk,
uint32_t layer,
VkImageUsageFlags imageUsageFlags,
VkFormat vkImageFormat,
angle::FormatID formatID,
const ImageView **imageViewOut);
// Creates a draw view with all layers of the level.

Просмотреть файл

@ -989,7 +989,7 @@ void InitExternalSemaphoreCapabilitiesFunctions(VkInstance instance)
GLenum CalculateGenerateMipmapFilter(ContextVk *contextVk, const vk::Format &format)
{
const bool formatSupportsLinearFiltering = contextVk->getRenderer()->hasImageFormatFeatureBits(
format.actualImageVkFormat, VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT);
format.actualImageFormatID, VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT);
const bool hintFastest = contextVk->getState().getGenerateMipmapHint() == GL_FASTEST;
return formatSupportsLinearFiltering && !hintFastest ? GL_LINEAR : GL_NEAREST;

Просмотреть файл

@ -163,7 +163,7 @@ void DisplayVkWin32::checkConfigSupport(egl::Config *config)
for (const VkSurfaceFormatKHR &surfaceFormat : mSurfaceFormats)
{
if (surfaceFormat.format == formatVk.actualImageVkFormat)
if (surfaceFormat.format == formatVk.actualImageVkFormat())
{
return;
}

Просмотреть файл

@ -70,20 +70,23 @@ TEST_P(VulkanFormatTablesTest, TestFormatSupport)
for (const ParametersToTest params : parametersToTest)
{
VkFormat actualImageVkFormat =
rx::vk::GetVkFormatFromFormatID(vkFormat.actualImageFormatID);
// Now let's verify that against vulkan.
VkFormatProperties formatProperties;
vkGetPhysicalDeviceFormatProperties(renderer->getPhysicalDevice(),
vkFormat.actualImageVkFormat, &formatProperties);
vkGetPhysicalDeviceFormatProperties(renderer->getPhysicalDevice(), actualImageVkFormat,
&formatProperties);
VkImageFormatProperties imageProperties;
// isTexturable?
bool isTexturable =
vkGetPhysicalDeviceImageFormatProperties(
renderer->getPhysicalDevice(), vkFormat.actualImageVkFormat, params.imageType,
renderer->getPhysicalDevice(), actualImageVkFormat, params.imageType,
VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_SAMPLED_BIT, params.createFlags,
&imageProperties) == VK_SUCCESS;
EXPECT_EQ(isTexturable, textureCaps.texturable) << vkFormat.actualImageVkFormat;
EXPECT_EQ(isTexturable, textureCaps.texturable) << actualImageVkFormat;
// TODO(jmadill): Support ES3 textures.
@ -91,23 +94,23 @@ TEST_P(VulkanFormatTablesTest, TestFormatSupport)
bool isFilterable = (formatProperties.optimalTilingFeatures &
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT) ==
VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
EXPECT_EQ(isFilterable, textureCaps.filterable) << vkFormat.actualImageVkFormat;
EXPECT_EQ(isFilterable, textureCaps.filterable) << actualImageVkFormat;
// isRenderable?
const bool isRenderableColor =
(vkGetPhysicalDeviceImageFormatProperties(
renderer->getPhysicalDevice(), vkFormat.actualImageVkFormat, params.imageType,
renderer->getPhysicalDevice(), actualImageVkFormat, params.imageType,
VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
params.createFlags, &imageProperties)) == VK_SUCCESS;
const bool isRenderableDepthStencil =
(vkGetPhysicalDeviceImageFormatProperties(
renderer->getPhysicalDevice(), vkFormat.actualImageVkFormat, params.imageType,
renderer->getPhysicalDevice(), actualImageVkFormat, params.imageType,
VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
params.createFlags, &imageProperties)) == VK_SUCCESS;
bool isRenderable = isRenderableColor || isRenderableDepthStencil;
EXPECT_EQ(isRenderable, textureCaps.textureAttachment) << vkFormat.actualImageVkFormat;
EXPECT_EQ(isRenderable, textureCaps.renderbuffer) << vkFormat.actualImageVkFormat;
EXPECT_EQ(isRenderable, textureCaps.textureAttachment) << actualImageVkFormat;
EXPECT_EQ(isRenderable, textureCaps.renderbuffer) << actualImageVkFormat;
}
}
}