in src/gpu/ganesh/d3d/GrD3DCaps.cpp [361:722]
void GrD3DCaps::initFormatTable(const DXGI_ADAPTER_DESC& adapterDesc, ID3D12Device* device) {
static_assert(std::size(kDxgiFormats) == GrD3DCaps::kNumDxgiFormats,
"Size of DXGI_FORMATs array must match static value in header");
std::fill_n(fColorTypeToFormatTable, kGrColorTypeCnt, DXGI_FORMAT_UNKNOWN);
// Go through all the formats and init their support surface and data GrColorTypes.
// Format: DXGI_FORMAT_R8G8B8A8_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kRGBA_8888;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R8G8B8A8_UNORM, Surface: kRGBA_8888
{
constexpr GrColorType ct = GrColorType::kRGBA_8888;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
// Format: DXGI_FORMAT_R8G8B8A8_UNORM, Surface: kRGB_888x
{
constexpr GrColorType ct = GrColorType::kRGB_888x;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
ctInfo.fReadSwizzle = skgpu::Swizzle("rgb1");
}
}
}
// Format: DXGI_FORMAT_R8_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R8_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kR_8;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 3;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R8_UNORM, Surface: kR_8
{
constexpr GrColorType ct = GrColorType::kR_8;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
// Format: DXGI_FORMAT_R8_UNORM, Surface: kAlpha_8
{
constexpr GrColorType ct = GrColorType::kAlpha_8;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
ctInfo.fWriteSwizzle = skgpu::Swizzle("a000");
}
// Format: DXGI_FORMAT_R8_UNORM, Surface: kGray_8
{
constexpr GrColorType ct = GrColorType::kGray_8;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
ctInfo.fReadSwizzle = skgpu::Swizzle("rrr1");
}
}
}
// Format: DXGI_FORMAT_B8G8R8A8_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kBGRA_8888;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_B8G8R8A8_UNORM, Surface: kBGRA_8888
{
constexpr GrColorType ct = GrColorType::kBGRA_8888;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: DXGI_FORMAT_B5G6R5_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_B5G6R5_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kBGR_565;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_B5G6R5_UNORM, Surface: kBGR_565
{
constexpr GrColorType ct = GrColorType::kBGR_565;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: DXGI_FORMAT_R16G16B16A16_FLOAT
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R16G16B16A16_FLOAT;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kRGBA_F16;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 3;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R16G16B16A16_FLOAT, Surface: GrColorType::kRGBA_F16
{
constexpr GrColorType ct = GrColorType::kRGBA_F16;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
// Format: DXGI_FORMAT_R16G16B16A16_FLOAT, Surface: GrColorType::kRGBA_F16_Clamped
{
constexpr GrColorType ct = GrColorType::kRGBA_F16_Clamped;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
// Format: DXGI_FORMAT_R16G16B16A16_FLOAT, Surface: GrColorType::kRGB_F16F16F16x
{
constexpr GrColorType ct = GrColorType::kRGB_F16F16F16x;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
ctInfo.fReadSwizzle = skgpu::Swizzle("rgb1");
}
}
}
// Format: DXGI_FORMAT_R16_FLOAT
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R16_FLOAT;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kR_F16;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R16_FLOAT, Surface: kAlpha_F16
{
constexpr GrColorType ct = GrColorType::kAlpha_F16;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
ctInfo.fWriteSwizzle = skgpu::Swizzle("a000");
}
}
}
// Format: DXGI_FORMAT_R8G8_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R8G8_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kRG_88;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R8G8_UNORM, Surface: kRG_88
{
constexpr GrColorType ct = GrColorType::kRG_88;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: DXGI_FORMAT_R10G10B10A2_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R10G10B10A2_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kRGBA_1010102;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 2;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R10G10B10A2_UNORM, Surface: kRGBA_1010102
{
constexpr GrColorType ct = GrColorType::kRGBA_1010102;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
// Format: DXGI_FORMAT_R10G10B10A2_UNORM, Surface: kRGB_101010x
{
constexpr GrColorType ct = GrColorType::kRGB_101010x;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag;
ctInfo.fReadSwizzle = skgpu::Swizzle("rgb1");
}
}
}
// Format: DXGI_FORMAT_B4G4R4A4_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_B4G4R4A4_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kBGRA_4444;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_B4G4R4A4_UNORM, Surface: kABGR_4444
{
constexpr GrColorType ct = GrColorType::kABGR_4444;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
ctInfo.fReadSwizzle = skgpu::Swizzle("argb");
ctInfo.fWriteSwizzle = skgpu::Swizzle("gbar");
}
}
}
// Format: DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kRGBA_8888_SRGB;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, Surface: kRGBA_8888_SRGB
{
constexpr GrColorType ct = GrColorType::kRGBA_8888_SRGB;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: DXGI_FORMAT_R16_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R16_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kR_16;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R16_UNORM, Surface: kAlpha_16
{
constexpr GrColorType ct = GrColorType::kAlpha_16;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
ctInfo.fReadSwizzle = skgpu::Swizzle("000r");
ctInfo.fWriteSwizzle = skgpu::Swizzle("a000");
}
}
}
// Format: DXGI_FORMAT_R16G16_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R16G16_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kRG_1616;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R16G16_UNORM, Surface: kRG_1616
{
constexpr GrColorType ct = GrColorType::kRG_1616;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: DXGI_FORMAT_R16G16B16A16_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R16G16B16A16_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kRGBA_16161616;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R16G16B16A16_UNORM, Surface: kRGBA_16161616
{
constexpr GrColorType ct = GrColorType::kRGBA_16161616;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: DXGI_FORMAT_R16G16_FLOAT
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_R16G16_FLOAT;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
info.fFormatColorType = GrColorType::kRG_F16;
if (SkToBool(info.fFlags & FormatInfo::kTexturable_Flag)) {
info.fColorTypeInfoCount = 1;
info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]());
int ctIdx = 0;
// Format: DXGI_FORMAT_R16G16_FLOAT, Surface: kRG_F16
{
constexpr GrColorType ct = GrColorType::kRG_F16;
auto& ctInfo = info.fColorTypeInfos[ctIdx++];
ctInfo.fColorType = ct;
ctInfo.fFlags = ColorTypeInfo::kUploadData_Flag | ColorTypeInfo::kRenderable_Flag;
}
}
}
// Format: DXGI_FORMAT_BC1_UNORM
{
constexpr DXGI_FORMAT format = DXGI_FORMAT_BC1_UNORM;
auto& info = this->getFormatInfo(format);
info.init(adapterDesc, device, format);
// No supported GrColorTypes.
}
////////////////////////////////////////////////////////////////////////////
// Map GrColorTypes (used for creating GrSurfaces) to DXGI_FORMATs. 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, { DXGI_FORMAT_R8_UNORM });
this->setColorType(GrColorType::kBGR_565, { DXGI_FORMAT_B5G6R5_UNORM });
this->setColorType(GrColorType::kABGR_4444, { DXGI_FORMAT_B4G4R4A4_UNORM });
this->setColorType(GrColorType::kRGBA_8888, { DXGI_FORMAT_R8G8B8A8_UNORM });
this->setColorType(GrColorType::kRGBA_8888_SRGB, { DXGI_FORMAT_R8G8B8A8_UNORM_SRGB });
this->setColorType(GrColorType::kRGB_888x, { DXGI_FORMAT_R8G8B8A8_UNORM });
this->setColorType(GrColorType::kRG_88, { DXGI_FORMAT_R8G8_UNORM });
this->setColorType(GrColorType::kBGRA_8888, { DXGI_FORMAT_B8G8R8A8_UNORM });
this->setColorType(GrColorType::kRGBA_1010102, { DXGI_FORMAT_R10G10B10A2_UNORM });
this->setColorType(GrColorType::kRGB_101010x, { DXGI_FORMAT_R10G10B10A2_UNORM });
this->setColorType(GrColorType::kGray_8, { DXGI_FORMAT_R8_UNORM });
this->setColorType(GrColorType::kAlpha_F16, { DXGI_FORMAT_R16_FLOAT });
this->setColorType(GrColorType::kRGBA_F16, { DXGI_FORMAT_R16G16B16A16_FLOAT });
this->setColorType(GrColorType::kRGBA_F16_Clamped, { DXGI_FORMAT_R16G16B16A16_FLOAT });
this->setColorType(GrColorType::kRGB_F16F16F16x, { DXGI_FORMAT_R16G16B16A16_FLOAT });
this->setColorType(GrColorType::kAlpha_16, { DXGI_FORMAT_R16_UNORM });
this->setColorType(GrColorType::kRG_1616, { DXGI_FORMAT_R16G16_UNORM });
this->setColorType(GrColorType::kRGBA_16161616, { DXGI_FORMAT_R16G16B16A16_UNORM });
this->setColorType(GrColorType::kRG_F16, { DXGI_FORMAT_R16G16_FLOAT });
}