Skip to content

Commit

Permalink
Add support for GL_EXT_texture_offset_non_const
Browse files Browse the repository at this point in the history
  • Loading branch information
rg3igalia committed Oct 29, 2024
1 parent 63ebbe3 commit e8bce4d
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 4 deletions.
357 changes: 357 additions & 0 deletions Test/baseResults/textureoffset_non_const.vert.out

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions Test/textureoffset_non_const.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#version 450 core
#extension GL_EXT_texture_offset_non_const : enable
layout(location = 0) in highp vec4 a_position;
layout(location = 4) in highp vec2 a_in0;
layout(location = 5) in highp float a_in1;
layout(location = 10) in highp ivec2 offsetValue;
layout(location = 0) out mediump vec4 v_color0;
layout(location = 1) out mediump vec4 v_color1;
layout(location = 2) out mediump vec4 v_color2;
layout(location = 3) out mediump vec4 v_color3;
layout(location = 4) out mediump vec4 v_color4;
layout(location = 5) out mediump vec4 v_color5;
layout(location = 6) out mediump vec4 v_color6;
layout(set = 0, binding = 0) uniform highp sampler2D u_sampler;
layout(set = 0, binding = 1) uniform buf0 { highp vec4 u_scale; };
layout(set = 0, binding = 2) uniform buf1 { highp vec4 u_bias; };
out gl_PerVertex {
vec4 gl_Position;
};

void main()
{
gl_Position = a_position;
v_color0 = vec4(textureOffset(u_sampler, a_in0, offsetValue))*u_scale + u_bias;
v_color1 = vec4(texelFetchOffset(u_sampler, ivec2(a_in0), int(a_in1), offsetValue))*u_scale + u_bias;
v_color2 = vec4(textureProjOffset(u_sampler, vec3(a_in0, 1.0), offsetValue))*u_scale + u_bias;
v_color3 = vec4(textureLodOffset(u_sampler, a_in0, a_in1, offsetValue))*u_scale + u_bias;
v_color4 = vec4(textureProjLodOffset(u_sampler, vec3(a_in0, 1.0), a_in1, offsetValue))*u_scale + u_bias;
v_color5 = vec4(textureGradOffset(u_sampler, a_in0, vec2(a_in1, a_in1), vec2(a_in1, a_in1), offsetValue))*u_scale + u_bias;
v_color6 = vec4(textureProjGradOffset(u_sampler, vec3(a_in0, 1.0), vec2(a_in1, a_in1), vec2(a_in1, a_in1), offsetValue))*u_scale + u_bias;
}
13 changes: 9 additions & 4 deletions glslang/MachineIndependent/ParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include <algorithm>

#include "Versions.h"
#include "preprocessor/PpContext.h"

extern int yyparse(glslang::TParseContext*);
Expand Down Expand Up @@ -2332,8 +2333,10 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan
arg0->getType().getSampler().shadow;
if (f16ShadowCompare)
++arg;
if (! (*argp)[arg]->getAsTyped()->getQualifier().isConstant())
error(loc, "argument must be compile-time constant", "texel offset", "");
if (! (*argp)[arg]->getAsTyped()->getQualifier().isConstant()) {
if (!extensionTurnedOn(E_GL_EXT_texture_offset_non_const))
error(loc, "argument must be compile-time constant", "texel offset", "");
}
else if ((*argp)[arg]->getAsConstantUnion()) {
const TType& type = (*argp)[arg]->getAsTyped()->getType();
for (int c = 0; c < type.getVectorSize(); ++c) {
Expand Down Expand Up @@ -2926,8 +2929,10 @@ void TParseContext::nonOpBuiltInCheck(const TSourceLoc& loc, const TFunction& fn
arg = 4;

if (arg > 0) {
if (! callNode.getSequence()[arg]->getAsConstantUnion())
error(loc, "argument must be compile-time constant", "texel offset", "");
if (! callNode.getSequence()[arg]->getAsConstantUnion()) {
if (!extensionTurnedOn(E_GL_EXT_texture_offset_non_const))
error(loc, "argument must be compile-time constant", "texel offset", "");
}
else {
const TType& type = callNode.getSequence()[arg]->getAsTyped()->getType();
for (int c = 0; c < type.getVectorSize(); ++c) {
Expand Down
6 changes: 6 additions & 0 deletions glslang/MachineIndependent/Versions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ void TParseVersions::initializeExtensionBehavior()
extensionBehavior[E_GL_EXT_texture_shadow_lod] = EBhDisable;
extensionBehavior[E_GL_EXT_draw_instanced] = EBhDisable;
extensionBehavior[E_GL_EXT_texture_array] = EBhDisable;
extensionBehavior[E_GL_EXT_texture_offset_non_const] = EBhDisable;

// OVR extensions
extensionBehavior[E_GL_OVR_multiview] = EBhDisable;
Expand Down Expand Up @@ -632,6 +633,11 @@ void TParseVersions::getPreamble(std::string& preamble)
;
}

if ((!isEsProfile() && version >= 130) ||
(isEsProfile() && version >= 300)) {
preamble += "#define GL_EXT_texture_offset_non_const 1\n";
}

if (version >= 300 /* both ES and non-ES */) {
preamble +=
"#define GL_OVR_multiview 1\n"
Expand Down
2 changes: 2 additions & 0 deletions glslang/MachineIndependent/Versions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Copyright (C) 2017, 2022-2024 Arm Limited.
// Copyright (C) 2015-2018 Google, Inc.
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
// Modifications Copyright (C) 2024 Valve Corporation.
//
// All rights reserved.
//
Expand Down Expand Up @@ -223,6 +224,7 @@ const char* const E_GL_EXT_maximal_reconvergence = "GL_EXT_maximal_re
const char* const E_GL_EXT_expect_assume = "GL_EXT_expect_assume";
const char* const E_GL_EXT_control_flow_attributes2 = "GL_EXT_control_flow_attributes2";
const char* const E_GL_EXT_spec_constant_composites = "GL_EXT_spec_constant_composites";
const char* const E_GL_EXT_texture_offset_non_const = "GL_EXT_texture_offset_non_const";

// Arrays of extensions for the above viewportEXTs duplications

Expand Down
1 change: 1 addition & 0 deletions gtests/AST.FromFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ INSTANTIATE_TEST_SUITE_P(
"ps_uint_int.frag",
"ps_sample.frag",
"tes_patch.tese",
"textureoffset_non_const.vert",
})),
FileNameAsCustomTestSuffix
);
Expand Down

0 comments on commit e8bce4d

Please sign in to comment.