Commit b80a5e9c by Jamie Madill Committed by Commit Bot

Store channel bits info in angle::Format.

This allows us to delete some duplicated code in the D3D11-side. BUG=angleproject:1389 BUG=angleproject:1459 Change-Id: Ifdcfcd4a56e06ff2ae8f5ca0bda72281d52c2964 Reviewed-on: https://chromium-review.googlesource.com/392208 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 91db32c5
......@@ -47,13 +47,25 @@ Format::Format(ID id,
GLenum glFormat,
GLenum fboFormat,
MipGenerationFunction mipGen,
ColorReadFunction colorRead)
ColorReadFunction colorRead,
GLuint redBits,
GLuint greenBits,
GLuint blueBits,
GLuint alphaBits,
GLuint depthBits,
GLuint stencilBits)
: id(id),
glInternalFormat(glFormat),
fboImplementationInternalFormat(fboFormat),
mipGenerationFunction(mipGen),
colorReadFunction(colorRead),
fastCopyFunctions(GetFastCopyFunctionsMap(id))
fastCopyFunctions(GetFastCopyFunctionsMap(id)),
redBits(redBits),
greenBits(greenBits),
blueBits(blueBits),
alphaBits(alphaBits),
depthBits(depthBits),
stencilBits(stencilBits)
{
}
......
......@@ -26,7 +26,13 @@ struct Format final : angle::NonCopyable
GLenum glFormat,
GLenum fboFormat,
rx::MipGenerationFunction mipGen,
rx::ColorReadFunction colorRead);
rx::ColorReadFunction colorRead,
GLuint redBits,
GLuint greenBits,
GLuint blueBits,
GLuint alphaBits,
GLuint depthBits,
GLuint stencilBits);
static const Format &Get(ID id);
......@@ -46,6 +52,13 @@ struct Format final : angle::NonCopyable
// A map from a gl::FormatType to a fast pixel copy function for this format.
rx::FastCopyFunctionMap fastCopyFunctions;
GLuint redBits;
GLuint greenBits;
GLuint blueBits;
GLuint alphaBits;
GLuint depthBits;
GLuint stencilBits;
};
} // namespace angle
......
......@@ -1459,26 +1459,26 @@ gl::Error Blit11::copyDepthStencilImpl(const TextureHelper11 &source,
const gl::Rectangle *scissor,
bool stencilOnly)
{
auto srcFormat = source.getFormat();
const auto &srcSizeInfo = d3d11::GetDXGIFormatSizeInfo(srcFormat);
auto srcDXGIFormat = source.getFormat();
const auto &srcSizeInfo = d3d11::GetDXGIFormatSizeInfo(srcDXGIFormat);
unsigned int srcPixelSize = srcSizeInfo.pixelBytes;
unsigned int copyOffset = 0;
unsigned int copyOffset = 0;
unsigned int copySize = srcPixelSize;
auto destFormat = dest.getFormat();
const auto &destSizeInfo = d3d11::GetDXGIFormatSizeInfo(destFormat);
auto destDXGIFormat = dest.getFormat();
const auto &destSizeInfo = d3d11::GetDXGIFormatSizeInfo(destDXGIFormat);
unsigned int destPixelSize = destSizeInfo.pixelBytes;
ASSERT(srcFormat == destFormat || destFormat == DXGI_FORMAT_R32_TYPELESS);
ASSERT(srcDXGIFormat == destDXGIFormat || destDXGIFormat == DXGI_FORMAT_R32_TYPELESS);
if (stencilOnly)
{
const d3d11::DXGIFormat &srcDXGIFormat = d3d11::GetDXGIFormatInfo(srcFormat);
const auto &srcFormat = source.getFormatSet().format;
// Stencil channel should be right after the depth channel. Some views to depth/stencil
// resources have red channel for depth, in which case the depth channel bit width is in
// redBits.
ASSERT((srcDXGIFormat.redBits != 0) != (srcDXGIFormat.depthBits != 0));
GLuint depthBits = srcDXGIFormat.redBits + srcDXGIFormat.depthBits;
ASSERT((srcFormat.redBits != 0) != (srcFormat.depthBits != 0));
GLuint depthBits = srcFormat.redBits + srcFormat.depthBits;
// Known formats have either 24 or 32 bits of depth.
ASSERT(depthBits == 24 || depthBits == 32);
copyOffset = depthBits / 8;
......@@ -1487,9 +1487,9 @@ gl::Error Blit11::copyDepthStencilImpl(const TextureHelper11 &source,
copySize = 1;
}
if (srcFormat != destFormat)
if (srcDXGIFormat != destDXGIFormat)
{
if (srcFormat == DXGI_FORMAT_R24G8_TYPELESS)
if (srcDXGIFormat == DXGI_FORMAT_R24G8_TYPELESS)
{
ASSERT(sourceArea == destArea && sourceSize == destSize && scissor == nullptr);
return copyAndConvert(source, sourceSubresource, sourceArea, sourceSize, dest,
......@@ -1497,7 +1497,7 @@ gl::Error Blit11::copyDepthStencilImpl(const TextureHelper11 &source,
copyOffset, copySize, srcPixelSize, destPixelSize,
BlitD24S8ToD32F);
}
ASSERT(srcFormat == DXGI_FORMAT_R32G8X24_TYPELESS);
ASSERT(srcDXGIFormat == DXGI_FORMAT_R32G8X24_TYPELESS);
return copyAndConvert(source, sourceSubresource, sourceArea, sourceSize, dest,
destSubresource, destArea, destSize, scissor, copyOffset, copyOffset,
copySize, srcPixelSize, destPixelSize, BlitD32FS8ToD32F);
......
......@@ -331,27 +331,26 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
return gl::Error(GL_OUT_OF_MEMORY, "Internal render target view pointer unexpectedly null.");
}
const auto &dxgiFormatInfo =
d3d11::GetDXGIFormatInfo(renderTarget->getFormatSet().rtvFormat);
const auto &nativeFormat = renderTarget->getFormatSet().format;
// Check if the actual format has a channel that the internal format does not and set them to the
// default values
float clearValues[4] = {
((formatInfo.redBits == 0 && dxgiFormatInfo.redBits > 0)
((formatInfo.redBits == 0 && nativeFormat.redBits > 0)
? 0.0f
: clearParams.colorFClearValue.red),
((formatInfo.greenBits == 0 && dxgiFormatInfo.greenBits > 0)
((formatInfo.greenBits == 0 && nativeFormat.greenBits > 0)
? 0.0f
: clearParams.colorFClearValue.green),
((formatInfo.blueBits == 0 && dxgiFormatInfo.blueBits > 0)
((formatInfo.blueBits == 0 && nativeFormat.blueBits > 0)
? 0.0f
: clearParams.colorFClearValue.blue),
((formatInfo.alphaBits == 0 && dxgiFormatInfo.alphaBits > 0)
((formatInfo.alphaBits == 0 && nativeFormat.alphaBits > 0)
? 1.0f
: clearParams.colorFClearValue.alpha),
};
if (dxgiFormatInfo.alphaBits == 1)
if (formatInfo.alphaBits == 1)
{
// Some drivers do not correctly handle calling Clear() on a format with 1-bit alpha.
// They can incorrectly round all non-zero values up to 1.0f. Note that WARP does not do this.
......@@ -392,10 +391,10 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
return error;
}
const auto &dxgiFormatInfo =
d3d11::GetDXGIFormatInfo(renderTarget->getFormatSet().dsvFormat);
const auto &nativeFormat = renderTarget->getFormatSet().format;
unsigned int stencilUnmasked = (stencilAttachment != nullptr) ? (1 << dxgiFormatInfo.stencilBits) - 1 : 0;
unsigned int stencilUnmasked =
(stencilAttachment != nullptr) ? (1 << nativeFormat.stencilBits) - 1 : 0;
bool needMaskedStencilClear = clearParams.clearStencil && (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked;
if (needScissoredClear || needMaskedStencilClear)
......
......@@ -3931,21 +3931,20 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
const auto &destFormatInfo = gl::GetInternalFormatInfo(drawRenderTarget->getInternalFormat());
const auto &srcFormatInfo = gl::GetInternalFormatInfo(readRenderTarget->getInternalFormat());
const auto &formatSet = drawRenderTarget11->getFormatSet();
const DXGI_FORMAT drawDXGIFormat = colorBlit ? formatSet.rtvFormat : formatSet.dsvFormat;
const auto &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(drawDXGIFormat);
const auto &nativeFormat = formatSet.format;
// Some blits require masking off emulated texture channels. eg: from RGBA8 to RGB8, we
// emulate RGB8 with RGBA8, so we need to mask off the alpha channel when we copy.
gl::Color<bool> colorMask;
colorMask.red = (srcFormatInfo.redBits > 0) && (destFormatInfo.redBits == 0) &&
(dxgiFormatInfo.redBits > 0);
colorMask.red =
(srcFormatInfo.redBits > 0) && (destFormatInfo.redBits == 0) && (nativeFormat.redBits > 0);
colorMask.green = (srcFormatInfo.greenBits > 0) && (destFormatInfo.greenBits == 0) &&
(dxgiFormatInfo.greenBits > 0);
(nativeFormat.greenBits > 0);
colorMask.blue = (srcFormatInfo.blueBits > 0) && (destFormatInfo.blueBits == 0) &&
(dxgiFormatInfo.blueBits > 0);
(nativeFormat.blueBits > 0);
colorMask.alpha = (srcFormatInfo.alphaBits > 0) && (destFormatInfo.alphaBits == 0) &&
(dxgiFormatInfo.alphaBits > 0);
(nativeFormat.alphaBits > 0);
// We only currently support masking off the alpha channel.
bool colorMaskingNeeded = colorMask.alpha;
......@@ -3966,7 +3965,8 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
drawRect.x < 0 || drawRect.x + drawRect.width > drawSize.width ||
drawRect.y < 0 || drawRect.y + drawRect.height > drawSize.height;
bool partialDSBlit = (dxgiFormatInfo.depthBits > 0 && depthBlit) != (dxgiFormatInfo.stencilBits > 0 && stencilBlit);
bool partialDSBlit =
(nativeFormat.depthBits > 0 && depthBlit) != (nativeFormat.stencilBits > 0 && stencilBlit);
if (readRenderTarget11->getFormatSet().format.id ==
drawRenderTarget11->getFormatSet().format.id &&
......
......@@ -217,7 +217,7 @@ gl::Error TextureStorage11::getSRV(const gl::TextureState &textureState,
// 1. the drop stencil workaround is enabled.
bool workaround = mRenderer->getWorkarounds().emulateTinyStencilTextures;
// 2. this is a stencil texture.
bool hasStencil = (d3d11::GetDXGIFormatInfo(mFormatInfo.dsvFormat).stencilBits > 0);
bool hasStencil = (mFormatInfo.format.stencilBits > 0);
// 3. the texture has a 1x1 or 2x2 mip.
bool hasSmallMips = (getLevelWidth(mMipLevels - 1) <= 2 || getLevelHeight(mMipLevels - 1) <= 2);
......@@ -249,8 +249,7 @@ gl::Error TextureStorage11::getCachedOrCreateSRV(const SRVKey &key,
if (key.swizzle)
{
ASSERT(!key.dropStencil ||
d3d11::GetDXGIFormatInfo(mFormatInfo.swizzle.dsvFormat).stencilBits == 0);
ASSERT(!key.dropStencil || mFormatInfo.swizzle.format.stencilBits == 0);
ANGLE_TRY(getSwizzleTexture(&texture));
format = mFormatInfo.swizzle.srvFormat;
}
......
......@@ -31,15 +31,6 @@ struct DXGIFormat
{
DXGIFormat();
GLuint redBits;
GLuint greenBits;
GLuint blueBits;
GLuint alphaBits;
GLuint sharedBits;
GLuint depthBits;
GLuint stencilBits;
GLenum componentType;
NativeMipmapGenerationSupportFunction nativeMipmapSupport;
......
......@@ -67,7 +67,7 @@ const Format &Format::Get(ID id)
}}
// clang-format on
static const Format noneInfo(ID::NONE, GL_NONE, GL_NONE, nullptr, nullptr);
static const Format noneInfo(ID::NONE, GL_NONE, GL_NONE, nullptr, nullptr, 0, 0, 0, 0, 0, 0);
return noneInfo;
}}
......@@ -128,7 +128,8 @@ format_entry_template = """{space}{{
{space} {glInternalFormat},
{space} {fboImplementationInternalFormat},
{space} {mipGenerationFunction},
{space} {colorReadFunction});
{space} {colorReadFunction},
{space} {R}, {G}, {B}, {A}, {D}, {S});
{space} return info;
{space}}}
"""
......@@ -205,6 +206,12 @@ def json_to_table_data(format_id, json, angle_to_gl):
parsed["mipGenerationFunction"] = get_mip_generation_function(parsed)
parsed["colorReadFunction"] = get_color_read_function(parsed)
for channel in "ABDGLRS":
if parsed["bits"] != None and channel in parsed["bits"]:
parsed[channel] = parsed["bits"][channel]
else:
parsed[channel] = "0"
return format_entry_template.format(**parsed)
def parse_json_into_angle_format_switch_string(all_angle, json_data, angle_to_gl):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment