mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-12-03 22:52:15 +09:00
[Feat, Test] (CMakeLists.txt, MobileGL, MG_Backend, MG_Impl, MG_Util, MG_Test, MG_IntegrationTest): advertise GL_ARB_texture_buffer_range (#23)
- Gate DirectGLES on a POST probe that checks glTexBufferRange honors its offset against a whole-buffer control - List a driver that ignores the offset under Known Driver Bugs - Detaching with buffer zero ignores the range and resets it to zero
This commit is contained in:
1 parent
45e343a71f
commit
dab4273129
15 files changed
+738
-31
No files matched your search
@@ -455,6 +455,7 @@ set(SOURCE_FILES
|
||||
MobileGL/MG_Util/SelfTest/DriverPostClipDistance.cpp
|
||||
MobileGL/MG_Util/SelfTest/DriverPostIterationRPWitness.cpp
|
||||
MobileGL/MG_Util/SelfTest/PrimitivesGeneratedNoXfbProbe.cpp
|
||||
MobileGL/MG_Util/SelfTest/TextureBufferRangeProbe.cpp
|
||||
|
||||
MobileGL/MG_Util/Texture/PixelStoreProcessor.cpp
|
||||
MobileGL/MG_Util/Texture/TextureFormatProcessor.cpp
|
||||
|
||||
@@ -108,6 +108,10 @@ namespace MobileGL {
|
||||
// both where the device was created with the multiview feature.
|
||||
Bool Multiview = false;
|
||||
Bool Multiview2 = false;
|
||||
// glTexBufferRange reaches the device with its offset and size. DirectGLES: buffer
|
||||
// textures, a range entry point, and the POST probe saw the offset honored.
|
||||
// DirectVulkan builds every buffer view from the bound range and does not read this.
|
||||
Bool TextureBufferRange = false;
|
||||
};
|
||||
|
||||
// Coarse GPU vendor identity for gating device-specific quirks. Detected from the
|
||||
|
||||
@@ -913,7 +913,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
.CullDistance = capabilities.MaxCullDistances > 0,
|
||||
.ClipControl = capabilities.SupportsClipControl,
|
||||
.Multiview = capabilities.SupportsMultiview,
|
||||
.Multiview2 = capabilities.SupportsMultiview2});
|
||||
.Multiview2 = capabilities.SupportsMultiview2,
|
||||
.TextureBufferRange = IsBufferTextureRangeSupported()});
|
||||
// Exactly what InitCapabilities forwards into the dynamic parameters: the base
|
||||
// extension and _primitive when the driver has them, _attachment not yet.
|
||||
auto& extensions = MutableRendererInfo().RendererGLInfo.Extensions;
|
||||
@@ -1665,6 +1666,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
extensions.push_back(E_GL_OVR_multiview2);
|
||||
}
|
||||
}
|
||||
// glTexBufferRange is core from 4.3, but LOD mods gate on the string. It follows the
|
||||
// driver: a range entry point, and a range view the POST probe saw start at its offset.
|
||||
if (features.TextureBufferRange) {
|
||||
extensions.push_back(E_GL_ARB_texture_buffer_range);
|
||||
}
|
||||
// Minecraft 26.3 checks this prerequisite before it even considers
|
||||
// GL_ARB_multi_draw_indirect. ES 3.1 supplies both single-draw entry points; the loader
|
||||
// folds the version and pointer checks into SupportsDrawIndirect.
|
||||
|
||||
@@ -182,6 +182,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// null entry point. False also means every shader declaring a samplerBuffer is
|
||||
// uncompilable on this driver, which the program build reports by name.
|
||||
Bool AreBufferTexturesSupported();
|
||||
// AreBufferTexturesSupported(), a glTexBufferRange spelling to call, and a driver whose range
|
||||
// view starts at its offset (SelfTest::ProbeTextureBufferRange).
|
||||
Bool IsBufferTextureRangeSupported();
|
||||
// Human-readable name of the buffer-texture tier for diagnostics and the driver POST:
|
||||
// "core (ES 3.2)", "GL_EXT_texture_buffer", "GL_OES_texture_buffer" or "unsupported".
|
||||
const char* GetBufferTextureTierName();
|
||||
|
||||
@@ -160,35 +160,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
|
||||
namespace {
|
||||
// The entry point the resolved tier's support ships, or null when there is none.
|
||||
MG_External::GLES::glTexBuffer_PTR ResolveTexBufferEntryPoint() {
|
||||
using Tier = MG_External::GLESCapabilities::TextureBufferTier;
|
||||
switch (g_GLESCapabilities.TextureBufferSupport) {
|
||||
case Tier::ExtensionEXT:
|
||||
return g_GLESFuncs.glTexBufferEXT ? g_GLESFuncs.glTexBufferEXT : g_GLESFuncs.glTexBuffer;
|
||||
case Tier::ExtensionOES:
|
||||
return g_GLESFuncs.glTexBufferOES ? g_GLESFuncs.glTexBufferOES : g_GLESFuncs.glTexBuffer;
|
||||
case Tier::CoreEs32:
|
||||
return g_GLESFuncs.glTexBuffer;
|
||||
case Tier::None:
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return MG_Util::BackendLoader::SelectTexBufferEntryPoint(g_GLESCapabilities, g_GLESFuncs);
|
||||
}
|
||||
|
||||
MG_External::GLES::glTexBufferRange_PTR ResolveTexBufferRangeEntryPoint() {
|
||||
using Tier = MG_External::GLESCapabilities::TextureBufferTier;
|
||||
switch (g_GLESCapabilities.TextureBufferSupport) {
|
||||
case Tier::ExtensionEXT:
|
||||
return g_GLESFuncs.glTexBufferRangeEXT ? g_GLESFuncs.glTexBufferRangeEXT : g_GLESFuncs.glTexBufferRange;
|
||||
case Tier::ExtensionOES:
|
||||
return g_GLESFuncs.glTexBufferRangeOES ? g_GLESFuncs.glTexBufferRangeOES : g_GLESFuncs.glTexBufferRange;
|
||||
case Tier::CoreEs32:
|
||||
return g_GLESFuncs.glTexBufferRange;
|
||||
case Tier::None:
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
return MG_Util::BackendLoader::SelectTexBufferRangeEntryPoint(g_GLESCapabilities, g_GLESFuncs);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -201,6 +178,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
ResolveTexBufferEntryPoint() != nullptr;
|
||||
}
|
||||
|
||||
Bool IsBufferTextureRangeSupported() {
|
||||
return AreBufferTexturesSupported() && ResolveTexBufferRangeEntryPoint() != nullptr &&
|
||||
g_GLESCapabilities.TextureBufferRangeSupport ==
|
||||
MG_External::GLESCapabilities::TextureBufferRangeVerdict::Honored;
|
||||
}
|
||||
|
||||
void CallTexBuffer(GLenum target, GLenum internalFormat, GLuint buffer) {
|
||||
MG_External::GLES::glTexBuffer_PTR entryPoint = ResolveTexBufferEntryPoint();
|
||||
if (entryPoint == nullptr) {
|
||||
|
||||
@@ -814,6 +814,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Sampling the stencil aspect through DEPTH_STENCIL_TEXTURE_MODE. Core from 4.3,
|
||||
// so on a 4.0 context the string is the only way to reach it.
|
||||
E_GL_ARB_stencil_texturing,
|
||||
// glTexBufferRange: every texel-buffer view is built over the bound offset and size.
|
||||
E_GL_ARB_texture_buffer_range,
|
||||
// Unconditional, unlike DirectGLES: a GL texture view is a second set of VkImageViews
|
||||
// over the same VkImage with a sub-range and possibly a reinterpreted VkFormat, which
|
||||
// is core Vulkan on every device MobileGL runs on. Format-reinterpreting views need
|
||||
|
||||
@@ -2589,7 +2589,8 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
"The effective target of `texture` is not `GL_TEXTURE_BUFFER`."));
|
||||
return;
|
||||
}
|
||||
if (size != TextureObjectBuffer::kWholeBuffer) {
|
||||
// GL 4.6 core 8.9: buffer zero detaches, ignores offset and size, and resets both to zero.
|
||||
if (buffer != 0 && size != TextureObjectBuffer::kWholeBuffer) {
|
||||
// GL 4.6 core 8.9: offset must be non-negative and aligned to
|
||||
// GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, and size must be positive.
|
||||
if (offset < 0) {
|
||||
@@ -2613,9 +2614,8 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
"offset is not a multiple of GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT."));
|
||||
return;
|
||||
}
|
||||
// The range has to lie inside the buffer that is being attached. Detaching (buffer
|
||||
// zero) carries no range to check.
|
||||
if (bufferObject && static_cast<SizeT>(offset) + size > bufferObject->GetSize()) {
|
||||
// The range has to lie inside the buffer that is being attached.
|
||||
if (static_cast<SizeT>(offset) + size > bufferObject->GetSize()) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidValue,
|
||||
MakeUnique<GenericErrorInfo>("MG_Impl/GLImpl", caller,
|
||||
@@ -2626,7 +2626,10 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
|
||||
auto* texBufferObject = static_cast<TextureObjectBuffer*>(textureObject.get());
|
||||
texBufferObject->GetBufferBindingSlot().Bind(bufferObject);
|
||||
texBufferObject->SetBufferRange(static_cast<SizeT>(offset < 0 ? 0 : offset), size);
|
||||
if (buffer == 0)
|
||||
texBufferObject->SetBufferRange(0, TextureObjectBuffer::kWholeBuffer);
|
||||
else
|
||||
texBufferObject->SetBufferRange(static_cast<SizeT>(offset), size);
|
||||
texBufferObject->SetInternalFormat(textureInternalFormat);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
// branch on. The driver POST's "Buffer textures" row is where that verdict is stated.
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -223,6 +224,75 @@ void main() {
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
}
|
||||
|
||||
// glTexBufferRange is core from GL 4.3, so a range view has to start at its offset whether or
|
||||
// not GL_ARB_texture_buffer_range is in the list. DirectGLES advertises the extension only when
|
||||
// SelfTest::ProbeTextureBufferRange saw the driver honor the offset; this scenario checks the
|
||||
// read itself and prints which way the advertisement went.
|
||||
TEST_F(BufferTextureScenario, ARangeViewReadsFromItsOffset) {
|
||||
if (!Ready()) return;
|
||||
HeadlessGL& gl = Gl();
|
||||
FirstGLError();
|
||||
|
||||
GLint extensionCount = 0;
|
||||
glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount);
|
||||
bool advertised = false;
|
||||
for (GLint i = 0; i < extensionCount; ++i) {
|
||||
const auto* name = reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, static_cast<GLuint>(i)));
|
||||
if (name != nullptr && std::strcmp(name, "GL_ARB_texture_buffer_range") == 0) advertised = true;
|
||||
}
|
||||
std::printf("GL_ARB_texture_buffer_range advertised: %s\n", advertised ? "yes" : "no");
|
||||
RecordProperty("ArbTextureBufferRangeAdvertised", advertised ? "yes" : "no");
|
||||
|
||||
GLint alignment = 1;
|
||||
glGetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &alignment);
|
||||
if (alignment < 1) alignment = 1;
|
||||
ASSERT_EQ(FirstGLError(), 0u);
|
||||
|
||||
// One byte per GL_R8I texel: the first texel of the buffer and the first texel of the
|
||||
// range carry different values, so the readback says which one the view started at.
|
||||
constexpr signed char kBufferStart = 11;
|
||||
constexpr signed char kRangeStart = 73;
|
||||
constexpr GLsizeiptr kRangeBytes = 16;
|
||||
std::vector<signed char> texels(static_cast<size_t>(alignment + kRangeBytes), 0);
|
||||
texels[0] = kBufferStart;
|
||||
texels[static_cast<size_t>(alignment)] = kRangeStart;
|
||||
|
||||
std::string error;
|
||||
const unsigned int program = CompileProgram(kVS, kFS, &error);
|
||||
ASSERT_NE(program, 0u) << error;
|
||||
|
||||
GLuint buffer = 0;
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, buffer);
|
||||
glBufferData(GL_TEXTURE_BUFFER, static_cast<GLsizeiptr>(texels.size()), texels.data(), GL_STATIC_DRAW);
|
||||
GLuint texture = 0;
|
||||
glGenTextures(1, &texture);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_BUFFER, texture);
|
||||
glTexBufferRange(GL_TEXTURE_BUFFER, GL_R8I, buffer, alignment, kRangeBytes);
|
||||
ASSERT_EQ(FirstGLError(), 0u) << "glTexBufferRange(GL_R8I) was refused";
|
||||
|
||||
ColorFbo target = MakeColorFbo(64, 64);
|
||||
ASSERT_NE(target.fbo, 0u) << "could not create the render target";
|
||||
BindFbo(target);
|
||||
glUseProgram(program);
|
||||
glUniform1i(glGetUniformLocation(program, "uFaces"), 0);
|
||||
|
||||
EXPECT_EQ(PaintedValue(program, target.width, target.height), static_cast<int>(kRangeStart))
|
||||
<< "a glTexBufferRange view at offset " << alignment << " did not start at its offset ("
|
||||
<< static_cast<int>(kBufferStart) << " means it read from the start of the buffer); "
|
||||
<< "GL_ARB_texture_buffer_range advertised: " << (advertised ? "yes" : "no");
|
||||
|
||||
BindDefaultFramebuffer();
|
||||
DestroyColorFbo(target);
|
||||
glUseProgram(0);
|
||||
glDeleteProgram(program);
|
||||
glDeleteTextures(1, &texture);
|
||||
glDeleteBuffers(1, &buffer);
|
||||
glViewport(0, 0, gl.Width(), gl.Height());
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
}
|
||||
|
||||
// A shader may WRITE a buffer texture too, through an image unit, and the bytes it writes
|
||||
// land in the backend's buffer - not in the frontend's CPU shadow, which is what MapBuffer
|
||||
// and GetBufferSubData hand back. A storage-block write is flagged for exactly this reason
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <MG_Backend/DirectVulkan/BackendObject_DirectVulkan.h>
|
||||
#include <MG_Util/BackendLoaders/OpenGL/Loader.h>
|
||||
#include <MG_Util/SelfTest/DriverBugProbes.h>
|
||||
#include <MG_Util/SelfTest/TextureBufferRangeProbe.h>
|
||||
|
||||
// ProbeIndirectInstanceIdIncludesBaseInstance is driven against a fake GLES driver:
|
||||
// a GLESFunctionsTable populated with captureless lambdas backed by the file-scope
|
||||
@@ -1392,6 +1393,24 @@ TEST(CoreSurfaceAdvertisement, ClipControlFollowsTheBackendsRoute) {
|
||||
MobileGL::E_GL_ARB_clip_control));
|
||||
}
|
||||
|
||||
// DirectGLES advertises ARB_texture_buffer_range only where a driver range entry point carries
|
||||
// the sub-range; DirectVulkan always, since its buffer views are built over the bound range.
|
||||
TEST(CoreSurfaceAdvertisement, TextureBufferRangeFollowsTheBackendsRoute) {
|
||||
const auto contains = [](const MobileGL::Vector<MobileGL::GLExtension>& extensions, MobileGL::GLExtension wanted) {
|
||||
return std::find(extensions.begin(), extensions.end(), wanted) != extensions.end();
|
||||
};
|
||||
EXPECT_FALSE(
|
||||
contains(MobileGL::MG_Backend::DirectGLES::BuildAdvertisedExtensions(false, false, false, false, false, false),
|
||||
MobileGL::E_GL_ARB_texture_buffer_range));
|
||||
const MobileGL::MG_Backend::AdvertisedFeatureSupport range{.TextureBufferRange = true};
|
||||
EXPECT_TRUE(contains(
|
||||
MobileGL::MG_Backend::DirectGLES::BuildAdvertisedExtensions(false, false, false, false, false, false, range),
|
||||
MobileGL::E_GL_ARB_texture_buffer_range));
|
||||
EXPECT_TRUE(
|
||||
contains(MobileGL::MG_Backend::DirectVulkan::BuildAdvertisedExtensions(false, false, false, false, false),
|
||||
MobileGL::E_GL_ARB_texture_buffer_range));
|
||||
}
|
||||
|
||||
// GL_OVR_multiview needs the driver's string and glFramebufferTextureMultiviewOVR, and a
|
||||
// GL_MAX_VIEWS_OVR of at least the spec minimum; GL_OVR_multiview2 only counts on top of it.
|
||||
TEST(MultiviewCapabilities, NeedTheExtensionTheEntryPointAndTwoViews) {
|
||||
@@ -1920,3 +1939,155 @@ TEST(SwapBuffersWithDamageResolution, PrefersExtThenKhrThenAnswersNothing) {
|
||||
EXPECT_EQ(MG_Util::BackendLoader::ResolveSwapBuffersWithDamage(funcs), nullptr);
|
||||
EXPECT_TRUE(g_damageQueries.empty());
|
||||
}
|
||||
|
||||
// ProbeTextureBufferRange against the same fake, extended with buffer-texture views: each
|
||||
// texture remembers the buffer and offset it was attached with, and a read returns the first two
|
||||
// words that view addresses. A driver that drops the offset reads from the start of the buffer.
|
||||
namespace {
|
||||
struct FakeBufferTextureView {
|
||||
GLuint buffer = 0;
|
||||
GLintptr offset = 0;
|
||||
};
|
||||
struct FakeBufferTextureState {
|
||||
bool rangeIgnoresOffset = false;
|
||||
bool rangeRaisesError = false;
|
||||
bool readsZeroes = false;
|
||||
GLuint nextTexture = 1;
|
||||
int aliveTextures = 0;
|
||||
GLuint boundTexture = 0;
|
||||
GLuint textureBindingBeforeProbe = 77;
|
||||
std::map<GLuint, FakeBufferTextureView> views;
|
||||
};
|
||||
FakeBufferTextureState g_tbr;
|
||||
|
||||
MobileGL::MG_External::GLESFunctionsTable MakeBufferTextureFake(bool withRangeEntryPoint) {
|
||||
ResetFakeDriver();
|
||||
g_tbr = FakeBufferTextureState{};
|
||||
auto funcs = MakeFakeGLESFunctions();
|
||||
funcs.glGenTextures = [](GLsizei n, GLuint* textures) {
|
||||
for (GLsizei i = 0; i < n; ++i) {
|
||||
textures[i] = g_tbr.nextTexture++;
|
||||
++g_tbr.aliveTextures;
|
||||
}
|
||||
};
|
||||
funcs.glDeleteTextures = [](GLsizei n, const GLuint* textures) {
|
||||
for (GLsizei i = 0; i < n; ++i) {
|
||||
if (textures[i] != 0) --g_tbr.aliveTextures;
|
||||
}
|
||||
};
|
||||
funcs.glActiveTexture = [](GLenum) {};
|
||||
funcs.glBindTexture = [](GLenum, GLuint texture) { g_tbr.boundTexture = texture; };
|
||||
funcs.glGetIntegerv = [](GLenum pname, GLint* data) {
|
||||
if (pname == GL_TEXTURE_BINDING_BUFFER) {
|
||||
*data = static_cast<GLint>(g_tbr.textureBindingBeforeProbe);
|
||||
return;
|
||||
}
|
||||
if (pname == GL_MAJOR_VERSION || pname == GL_MINOR_VERSION) *data = pname == GL_MAJOR_VERSION ? 3 : 2;
|
||||
};
|
||||
funcs.glTexBuffer = [](GLenum, GLenum, GLuint buffer) { g_tbr.views[g_tbr.boundTexture] = {buffer, 0}; };
|
||||
funcs.glTexBufferRange =
|
||||
withRangeEntryPoint
|
||||
? static_cast<MobileGL::MG_External::GLES::glTexBufferRange_PTR>(
|
||||
[](GLenum, GLenum, GLuint buffer, GLintptr offset, GLsizeiptr) {
|
||||
if (g_tbr.rangeRaisesError) {
|
||||
g_fake.pendingError = GL_INVALID_VALUE;
|
||||
return;
|
||||
}
|
||||
g_tbr.views[g_tbr.boundTexture] = {buffer, g_tbr.rangeIgnoresOffset ? 0 : offset};
|
||||
})
|
||||
: nullptr;
|
||||
funcs.glReadPixels = [](GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, void* pixels) {
|
||||
auto* out = static_cast<GLuint*>(pixels);
|
||||
out[0] = out[1] = out[2] = 0;
|
||||
out[3] = 1;
|
||||
if (g_tbr.readsZeroes) return;
|
||||
const auto view = g_tbr.views[g_tbr.boundTexture];
|
||||
const auto storeIt = g_fake.bufferStores.find(view.buffer);
|
||||
if (storeIt == g_fake.bufferStores.end()) return;
|
||||
const auto& store = storeIt->second;
|
||||
if (static_cast<std::size_t>(view.offset) + 2 * sizeof(GLuint) > store.size()) return;
|
||||
std::memcpy(out, store.data() + view.offset, 2 * sizeof(GLuint));
|
||||
};
|
||||
return funcs;
|
||||
}
|
||||
|
||||
MobileGL::MG_External::GLESCapabilities MakeBufferTextureCaps(GLint alignment) {
|
||||
MobileGL::MG_External::GLESCapabilities caps;
|
||||
caps.GLESVersion = {3, 2, 0};
|
||||
caps.TextureBufferSupport = MobileGL::MG_External::GLESCapabilities::TextureBufferTier::CoreEs32;
|
||||
caps.TextureBufferOffsetAlignment = alignment;
|
||||
return caps;
|
||||
}
|
||||
|
||||
using RangeVerdict = MobileGL::MG_External::GLESCapabilities::TextureBufferRangeVerdict;
|
||||
} // namespace
|
||||
|
||||
TEST(TextureBufferRangeProbe, HonoringDriverIsHonoredAndEverythingIsRestored) {
|
||||
const auto funcs = MakeBufferTextureFake(true);
|
||||
EXPECT_EQ(MobileGL::MG_Util::SelfTest::ProbeTextureBufferRange(MakeBufferTextureCaps(16), funcs),
|
||||
RangeVerdict::Honored);
|
||||
EXPECT_EQ(g_tbr.boundTexture, g_tbr.textureBindingBeforeProbe);
|
||||
EXPECT_EQ(g_tbr.aliveTextures, 0);
|
||||
EXPECT_EQ(g_fake.alivePrograms, 0);
|
||||
EXPECT_EQ(g_fake.aliveShaders, 0);
|
||||
EXPECT_EQ(g_fake.aliveBuffers, 0);
|
||||
EXPECT_EQ(g_fake.aliveFramebuffers, 0);
|
||||
EXPECT_EQ(g_fake.aliveRenderbuffers, 0);
|
||||
EXPECT_EQ(g_fake.pendingError, static_cast<GLenum>(GL_NO_ERROR));
|
||||
}
|
||||
|
||||
TEST(TextureBufferRangeProbe, AnOffsetSmallerThanAWordIsRoundedUpToOne) {
|
||||
const auto funcs = MakeBufferTextureFake(true);
|
||||
EXPECT_EQ(MobileGL::MG_Util::SelfTest::ProbeTextureBufferRange(MakeBufferTextureCaps(1), funcs),
|
||||
RangeVerdict::Honored);
|
||||
}
|
||||
|
||||
TEST(TextureBufferRangeProbe, DriverDroppingTheOffsetIsReported) {
|
||||
const auto funcs = MakeBufferTextureFake(true);
|
||||
g_tbr.rangeIgnoresOffset = true;
|
||||
EXPECT_EQ(MobileGL::MG_Util::SelfTest::ProbeTextureBufferRange(MakeBufferTextureCaps(16), funcs),
|
||||
RangeVerdict::OffsetIgnored);
|
||||
EXPECT_EQ(g_tbr.aliveTextures, 0);
|
||||
}
|
||||
|
||||
TEST(TextureBufferRangeProbe, AFailingControlOrRangeCallIsInconclusive) {
|
||||
auto funcs = MakeBufferTextureFake(true);
|
||||
g_tbr.readsZeroes = true;
|
||||
EXPECT_EQ(MobileGL::MG_Util::SelfTest::ProbeTextureBufferRange(MakeBufferTextureCaps(16), funcs),
|
||||
RangeVerdict::Inconclusive);
|
||||
|
||||
funcs = MakeBufferTextureFake(true);
|
||||
g_tbr.rangeRaisesError = true;
|
||||
EXPECT_EQ(MobileGL::MG_Util::SelfTest::ProbeTextureBufferRange(MakeBufferTextureCaps(16), funcs),
|
||||
RangeVerdict::Inconclusive);
|
||||
EXPECT_EQ(g_fake.pendingError, static_cast<GLenum>(GL_NO_ERROR));
|
||||
|
||||
funcs = MakeBufferTextureFake(true);
|
||||
EXPECT_EQ(MobileGL::MG_Util::SelfTest::ProbeTextureBufferRange(MakeBufferTextureCaps(1 << 20), funcs),
|
||||
RangeVerdict::Inconclusive);
|
||||
}
|
||||
|
||||
TEST(TextureBufferRangeProbe, MissingEntryPointOrTierDoesNotRun) {
|
||||
auto funcs = MakeBufferTextureFake(false);
|
||||
EXPECT_EQ(MobileGL::MG_Util::SelfTest::ProbeTextureBufferRange(MakeBufferTextureCaps(16), funcs),
|
||||
RangeVerdict::NotRun);
|
||||
EXPECT_EQ(g_fake.createdPrograms, 0);
|
||||
|
||||
funcs = MakeBufferTextureFake(true);
|
||||
auto caps = MakeBufferTextureCaps(16);
|
||||
caps.TextureBufferSupport = MobileGL::MG_External::GLESCapabilities::TextureBufferTier::None;
|
||||
EXPECT_EQ(MobileGL::MG_Util::SelfTest::ProbeTextureBufferRange(caps, funcs), RangeVerdict::NotRun);
|
||||
EXPECT_EQ(g_fake.createdPrograms, 0);
|
||||
}
|
||||
|
||||
// Only a driver measured to drop the offset lands in the POST's Known Driver Bugs section.
|
||||
TEST(TextureBufferRangeProbe, OnlyAnIgnoredOffsetIsAKnownDriverBug) {
|
||||
using MobileGL::MG_Util::SelfTest::DescribeTextureBufferRangeBug;
|
||||
const auto finding = DescribeTextureBufferRangeBug(RangeVerdict::OffsetIgnored);
|
||||
ASSERT_TRUE(finding.has_value());
|
||||
EXPECT_EQ(finding->verdict, MobileGL::MG_Util::SelfTest::DriverBugVerdict::Unfixable);
|
||||
EXPECT_FALSE(finding->name.empty());
|
||||
for (const RangeVerdict verdict : {RangeVerdict::Honored, RangeVerdict::Inconclusive, RangeVerdict::NotRun}) {
|
||||
EXPECT_FALSE(DescribeTextureBufferRangeBug(verdict).has_value());
|
||||
}
|
||||
}
|
||||
@@ -6708,6 +6708,52 @@ TEST_F(TextureTest, TexBufferRejectsAnInternalFormatABufferTextureCannotTake) {
|
||||
DrainPendingGlErrors();
|
||||
}
|
||||
|
||||
// GL 4.6 core 8.9: detaching with buffer zero ignores offset and size, so a range form passes
|
||||
// even with values that would fail its checks, and resets both to zero.
|
||||
TEST_F(TextureTest, TexBufferRangeDetachIgnoresAndResetsTheRange) {
|
||||
GLuint texture = 0;
|
||||
MG_Impl::GLImpl::GenTextures(1, &texture);
|
||||
MG_Impl::GLImpl::BindTexture(GL_TEXTURE_BUFFER, texture);
|
||||
GLuint buffer = 0;
|
||||
MG_Impl::GLImpl::GenBuffers(1, &buffer);
|
||||
MG_Impl::GLImpl::BindBuffer(GL_TEXTURE_BUFFER, buffer);
|
||||
MG_Impl::GLImpl::BufferData(GL_TEXTURE_BUFFER, 4096, nullptr, GL_STATIC_DRAW);
|
||||
DrainPendingGlErrors();
|
||||
|
||||
GLint alignment = 0;
|
||||
MG_Impl::GLImpl::GetIntegerv(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, &alignment);
|
||||
alignment = std::max(alignment, 1);
|
||||
ASSERT_LE(alignment, 1024);
|
||||
MG_Impl::GLImpl::TexBufferRange(GL_TEXTURE_BUFFER, GL_R32UI, buffer, alignment, 64);
|
||||
ASSERT_EQ(MG_Impl::GLImpl::GetError(), GL_NO_ERROR);
|
||||
GLint offset = -1;
|
||||
GLint size = -1;
|
||||
MG_Impl::GLImpl::GetTexLevelParameteriv(GL_TEXTURE_BUFFER, 0, GL_TEXTURE_BUFFER_OFFSET, &offset);
|
||||
MG_Impl::GLImpl::GetTexLevelParameteriv(GL_TEXTURE_BUFFER, 0, GL_TEXTURE_BUFFER_SIZE, &size);
|
||||
EXPECT_EQ(offset, alignment);
|
||||
EXPECT_EQ(size, 64);
|
||||
|
||||
// A negative offset and a zero size would each be GL_INVALID_VALUE with a buffer attached.
|
||||
MG_Impl::GLImpl::TexBufferRange(GL_TEXTURE_BUFFER, GL_R32UI, 0, -1, 0);
|
||||
EXPECT_EQ(MG_Impl::GLImpl::GetError(), GL_NO_ERROR);
|
||||
MG_Impl::GLImpl::GetTexLevelParameteriv(GL_TEXTURE_BUFFER, 0, GL_TEXTURE_BUFFER_OFFSET, &offset);
|
||||
MG_Impl::GLImpl::GetTexLevelParameteriv(GL_TEXTURE_BUFFER, 0, GL_TEXTURE_BUFFER_SIZE, &size);
|
||||
EXPECT_EQ(offset, 0);
|
||||
EXPECT_EQ(size, 0);
|
||||
GLint binding = -1;
|
||||
MG_Impl::GLImpl::GetTexLevelParameteriv(GL_TEXTURE_BUFFER, 0, GL_TEXTURE_BUFFER_DATA_STORE_BINDING, &binding);
|
||||
EXPECT_EQ(binding, 0);
|
||||
|
||||
MG_Impl::GLImpl::TextureBufferRange(texture, GL_R32UI, 0, 3, 7);
|
||||
EXPECT_EQ(MG_Impl::GLImpl::GetError(), GL_NO_ERROR);
|
||||
|
||||
MG_Impl::GLImpl::BindTexture(GL_TEXTURE_BUFFER, 0);
|
||||
MG_Impl::GLImpl::BindBuffer(GL_TEXTURE_BUFFER, 0);
|
||||
MG_Impl::GLImpl::DeleteBuffers(1, &buffer);
|
||||
MG_Impl::GLImpl::DeleteTextures(1, &texture);
|
||||
DrainPendingGlErrors();
|
||||
}
|
||||
|
||||
// The DSA form keeps its own, DIFFERENT code for the corresponding shape: a texture that is not a
|
||||
// buffer texture is a wrong OBJECT, not a wrong token. The two must not be unified.
|
||||
TEST_F(TextureTest, TextureBufferKeepsInvalidOperationForANonBufferTexture) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "Loader.h"
|
||||
#include "MG_Util/SelfTest/DriverBugProbes.h"
|
||||
#include "MG_Util/SelfTest/TextureBufferRangeProbe.h"
|
||||
#include "MG_Util/Types.h"
|
||||
#include <Config.h>
|
||||
#include <cmath>
|
||||
@@ -972,6 +973,38 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
return includesBase;
|
||||
}
|
||||
|
||||
MG_External::GLES::glTexBuffer_PTR SelectTexBufferEntryPoint(const MG_External::GLESCapabilities& caps,
|
||||
const MG_External::GLESFunctionsTable& f) {
|
||||
using Tier = MG_External::GLESCapabilities::TextureBufferTier;
|
||||
switch (caps.TextureBufferSupport) {
|
||||
case Tier::ExtensionEXT:
|
||||
return f.glTexBufferEXT ? f.glTexBufferEXT : f.glTexBuffer;
|
||||
case Tier::ExtensionOES:
|
||||
return f.glTexBufferOES ? f.glTexBufferOES : f.glTexBuffer;
|
||||
case Tier::CoreEs32:
|
||||
return f.glTexBuffer;
|
||||
case Tier::None:
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
MG_External::GLES::glTexBufferRange_PTR SelectTexBufferRangeEntryPoint(const MG_External::GLESCapabilities& caps,
|
||||
const MG_External::GLESFunctionsTable& f) {
|
||||
using Tier = MG_External::GLESCapabilities::TextureBufferTier;
|
||||
switch (caps.TextureBufferSupport) {
|
||||
case Tier::ExtensionEXT:
|
||||
return f.glTexBufferRangeEXT ? f.glTexBufferRangeEXT : f.glTexBufferRange;
|
||||
case Tier::ExtensionOES:
|
||||
return f.glTexBufferRangeOES ? f.glTexBufferRangeOES : f.glTexBufferRange;
|
||||
case Tier::CoreEs32:
|
||||
return f.glTexBufferRange;
|
||||
case Tier::None:
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// GL 4.6 table 23.65 admits exactly four answers for GL_LAYER_PROVOKING_VERTEX and
|
||||
// GL_VIEWPORT_INDEX_PROVOKING_VERTEX. Anything else means the driver wrote something MobileGL
|
||||
// cannot forward as a convention, and GL_UNDEFINED_VERTEX - a legal answer, not a placeholder
|
||||
@@ -2090,6 +2123,10 @@ namespace MobileGL::MG_Util::BackendLoader {
|
||||
MGLOG_I(" Indirect draw gl_InstanceID includes baseInstance: %s",
|
||||
caps.IndirectDrawInstanceIdIncludesBaseInstance ? "true" : "false");
|
||||
|
||||
caps.TextureBufferRangeSupport = SelfTest::ProbeTextureBufferRange(caps, glesFuncs);
|
||||
MGLOG_I(" glTexBufferRange honors its offset: %s",
|
||||
SelfTest::TextureBufferRangeVerdictName(caps.TextureBufferRangeSupport));
|
||||
|
||||
// ForceOn means "emit the blocks unlocated", i.e. treat the driver as NOT supporting
|
||||
// located blocks - which is why the override reads inverted here. Auto is the probe's
|
||||
// own answer and is what every real run uses; the two forced settings exist so the
|
||||
|
||||
@@ -1178,6 +1178,16 @@ namespace MobileGL {
|
||||
ExtensionOES, // GL_OES_texture_buffer; ESSL below 320 must say GL_OES_texture_buffer
|
||||
};
|
||||
TextureBufferTier TextureBufferSupport = TextureBufferTier::None;
|
||||
// What SelfTest::ProbeTextureBufferRange measured: whether a glTexBufferRange view
|
||||
// starts at its offset. Only Honored lets DirectGLES advertise
|
||||
// GL_ARB_texture_buffer_range.
|
||||
enum class TextureBufferRangeVerdict : Uint8 {
|
||||
NotRun = 0, // no buffer textures or no range entry point
|
||||
Honored, // the view's texel 0 is the texel at its offset
|
||||
OffsetIgnored, // the view read from the start of the buffer
|
||||
Inconclusive, // the whole-buffer control or the probe's setup failed
|
||||
};
|
||||
TextureBufferRangeVerdict TextureBufferRangeSupport = TextureBufferRangeVerdict::NotRun;
|
||||
// Which spelling of per-vertex point size a NON-VERTEX stage has, if any. In desktop
|
||||
// GL gl_PointSize is an ordinary gl_PerVertex member that any vertex-processing stage
|
||||
// may write and any program may capture by name; in ESSL it does not EXIST in a
|
||||
@@ -1486,6 +1496,13 @@ namespace MobileGL {
|
||||
// so MG_Test can drive it against a fake GLES functions table.
|
||||
Bool ProbeIndirectInstanceIdIncludesBaseInstance(const MG_External::GLESCapabilities& caps,
|
||||
const MG_External::GLESFunctionsTable& glesFuncs);
|
||||
// The glTexBuffer / glTexBufferRange spelling that caps.TextureBufferSupport ships, or
|
||||
// null: the unsuffixed names are ES 3.2 core, an EXT/OES driver exports the suffixed ones,
|
||||
// and drivers that have both alias them.
|
||||
MG_External::GLES::glTexBuffer_PTR SelectTexBufferEntryPoint(const MG_External::GLESCapabilities& caps,
|
||||
const MG_External::GLESFunctionsTable& glesFuncs);
|
||||
MG_External::GLES::glTexBufferRange_PTR SelectTexBufferRangeEntryPoint(
|
||||
const MG_External::GLESCapabilities& caps, const MG_External::GLESFunctionsTable& glesFuncs);
|
||||
} // namespace MG_Util::BackendLoader
|
||||
} // namespace MobileGL
|
||||
#undef MOBILEGL_EXTERNAL_GLES
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "DriverPostIterationRPWitness.h"
|
||||
#include "DriverPostIterationRPWitnessSpv.h"
|
||||
#include "PrimitivesGeneratedNoXfbProbe.h"
|
||||
#include "TextureBufferRangeProbe.h"
|
||||
#include "MG_Util/BackendLoaders/OpenGL/Loader.h"
|
||||
#include <Config.h>
|
||||
#include <MGGitHash.h>
|
||||
@@ -1289,6 +1290,10 @@ namespace MobileGL::MG_Util::SelfTest {
|
||||
// the backend verdict, which is about whether the backend can RUN on this driver.
|
||||
// Only bugs the device actually has come back, so a clean driver adds nothing here.
|
||||
builder.report.knownDriverBugs = CollectGlesKnownDriverBugs(glesFuncs);
|
||||
// Measured by FillInGLESCapabilities, which already ran SelfTest::ProbeTextureBufferRange.
|
||||
if (Optional<DriverBugFinding> finding = DescribeTextureBufferRangeBug(caps.TextureBufferRangeSupport)) {
|
||||
builder.report.knownDriverBugs.push_back(Move(*finding));
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,322 @@
|
||||
// MobileGL - MobileGL/MG_Util/SelfTest/TextureBufferRangeProbe.cpp
|
||||
// Copyright (c) 2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "TextureBufferRangeProbe.h"
|
||||
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
namespace MobileGL::MG_Util::SelfTest {
|
||||
namespace {
|
||||
using MG_External::GLESCapabilities;
|
||||
using MG_External::GLESFunctionsTable;
|
||||
using Verdict = GLESCapabilities::TextureBufferRangeVerdict;
|
||||
|
||||
constexpr const char* kProbeName = "texture buffer range";
|
||||
constexpr Uint32 kTexelTag = 0x5A000000u;
|
||||
constexpr GLsizeiptr kRangeBytes = 16;
|
||||
// Far above any real GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT (the GL maximum is 256): a driver
|
||||
// answer beyond it is not trusted with an allocation.
|
||||
constexpr GLint kMaxProbedAlignment = 4096;
|
||||
|
||||
Bool HasEveryEntryPoint(const GLESFunctionsTable& gl) {
|
||||
return gl.glCreateShader && gl.glShaderSource && gl.glCompileShader && gl.glGetShaderiv &&
|
||||
gl.glGetShaderInfoLog && gl.glDeleteShader && gl.glCreateProgram && gl.glAttachShader &&
|
||||
gl.glLinkProgram && gl.glGetProgramiv && gl.glDeleteProgram && gl.glUseProgram && gl.glGenBuffers &&
|
||||
gl.glBindBuffer && gl.glBufferData && gl.glDeleteBuffers && gl.glGenTextures && gl.glBindTexture &&
|
||||
gl.glDeleteTextures && gl.glActiveTexture && gl.glGenVertexArrays && gl.glBindVertexArray &&
|
||||
gl.glDeleteVertexArrays && gl.glGenFramebuffers && gl.glBindFramebuffer &&
|
||||
gl.glFramebufferRenderbuffer && gl.glCheckFramebufferStatus && gl.glDeleteFramebuffers &&
|
||||
gl.glGenRenderbuffers && gl.glBindRenderbuffer && gl.glRenderbufferStorage &&
|
||||
gl.glDeleteRenderbuffers && gl.glViewport && gl.glDrawArrays && gl.glReadPixels &&
|
||||
gl.glGetIntegerv && gl.glGetBooleanv && gl.glIsEnabled && gl.glEnable && gl.glDisable &&
|
||||
gl.glColorMask && gl.glPixelStorei && gl.glGetError;
|
||||
}
|
||||
|
||||
void Drain(const GLESFunctionsTable& gl) {
|
||||
for (Int i = 0; i < 32 && gl.glGetError() != GL_NO_ERROR; ++i) {}
|
||||
}
|
||||
|
||||
// The ESSL header the tier's buffer textures need: core at 320, a directive below it.
|
||||
const char* ShaderHeader(GLESCapabilities::TextureBufferTier tier) {
|
||||
using Tier = GLESCapabilities::TextureBufferTier;
|
||||
switch (tier) {
|
||||
case Tier::CoreEs32:
|
||||
return "#version 320 es\n";
|
||||
case Tier::ExtensionEXT:
|
||||
return "#version 310 es\n#extension GL_EXT_texture_buffer : require\n";
|
||||
case Tier::ExtensionOES:
|
||||
return "#version 310 es\n#extension GL_OES_texture_buffer : require\n";
|
||||
case Tier::None:
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
GLuint CompileStage(const GLESFunctionsTable& gl, GLenum stage, const String& source) {
|
||||
const GLuint shader = gl.glCreateShader(stage);
|
||||
if (shader == 0) return 0;
|
||||
const char* text = source.c_str();
|
||||
gl.glShaderSource(shader, 1, &text, nullptr);
|
||||
gl.glCompileShader(shader);
|
||||
GLint compiled = GL_FALSE;
|
||||
gl.glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
|
||||
if (compiled == GL_FALSE) {
|
||||
char log[512] = {0};
|
||||
gl.glGetShaderInfoLog(shader, static_cast<GLsizei>(sizeof(log) - 1), nullptr, log);
|
||||
MGLOG_I("[post] %s probe: a stage did not compile: %s", kProbeName, log);
|
||||
gl.glDeleteShader(shader);
|
||||
return 0;
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLuint BuildProgram(const GLESFunctionsTable& gl, const char* header) {
|
||||
const String vertex = String(header) + "void main() {\n"
|
||||
" vec2 p = vec2(float((gl_VertexID & 1) * 4) - 1.0,\n"
|
||||
" float((gl_VertexID & 2) * 2) - 1.0);\n"
|
||||
" gl_Position = vec4(p, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
const String fragment = String(header) +
|
||||
"precision highp float;\n"
|
||||
"precision highp int;\n"
|
||||
"layout(binding = 0) uniform highp usamplerBuffer mg_probeTexels;\n"
|
||||
"layout(location = 0) out highp uvec4 mg_probeColor;\n"
|
||||
"void main() {\n"
|
||||
" mg_probeColor = uvec4(texelFetch(mg_probeTexels, 0).r,\n"
|
||||
" texelFetch(mg_probeTexels, 1).r, 0u, 1u);\n"
|
||||
"}\n";
|
||||
const GLuint vs = CompileStage(gl, GL_VERTEX_SHADER, vertex);
|
||||
const GLuint fs = vs != 0 ? CompileStage(gl, GL_FRAGMENT_SHADER, fragment) : 0;
|
||||
GLuint program = 0;
|
||||
if (vs != 0 && fs != 0) {
|
||||
program = gl.glCreateProgram();
|
||||
if (program != 0) {
|
||||
gl.glAttachShader(program, vs);
|
||||
gl.glAttachShader(program, fs);
|
||||
gl.glLinkProgram(program);
|
||||
GLint linked = GL_FALSE;
|
||||
gl.glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
||||
if (linked == GL_FALSE) {
|
||||
MGLOG_I("[post] %s probe: the program did not link", kProbeName);
|
||||
gl.glDeleteProgram(program);
|
||||
program = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vs != 0) gl.glDeleteShader(vs);
|
||||
if (fs != 0) gl.glDeleteShader(fs);
|
||||
return program;
|
||||
}
|
||||
|
||||
// Everything the probe disturbs, put back on the way out.
|
||||
struct SavedState {
|
||||
GLint program = 0, vertexArray = 0, drawFramebuffer = 0, readFramebuffer = 0, renderbuffer = 0;
|
||||
GLint activeTexture = GL_TEXTURE0, textureBuffer = 0, bufferBinding = 0, packBuffer = 0;
|
||||
GLint packAlignment = 4, packRowLength = 0, packSkipPixels = 0, packSkipRows = 0;
|
||||
GLint viewport[4] = {0, 0, 0, 0};
|
||||
GLboolean colorMask[4] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE};
|
||||
GLboolean scissorTest = GL_FALSE, rasterizerDiscard = GL_FALSE, cullFace = GL_FALSE;
|
||||
GLboolean depthTest = GL_FALSE, blend = GL_FALSE;
|
||||
|
||||
void Save(const GLESFunctionsTable& gl) {
|
||||
gl.glGetIntegerv(GL_CURRENT_PROGRAM, &program);
|
||||
gl.glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &vertexArray);
|
||||
gl.glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFramebuffer);
|
||||
gl.glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFramebuffer);
|
||||
gl.glGetIntegerv(GL_RENDERBUFFER_BINDING, &renderbuffer);
|
||||
gl.glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexture);
|
||||
gl.glActiveTexture(GL_TEXTURE0);
|
||||
gl.glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &textureBuffer);
|
||||
gl.glGetIntegerv(GL_TEXTURE_BUFFER_BINDING, &bufferBinding);
|
||||
gl.glGetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &packBuffer);
|
||||
gl.glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
|
||||
gl.glGetIntegerv(GL_PACK_ROW_LENGTH, &packRowLength);
|
||||
gl.glGetIntegerv(GL_PACK_SKIP_PIXELS, &packSkipPixels);
|
||||
gl.glGetIntegerv(GL_PACK_SKIP_ROWS, &packSkipRows);
|
||||
gl.glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
gl.glGetBooleanv(GL_COLOR_WRITEMASK, colorMask);
|
||||
scissorTest = gl.glIsEnabled(GL_SCISSOR_TEST);
|
||||
rasterizerDiscard = gl.glIsEnabled(GL_RASTERIZER_DISCARD);
|
||||
cullFace = gl.glIsEnabled(GL_CULL_FACE);
|
||||
depthTest = gl.glIsEnabled(GL_DEPTH_TEST);
|
||||
blend = gl.glIsEnabled(GL_BLEND);
|
||||
}
|
||||
|
||||
static void SetEnabled(const GLESFunctionsTable& gl, GLenum cap, GLboolean enabled) {
|
||||
if (enabled != GL_FALSE)
|
||||
gl.glEnable(cap);
|
||||
else
|
||||
gl.glDisable(cap);
|
||||
}
|
||||
|
||||
void Restore(const GLESFunctionsTable& gl) const {
|
||||
gl.glUseProgram(static_cast<GLuint>(program));
|
||||
gl.glBindVertexArray(static_cast<GLuint>(vertexArray));
|
||||
gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, static_cast<GLuint>(drawFramebuffer));
|
||||
gl.glBindFramebuffer(GL_READ_FRAMEBUFFER, static_cast<GLuint>(readFramebuffer));
|
||||
gl.glBindRenderbuffer(GL_RENDERBUFFER, static_cast<GLuint>(renderbuffer));
|
||||
gl.glActiveTexture(GL_TEXTURE0);
|
||||
gl.glBindTexture(GL_TEXTURE_BUFFER, static_cast<GLuint>(textureBuffer));
|
||||
gl.glActiveTexture(static_cast<GLenum>(activeTexture));
|
||||
gl.glBindBuffer(GL_TEXTURE_BUFFER, static_cast<GLuint>(bufferBinding));
|
||||
gl.glBindBuffer(GL_PIXEL_PACK_BUFFER, static_cast<GLuint>(packBuffer));
|
||||
gl.glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);
|
||||
gl.glPixelStorei(GL_PACK_ROW_LENGTH, packRowLength);
|
||||
gl.glPixelStorei(GL_PACK_SKIP_PIXELS, packSkipPixels);
|
||||
gl.glPixelStorei(GL_PACK_SKIP_ROWS, packSkipRows);
|
||||
gl.glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
|
||||
gl.glColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
|
||||
SetEnabled(gl, GL_SCISSOR_TEST, scissorTest);
|
||||
SetEnabled(gl, GL_RASTERIZER_DISCARD, rasterizerDiscard);
|
||||
SetEnabled(gl, GL_CULL_FACE, cullFace);
|
||||
SetEnabled(gl, GL_DEPTH_TEST, depthTest);
|
||||
SetEnabled(gl, GL_BLEND, blend);
|
||||
}
|
||||
};
|
||||
|
||||
// Draws one pixel through the view bound to unit 0 and returns its first two channels.
|
||||
Bool DrawAndRead(const GLESFunctionsTable& gl, Uint32 (&texels)[2]) {
|
||||
gl.glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
GLuint pixel[4] = {0, 0, 0, 0};
|
||||
gl.glReadPixels(0, 0, 1, 1, GL_RGBA_INTEGER, GL_UNSIGNED_INT, pixel);
|
||||
if (gl.glGetError() != GL_NO_ERROR) return false;
|
||||
texels[0] = pixel[0];
|
||||
texels[1] = pixel[1];
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
const char* TextureBufferRangeVerdictName(Verdict verdict) {
|
||||
switch (verdict) {
|
||||
case Verdict::Honored:
|
||||
return "honored";
|
||||
case Verdict::OffsetIgnored:
|
||||
return "offset ignored";
|
||||
case Verdict::Inconclusive:
|
||||
return "inconclusive";
|
||||
case Verdict::NotRun:
|
||||
default:
|
||||
return "not run";
|
||||
}
|
||||
}
|
||||
|
||||
Optional<DriverBugFinding> DescribeTextureBufferRangeBug(Verdict verdict) {
|
||||
if (verdict != Verdict::OffsetIgnored) return std::nullopt;
|
||||
return DriverBugFinding{
|
||||
"glTexBufferRange views ignore their offset", DriverBugVerdict::Unfixable,
|
||||
"A glTexBufferRange view reads from the start of the buffer instead of from its offset. MobileGL "
|
||||
"does not advertise GL_ARB_texture_buffer_range, but GL 4.3 core glTexBufferRange calls still reach "
|
||||
"the driver unchanged."};
|
||||
}
|
||||
|
||||
Verdict ProbeTextureBufferRange(const GLESCapabilities& caps, const GLESFunctionsTable& gl) {
|
||||
const auto texBuffer = BackendLoader::SelectTexBufferEntryPoint(caps, gl);
|
||||
const auto texBufferRange = BackendLoader::SelectTexBufferRangeEntryPoint(caps, gl);
|
||||
const char* header = ShaderHeader(caps.TextureBufferSupport);
|
||||
if (texBuffer == nullptr || texBufferRange == nullptr || header == nullptr || !HasEveryEntryPoint(gl)) {
|
||||
return Verdict::NotRun;
|
||||
}
|
||||
const GLint alignment = std::max(1, caps.TextureBufferOffsetAlignment);
|
||||
if (alignment > kMaxProbedAlignment) {
|
||||
MGLOG_I("[post] %s probe: GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT = %d is not plausible", kProbeName, alignment);
|
||||
return Verdict::Inconclusive;
|
||||
}
|
||||
const GLintptr offset = std::lcm(static_cast<GLintptr>(alignment), static_cast<GLintptr>(sizeof(Uint32)));
|
||||
const SizeT texelCount = static_cast<SizeT>(offset + kRangeBytes) / sizeof(Uint32);
|
||||
Vector<Uint32> words(texelCount);
|
||||
for (SizeT i = 0; i < texelCount; ++i) {
|
||||
words[i] = kTexelTag | static_cast<Uint32>(i);
|
||||
}
|
||||
const SizeT offsetTexel = static_cast<SizeT>(offset) / sizeof(Uint32);
|
||||
|
||||
Drain(gl);
|
||||
SavedState saved;
|
||||
saved.Save(gl);
|
||||
|
||||
const GLuint program = BuildProgram(gl, header);
|
||||
GLuint vao = 0, buffer = 0, framebuffer = 0, renderbuffer = 0;
|
||||
GLuint textures[2] = {0, 0}; // [0] whole-buffer control, [1] range subject
|
||||
Verdict verdict = Verdict::Inconclusive;
|
||||
if (program != 0) {
|
||||
gl.glGenVertexArrays(1, &vao);
|
||||
gl.glGenBuffers(1, &buffer);
|
||||
gl.glGenTextures(2, textures);
|
||||
gl.glGenFramebuffers(1, &framebuffer);
|
||||
gl.glGenRenderbuffers(1, &renderbuffer);
|
||||
|
||||
gl.glBindBuffer(GL_TEXTURE_BUFFER, buffer);
|
||||
gl.glBufferData(GL_TEXTURE_BUFFER, static_cast<GLsizeiptr>(words.size() * sizeof(Uint32)), words.data(),
|
||||
GL_STATIC_DRAW);
|
||||
gl.glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
|
||||
gl.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA32UI, 1, 1);
|
||||
gl.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
gl.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
|
||||
gl.glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
gl.glPixelStorei(GL_PACK_ALIGNMENT, 4);
|
||||
gl.glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
gl.glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
||||
gl.glPixelStorei(GL_PACK_SKIP_ROWS, 0);
|
||||
gl.glViewport(0, 0, 1, 1);
|
||||
gl.glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
gl.glDisable(GL_SCISSOR_TEST);
|
||||
gl.glDisable(GL_RASTERIZER_DISCARD);
|
||||
gl.glDisable(GL_CULL_FACE);
|
||||
gl.glDisable(GL_DEPTH_TEST);
|
||||
gl.glDisable(GL_BLEND);
|
||||
gl.glUseProgram(program);
|
||||
gl.glBindVertexArray(vao);
|
||||
gl.glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
Uint32 control[2] = {0, 0};
|
||||
Uint32 subject[2] = {0, 0};
|
||||
const Bool ready = gl.glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE &&
|
||||
gl.glGetError() == GL_NO_ERROR;
|
||||
Bool controlRead = false;
|
||||
Bool subjectRead = false;
|
||||
if (ready) {
|
||||
gl.glBindTexture(GL_TEXTURE_BUFFER, textures[0]);
|
||||
texBuffer(GL_TEXTURE_BUFFER, GL_R32UI, buffer);
|
||||
controlRead = DrawAndRead(gl, control);
|
||||
}
|
||||
if (controlRead) {
|
||||
gl.glBindTexture(GL_TEXTURE_BUFFER, textures[1]);
|
||||
texBufferRange(GL_TEXTURE_BUFFER, GL_R32UI, buffer, offset, kRangeBytes);
|
||||
subjectRead = gl.glGetError() == GL_NO_ERROR && DrawAndRead(gl, subject);
|
||||
}
|
||||
const Bool controlPassed = controlRead && control[0] == words[0] && control[1] == words[1];
|
||||
if (!controlPassed) {
|
||||
MGLOG_I("[post] %s probe reached no verdict: the whole-buffer control read 0x%08x 0x%08x", kProbeName,
|
||||
control[0], control[1]);
|
||||
} else if (!subjectRead) {
|
||||
MGLOG_I("[post] %s probe reached no verdict: the range view raised a GL error", kProbeName);
|
||||
} else if (subject[0] == words[offsetTexel] && subject[1] == words[offsetTexel + 1]) {
|
||||
verdict = Verdict::Honored;
|
||||
} else if (subject[0] == words[0] && subject[1] == words[1]) {
|
||||
verdict = Verdict::OffsetIgnored;
|
||||
} else {
|
||||
MGLOG_I("[post] %s probe reached no verdict: the range view read 0x%08x 0x%08x", kProbeName, subject[0],
|
||||
subject[1]);
|
||||
}
|
||||
MGLOG_I("[post] %s probe: offset %lld (alignment %d): %s", kProbeName, static_cast<long long>(offset),
|
||||
alignment, TextureBufferRangeVerdictName(verdict));
|
||||
}
|
||||
|
||||
saved.Restore(gl);
|
||||
if (program != 0) gl.glDeleteProgram(program);
|
||||
if (vao != 0) gl.glDeleteVertexArrays(1, &vao);
|
||||
if (buffer != 0) gl.glDeleteBuffers(1, &buffer);
|
||||
if (textures[0] != 0 || textures[1] != 0) gl.glDeleteTextures(2, textures);
|
||||
if (framebuffer != 0) gl.glDeleteFramebuffers(1, &framebuffer);
|
||||
if (renderbuffer != 0) gl.glDeleteRenderbuffers(1, &renderbuffer);
|
||||
Drain(gl);
|
||||
return verdict;
|
||||
}
|
||||
} // namespace MobileGL::MG_Util::SelfTest
|
||||
@@ -0,0 +1,37 @@
|
||||
// MobileGL - MobileGL/MG_Util/SelfTest/TextureBufferRangeProbe.h
|
||||
// Copyright (c) 2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Includes.h>
|
||||
#include <MG_Util/BackendLoaders/OpenGL/Loader.h>
|
||||
#include <MG_Util/SelfTest/DriverBugProbes.h>
|
||||
|
||||
namespace MobileGL::MG_Util::SelfTest {
|
||||
// Whether the driver's glTexBufferRange view starts at its offset (GL 4.6 / ES 3.2 section
|
||||
// 8.9: texel 0 of the view is the texel at `offset` bytes into the buffer). DirectGLES
|
||||
// advertises GL_ARB_texture_buffer_range only on Honored.
|
||||
//
|
||||
// THE CONTROL first: a whole-buffer glTexBuffer view must read texels 0 and 1 of the buffer,
|
||||
// or the draw and readback themselves are broken and there is no verdict. Then THE SUBJECT:
|
||||
// a glTexBufferRange view at the smallest offset that is a multiple of both
|
||||
// GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT and the 4-byte texel must read the texels at that
|
||||
// offset. Reading the control's texels instead is OffsetIgnored; anything else, a GL error
|
||||
// or a setup failure is Inconclusive.
|
||||
//
|
||||
// Needs the buffer-texture tier and offset alignment already in `caps`. Restores every piece
|
||||
// of GL state it touches.
|
||||
MG_External::GLESCapabilities::TextureBufferRangeVerdict ProbeTextureBufferRange(
|
||||
const MG_External::GLESCapabilities& caps, const MG_External::GLESFunctionsTable& gl);
|
||||
|
||||
const char* TextureBufferRangeVerdictName(MG_External::GLESCapabilities::TextureBufferRangeVerdict verdict);
|
||||
|
||||
// The POST's Known Driver Bugs entry for an OffsetIgnored verdict, and nothing for any other.
|
||||
Optional<DriverBugFinding> DescribeTextureBufferRangeBug(
|
||||
MG_External::GLESCapabilities::TextureBufferRangeVerdict verdict);
|
||||
} // namespace MobileGL::MG_Util::SelfTest
|
||||
Reference in new issue
Block a user