Vulkan: Consolidate SamplerYcbcrConversionCache

Now that SamplerDesc and ImageHelper have the fully qualified
description of a VkSamplerYcbcrConversion, we can lazy allocate
the conversion handle along with streamlining the interface to the
SamplerYcbcrConversionCache class.

Bug: angleproject:6732
Test: Texture2DTestES3.*Yuv*Vulkan
Change-Id: I7deaa0220031bc4c500d88021459017bf937218c
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3333629
Reviewed-by: Shahbaz Youssefi <[email protected]>
Reviewed-by: Jamie Madill <[email protected]>
Commit-Queue: mohan maiya <[email protected]>
This commit is contained in:
Mohan Maiya authored and Angle LUCI CQ committed 2021-12-14 20:50:18 +00:00
1 parent 9907d86e3d
commit 36fcf80b1f
7 files changed
+155 -157

No files matched your search

@@ -253,7 +253,7 @@ angle::Result MemoryObjectVk::createImage(ContextVk *contextVk,
VkMemoryPropertyFlags flags = hasProtectedContent ? VK_MEMORY_PROPERTY_PROTECTED_BIT : 0;
ANGLE_TRY(image->initExternalMemory(contextVk, renderer->getMemoryProperties(),
externalMemoryRequirements, nullptr, 1, &importMemoryInfo,
externalMemoryRequirements, 1, &importMemoryInfo,
renderer->getQueueFamilyIndex(), flags));
return angle::Result::Continue;
@@ -320,8 +320,6 @@ angle::Result HardwareBufferImageSiblingVkAndroid::initImpl(DisplayVk *displayVk
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
(hasProtectedContent() ? VK_MEMORY_PROPERTY_PROTECTED_BIT : 0);
VkSamplerYcbcrConversionCreateInfo yuvConversionInfo = {};
VkSamplerYcbcrConversionCreateInfo *yuvConversionInfoPtr = nullptr;
if (bufferFormatProperties.format == VK_FORMAT_UNDEFINED)
{
// Note from Vulkan spec: Since GL_OES_EGL_image_external does not require the same sampling
@@ -331,24 +329,19 @@ angle::Result HardwareBufferImageSiblingVkAndroid::initImpl(DisplayVk *displayVk
VK_ERROR_FEATURE_NOT_PRESENT);
ASSERT(externalFormat.pNext == nullptr);
yuvConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO;
yuvConversionInfo.pNext = &externalFormat;
yuvConversionInfo.format = VK_FORMAT_UNDEFINED;
yuvConversionInfo.xChromaOffset = bufferFormatProperties.suggestedXChromaOffset;
yuvConversionInfo.yChromaOffset = bufferFormatProperties.suggestedYChromaOffset;
yuvConversionInfo.ycbcrModel = bufferFormatProperties.suggestedYcbcrModel;
yuvConversionInfo.ycbcrRange = bufferFormatProperties.suggestedYcbcrRange;
yuvConversionInfo.chromaFilter = VK_FILTER_NEAREST;
yuvConversionInfo.components = bufferFormatProperties.samplerYcbcrConversionComponents;
yuvConversionInfoPtr = &yuvConversionInfo;
// Update the SamplerYcbcrConversionCache key
mImage->updateYcbcbConversionDesc(
renderer, bufferFormatProperties.externalFormat,
bufferFormatProperties.suggestedYcbcrModel, bufferFormatProperties.suggestedYcbcrRange,
bufferFormatProperties.suggestedXChromaOffset,
bufferFormatProperties.suggestedYChromaOffset, VK_FILTER_NEAREST,
bufferFormatProperties.samplerYcbcrConversionComponents, angle::FormatID::NONE);
mYUV = true;
}
ANGLE_TRY(mImage->initExternalMemory(
displayVk, renderer->getMemoryProperties(), externalMemoryRequirements,
yuvConversionInfoPtr, 1, &dedicatedAllocInfoPtr, VK_QUEUE_FAMILY_FOREIGN_EXT, flags));
ANGLE_TRY(mImage->initExternalMemory(displayVk, renderer->getMemoryProperties(),
externalMemoryRequirements, 1, &dedicatedAllocInfoPtr,
VK_QUEUE_FAMILY_FOREIGN_EXT, flags));
constexpr uint32_t kColorRenderableRequiredBits = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
constexpr uint32_t kDepthStencilRenderableRequiredBits = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
@@ -466,8 +466,6 @@ angle::Result DmaBufImageSiblingVkLinux::initImpl(DisplayVk *displayVk)
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
(hasProtectedContent() ? VK_MEMORY_PROPERTY_PROTECTED_BIT : 0);
VkSamplerYcbcrConversionCreateInfo yuvConversionInfo = {};
VkSamplerYcbcrConversionCreateInfo *yuvConversionInfoPtr = nullptr;
if (mYUV)
{
const VkChromaLocation xChromaOffset =
@@ -476,30 +474,27 @@ angle::Result DmaBufImageSiblingVkLinux::initImpl(DisplayVk *displayVk)
GetChromaLocation(mAttribs, EGL_YUV_CHROMA_VERTICAL_SITING_HINT_EXT);
const VkSamplerYcbcrModelConversion model = GetYcbcrModel(mAttribs);
const VkSamplerYcbcrRange range = GetYcbcrRange(mAttribs);
const VkComponentMapping components = {
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY,
};
ANGLE_VK_CHECK(displayVk, renderer->getFeatures().supportsYUVSamplerConversion.enabled,
VK_ERROR_FEATURE_NOT_PRESENT);
yuvConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO;
yuvConversionInfo.format = vulkanFormat;
yuvConversionInfo.xChromaOffset = xChromaOffset;
yuvConversionInfo.yChromaOffset = yChromaOffset;
yuvConversionInfo.ycbcrModel = model;
yuvConversionInfo.ycbcrRange = range;
yuvConversionInfo.chromaFilter = VK_FILTER_NEAREST;
// yuvConversionInfo.components = {}; // TODO: swizzle?
yuvConversionInfoPtr = &yuvConversionInfo;
mImage->updateYcbcbConversionDesc(renderer, 0, model, range, xChromaOffset, yChromaOffset,
VK_FILTER_NEAREST, components, intendedFormatID);
}
AllocateInfo allocateInfo;
const uint32_t allocateInfoCount = GetAllocateInfo(
mAttribs, mImage->getImage().getHandle(), planeCount, modifierProperties, &allocateInfo);
return mImage->initExternalMemory(displayVk, renderer->getMemoryProperties(),
externalMemoryRequirements, yuvConversionInfoPtr,
allocateInfoCount, allocateInfo.allocateInfoPtr.data(),
VK_QUEUE_FAMILY_FOREIGN_EXT, flags);
return mImage->initExternalMemory(
displayVk, renderer->getMemoryProperties(), externalMemoryRequirements, allocateInfoCount,
allocateInfo.allocateInfoPtr.data(), VK_QUEUE_FAMILY_FOREIGN_EXT, flags);
}
void DmaBufImageSiblingVkLinux::onDestroy(const egl::Display *display)
+70 -44
View File
@@ -3182,9 +3182,12 @@ void YcbcrConversionDesc::reset()
mXChromaOffset = 0;
mYChromaOffset = 0;
mChromaFilter = 0;
mRSwizzle = 0;
mGSwizzle = 0;
mBSwizzle = 0;
mASwizzle = 0;
mPadding = 0;
mReserved0 = 0;
mReserved1 = 0;
mReserved = 0;
}
void YcbcrConversionDesc::update(RendererVk *rendererVk,
@@ -3194,6 +3197,7 @@ void YcbcrConversionDesc::update(RendererVk *rendererVk,
VkChromaLocation xChromaOffset,
VkChromaLocation yChromaOffset,
VkFilter chromaFilter,
VkComponentMapping components,
angle::FormatID intendedFormatID)
{
const vk::Format &vkFormat = rendererVk->getFormat(intendedFormatID);
@@ -3208,6 +3212,10 @@ void YcbcrConversionDesc::update(RendererVk *rendererVk,
SetBitField(mXChromaOffset, xChromaOffset);
SetBitField(mYChromaOffset, yChromaOffset);
SetBitField(mChromaFilter, chromaFilter);
SetBitField(mRSwizzle, components.r);
SetBitField(mGSwizzle, components.g);
SetBitField(mBSwizzle, components.b);
SetBitField(mASwizzle, components.a);
}
// SamplerDesc implementation.
@@ -3280,6 +3288,7 @@ void SamplerDesc::update(ContextVk *contextVk,
if (ycbcrConversionDesc && ycbcrConversionDesc->valid())
{
// Update the SamplerYcbcrConversionCache key
mYcbcrConversionDesc = *ycbcrConversionDesc;
}
@@ -3379,16 +3388,15 @@ angle::Result SamplerDesc::init(ContextVk *contextVk, Sampler *sampler) const
AddToPNextChain(&createInfo, &filteringInfo);
}
VkSamplerYcbcrConversionInfo yuvConversionInfo = {};
VkSamplerYcbcrConversionInfo samplerYcbcrConversionInfo = {};
if (mYcbcrConversionDesc.valid())
{
ASSERT((contextVk->getRenderer()->getFeatures().supportsYUVSamplerConversion.enabled));
yuvConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
yuvConversionInfo.pNext = nullptr;
yuvConversionInfo.conversion =
contextVk->getRenderer()->getYuvConversionCache().getSamplerYcbcrConversion(
mYcbcrConversionDesc);
AddToPNextChain(&createInfo, &yuvConversionInfo);
samplerYcbcrConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
samplerYcbcrConversionInfo.pNext = nullptr;
ANGLE_TRY(contextVk->getRenderer()->getYuvConversionCache().getSamplerYcbcrConversion(
contextVk, mYcbcrConversionDesc, &samplerYcbcrConversionInfo.conversion));
AddToPNextChain(&createInfo, &samplerYcbcrConversionInfo);
// Vulkan spec requires these settings:
createInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
@@ -3870,18 +3878,16 @@ void SamplerYcbcrConversionCache::destroy(RendererVk *rendererVk)
for (auto &iter : mExternalFormatPayload)
{
vk::RefCountedSamplerYcbcrConversion &yuvSampler = iter.second;
ASSERT(!yuvSampler.isReferenced());
yuvSampler.get().destroy(device);
vk::SamplerYcbcrConversion &samplerYcbcrConversion = iter.second;
samplerYcbcrConversion.destroy(device);
rendererVk->onDeallocateHandle(vk::HandleType::SamplerYcbcrConversion);
}
for (auto &iter : mVkFormatPayload)
{
vk::RefCountedSamplerYcbcrConversion &yuvSampler = iter.second;
ASSERT(!yuvSampler.isReferenced());
yuvSampler.get().destroy(device);
vk::SamplerYcbcrConversion &samplerYcbcrConversion = iter.second;
samplerYcbcrConversion.destroy(device);
rendererVk->onDeallocateHandle(vk::HandleType::SamplerYcbcrConversion);
}
@@ -3890,56 +3896,76 @@ void SamplerYcbcrConversionCache::destroy(RendererVk *rendererVk)
mVkFormatPayload.clear();
}
angle::Result SamplerYcbcrConversionCache::getYuvConversion(
angle::Result SamplerYcbcrConversionCache::getSamplerYcbcrConversion(
vk::Context *context,
const vk::YcbcrConversionDesc &ycbcrConversionDesc,
const VkSamplerYcbcrConversionCreateInfo &yuvConversionCreateInfo,
vk::BindingPointer<vk::SamplerYcbcrConversion> *yuvConversionOut)
VkSamplerYcbcrConversion *vkSamplerYcbcrConversionOut)
{
ASSERT(ycbcrConversionDesc.valid());
ASSERT(vkSamplerYcbcrConversionOut);
SamplerYcbcrConversionMap &payload =
(ycbcrConversionDesc.mIsExternalFormat) ? mExternalFormatPayload : mVkFormatPayload;
const auto iter = payload.find(ycbcrConversionDesc);
if (iter != payload.end())
{
vk::RefCountedSamplerYcbcrConversion &yuvConversion = iter->second;
yuvConversionOut->set(&yuvConversion);
vk::SamplerYcbcrConversion &samplerYcbcrConversion = iter->second;
mCacheStats.hit();
*vkSamplerYcbcrConversionOut = samplerYcbcrConversion.getHandle();
return angle::Result::Continue;
}
mCacheStats.miss();
vk::SamplerYcbcrConversion wrappedYuvConversion;
ANGLE_VK_TRY(context, wrappedYuvConversion.init(context->getDevice(), yuvConversionCreateInfo));
// Create the VkSamplerYcbcrConversion
VkSamplerYcbcrConversionCreateInfo samplerYcbcrConversionInfo = {};
samplerYcbcrConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO;
samplerYcbcrConversionInfo.format = static_cast<VkFormat>(
(ycbcrConversionDesc.mIsExternalFormat) ? VK_FORMAT_UNDEFINED
: ycbcrConversionDesc.mExternalOrVkFormat);
samplerYcbcrConversionInfo.xChromaOffset =
static_cast<VkChromaLocation>(ycbcrConversionDesc.mXChromaOffset);
samplerYcbcrConversionInfo.yChromaOffset =
static_cast<VkChromaLocation>(ycbcrConversionDesc.mYChromaOffset);
samplerYcbcrConversionInfo.ycbcrModel =
static_cast<VkSamplerYcbcrModelConversion>(ycbcrConversionDesc.mConversionModel);
samplerYcbcrConversionInfo.ycbcrRange =
static_cast<VkSamplerYcbcrRange>(ycbcrConversionDesc.mColorRange);
samplerYcbcrConversionInfo.chromaFilter =
static_cast<VkFilter>(ycbcrConversionDesc.mChromaFilter);
samplerYcbcrConversionInfo.components = {
static_cast<VkComponentSwizzle>(ycbcrConversionDesc.mRSwizzle),
static_cast<VkComponentSwizzle>(ycbcrConversionDesc.mGSwizzle),
static_cast<VkComponentSwizzle>(ycbcrConversionDesc.mBSwizzle),
static_cast<VkComponentSwizzle>(ycbcrConversionDesc.mASwizzle)};
#ifdef VK_USE_PLATFORM_ANDROID_KHR
VkExternalFormatANDROID externalFormat = {};
if (ycbcrConversionDesc.mIsExternalFormat)
{
externalFormat.sType = VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID;
externalFormat.externalFormat = ycbcrConversionDesc.mExternalOrVkFormat;
samplerYcbcrConversionInfo.pNext = &externalFormat;
}
#else
// We do not support external format for any platform other than Android.
ASSERT(ycbcrConversionDesc.mIsExternalFormat == 0);
#endif // VK_USE_PLATFORM_ANDROID_KHR
vk::SamplerYcbcrConversion wrappedSamplerYcbcrConversion;
ANGLE_VK_TRY(context, wrappedSamplerYcbcrConversion.init(context->getDevice(),
samplerYcbcrConversionInfo));
auto insertedItem = payload.emplace(
ycbcrConversionDesc, vk::RefCountedSamplerYcbcrConversion(std::move(wrappedYuvConversion)));
vk::RefCountedSamplerYcbcrConversion &insertedYuvConversion = insertedItem.first->second;
yuvConversionOut->set(&insertedYuvConversion);
ycbcrConversionDesc, vk::SamplerYcbcrConversion(std::move(wrappedSamplerYcbcrConversion)));
vk::SamplerYcbcrConversion &insertedSamplerYcbcrConversion = insertedItem.first->second;
*vkSamplerYcbcrConversionOut = insertedSamplerYcbcrConversion.getHandle();
context->getRenderer()->onAllocateHandle(vk::HandleType::SamplerYcbcrConversion);
return angle::Result::Continue;
}
VkSamplerYcbcrConversion SamplerYcbcrConversionCache::getSamplerYcbcrConversion(
const vk::YcbcrConversionDesc &ycbcrConversionDesc) const
{
ASSERT(ycbcrConversionDesc.valid());
const SamplerYcbcrConversionMap &payload =
(ycbcrConversionDesc.mIsExternalFormat) ? mExternalFormatPayload : mVkFormatPayload;
const auto iter = payload.find(ycbcrConversionDesc);
if (iter != payload.end())
{
const vk::RefCountedSamplerYcbcrConversion &yuvConversion = iter->second;
return yuvConversion.get().getHandle();
}
// Should never get here if we have a valid format.
UNREACHABLE();
return VK_NULL_HANDLE;
}
// SamplerCache implementation.
SamplerCache::SamplerCache() = default;
+21 -17
View File
@@ -849,6 +849,7 @@ struct YcbcrConversionDesc final
VkChromaLocation xChromaOffset,
VkChromaLocation yChromaOffset,
VkFilter chromaFilter,
VkComponentMapping components,
angle::FormatID intendedFormatID);
// If the sampler needs to convert the image content (e.g. from YUV to RGB) then
@@ -858,20 +859,27 @@ struct YcbcrConversionDesc final
// mConversionModel and mColorRange works as a Serial() used elsewhere in ANGLE.
uint64_t mExternalOrVkFormat;
// 1 bit to identify if external format is used
uint16_t mIsExternalFormat : 1;
uint32_t mIsExternalFormat : 1;
// 3 bits to identify conversion model
uint16_t mConversionModel : 3;
uint32_t mConversionModel : 3;
// 1 bit to identify color component range
uint16_t mColorRange : 1;
uint32_t mColorRange : 1;
// 1 bit to identify x chroma location
uint16_t mXChromaOffset : 1;
uint32_t mXChromaOffset : 1;
// 1 bit to identify y chroma location
uint16_t mYChromaOffset : 1;
uint32_t mYChromaOffset : 1;
// 1 bit to identify chroma filtering
uint16_t mChromaFilter : 1;
uint16_t mPadding : 8;
uint16_t mReserved0;
uint32_t mReserved1;
uint32_t mChromaFilter : 1;
// 3 bit to identify R component swizzle
uint32_t mRSwizzle : 3;
// 3 bit to identify G component swizzle
uint32_t mGSwizzle : 3;
// 3 bit to identify B component swizzle
uint32_t mBSwizzle : 3;
// 3 bit to identify A component swizzle
uint32_t mASwizzle : 3;
uint32_t mPadding : 12;
uint32_t mReserved;
};
static_assert(sizeof(YcbcrConversionDesc) == 16, "Unexpected YcbcrConversionDesc size");
@@ -1684,17 +1692,13 @@ class SamplerYcbcrConversionCache final
void destroy(RendererVk *rendererVk);
angle::Result getYuvConversion(
vk::Context *context,
const vk::YcbcrConversionDesc &ycbcrConversionDesc,
const VkSamplerYcbcrConversionCreateInfo &yuvConversionCreateInfo,
vk::BindingPointer<vk::SamplerYcbcrConversion> *yuvConversionOut);
VkSamplerYcbcrConversion getSamplerYcbcrConversion(
const vk::YcbcrConversionDesc &ycbcrConversionDesc) const;
angle::Result getSamplerYcbcrConversion(vk::Context *context,
const vk::YcbcrConversionDesc &ycbcrConversionDesc,
VkSamplerYcbcrConversion *vkSamplerYcbcrConversionOut);
private:
using SamplerYcbcrConversionMap =
std::unordered_map<vk::YcbcrConversionDesc, vk::RefCountedSamplerYcbcrConversion>;
std::unordered_map<vk::YcbcrConversionDesc, vk::SamplerYcbcrConversion>;
SamplerYcbcrConversionMap mExternalFormatPayload;
SamplerYcbcrConversionMap mVkFormatPayload;
};
+21 -52
View File
@@ -3986,7 +3986,6 @@ ImageHelper::ImageHelper(ImageHelper &&other)
mLastNonShaderReadOnlyLayout(other.mLastNonShaderReadOnlyLayout),
mCurrentShaderReadStageMask(other.mCurrentShaderReadStageMask),
mYcbcrConversionDesc(other.mYcbcrConversionDesc),
mYuvConversionSampler(std::move(other.mYuvConversionSampler)),
mFirstAllocatedLevel(other.mFirstAllocatedLevel),
mLayerCount(other.mLayerCount),
mLevelCount(other.mLevelCount),
@@ -4222,7 +4221,6 @@ angle::Result ImageHelper::initExternal(Context *context,
}
mYcbcrConversionDesc.reset();
mYuvConversionSampler.reset();
const angle::Format &actualFormat = angle::Format::Get(actualFormatID);
VkFormat actualVkFormat = GetVkFormatFromFormatID(actualFormatID);
@@ -4251,23 +4249,17 @@ angle::Result ImageHelper::initExternal(Context *context,
VkSamplerYcbcrModelConversion conversionModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601;
VkSamplerYcbcrRange colorRange = VK_SAMPLER_YCBCR_RANGE_ITU_NARROW;
VkFilter chromaFilter = VK_FILTER_NEAREST;
VkComponentMapping components = {
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY,
};
// Create the VkSamplerYcbcrConversion to associate with image views and samplers
VkSamplerYcbcrConversionCreateInfo yuvConversionInfo = {};
yuvConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_CREATE_INFO;
yuvConversionInfo.format = actualVkFormat;
yuvConversionInfo.xChromaOffset = supportedLocation;
yuvConversionInfo.yChromaOffset = supportedLocation;
yuvConversionInfo.ycbcrModel = conversionModel;
yuvConversionInfo.ycbcrRange = colorRange;
yuvConversionInfo.chromaFilter = chromaFilter;
// Update the YuvConversionCache key
// Update the SamplerYcbcrConversionCache key
mYcbcrConversionDesc.update(rendererVk, 0, conversionModel, colorRange, supportedLocation,
supportedLocation, chromaFilter, intendedFormatID);
ANGLE_TRY(rendererVk->getYuvConversionCache().getYuvConversion(
context, mYcbcrConversionDesc, yuvConversionInfo, &mYuvConversionSampler));
supportedLocation, chromaFilter, components, intendedFormatID);
}
if (hasProtectedContent)
@@ -4554,15 +4546,13 @@ angle::Result ImageHelper::initMemory(Context *context,
return angle::Result::Continue;
}
angle::Result ImageHelper::initExternalMemory(
Context *context,
const MemoryProperties &memoryProperties,
const VkMemoryRequirements &memoryRequirements,
const VkSamplerYcbcrConversionCreateInfo *samplerYcbcrConversionCreateInfo,
uint32_t extraAllocationInfoCount,
const void **extraAllocationInfo,
uint32_t currentQueueFamilyIndex,
VkMemoryPropertyFlags flags)
angle::Result ImageHelper::initExternalMemory(Context *context,
const MemoryProperties &memoryProperties,
const VkMemoryRequirements &memoryRequirements,
uint32_t extraAllocationInfoCount,
const void **extraAllocationInfo,
uint32_t currentQueueFamilyIndex,
VkMemoryPropertyFlags flags)
{
// Vulkan allows up to 4 memory planes.
constexpr size_t kMaxMemoryPlanes = 4;
@@ -4590,28 +4580,6 @@ angle::Result ImageHelper::initExternalMemory(
}
mCurrentQueueFamilyIndex = currentQueueFamilyIndex;
#ifdef VK_USE_PLATFORM_ANDROID_KHR
if (samplerYcbcrConversionCreateInfo)
{
const VkExternalFormatANDROID *vkExternalFormat =
reinterpret_cast<const VkExternalFormatANDROID *>(
samplerYcbcrConversionCreateInfo->pNext);
ASSERT(vkExternalFormat->sType == VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID);
// Update the YuvConversionCache key
mYcbcrConversionDesc.update(context->getRenderer(), vkExternalFormat->externalFormat,
samplerYcbcrConversionCreateInfo->ycbcrModel,
samplerYcbcrConversionCreateInfo->ycbcrRange,
samplerYcbcrConversionCreateInfo->xChromaOffset,
samplerYcbcrConversionCreateInfo->yChromaOffset,
samplerYcbcrConversionCreateInfo->chromaFilter,
angle::FormatID::NONE);
ANGLE_TRY(context->getRenderer()->getYuvConversionCache().getYuvConversion(
context, mYcbcrConversionDesc, *samplerYcbcrConversionCreateInfo,
&mYuvConversionSampler));
}
#endif
return angle::Result::Continue;
}
@@ -4694,7 +4662,7 @@ angle::Result ImageHelper::initLayerImageViewImpl(
viewInfo.viewType = gl_vk::GetImageViewType(textureType);
viewInfo.format = imageFormat;
if (swizzleMap.swizzleRequired() && !mYuvConversionSampler.valid())
if (swizzleMap.swizzleRequired() && !mYcbcrConversionDesc.valid())
{
viewInfo.components.r = gl_vk::GetSwizzle(swizzleMap.swizzleRed);
viewInfo.components.g = gl_vk::GetSwizzle(swizzleMap.swizzleGreen);
@@ -4717,12 +4685,13 @@ angle::Result ImageHelper::initLayerImageViewImpl(
viewInfo.pNext = imageViewUsageCreateInfo;
VkSamplerYcbcrConversionInfo yuvConversionInfo = {};
if (mYuvConversionSampler.valid())
if (mYcbcrConversionDesc.valid())
{
ASSERT((context->getRenderer()->getFeatures().supportsYUVSamplerConversion.enabled));
yuvConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
yuvConversionInfo.pNext = nullptr;
yuvConversionInfo.conversion = mYuvConversionSampler.get().getHandle();
yuvConversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
yuvConversionInfo.pNext = nullptr;
ANGLE_TRY(context->getRenderer()->getYuvConversionCache().getSamplerYcbcrConversion(
context, mYcbcrConversionDesc, &yuvConversionInfo.conversion));
AddToPNextChain(&viewInfo, &yuvConversionInfo);
// VUID-VkImageViewCreateInfo-image-02399
+21 -10
View File
@@ -1519,15 +1519,13 @@ class ImageHelper final : public Resource, public angle::Subject
bool hasProtectedContent,
const MemoryProperties &memoryProperties,
VkMemoryPropertyFlags flags);
angle::Result initExternalMemory(
Context *context,
const MemoryProperties &memoryProperties,
const VkMemoryRequirements &memoryRequirements,
const VkSamplerYcbcrConversionCreateInfo *samplerYcbcrConversionCreateInfo,
uint32_t extraAllocationInfoCount,
const void **extraAllocationInfo,
uint32_t currentQueueFamilyIndex,
VkMemoryPropertyFlags flags);
angle::Result initExternalMemory(Context *context,
const MemoryProperties &memoryProperties,
const VkMemoryRequirements &memoryRequirements,
uint32_t extraAllocationInfoCount,
const void **extraAllocationInfo,
uint32_t currentQueueFamilyIndex,
VkMemoryPropertyFlags flags);
angle::Result initLayerImageView(Context *context,
gl::TextureType textureType,
VkImageAspectFlags aspectMask,
@@ -2013,6 +2011,20 @@ class ImageHelper final : public Resource, public angle::Subject
: 0;
}
const YcbcrConversionDesc *getYcbcrConversionDesc() const { return &mYcbcrConversionDesc; }
void updateYcbcbConversionDesc(RendererVk *rendererVk,
uint64_t externalFormat,
VkSamplerYcbcrModelConversion conversionModel,
VkSamplerYcbcrRange colorRange,
VkChromaLocation xChromaOffset,
VkChromaLocation yChromaOffset,
VkFilter chromaFilter,
VkComponentMapping components,
angle::FormatID intendedFormatID)
{
mYcbcrConversionDesc.update(rendererVk, externalFormat, conversionModel, colorRange,
xChromaOffset, yChromaOffset, chromaFilter, components,
intendedFormatID);
}
// Used by framebuffer and render pass functions to decide loadOps and invalidate/un-invalidate
// render target contents.
@@ -2273,7 +2285,6 @@ class ImageHelper final : public Resource, public angle::Subject
// For imported images
YcbcrConversionDesc mYcbcrConversionDesc;
BindingPointer<SamplerYcbcrConversion> mYuvConversionSampler;
// The first level that has been allocated. For mutable textures, this should be same as
// mBaseLevel since we always reallocate VkImage based on mBaseLevel change. But for immutable