[Fix, Test] (3rdparty/glslang, MG_IntegrationTest/Scenarios, MG_Test): let shaders below 440 use the ARB draw-parameter built-ins (#23)

This commit is contained in:
swung0x48 committed 2026-12-02 19:58:02 -04:00
1 parent 6196653b92
commit dcfb9c7964
3 files changed
+75 -1

No files matched your search

@@ -30,6 +30,7 @@
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "../Harness/HeadlessGL.h"
@@ -223,6 +224,39 @@ void main() {
ExpectParams(image, 0, {0, 5, 0}, "glDrawArraysInstancedBaseInstance(baseInstance=5)");
}
// GL_ARB_shader_draw_parameters needs only OpenGL 3.1, so a 3.30 shader may enable it
// behind the usual `#ifdef` probe and read the ARB built-ins.
TEST_F(DrawParametersScenario, A330ShaderReadsTheArbBuiltIns) {
if (!Ready()) return;
constexpr const char* kVertex330 = R"(#version 330 core
#ifdef GL_ARB_shader_draw_parameters
#extension GL_ARB_shader_draw_parameters : enable
#endif
layout(location = 0) in vec2 aPos;
flat out vec3 vParams;
const int kStep[8] = int[8](0, 8, 16, 24, 32, 40, 48, 56);
void main() {
vParams = (vec3(gl_BaseVertexARB * 8, kStep[gl_BaseInstanceARB], gl_DrawIDARB * 8) + 16.0) / 255.0;
gl_Position = vec4(aPos, 0.0, 1.0);
}
)";
constexpr const char* kFragment330 = R"(#version 330 core
flat in vec3 vParams;
out vec4 oColor;
void main() { oColor = vec4(vParams, 1.0); }
)";
std::string error;
GLuint program = CompileProgram(kVertex330, kFragment330, &error);
ASSERT_NE(program, 0u) << error;
// Render draws with m_program, and TearDown deletes whatever m_program holds.
std::swap(m_program, program);
glDeleteProgram(program);
const Image image =
Render([&] { glDrawArraysInstancedBaseInstance(GL_TRIANGLES, kLeftFirst, 2 * kHalfCount, 1, 5); });
EXPECT_EQ(FirstGLError(), GLenum(GL_NO_ERROR));
ExpectParams(image, 0, {0, 5, 0}, "#version 330 glDrawArraysInstancedBaseInstance(baseInstance=5)");
}
// The base instance of one draw must not survive into the next one. This is
// the shape that broke on DirectGLES: the emulation uniform is per-program
// state, so a draw that never writes it inherits the last writer's value.
+40
View File
@@ -1568,6 +1568,46 @@ void main() { mgColor = vec4(float(gl_MaxCullDistances)); }
MG_State::pGLContext = Move(previousContext);
}
// GL_ARB_shader_draw_parameters needs only OpenGL 3.1: below #version 440 its built-ins are usable
// behind the extension's `#ifdef` probe, and still unreachable without the extension.
TEST(ShaderCompilerSanity, ArbShaderDrawParametersIsUsableBelow440) {
using namespace MobileGL;
auto previousContext = MG_State::pGLContext.Take();
auto previousBackend = Move(MG_Backend::pActiveBackendObject);
MG_State::pGLContext = MakeUnique<MG_State::GLState::GLContext>();
MG_Backend::pActiveBackendObject = MakeUnique<DynamicParameterBackend>(MG_Backend::DynamicBackendParameters{});
const auto env = MG_Util::ShaderTranspiler::CaptureCompileEnv();
const auto compileVertex = [&env](const String& source) {
return MG_Util::ShaderTranspiler::ShaderCompiler::CompileShader({
.shaderType = GL_VERTEX_SHADER,
.sourceStr = source,
.env = env.get(),
});
};
for (const char* version : {"140", "330 core", "430 core"}) {
const String probed = String("#version ") + version + R"(
#ifdef GL_ARB_shader_draw_parameters
#extension GL_ARB_shader_draw_parameters : enable
#else
#error GL_ARB_shader_draw_parameters should be defined from 140 up
#endif
const int offsets[4] = int[4](0, 1, 2, 3);
void main() { gl_Position = vec4(float(offsets[gl_BaseInstanceARB] + gl_BaseVertexARB + gl_DrawIDARB)); }
)";
auto compiled = compileVertex(probed);
EXPECT_TRUE(compiled) << version << ": " << (compiled ? String() : compiled.error().log);
}
const String withoutExtension = R"(#version 330 core
void main() { gl_Position = vec4(float(gl_BaseInstanceARB)); }
)";
EXPECT_FALSE(compileVertex(withoutExtension)) << "gl_BaseInstanceARB must require GL_ARB_shader_draw_parameters";
MG_Backend::pActiveBackendObject = Move(previousBackend);
MG_State::pGLContext = Move(previousContext);
}
// GL_EXT_shader_integer_mix (KHR-GL4x.shader_integer_mix.*): a 3.30 shader that requires the
// extension must see its macro and must be able to mix integer and boolean vectors under a
// boolean selector. Both backends carry the result: SPIR-V lowers the call to OpSelect, which