Remove uses of GrPixelConfig in GrVkCaps and other vk files.
Bug: skia:6718
Change-Id: I2f0d38b2b7a68a424732ced56e8b6c7e5965a722
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/235023
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 82266b1..683d84c 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -483,7 +483,11 @@
SkASSERT(GrCaps::AreConfigsCompatible(desc.fConfig,
caps->getConfigFromBackendFormat(format, colorType)));
- SkASSERT(caps->areColorTypeAndFormatCompatible(colorType, format));
+ // TODO: This check should be removed once we get the swizzle outside of GrProxyProvider and
+ // either pass them to the proxy or store the on some view object.
+ if (!caps->areColorTypeAndFormatCompatible(colorType, format)) {
+ return nullptr;
+ }
if (GrMipMapped::kYes == mipMapped) {
// SkMipMap doesn't include the base level in the level count so we have to add 1
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 1b2fbf0..3a1419f 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -3960,7 +3960,14 @@
bool GrGLCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
const GrBackendFormat& format) const {
- return kUnknown_GrPixelConfig != validate_sized_format(format.asGLFormat(), ct, fStandard);
+ GrGLFormat glFormat = format.asGLFormat();
+ const auto& info = this->getFormatInfo(glFormat);
+ for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
+ if (info.fColorTypeInfos[i].fColorType == ct) {
+ return true;
+ }
+ }
+ return false;
}
GrPixelConfig GrGLCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
@@ -4097,12 +4104,6 @@
GrBackendFormat::MakeGL(GR_GL_BGRA8, GR_GL_TEXTURE_2D) });
}
-#ifdef SK_DEBUG
- for (auto combo : combos) {
- SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
- }
-#endif
-
return combos;
}
#endif
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 95fbc5a..f15ee7d 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -654,6 +654,37 @@
VK_FORMAT_R16G16_SFLOAT,
};
+void GrVkCaps::setColorType(GrColorType colorType, std::initializer_list<VkFormat> formats) {
+#ifdef SK_DEBUG
+ for (size_t i = 0; i < kNumVkFormats; ++i) {
+ const auto& formatInfo = fFormatTable[i];
+ for (int j = 0; j < formatInfo.fColorTypeInfoCount; ++j) {
+ const auto& ctInfo = formatInfo.fColorTypeInfos[j];
+ if (ctInfo.fColorType == colorType &&
+ !SkToBool(ctInfo.fFlags & ColorTypeInfo::kWrappedOnly_Flag)) {
+ bool found = false;
+ for (auto it = formats.begin(); it != formats.end(); ++it) {
+ if (kVkFormats[i] == *it) {
+ found = true;
+ }
+ }
+ SkASSERT(found);
+ }
+ }
+ }
+#endif
+ int idx = static_cast<int>(colorType);
+ for (auto it = formats.begin(); it != formats.end(); ++it) {
+ const auto& info = this->getFormatInfo(*it);
+ for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
+ if (info.fColorTypeInfos[i].fColorType == colorType) {
+ fColorTypeToFormatTable[idx] = *it;
+ return;
+ }
+ }
+ }
+}
+
const GrVkCaps::FormatInfo& GrVkCaps::getFormatInfo(VkFormat format) const {
GrVkCaps* nonConstThis = const_cast<GrVkCaps*>(this);
return nonConstThis->getFormatInfo(format);
@@ -676,26 +707,30 @@
static_assert(SK_ARRAY_COUNT(kVkFormats) == GrVkCaps::kNumVkFormats,
"Size of VkFormats array must match static value in header");
- // Go through all the formats and init their support surface and data GrColorTypes.
+ std::fill_n(fColorTypeToFormatTable, kGrColorTypeCnt, VK_FORMAT_UNDEFINED);
+ // Go through all the formats and init their support surface and data GrColorTypes.
// Format: VK_FORMAT_R8G8B8A8_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_R8G8B8A8_UNORM);
- info.init(interface, physDev, properties, VK_FORMAT_R8G8B8A8_UNORM);
+ constexpr VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGBA_8888
{
+ constexpr GrColorType ct = GrColorType::kRGBA_8888;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGBA_8888;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
// Format: VK_FORMAT_R8G8B8A8_UNORM, Surface: kRGB_888x
{
+ constexpr GrColorType ct = GrColorType::kRGB_888x;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGB_888x;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
ctInfo.fTextureSwizzle = GrSwizzle::RGB1();
}
@@ -704,24 +739,27 @@
// Format: VK_FORMAT_R8_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_R8_UNORM);
- info.init(interface, physDev, properties, VK_FORMAT_R8_UNORM);
+ constexpr VkFormat format = VK_FORMAT_R8_UNORM;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R8_UNORM, Surface: kAlpha_8
{
+ constexpr GrColorType ct = GrColorType::kAlpha_8;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kAlpha_8;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
}
// Format: VK_FORMAT_R8_UNORM, Surface: kGray_8
{
+ constexpr GrColorType ct = GrColorType::kGray_8;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kGray_8;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
ctInfo.fTextureSwizzle = GrSwizzle("rrr1");
}
@@ -729,70 +767,79 @@
}
// Format: VK_FORMAT_B8G8R8A8_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_B8G8R8A8_UNORM);
- info.init(interface, physDev, properties, VK_FORMAT_B8G8R8A8_UNORM);
+ constexpr VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_B8G8R8A8_UNORM, Surface: kBGRA_8888
{
+ constexpr GrColorType ct = GrColorType::kBGRA_8888;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kBGRA_8888;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R5G6B5_UNORM_PACK16
{
- auto& info = this->getFormatInfo(VK_FORMAT_R5G6B5_UNORM_PACK16);
- info.init(interface, physDev, properties, VK_FORMAT_R5G6B5_UNORM_PACK16);
+ constexpr VkFormat format = VK_FORMAT_R5G6B5_UNORM_PACK16;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R5G6B5_UNORM_PACK16, Surface: kBGR_565
{
+ constexpr GrColorType ct = GrColorType::kBGR_565;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kBGR_565;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R16G16B16A16_SFLOAT
{
- auto& info = this->getFormatInfo(VK_FORMAT_R16G16B16A16_SFLOAT);
- info.init(interface, physDev, properties, VK_FORMAT_R16G16B16A16_SFLOAT);
+ constexpr VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16
{
+ constexpr GrColorType ct = GrColorType::kRGBA_F16;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGBA_F16;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
// Format: VK_FORMAT_R16G16B16A16_SFLOAT, Surface: GrColorType::kRGBA_F16_Clamped
{
+ constexpr GrColorType ct = GrColorType::kRGBA_F16_Clamped;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGBA_F16_Clamped;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R16_SFLOAT
{
- auto& info = this->getFormatInfo(VK_FORMAT_R16_SFLOAT);
- info.init(interface, physDev, properties, VK_FORMAT_R16_SFLOAT);
+ constexpr VkFormat format = VK_FORMAT_R16_SFLOAT;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R16_SFLOAT, Surface: kAlpha_F16
{
+ constexpr GrColorType ct = GrColorType::kAlpha_F16;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kAlpha_F16;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
ctInfo.fTextureSwizzle = GrSwizzle::RRRR();
ctInfo.fOutputSwizzle = GrSwizzle::AAAA();
@@ -801,64 +848,72 @@
}
// Format: VK_FORMAT_R8G8B8_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_R8G8B8_UNORM);
- info.init(interface, physDev, properties, VK_FORMAT_R8G8B8_UNORM);
+ constexpr VkFormat format = VK_FORMAT_R8G8B8_UNORM;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R8G8B8_UNORM, Surface: kRGB_888x
{
+ constexpr GrColorType ct = GrColorType::kRGB_888x;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGB_888x;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R8G8_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_R8G8_UNORM);
- info.init(interface, physDev, properties, VK_FORMAT_R8G8_UNORM);
+ constexpr VkFormat format = VK_FORMAT_R8G8_UNORM;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R8G8_UNORM, Surface: kRG_88
{
+ constexpr GrColorType ct = GrColorType::kRG_88;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRG_88;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32
{
- auto& info = this->getFormatInfo(VK_FORMAT_A2B10G10R10_UNORM_PACK32);
- info.init(interface, physDev, properties, VK_FORMAT_A2B10G10R10_UNORM_PACK32);
+ constexpr VkFormat format = VK_FORMAT_A2B10G10R10_UNORM_PACK32;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_A2B10G10R10_UNORM_PACK32, Surface: kRGBA_1010102
{
+ constexpr GrColorType ct = GrColorType::kRGBA_1010102;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGBA_1010102;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16
{
- auto& info = this->getFormatInfo(VK_FORMAT_B4G4R4A4_UNORM_PACK16);
- info.init(interface, physDev, properties, VK_FORMAT_B4G4R4A4_UNORM_PACK16);
+ constexpr VkFormat format = VK_FORMAT_B4G4R4A4_UNORM_PACK16;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_B4G4R4A4_UNORM_PACK16, Surface: kABGR_4444
{
+ constexpr GrColorType ct = GrColorType::kABGR_4444;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kABGR_4444;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
ctInfo.fTextureSwizzle = GrSwizzle::BGRA();
ctInfo.fOutputSwizzle = GrSwizzle::BGRA();
@@ -867,41 +922,46 @@
}
// Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16
{
- auto& info = this->getFormatInfo(VK_FORMAT_R4G4B4A4_UNORM_PACK16);
- info.init(interface, physDev, properties, VK_FORMAT_R4G4B4A4_UNORM_PACK16);
+ constexpr VkFormat format = VK_FORMAT_R4G4B4A4_UNORM_PACK16;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R4G4B4A4_UNORM_PACK16, Surface: kABGR_4444
{
+ constexpr GrColorType ct = GrColorType::kABGR_4444;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kABGR_4444;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R32G32B32A32_SFLOAT
{
- auto& info = this->getFormatInfo(VK_FORMAT_R32G32B32A32_SFLOAT);
- info.init(interface, physDev, properties, VK_FORMAT_R32G32B32A32_SFLOAT);
+ constexpr VkFormat format = VK_FORMAT_R32G32B32A32_SFLOAT;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R32G32B32A32_SFLOAT, Surface: kRGBA_F32
{
+ constexpr GrColorType ct = GrColorType::kRGBA_F32;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGBA_F32;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R8G8B8A8_SRGB
{
- auto& info = this->getFormatInfo(VK_FORMAT_R8G8B8A8_SRGB);
+ constexpr VkFormat format = VK_FORMAT_R8G8B8A8_SRGB;
+ auto& info = this->getFormatInfo(format);
if (fSRGBSupport) {
- info.init(interface, physDev, properties, VK_FORMAT_R8G8B8A8_SRGB);
+ info.init(interface, physDev, properties, format);
}
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
@@ -909,81 +969,91 @@
int ctIdx = 0;
// Format: VK_FORMAT_R8G8B8A8_SRGB, Surface: kRGBA_8888_SRGB
{
+ constexpr GrColorType ct = GrColorType::kRGBA_8888_SRGB;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGBA_8888_SRGB;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R16_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_R16_UNORM);
- info.init(interface, physDev, properties, VK_FORMAT_R16_UNORM);
+ constexpr VkFormat format = VK_FORMAT_R16_UNORM;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R16_UNORM, Surface: kR_16
{
+ constexpr GrColorType ct = GrColorType::kR_16;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kR_16;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R16G16_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_R16G16_UNORM);
- info.init(interface, physDev, properties, VK_FORMAT_R16G16_UNORM);
+ constexpr VkFormat format = VK_FORMAT_R16G16_UNORM;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R16G16_UNORM, Surface: kRG_1616
{
+ constexpr GrColorType ct = GrColorType::kRG_1616;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRG_1616;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R16G16B16A16_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_R16G16B16A16_UNORM);
- info.init(interface, physDev, properties, VK_FORMAT_R16G16B16A16_UNORM);
+ constexpr VkFormat format = VK_FORMAT_R16G16B16A16_UNORM;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R16G16B16A16_UNORM, Surface: kRGBA_16161616
{
+ constexpr GrColorType ct = GrColorType::kRGBA_16161616;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGBA_16161616;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_R16G16_SFLOAT
{
- auto& info = this->getFormatInfo(VK_FORMAT_R16G16_SFLOAT);
- info.init(interface, physDev, properties, VK_FORMAT_R16G16_SFLOAT);
+ constexpr VkFormat format = VK_FORMAT_R16G16_SFLOAT;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: VK_FORMAT_R16G16_SFLOAT, Surface: kRG_F16
{
+ constexpr GrColorType ct = GrColorType::kRG_F16;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRG_F16;
+ ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM);
+ constexpr VkFormat format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
+ auto& info = this->getFormatInfo(format);
if (fSupportsYcbcrConversion) {
- info.init(interface, physDev, properties, VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM);
+ info.init(interface, physDev, properties, format);
}
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
@@ -991,17 +1061,19 @@
int ctIdx = 0;
// Format: VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM, Surface: kRGB_888x
{
+ constexpr GrColorType ct = GrColorType::kRGB_888x;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGB_888x;
- ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
+ ctInfo.fColorType = ct;
+ ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag;
}
}
}
// Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM
{
- auto& info = this->getFormatInfo(VK_FORMAT_G8_B8R8_2PLANE_420_UNORM);
+ constexpr VkFormat format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
+ auto& info = this->getFormatInfo(format);
if (fSupportsYcbcrConversion) {
- info.init(interface, physDev, properties, VK_FORMAT_G8_B8R8_2PLANE_420_UNORM);
+ info.init(interface, physDev, properties, format);
}
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
@@ -1009,18 +1081,46 @@
int ctIdx = 0;
// Format: VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, Surface: kRGB_888x
{
+ constexpr GrColorType ct = GrColorType::kRGB_888x;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
- ctInfo.fColorType = GrColorType::kRGB_888x;
- ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
+ ctInfo.fColorType = ct;
+ ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kWrappedOnly_Flag;
}
}
}
// Format: VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK
{
- auto& info = this->getFormatInfo(VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK);
- info.init(interface, physDev, properties, VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK);
+ constexpr VkFormat format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
+ auto& info = this->getFormatInfo(format);
+ info.init(interface, physDev, properties, format);
// No supported GrColorTypes.
}
+
+ ////////////////////////////////////////////////////////////////////////////
+ // Map GrColorTypes (used for creating GrSurfaces) to VkFormats. The order in which the formats
+ // are passed into the setColorType function indicates the priority in selecting which format
+ // we use for a given GrcolorType.
+
+ this->setColorType(GrColorType::kAlpha_8, { VK_FORMAT_R8_UNORM });
+ this->setColorType(GrColorType::kBGR_565, { VK_FORMAT_R5G6B5_UNORM_PACK16 });
+ this->setColorType(GrColorType::kABGR_4444, { VK_FORMAT_R4G4B4A4_UNORM_PACK16,
+ VK_FORMAT_B4G4R4A4_UNORM_PACK16 });
+ this->setColorType(GrColorType::kRGBA_8888, { VK_FORMAT_R8G8B8A8_UNORM });
+ this->setColorType(GrColorType::kRGBA_8888_SRGB, { VK_FORMAT_R8G8B8A8_SRGB });
+ this->setColorType(GrColorType::kRGB_888x, { VK_FORMAT_R8G8B8_UNORM,
+ VK_FORMAT_R8G8B8A8_UNORM });
+ this->setColorType(GrColorType::kRG_88, { VK_FORMAT_R8G8_UNORM });
+ this->setColorType(GrColorType::kBGRA_8888, { VK_FORMAT_B8G8R8A8_UNORM });
+ this->setColorType(GrColorType::kRGBA_1010102, { VK_FORMAT_A2B10G10R10_UNORM_PACK32 });
+ this->setColorType(GrColorType::kGray_8, { VK_FORMAT_R8_UNORM });
+ this->setColorType(GrColorType::kAlpha_F16, { VK_FORMAT_R16_SFLOAT });
+ this->setColorType(GrColorType::kRGBA_F16, { VK_FORMAT_R16G16B16A16_SFLOAT });
+ this->setColorType(GrColorType::kRGBA_F16_Clamped, { VK_FORMAT_R16G16B16A16_SFLOAT });
+ this->setColorType(GrColorType::kRGBA_F32, { VK_FORMAT_R32G32B32A32_SFLOAT });
+ this->setColorType(GrColorType::kR_16, { VK_FORMAT_R16_UNORM });
+ this->setColorType(GrColorType::kRG_1616, { VK_FORMAT_R16G16_UNORM });
+ this->setColorType(GrColorType::kRGBA_16161616, { VK_FORMAT_R16G16B16A16_UNORM });
+ this->setColorType(GrColorType::kRG_F16, { VK_FORMAT_R16G16_SFLOAT });
}
void GrVkCaps::FormatInfo::InitFormatFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) {
@@ -1300,6 +1400,32 @@
return true;
}
+bool GrVkCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
+ const GrBackendFormat& format) const {
+ VkFormat vkFormat;
+ if (!format.asVkFormat(&vkFormat)) {
+ return false;
+ }
+ const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo();
+ SkASSERT(ycbcrInfo);
+
+ if (ycbcrInfo->isValid() && !GrVkFormatNeedsYcbcrSampler(vkFormat)) {
+ // Format may be undefined for external images, which are required to have YCbCr conversion.
+ if (VK_FORMAT_UNDEFINED == vkFormat) {
+ return true;
+ }
+ return false;
+ }
+
+ const auto& info = this->getFormatInfo(vkFormat);
+ for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
+ if (info.fColorTypeInfos[i].fColorType == ct) {
+ return true;
+ }
+ }
+ return false;
+}
+
static GrPixelConfig validate_image_info(VkFormat format, GrColorType ct, bool hasYcbcrConversion) {
if (hasYcbcrConversion) {
if (GrVkFormatNeedsYcbcrSampler(format)) {
@@ -1429,19 +1555,6 @@
return kUnknown_GrPixelConfig;
}
-bool GrVkCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
- const GrBackendFormat& format) const {
- VkFormat vkFormat;
- if (!format.asVkFormat(&vkFormat)) {
- return false;
- }
- const GrVkYcbcrConversionInfo* ycbcrInfo = format.getVkYcbcrConversionInfo();
- SkASSERT(ycbcrInfo);
-
- return kUnknown_GrPixelConfig != validate_image_info(vkFormat, ct, ycbcrInfo->isValid());
-}
-
-
GrPixelConfig GrVkCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
GrColorType ct) const {
VkFormat vkFormat;
@@ -1481,12 +1594,8 @@
GrBackendFormat GrVkCaps::onGetDefaultBackendFormat(GrColorType ct,
GrRenderable renderable) const {
- GrPixelConfig config = GrColorTypeToPixelConfig(ct);
- if (config == kUnknown_GrPixelConfig) {
- return GrBackendFormat();
- }
- VkFormat format;
- if (!GrPixelConfigToVkFormat(config, &format)) {
+ VkFormat format = this->getFormatFromColorType(ct);
+ if (format == VK_FORMAT_UNDEFINED) {
return GrBackendFormat();
}
return GrBackendFormat::MakeVk(format);
@@ -1588,12 +1697,6 @@
{ GrColorType::kRG_F16, GrBackendFormat::MakeVk(VK_FORMAT_R16G16_SFLOAT) },
};
-#ifdef SK_DEBUG
- for (auto combo : combos) {
- SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
- }
-#endif
-
return combos;
}
#endif
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index 4806390..2cc3397 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -161,6 +161,11 @@
GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
+ VkFormat getFormatFromColorType(GrColorType colorType) const {
+ int idx = static_cast<int>(colorType);
+ return fColorTypeToFormatTable[idx];
+ }
+
bool canClearTextureOnCreation() const override;
GrSwizzle getTextureSwizzle(const GrBackendFormat&, GrColorType) const override;
@@ -218,6 +223,9 @@
// Does Ganesh itself support rendering to this colorType & format pair. Renderability
// still additionally depends on if the format itself is renderable.
kRenderable_Flag = 0x2,
+ // Indicates that this colorType is supported only if we are wrapping a texture with
+ // the given format and colorType. We do not allow creation with this pair.
+ kWrappedOnly_Flag = 0x4,
};
uint32_t fFlags = 0;
@@ -262,6 +270,9 @@
FormatInfo& getFormatInfo(VkFormat);
const FormatInfo& getFormatInfo(VkFormat) const;
+ VkFormat fColorTypeToFormatTable[kGrColorTypeCnt];
+ void setColorType(GrColorType, std::initializer_list<VkFormat> formats);
+
StencilFormat fPreferredStencilFormat;
SkSTArray<1, GrVkYcbcrConversionInfo> fYcbcrInfos;
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index a347945..a5b451a 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -1929,14 +1929,7 @@
return GrBackendRenderTarget();
}
- auto config = GrColorTypeToPixelConfig(ct);
- if (kUnknown_GrPixelConfig == config) {
- return {};
- }
- VkFormat vkFormat;
- if (!GrPixelConfigToVkFormat(config, &vkFormat)) {
- return {};
- }
+ VkFormat vkFormat = this->vkCaps().getFormatFromColorType(ct);
GrVkImageInfo info;
if (!this->createVkImageForBackendSurface(vkFormat, w, h, false, true, GrMipMapped::kNo,
diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp
index 819eb0e..d7d53fb 100644
--- a/src/gpu/vk/GrVkRenderTarget.cpp
+++ b/src/gpu/vk/GrVkRenderTarget.cpp
@@ -139,8 +139,7 @@
SkASSERT(VK_NULL_HANDLE != info.fImage);
SkASSERT(1 == info.fLevelCount);
- VkFormat pixelFormat;
- GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat);
+ VkFormat pixelFormat = info.fFormat;
VkImage colorImage;
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.cpp b/src/gpu/vk/GrVkTextureRenderTarget.cpp
index 2288db2..50aae23 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.cpp
+++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp
@@ -117,8 +117,7 @@
return {};
}
- VkFormat pixelFormat;
- GrPixelConfigToVkFormat(desc.fConfig, &pixelFormat);
+ VkFormat pixelFormat = info.fFormat;
VkImage colorImage;
diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp
index e7164ff..c3f3f9a 100644
--- a/src/gpu/vk/GrVkUtil.cpp
+++ b/src/gpu/vk/GrVkUtil.cpp
@@ -12,91 +12,6 @@
#include "src/gpu/vk/GrVkGpu.h"
#include "src/sksl/SkSLCompiler.h"
-bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) {
- VkFormat dontCare;
- if (!format) {
- format = &dontCare;
- }
-
- switch (config) {
- case kUnknown_GrPixelConfig:
- return false;
- case kRGBA_8888_GrPixelConfig:
- *format = VK_FORMAT_R8G8B8A8_UNORM;
- return true;
- case kRGB_888_GrPixelConfig:
- *format = VK_FORMAT_R8G8B8_UNORM;
- return true;
- case kRGB_888X_GrPixelConfig:
- *format = VK_FORMAT_R8G8B8A8_UNORM;
- return true;
- case kRG_88_GrPixelConfig:
- *format = VK_FORMAT_R8G8_UNORM;
- return true;
- case kBGRA_8888_GrPixelConfig:
- *format = VK_FORMAT_B8G8R8A8_UNORM;
- return true;
- case kSRGBA_8888_GrPixelConfig:
- *format = VK_FORMAT_R8G8B8A8_SRGB;
- return true;
- case kRGBA_1010102_GrPixelConfig:
- *format = VK_FORMAT_A2B10G10R10_UNORM_PACK32;
- return true;
- case kRGB_565_GrPixelConfig:
- *format = VK_FORMAT_R5G6B5_UNORM_PACK16;
- return true;
- case kRGBA_4444_GrPixelConfig:
- // R4G4B4A4 is not required to be supported so we actually
- // store the data is if it was B4G4R4A4 and swizzle in shaders
- *format = VK_FORMAT_B4G4R4A4_UNORM_PACK16;
- return true;
- case kAlpha_8_GrPixelConfig: // fall through
- case kAlpha_8_as_Red_GrPixelConfig:
- *format = VK_FORMAT_R8_UNORM;
- return true;
- case kAlpha_8_as_Alpha_GrPixelConfig:
- return false;
- case kGray_8_GrPixelConfig:
- case kGray_8_as_Red_GrPixelConfig:
- *format = VK_FORMAT_R8_UNORM;
- return true;
- case kGray_8_as_Lum_GrPixelConfig:
- return false;
- case kRGBA_float_GrPixelConfig:
- *format = VK_FORMAT_R32G32B32A32_SFLOAT;
- return true;
- case kRGBA_half_GrPixelConfig:
- case kRGBA_half_Clamped_GrPixelConfig:
- *format = VK_FORMAT_R16G16B16A16_SFLOAT;
- return true;
- case kRGB_ETC1_GrPixelConfig:
- // converting to ETC2 which is a superset of ETC1
- *format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
- return true;
- case kAlpha_half_GrPixelConfig: // fall through
- case kAlpha_half_as_Red_GrPixelConfig:
- *format = VK_FORMAT_R16_SFLOAT;
- return true;
- case kAlpha_half_as_Lum_GrPixelConfig:
- return false;
- case kR_16_GrPixelConfig:
- *format = VK_FORMAT_R16_UNORM;
- return true;
- case kRG_1616_GrPixelConfig:
- *format = VK_FORMAT_R16G16_UNORM;
- return true;
- // Experimental (for Y416 and mutant P016/P010)
- case kRGBA_16161616_GrPixelConfig:
- *format = VK_FORMAT_R16G16B16A16_UNORM;
- return true;
- case kRG_half_GrPixelConfig:
- *format = VK_FORMAT_R16G16_SFLOAT;
- return true;
-
- }
- SK_ABORT("Unexpected config");
-}
-
#ifdef SK_DEBUG
bool GrVkFormatColorTypePairIsValid(VkFormat format, GrColorType colorType) {
switch (format) {
diff --git a/src/gpu/vk/GrVkUtil.h b/src/gpu/vk/GrVkUtil.h
index dded319..9c2fe4f 100644
--- a/src/gpu/vk/GrVkUtil.h
+++ b/src/gpu/vk/GrVkUtil.h
@@ -29,11 +29,6 @@
#define GR_VK_CALL_ERRCHECK(IFACE, X) (void) GR_VK_CALL(IFACE, X)
#endif
-/**
- * Returns the vulkan texture format for the given GrPixelConfig
- */
-bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format);
-
bool GrVkFormatIsSupported(VkFormat);
bool GrVkFormatNeedsYcbcrSampler(VkFormat format);