Move vulkan BytesPerPixel to format table.

Bug: skia:6718
Change-Id: I1d540042d8b69393d1676d0f0cedca7f37ac88d7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/246852
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Greg Daniel 2019-10-07 16:43:56 -04:00 committed by Skia Commit-Bot
parent a6f07c5b5c
commit 7efb1a6dbc
5 changed files with 31 additions and 44 deletions

View File

@ -713,6 +713,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R8G8B8A8_UNORM;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 4;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -740,6 +741,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R8_UNORM;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 1;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -768,6 +770,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_B8G8R8A8_UNORM;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 4;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -786,6 +789,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R5G6B5_UNORM_PACK16;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 2;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -804,6 +808,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 8;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -829,6 +834,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R16_SFLOAT;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 2;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -849,6 +855,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R8G8B8_UNORM;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 3;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -867,6 +874,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R8G8_UNORM;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 2;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -885,6 +893,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_A2B10G10R10_UNORM_PACK32;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 4;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -903,6 +912,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_B4G4R4A4_UNORM_PACK16;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 2;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -923,6 +933,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R4G4B4A4_UNORM_PACK16;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 2;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -941,6 +952,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R8G8B8A8_SRGB;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 4;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -959,6 +971,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R16_UNORM;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 2;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -979,6 +992,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R16G16_UNORM;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 4;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -997,6 +1011,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R16G16B16A16_UNORM;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 8;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -1015,6 +1030,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_R16G16_SFLOAT;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 4;
if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
@ -1032,6 +1048,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
{
constexpr VkFormat format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
auto& info = this->getFormatInfo(format);
info.fBytesPerPixel = 0;
if (fSupportsYcbcrConversion) {
info.init(interface, physDev, properties, format);
}
@ -1052,6 +1069,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
{
constexpr VkFormat format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
auto& info = this->getFormatInfo(format);
info.fBytesPerPixel = 0;
if (fSupportsYcbcrConversion) {
info.init(interface, physDev, properties, format);
}
@ -1073,6 +1091,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice
constexpr VkFormat format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
auto& info = this->getFormatInfo(format);
info.init(interface, physDev, properties, format);
info.fBytesPerPixel = 0;
// No supported GrColorTypes.
}
@ -1360,7 +1379,7 @@ GrCaps::SupportedWrite GrVkCaps::supportedWritePixelsColorType(GrColorType surfa
}
// The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel.
size_t offsetAlignment = align_to_4(GrVkBytesPerFormat(vkFormat));
size_t offsetAlignment = align_to_4(this->bytesPerPixel(vkFormat));
const auto& info = this->getFormatInfo(vkFormat);
for (int i = 0; i < info.fColorTypeInfoCount; ++i) {
@ -1650,7 +1669,7 @@ GrCaps::SupportedRead GrVkCaps::onSupportedReadPixelsColorType(
}
// The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel.
size_t offsetAlignment = align_to_4(GrVkBytesPerFormat(vkFormat));
size_t offsetAlignment = align_to_4(this->bytesPerPixel(vkFormat));
const auto& info = this->getFormatInfo(vkFormat);
for (int i = 0; i < info.fColorTypeInfoCount; ++i) {

View File

@ -53,6 +53,12 @@ public:
int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
int maxRenderTargetSampleCount(VkFormat format) const;
size_t bytesPerPixel(VkFormat format) const {
// We shouldn't be calling this for compressed or planar formats.
SkASSERT(this->getFormatInfo(format).fBytesPerPixel);
return this->getFormatInfo(format).fBytesPerPixel;
}
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
const GrBackendFormat& surfaceFormat,
GrColorType srcColorType) const override;
@ -267,6 +273,8 @@ private:
uint16_t fLinearFlags = 0;
SkTDArray<int> fColorSampleCounts;
// This value is only valid for regular formats. Planar and compressed formats will be 0.
size_t fBytesPerPixel = 0;
std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
int fColorTypeInfoCount = 0;

View File

@ -1463,7 +1463,7 @@ bool copy_src_data(GrVkGpu* gpu, const GrVkAlloc& alloc, VkFormat vkFormat,
if (!mapPtr) {
return false;
}
size_t bytesPerPixel = GrVkBytesPerFormat(vkFormat);
size_t bytesPerPixel = gpu->vkCaps().bytesPerPixel(vkFormat);
for (int level = 0; level < numMipLevels; ++level) {
const size_t trimRB = srcData[level].width() * bytesPerPixel;
@ -1611,7 +1611,7 @@ bool GrVkGpu::createVkImageForBackendSurface(VkFormat vkFormat, int w, int h, bo
mipLevelCount, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
if (srcData) {
size_t bytesPerPixel = GrVkBytesPerFormat(vkFormat);
size_t bytesPerPixel = fVkCaps->bytesPerPixel(vkFormat);
SkASSERT(w && h);
SkTArray<size_t> individualMipOffsets(mipLevelCount);

View File

@ -177,44 +177,6 @@ bool GrInstallVkShaderModule(const GrVkGpu* gpu,
return true;
}
size_t GrVkBytesPerFormat(VkFormat vkFormat) {
switch (vkFormat) {
case VK_FORMAT_R8_UNORM:
return 1;
case VK_FORMAT_R5G6B5_UNORM_PACK16:
case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
case VK_FORMAT_R8G8_UNORM:
case VK_FORMAT_R16_SFLOAT:
case VK_FORMAT_R16_UNORM:
return 2;
case VK_FORMAT_R8G8B8_UNORM:
return 3;
case VK_FORMAT_R8G8B8A8_UNORM:
case VK_FORMAT_R8G8B8A8_SRGB:
case VK_FORMAT_B8G8R8A8_UNORM:
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16_SFLOAT:
return 4;
case VK_FORMAT_R16G16B16A16_SFLOAT:
case VK_FORMAT_R16G16B16A16_UNORM:
return 8;
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
return 0;
default:
SK_ABORT("Invalid Vk format");
}
SK_ABORT("Invalid Vk format");
}
bool GrVkFormatIsCompressed(VkFormat vkFormat) {
switch (vkFormat) {
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:

View File

@ -57,8 +57,6 @@ bool GrInstallVkShaderModule(const GrVkGpu* gpu,
VkShaderModule* shaderModule,
VkPipelineShaderStageCreateInfo* stageInfo);
size_t GrVkBytesPerFormat(VkFormat);
/**
* Returns true if the format is compressed.
*/