Backed out changeset 0a2985a48339 (bug 1769747) for causing gl failures.

This commit is contained in:
Butkovits Atila 2022-10-05 01:38:13 +03:00
parent dd8f948670
commit 14c4666a5f
12 changed files with 98 additions and 266 deletions

View File

@ -4049,35 +4049,6 @@ void webgl::TexUnpackBlobDesc::Shrink(const webgl::PackingInfo& pi) {
// -
// Because often you need a null-terminated copy for printf.
inline std::string ToString(std::string_view s) { return std::string{s}; }
std::string_view ToString(const layers::SurfaceDescriptor::Type t) {
switch (t) {
#define _(X) \
case layers::SurfaceDescriptor::X: \
return #X;
_(T__None)
_(TSurfaceDescriptorBuffer)
_(TSurfaceDescriptorD3D10)
_(TSurfaceDescriptorDXGIYCbCr)
_(TSurfaceDescriptorDMABuf)
_(TSurfaceTextureDescriptor)
_(TSurfaceDescriptorAndroidHardwareBuffer)
_(TEGLImageDescriptor)
_(TSurfaceDescriptorMacIOSurface)
_(TSurfaceDescriptorSharedGLTexture)
_(TSurfaceDescriptorGPUVideo)
_(TSurfaceDescriptorRecorded)
_(TSurfaceDescriptorRemoteTexture)
_(TSurfaceDescriptorDcompSurface)
_(Tnull_t)
#undef _
}
MOZ_ASSERT_UNREACHABLE();
}
void ClientWebGLContext::TexImage(uint8_t funcDims, GLenum imageTarget,
GLint level, GLenum respecFormat,
const ivec3& offset,
@ -4275,8 +4246,7 @@ void ClientWebGLContext::TexImage(uint8_t funcDims, GLenum imageTarget,
const bool canUploadViaSd = contextInfo.uploadableSdTypes[sdType];
if (!canUploadViaSd) {
const nsPrintfCString msg(
"Fast uploads for resource type %s not implemented.",
ToString(ToString(sdType)).c_str());
"Fast uploads for resource type %i not implemented.", int(sdType));
return Some(ToString(msg));
}

View File

@ -393,8 +393,8 @@ bool TexUnpackBlob::ConvertIfNeeded(
if (srcFormat != dstFormat) {
webgl->GeneratePerfWarning(
"Conversion requires pixel reformatting. (%s->%s)",
ToString(srcFormat).c_str(), ToString(dstFormat).c_str());
"Conversion requires pixel reformatting. (%u->%u)", uint32_t(srcFormat),
uint32_t(dstFormat));
} else if (fnHasPremultMismatch()) {
webgl->GeneratePerfWarning(
"Conversion requires change in"
@ -664,61 +664,48 @@ Maybe<std::string> BlitPreventReason(const int32_t level, const ivec3& offset,
const auto& size = desc.size;
const auto& unpacking = desc.unpacking;
if (size.z != 1) {
return Some(std::string("depth is not 1"));
}
if (offset.x != 0 || offset.y != 0 || offset.z != 0) {
return Some(std::string("x/y/zOffset is not 0"));
}
if (unpacking.skipPixels || unpacking.skipRows || unpacking.skipImages) {
return Some(std::string("non-zero UNPACK_SKIP_* not yet supported"));
}
const auto premultReason = [&]() -> const char* {
if (desc.srcAlphaType == gfxAlphaType::Opaque) return nullptr;
const bool srcIsPremult = (desc.srcAlphaType == gfxAlphaType::Premult);
const auto& dstIsPremult = unpacking.premultiplyAlpha;
if (srcIsPremult == dstIsPremult) return nullptr;
if (dstIsPremult) {
return "UNPACK_PREMULTIPLY_ALPHA_WEBGL is not true";
} else {
return "UNPACK_PREMULTIPLY_ALPHA_WEBGL is not false";
const auto ret = [&]() -> const char* {
if (size.z != 1) {
return "depth is not 1";
}
if (offset.x != 0 || offset.y != 0 || offset.z != 0) {
return "x/y/zOffset is not 0";
}
if (unpacking.skipPixels || unpacking.skipRows || unpacking.skipImages) {
return "non-zero UNPACK_SKIP_* not yet supported";
}
const auto premultReason = [&]() -> const char* {
if (desc.srcAlphaType == gfxAlphaType::Opaque) return nullptr;
const bool srcIsPremult = (desc.srcAlphaType == gfxAlphaType::Premult);
const auto& dstIsPremult = unpacking.premultiplyAlpha;
if (srcIsPremult == dstIsPremult) return nullptr;
if (dstIsPremult) {
return "UNPACK_PREMULTIPLY_ALPHA_WEBGL is not true";
} else {
return "UNPACK_PREMULTIPLY_ALPHA_WEBGL is not false";
}
}();
if (premultReason) return premultReason;
if (pi.format != LOCAL_GL_RGBA) {
return "`format` is not RGBA";
}
if (pi.type != LOCAL_GL_UNSIGNED_BYTE) {
return "`type` is not UNSIGNED_BYTE";
}
return nullptr;
}();
if (premultReason) return Some(std::string(premultReason));
// RGBA8 spec'd as renderable.
// RGB8 we can probably guarantee to be renderable, with an init-time test.
// RG8 (etc) via draw-to-RGBA8 then copyTexSubImage.
switch (pi.format) {
case LOCAL_GL_RGBA:
case LOCAL_GL_RGB:
break;
default:
return Some(std::string("`format` is ") + EnumString(pi.format) +
", not RGB/RGBA");
if (ret) {
return Some(std::string(ret));
}
if (pi.type != LOCAL_GL_UNSIGNED_BYTE) {
// Eventually, we can upload other types, so long as we know that
// (RGBA, type) is renderable.
return Some(std::string("`type` is ") + EnumString(pi.type) +
", not UNSIGNED_BYTE");
}
return {};
}
} // namespace webgl
void CopyTexSubImage(gl::GLContext* gl, TexImageTarget target, GLint level,
GLint xOffset, GLint yOffset, GLint zOffset, GLint x,
GLint y, GLsizei width, GLsizei height);
namespace webgl {
bool TexUnpackImage::TexOrSubImage(bool isSubImage, bool needsRespec,
WebGLTexture* tex, GLint level,
const webgl::DriverUnpackInfo* dui,
@ -760,64 +747,20 @@ bool TexUnpackImage::TexOrSubImage(bool isSubImage, bool needsRespec,
gl::ScopedFramebuffer scopedFB(gl);
gl::ScopedBindFramebuffer bindFB(gl, scopedFB.FB());
MOZ_RELEASE_ASSERT(pi.type == LOCAL_GL_UNSIGNED_BYTE);
{
gl::GLContext::LocalErrorScope errorScope(*gl);
UniquePtr<gl::MozFramebuffer> intermediate;
auto blitDestTarget = target;
auto blitDestTex = tex->mGLName;
auto blitDestLevel = level;
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
LOCAL_GL_COLOR_ATTACHMENT0, target,
tex->mGLName, level);
const auto AttachToFb = [&]() {
switch (blitDestTarget) {
case LOCAL_GL_TEXTURE_2D:
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
gl->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
LOCAL_GL_COLOR_ATTACHMENT0, blitDestTarget,
blitDestTex, blitDestLevel);
break;
case LOCAL_GL_TEXTURE_3D:
case LOCAL_GL_TEXTURE_2D_ARRAY:
gl->fFramebufferTextureLayer(LOCAL_GL_FRAMEBUFFER,
LOCAL_GL_COLOR_ATTACHMENT0, blitDestTex,
blitDestLevel, zOffset);
break;
default:
MOZ_ASSERT_UNREACHABLE("blitDestTarget");
}
const GLenum status = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
if (status != LOCAL_GL_FRAMEBUFFER_COMPLETE) {
MOZ_ASSERT(status == LOCAL_GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
return false;
}
return true;
};
auto fbOk = AttachToFb();
if (!fbOk) {
// If not renderable, create intermediate rgba8.
webgl->GeneratePerfWarning(
"Copying to (%s,%s) requires an intermediate RGBA8 renderable.",
EnumString(pi.format).c_str(), EnumString(pi.type).c_str());
intermediate = gl::MozFramebuffer::Create(gl, {size.x, size.y}, 0, false);
blitDestTarget = LOCAL_GL_TEXTURE_2D;
blitDestTex = intermediate->ColorTex();
blitDestLevel = 0;
fbOk = AttachToFb();
}
MOZ_ASSERT(fbOk);
if (!fbOk) {
webgl->ErrorImplementationBug("Texture upload gpu-copy fastpath failed!");
tex->Truncate();
return false;
const auto err = errorScope.GetError();
MOZ_ALWAYS_TRUE(!err);
}
const GLenum status = gl->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
MOZ_ALWAYS_TRUE(status == LOCAL_GL_FRAMEBUFFER_COMPLETE);
const auto dstOrigin =
(unpacking.flipY ? gl::OriginPos::TopLeft : gl::OriginPos::BottomLeft);
if (!gl->BlitHelper()->BlitSdToFramebuffer(sd, {size.x, size.y},
@ -833,12 +776,6 @@ bool TexUnpackImage::TexOrSubImage(bool isSubImage, bool needsRespec,
"Fast Tex(Sub)Image upload failed without recourse, clearing to "
"[0.2, 0.0, 0.2, 1.0]. Please file a bug!");
}
if (intermediate) {
gl->fBindTexture(target, tex->mGLName);
CopyTexSubImage(gl, target, level, xOffset, yOffset, zOffset, 0, 0,
size.x, size.y);
}
}
return true;

View File

@ -691,9 +691,12 @@ GLenum DoCompressedTexSubImage(gl::GLContext* gl, TexImageTarget target,
return errorScope.GetError();
}
void CopyTexSubImage(gl::GLContext* gl, TexImageTarget target, GLint level,
GLint xOffset, GLint yOffset, GLint zOffset, GLint x,
GLint y, GLsizei width, GLsizei height) {
static inline GLenum DoCopyTexSubImage(gl::GLContext* gl, TexImageTarget target,
GLint level, GLint xOffset,
GLint yOffset, GLint zOffset, GLint x,
GLint y, GLsizei width, GLsizei height) {
gl::GLContext::LocalErrorScope errorScope(*gl);
if (IsTarget3D(target)) {
gl->fCopyTexSubImage3D(target.get(), level, xOffset, yOffset, zOffset, x, y,
width, height);
@ -702,6 +705,8 @@ void CopyTexSubImage(gl::GLContext* gl, TexImageTarget target, GLint level,
gl->fCopyTexSubImage2D(target.get(), level, xOffset, yOffset, x, y, width,
height);
}
return errorScope.GetError();
}
//////////////////////////////////////////////////////////////////////////////////////////
@ -1786,15 +1791,12 @@ static bool DoCopyTexOrSubImage(WebGLContext* webgl, bool isSubImage,
const auto& srcFormat = srcUsage->format;
ScopedCopyTexImageSource maybeSwizzle(webgl, srcTotalWidth, srcTotalHeight,
srcFormat, dstUsage);
{
auto errorScope = gl::GLContext::LocalErrorScope(*gl);
CopyTexSubImage(gl, target, level, writeX, writeY, zOffset, readX, readY,
rwWidth, rwHeight);
error = errorScope.GetError();
}
error = DoCopyTexSubImage(gl, target, level, writeX, writeY, zOffset, readX,
readY, rwWidth, rwHeight);
if (error) {
errorText = nsPrintfCString(
"CopyTexSubImage(0x%04x, %i, %i,%i,%i, %i,%i, %u,%u) -> 0x%04x",
"DoCopyTexSubImage(0x%04x, %i, %i,%i,%i, %i,%i, %u,%u) -> 0x%04x",
target.get(), level, writeX, writeY, zOffset, readX, readY, rwWidth,
rwHeight, error);
break;

View File

@ -1,54 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGLTypes.h"
// -
namespace mozilla {
std::string ToString(const WebGLTexelFormat format) {
switch (format) {
#define _(X) case WebGLTexelFormat::X: return #X;
_(None)
_(FormatNotSupportingAnyConversion)
_(Auto)
// 1-channel formats
_(A8)
_(A16F)
_(A32F)
_(R8)
_(R16F)
_(R32F)
// 2-channel formats
_(RA8)
_(RA16F)
_(RA32F)
_(RG8)
_(RG16F)
_(RG32F)
// 3-channel formats
_(RGB8)
_(RGB565)
_(RGB11F11F10F)
_(RGB16F)
_(RGB32F)
// 4-channel formats
_(RGBA8)
_(RGBA5551)
_(RGBA4444)
_(RGBA16F)
_(RGBA32F)
// DOM element source only formats.
_(RGBX8)
_(BGRX8)
_(BGRA8)
#undef _
}
MOZ_ASSERT_UNREACHABLE();
}
} // namespace mozilla

View File

@ -209,8 +209,6 @@ enum class WebGLTexelFormat : uint8_t {
BGRA8
};
std::string ToString(WebGLTexelFormat);
enum class WebGLTexImageFunc : uint8_t {
TexImage,
TexSubImage,

View File

@ -159,7 +159,6 @@ UNIFIED_SOURCES += [
"WebGLTexture.cpp",
"WebGLTextureUpload.cpp",
"WebGLTransformFeedback.cpp",
"WebGLTypes.cpp",
"WebGLValidateStrings.cpp",
"WebGLVertexArray.cpp",
"WebGLVertexArrayFake.cpp",

View File

@ -488,7 +488,7 @@ DrawBlitProg::~DrawBlitProg() {
gl->fDeleteProgram(mProg);
}
bool DrawBlitProg::Draw(const BaseArgs& args,
void DrawBlitProg::Draw(const BaseArgs& args,
const YUVArgs* const argsYUV) const {
const auto& gl = mParent.mGL;
@ -546,7 +546,6 @@ bool DrawBlitProg::Draw(const BaseArgs& args,
default:
gfxCriticalError()
<< "Bad mType_uColorMatrix: " << gfx::hexa(mType_uColorMatrix);
return false;
}
}
}
@ -582,41 +581,22 @@ bool DrawBlitProg::Draw(const BaseArgs& args,
gl->fVertexAttribPointer(0, 2, LOCAL_GL_FLOAT, false, 0, 0);
}
const auto restore = MakeScopeExit([&]() {
if (mParent.mQuadVAO) {
gl->fBindVertexArray(oldVAO);
gl->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
if (mParent.mQuadVAO) {
gl->fBindVertexArray(oldVAO);
} else {
if (vaa0Enabled) {
gl->fEnableVertexAttribArray(0);
} else {
if (vaa0Enabled) {
gl->fEnableVertexAttribArray(0);
} else {
gl->fDisableVertexAttribArray(0);
}
// The current VERTEX_ARRAY_BINDING is not necessarily the same as the
// buffer set for vaa0Buffer.
const ScopedBindArrayBuffer bindVBO(gl, vaa0Buffer);
gl->fVertexAttribPointer(0, vaa0Size, vaa0Type, bool(vaa0Normalized),
vaa0Stride, vaa0Pointer);
}
});
{
auto errorScope = GLContext::LocalErrorScope(*gl);
gl->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
const auto err = errorScope.GetError();
if (err) {
MOZ_ASSERT(err ==
LOCAL_GL_INVALID_OPERATION); // ANGLE does this if we hand it
// an invalid share handle.
gfxCriticalNote << "glDrawArrays generated "
<< GLContext::GLErrorToString(err)
<< " in DrawBlitProg::Draw.";
return false;
gl->fDisableVertexAttribArray(0);
}
// The current VERTEX_ARRAY_BINDING is not necessarily the same as the
// buffer set for vaa0Buffer.
const ScopedBindArrayBuffer bindVBO(gl, vaa0Buffer);
gl->fVertexAttribPointer(0, vaa0Size, vaa0Type, bool(vaa0Normalized),
vaa0Stride, vaa0Pointer);
}
return true;
}
// --
@ -1000,11 +980,6 @@ bool GLBlitHelper::Blit(const java::GeckoSurfaceTexture::Ref& surfaceTexture,
const ScopedBindTexture savedTex(mGL, surfaceTexture->GetTexName(),
LOCAL_GL_TEXTURE_EXTERNAL);
surfaceTexture->UpdateTexImage();
const auto scopedRelease = MakeScopeExit([&]() {
if (surfaceTexture->IsSingleBuffer()) {
surfaceTexture->ReleaseTexImage();
}
});
const auto transform3 = Mat3::I();
const auto srcOrigin = OriginPos::TopLeft;
const bool yFlip = (srcOrigin != destOrigin);
@ -1012,7 +987,13 @@ bool GLBlitHelper::Blit(const java::GeckoSurfaceTexture::Ref& surfaceTexture,
{kFragHeader_TexExt, {kFragSample_OnePlane, kFragConvert_None}});
const DrawBlitProg::BaseArgs baseArgs = {transform3, yFlip, destSize,
Nothing()};
return prog->Draw(baseArgs, nullptr);
prog->Draw(baseArgs, nullptr);
if (surfaceTexture->IsSingleBuffer()) {
surfaceTexture->ReleaseTexImage();
}
return true;
}
#endif
@ -1148,7 +1129,8 @@ bool GLBlitHelper::BlitPlanarYCbCr(const PlanarYCbCrData& yuvData,
yFlip, destSize, Nothing()};
const DrawBlitProg::YUVArgs yuvArgs = {
SubRectMat3(clipRect, uvTexSize, divisors), Some(yuvData.mYUVColorSpace)};
return prog->Draw(baseArgs, &yuvArgs);
prog->Draw(baseArgs, &yuvArgs);
return true;
}
// -------------------------------------
@ -1293,7 +1275,8 @@ bool GLBlitHelper::BlitImage(MacIOSurface* const iosurf,
kFragHeader_Tex2DRect,
{fragSample, kFragConvert_ColorMatrix},
});
return prog->Draw(baseArgs, pYuvArgs);
prog->Draw(baseArgs, pYuvArgs);
return true;
}
#endif
@ -1332,7 +1315,7 @@ void GLBlitHelper::DrawBlitTextureToFramebuffer(const GLuint srcTex,
const bool yFlip = false;
const DrawBlitProg::BaseArgs baseArgs = {texMatrix0, yFlip, destSize,
Nothing()};
(void)prog->Draw(baseArgs);
prog->Draw(baseArgs);
}
// -----------------------------------------------------------------------------
@ -1532,7 +1515,9 @@ bool GLBlitHelper::Blit(DMABufSurface* surface, const gfx::IntSize& destSize,
const auto& prog =
GetDrawBlitProg({kFragHeader_Tex2D, {fragSample, fragConvert}});
return prog->Draw(baseArgs, pYuvArgs);
prog->Draw(baseArgs, pYuvArgs);
return true;
}
bool GLBlitHelper::BlitImage(layers::DMABUFSurfaceImage* srcImage,

View File

@ -161,8 +161,7 @@ class DrawBlitProg final {
Maybe<gfx::YUVColorSpace> colorSpaceForMatrix;
};
[[nodiscard]] bool Draw(const BaseArgs& args,
const YUVArgs* argsYUV = nullptr) const;
void Draw(const BaseArgs& args, const YUVArgs* argsYUV = nullptr) const;
};
class ScopedSaveMultiTex final {

View File

@ -263,8 +263,7 @@ bool GLBlitHelper::BlitDescriptor(const layers::SurfaceDescriptorD3D10& desc,
tex = OpenSharedTexture(d3d, handle);
}
if (!tex) {
gfxCriticalNote
<< "Failed to open ID3D11Texture2D in GLBlitHelper::BlitDescriptor.";
MOZ_GL_ASSERT(mGL, false); // Get a nullptr from OpenSharedResource.
return false;
}
const RefPtr<ID3D11Texture2D> texList[2] = {tex, tex};
@ -320,7 +319,8 @@ bool GLBlitHelper::BlitDescriptor(const layers::SurfaceDescriptorD3D10& desc,
const auto& prog = GetDrawBlitProg(
{kFragHeader_TexExt, {kFragSample_TwoPlane, kFragConvert_ColorMatrix}});
return prog->Draw(baseArgs, &yuvArgs);
prog->Draw(baseArgs, &yuvArgs);
return true;
}
bool GLBlitHelper::BlitDescriptor(
@ -370,7 +370,8 @@ bool GLBlitHelper::BlitAngleYCbCr(const WindowsHandle (&handleList)[3],
const auto& prog = GetDrawBlitProg(
{kFragHeader_TexExt, {kFragSample_ThreePlane, kFragConvert_ColorMatrix}});
return prog->Draw(baseArgs, &yuvArgs);
prog->Draw(baseArgs, &yuvArgs);
return true;
}
} // namespace gl

View File

@ -580,10 +580,6 @@ class GLContext : public GenericAtomicRefCounted, public SupportsWeakPtr {
mOldTop = mGL.GetError();
}
private:
LocalErrorScope(const LocalErrorScope&) = default;
public:
/// Never returns CONTEXT_LOST.
GLenum GetError() {
MOZ_ASSERT(!mHasBeenChecked);

View File

@ -56,8 +56,7 @@ class MozFramebuffer final {
const GLuint mColorName;
public:
// Create a new RGBA8 framebuffer with the specified properties.
// samples:0 for texture, samples:1 is subtly-different 1xMSAA.
// Create a new framebuffer with the specified properties.
static UniquePtr<MozFramebuffer> Create(GLContext* gl,
const gfx::IntSize& size,
uint32_t samples, bool depthStencil);

View File

@ -1949,7 +1949,7 @@ Maybe<HANDLE> GpuProcessD3D11TextureMap::GetSharedHandleOfCopiedTexture(
auto it = textures->find(aTextureId);
if (it == textures->end()) {
gfxCriticalNoteOnce << "Didn't find id in mD3D11TexturesById.";
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
return Nothing();
}