Bug 1285676 - Use actual bit depths for depth and stencil. - r=ethlin

MozReview-Commit-ID: FX3Ev3noJ6U
This commit is contained in:
Jeff Gilbert committed 2016-07-11 13:10:18 -07:00
1 parent 527a52767e
commit 107386595e
7 files changed
+101 -82

No files matched your search

+5 -5
View File
@@ -2105,19 +2105,19 @@ ZeroTexImageWithClear(WebGLContext* webgl, GLContext* gl, TexImageTarget target,
GLenum attachPoint = 0;
GLbitfield clearBits = 0;
if (format->isColorFormat) {
if (format->IsColorFormat()) {
attachPoint = LOCAL_GL_COLOR_ATTACHMENT0;
clearBits = LOCAL_GL_COLOR_BUFFER_BIT;
}
if (format->hasDepth) {
if (format->d) {
attachPoint = LOCAL_GL_DEPTH_ATTACHMENT;
clearBits |= LOCAL_GL_DEPTH_BUFFER_BIT;
}
if (format->hasStencil) {
attachPoint = (format->hasDepth ? LOCAL_GL_DEPTH_STENCIL_ATTACHMENT
: LOCAL_GL_STENCIL_ATTACHMENT);
if (format->s) {
attachPoint = (format->d ? LOCAL_GL_DEPTH_STENCIL_ATTACHMENT
: LOCAL_GL_STENCIL_ATTACHMENT);
clearBits |= LOCAL_GL_STENCIL_BUFFER_BIT;
}
+61 -51
View File
@@ -129,57 +129,67 @@ AddFormatInfo(EffectiveFormat format, const char* name, GLenum sizedFormat,
uint8_t d, uint8_t s, UnsizedFormat unsizedFormat, bool isSRGB,
ComponentType componentType)
{
#ifdef DEBUG
uint8_t totalBits = r + g + b + a + d + s;
if (format == EffectiveFormat::RGB9_E5) {
totalBits = 9 + 9 + 9 + 5;
}
MOZ_ASSERT(totalBits == bytesPerPixel*8);
#endif
bool isColorFormat = false;
bool hasAlpha = false;
bool hasDepth = false;
bool hasStencil = false;
switch (unsizedFormat) {
case UnsizedFormat::L:
case UnsizedFormat::R:
MOZ_ASSERT(r && !g && !b && !a && !d && !s);
break;
case UnsizedFormat::RG:
MOZ_ASSERT(r && g && !b && !a && !d && !s);
break;
case UnsizedFormat::RGB:
isColorFormat = true;
MOZ_ASSERT(r && g && b && !a && !d && !s);
break;
case UnsizedFormat::A: // Alpha is a 'color format' since it's 'color-attachable'.
case UnsizedFormat::LA:
case UnsizedFormat::RGBA:
isColorFormat = true;
hasAlpha = true;
MOZ_ASSERT(r && g && b && a && !d && !s);
break;
case UnsizedFormat::L:
MOZ_ASSERT(r && !g && !b && !a && !d && !s);
break;
case UnsizedFormat::A:
MOZ_ASSERT(!r && !g && !b && a && !d && !s);
break;
case UnsizedFormat::LA:
MOZ_ASSERT(r && !g && !b && a && !d && !s);
break;
case UnsizedFormat::D:
hasDepth = true;
MOZ_ASSERT(!r && !g && !b && !a && d && !s);
break;
case UnsizedFormat::S:
hasStencil = true;
MOZ_ASSERT(!r && !g && !b && !a && !d && s);
break;
case UnsizedFormat::DS:
hasDepth = true;
hasStencil = true;
MOZ_ASSERT(!r && !g && !b && !a && d && s);
break;
default:
MOZ_CRASH("GFX: Missing UnsizedFormat case.");
}
const CompressedFormatInfo* compressedFormatInfo = GetCompressedFormatInfo(format);
MOZ_ASSERT(!bytesPerPixel == bool(compressedFormatInfo));
#ifdef DEBUG
uint8_t totalBits = r + g + b + a + d + s;
if (format == EffectiveFormat::RGB9_E5) {
totalBits = 9 + 9 + 9 + 5;
}
if (compressedFormatInfo) {
MOZ_ASSERT(totalBits);
MOZ_ASSERT(!bytesPerPixel);
} else {
MOZ_ASSERT(totalBits == bytesPerPixel*8);
}
#endif
const FormatInfo info = { format, name, sizedFormat, unsizedFormat, componentType,
bytesPerPixel, r,g,b,a, isColorFormat, isSRGB, hasAlpha,
hasDepth, hasStencil, compressedFormatInfo };
isSRGB, compressedFormatInfo, bytesPerPixel, r,g,b,a,d,s };
AlwaysInsert(gFormatInfoMap, format, info);
}
@@ -258,36 +268,36 @@ InitFormatInfo()
// GLES 3.0.4, p147, table 3.19
// GLES 3.0.4 p286+ $C.1 "ETC Compressed Texture Image Formats"
AddFormatInfo(FOO(COMPRESSED_RGB8_ETC2 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_SRGB8_ETC2 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , true , ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA8_ETC2_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_SRGB8_ALPHA8_ETC2_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_R11_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::R , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RG11_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::RG , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_SIGNED_R11_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::R , false, ComponentType::NormInt );
AddFormatInfo(FOO(COMPRESSED_SIGNED_RG11_EAC ), 0, 0,0,0,0, 0,0, UnsizedFormat::RG , false, ComponentType::NormInt );
AddFormatInfo(FOO(COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGB8_ETC2 ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_SRGB8_ETC2 ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , true , ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA8_ETC2_EAC ), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_SRGB8_ALPHA8_ETC2_EAC ), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_R11_EAC ), 0, 1,0,0,0, 0,0, UnsizedFormat::R , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RG11_EAC ), 0, 1,1,0,0, 0,0, UnsizedFormat::RG , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_SIGNED_R11_EAC ), 0, 1,0,0,0, 0,0, UnsizedFormat::R , false, ComponentType::NormInt );
AddFormatInfo(FOO(COMPRESSED_SIGNED_RG11_EAC ), 0, 1,1,0,0, 0,0, UnsizedFormat::RG , false, ComponentType::NormInt );
AddFormatInfo(FOO(COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 ), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, true , ComponentType::NormUInt);
// AMD_compressed_ATC_texture
AddFormatInfo(FOO(ATC_RGB_AMD ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(ATC_RGBA_EXPLICIT_ALPHA_AMD ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(ATC_RGBA_INTERPOLATED_ALPHA_AMD), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(ATC_RGB_AMD ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(ATC_RGBA_EXPLICIT_ALPHA_AMD ), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(ATC_RGBA_INTERPOLATED_ALPHA_AMD), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
// EXT_texture_compression_s3tc
AddFormatInfo(FOO(COMPRESSED_RGB_S3TC_DXT1_EXT ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT1_EXT), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT3_EXT), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT5_EXT), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGB_S3TC_DXT1_EXT ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT1_EXT), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT3_EXT), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_S3TC_DXT5_EXT), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
// IMG_texture_compression_pvrtc
AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_4BPPV1 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_4BPPV1), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_2BPPV1 ), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_2BPPV1), 0, 0,0,0,0, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_4BPPV1 ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_4BPPV1), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGB_PVRTC_2BPPV1 ), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB , false, ComponentType::NormUInt);
AddFormatInfo(FOO(COMPRESSED_RGBA_PVRTC_2BPPV1), 0, 1,1,1,1, 0,0, UnsizedFormat::RGBA, false, ComponentType::NormUInt);
// OES_compressed_ETC1_RGB8_texture
AddFormatInfo(FOO(ETC1_RGB8_OES), 0, 0,0,0,0, 0,0, UnsizedFormat::RGB, false, ComponentType::NormUInt);
AddFormatInfo(FOO(ETC1_RGB8_OES), 0, 1,1,1,0, 0,0, UnsizedFormat::RGB, false, ComponentType::NormUInt);
#undef FOO
@@ -639,7 +649,7 @@ FormatUsageInfo::SetRenderable()
#ifdef DEBUG
const auto format = this->format;
if (format->isColorFormat) {
if (format->IsColorFormat()) {
const auto& map = format->copyDecayFormats;
const auto itr = map.find(format->unsizedFormat);
MOZ_ASSERT(itr != map.end(), "Renderable formats must be in copyDecayFormats.");
+16 -7
View File
@@ -198,22 +198,31 @@ struct FormatInfo
const GLenum sizedFormat;
const UnsizedFormat unsizedFormat;
const ComponentType componentType;
const uint8_t estimatedBytesPerPixel; // 0 iff `!!compression`. Only use this for
const bool isSRGB;
const CompressedFormatInfo* const compression;
const uint8_t estimatedBytesPerPixel; // 0 iff bool(compression).
// In bits. Iff bool(compression), active channels are 1.
const uint8_t r;
const uint8_t g;
const uint8_t b;
const uint8_t a;
const bool isColorFormat; // memory usage estimation. Use
const bool isSRGB; // BytesPerPixel(packingFormat, packingType) for
const bool hasAlpha; // calculating pack/unpack byte count.
const bool hasDepth;
const bool hasStencil;
const uint8_t d;
const uint8_t s;
const CompressedFormatInfo* const compression;
//////
std::map<UnsizedFormat, const FormatInfo*> copyDecayFormats;
const FormatInfo* GetCopyDecayFormat(UnsizedFormat) const;
bool IsColorFormat() const {
// Alpha is a 'color format' since it's 'color-attachable'.
return bool(compression) ||
bool(r | g | b | a);
}
};
struct PackingInfo
+8 -8
View File
@@ -83,7 +83,7 @@ WebGLFBAttachPoint::Samples() const
bool
WebGLFBAttachPoint::HasAlpha() const
{
return Format()->format->hasAlpha;
return Format()->format->a;
}
const webgl::FormatUsageInfo*
@@ -102,7 +102,7 @@ WebGLFBAttachPoint::IsReadableFloat() const
MOZ_ASSERT(formatUsage);
auto format = formatUsage->format;
if (!format->isColorFormat)
if (!format->IsColorFormat())
return false;
return format->componentType == webgl::ComponentType::Float;
@@ -294,21 +294,21 @@ WebGLFBAttachPoint::IsComplete(WebGLContext* webgl, nsCString* const out_info) c
switch (mAttachmentPoint) {
case LOCAL_GL_DEPTH_ATTACHMENT:
hasRequiredBits = format->hasDepth;
hasRequiredBits = format->d;
break;
case LOCAL_GL_STENCIL_ATTACHMENT:
hasRequiredBits = format->hasStencil;
hasRequiredBits = format->s;
break;
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
MOZ_ASSERT(!webgl->IsWebGL2());
hasRequiredBits = (format->hasDepth && format->hasStencil);
hasRequiredBits = (format->d && format->s);
break;
default:
MOZ_ASSERT(mAttachmentPoint >= LOCAL_GL_COLOR_ATTACHMENT0);
hasRequiredBits = format->isColorFormat;
hasRequiredBits = format->IsColorFormat();
break;
}
@@ -323,11 +323,11 @@ WebGLFBAttachPoint::IsComplete(WebGLContext* webgl, nsCString* const out_info) c
switch (mAttachmentPoint) {
case LOCAL_GL_DEPTH_ATTACHMENT:
hasSurplusPlanes = format->hasStencil;
hasSurplusPlanes = format->s;
break;
case LOCAL_GL_STENCIL_ATTACHMENT:
hasSurplusPlanes = format->hasDepth;
hasSurplusPlanes = format->d;
break;
}
+1 -1
View File
@@ -258,7 +258,7 @@ WebGLRenderbuffer::GetRenderbufferParameter(RBTarget target,
if (!mFormat)
return 0;
if (!mFormat->format->hasStencil)
if (!mFormat->format->s)
return 0;
return 8;
+6 -6
View File
@@ -343,7 +343,7 @@ WebGLTexture::IsComplete(uint32_t texUnit, const char** const out_reason) const
// NEAREST nor NEAREST_MIPMAP_NEAREST."
// Since all (GLES3) unsized color formats are filterable just like their sized
// equivalents, we don't have to care whether its sized or not.
if (format->isColorFormat && !formatUsage->isFilterable) {
if (format->IsColorFormat() && !formatUsage->isFilterable) {
*out_reason = "Because minification or magnification filtering is not NEAREST"
" or NEAREST_MIPMAP_NEAREST, and the texture's format is a"
" color format, its format must be \"texture-filterable\".";
@@ -363,7 +363,7 @@ WebGLTexture::IsComplete(uint32_t texUnit, const char** const out_reason) const
// a DEPTH_STENCIL_OES texture with a min-filter of LINEAR. Therefore we relax
// this restriction if WEBGL_depth_texture is enabled.
if (!mContext->IsExtensionEnabled(WebGLExtensionID::WEBGL_depth_texture)) {
if (format->hasDepth && mTexCompareMode != LOCAL_GL_NONE) {
if (format->d && mTexCompareMode != LOCAL_GL_NONE) {
*out_reason = "A depth or depth-stencil format with TEXTURE_COMPARE_MODE"
" of NONE must have minification or magnification filtering"
" of NEAREST or NEAREST_MIPMAP_NEAREST.";
@@ -486,9 +486,9 @@ WebGLTexture::GetFakeBlackType(const char* funcName, uint32_t texUnit,
if (!hasInitializedData) {
const auto format = ImageInfoAtFace(0, mBaseMipmapLevel).mFormat->format;
if (format->isColorFormat) {
*out_fakeBlack = (format->hasAlpha ? FakeBlackType::RGBA0000
: FakeBlackType::RGBA0001);
if (format->IsColorFormat()) {
*out_fakeBlack = (format->a ? FakeBlackType::RGBA0000
: FakeBlackType::RGBA0001);
return true;
}
@@ -736,7 +736,7 @@ WebGLTexture::GenerateMipmap(TexTarget texTarget)
return;
}
if (format->hasDepth) {
if (format->d) {
mContext->ErrorInvalidOperation("generateMipmap: Depth textures are not"
" supported.");
return;
+4 -4
View File
@@ -1261,7 +1261,7 @@ WebGLTexture::TexImage(const char* funcName, TexImageTarget target, GLint level,
if (!ValidateTargetForFormat(funcName, mContext, target, dstFormat))
return;
if (!mContext->IsWebGL2() && dstFormat->hasDepth) {
if (!mContext->IsWebGL2() && dstFormat->d) {
if (target != LOCAL_GL_TEXTURE_2D ||
blob->mHasData ||
level != 0)
@@ -1345,7 +1345,7 @@ WebGLTexture::TexSubImage(const char* funcName, TexImageTarget target, GLint lev
return;
}
if (!mContext->IsWebGL2() && dstFormat->hasDepth) {
if (!mContext->IsWebGL2() && dstFormat->d) {
mContext->ErrorInvalidOperation("%s: Function may not be called on a texture of"
" format %s.",
funcName, dstFormat->name);
@@ -1995,7 +1995,7 @@ WebGLTexture::CopyTexImage2D(TexImageTarget target, GLint level, GLenum internal
if (!ValidateTargetForFormat(funcName, mContext, target, dstFormat))
return;
if (!mContext->IsWebGL2() && dstFormat->hasDepth) {
if (!mContext->IsWebGL2() && dstFormat->d) {
mContext->ErrorInvalidOperation("%s: Function may not be called with format %s.",
funcName, dstFormat->name);
return;
@@ -2095,7 +2095,7 @@ WebGLTexture::CopyTexSubImage(const char* funcName, TexImageTarget target, GLint
MOZ_ASSERT(dstUsage);
auto dstFormat = dstUsage->format;
if (!mContext->IsWebGL2() && dstFormat->hasDepth) {
if (!mContext->IsWebGL2() && dstFormat->d) {
mContext->ErrorInvalidOperation("%s: Function may not be called on a texture of"
" format %s.",
funcName, dstFormat->name);