mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-18 05:18:09 +00:00
[client] egl: switch to using GL_TEXTURE_EXTERNAL_OES for DMABUF
According to Erik @ NVidia the open source NVidia driver will not create a EGLImage from a DMABUF if the target is not GL_TEXTURE_EXTERNAL_OES. This change set converts the dmabuf texture from GL_TEXTURE_2D to GL_TEXTURE_EXTERNAL_OES and at runtime performs a global search & replace on fragment shaders as needed to remain compatible, replacing `sampler2D` with `samplerExternalOES`. Ref: https://github.com/NVIDIA/open-gpu-kernel-modules/discussions/243#discussioncomment-3283415
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
#if __VERSION__ == 300
|
||||
vec4 textureGather(sampler2D tex, vec2 uv, int comp)
|
||||
{
|
||||
vec4 c0 = textureOffset(tex, uv, ivec2(0,1));
|
||||
vec4 c1 = textureOffset(tex, uv, ivec2(1,1));
|
||||
vec4 c2 = textureOffset(tex, uv, ivec2(1,0));
|
||||
vec4 c3 = textureOffset(tex, uv, ivec2(0,0));
|
||||
vec2 res = vec2(textureSize(tex, 0));
|
||||
ivec2 p = ivec2((uv * res) - 0.5f);
|
||||
|
||||
// NOTE: we can't use texelFecthOffset because sampler2D may actually be samplerExternalOES
|
||||
vec4 c0 = texelFetch(tex, p+ivec2(0,1), 0);
|
||||
vec4 c1 = texelFetch(tex, p+ivec2(1,1), 0);
|
||||
vec4 c2 = texelFetch(tex, p+ivec2(1,0), 0);
|
||||
vec4 c3 = texelFetch(tex, p+ivec2(0,0), 0);
|
||||
|
||||
return vec4(c0[comp], c1[comp], c2[comp],c3[comp]);
|
||||
}
|
||||
#elif __VERSION__ < 300
|
||||
vec4 textureGather(sampler2D tex, vec2 uv, int comp)
|
||||
{
|
||||
vec4 c3 = texture2D(tex, uv);
|
||||
vec4 c3 = texture(tex, uv);
|
||||
return vec4(c3[comp], c3[comp], c3[comp],c3[comp]);
|
||||
}
|
||||
#endif
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#version 300 es
|
||||
#extension GL_OES_EGL_image_external_essl3 : enable
|
||||
|
||||
precision highp float;
|
||||
|
||||
#define EGL_SCALE_AUTO 0
|
||||
@@ -23,13 +25,17 @@ void main()
|
||||
switch (scaleAlgo)
|
||||
{
|
||||
case EGL_SCALE_NEAREST:
|
||||
{
|
||||
vec2 ts = vec2(textureSize(sampler1, 0));
|
||||
color = texelFetch(sampler1, ivec2(uv * ts), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case EGL_SCALE_LINEAR:
|
||||
{
|
||||
color = texture(sampler1, uv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cbMode > 0)
|
||||
|
@@ -1,10 +1,12 @@
|
||||
#version 300 es
|
||||
#extension GL_OES_EGL_image_external_essl3 : enable
|
||||
|
||||
precision highp float;
|
||||
|
||||
in vec2 fragCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D sampler1;
|
||||
uniform vec3 uConfig;
|
||||
|
||||
void main()
|
||||
@@ -13,7 +15,7 @@ void main()
|
||||
float vOffset = uConfig.y;
|
||||
float hOffset = uConfig.z;
|
||||
|
||||
vec2 inRes = vec2(textureSize(texture, 0));
|
||||
vec2 inRes = vec2(textureSize(sampler1, 0));
|
||||
ivec2 point = ivec2(
|
||||
(floor((fragCoord * inRes) / pixelSize) * pixelSize) +
|
||||
pixelSize / 2.0f
|
||||
@@ -22,5 +24,5 @@ void main()
|
||||
point.x += int(pixelSize * hOffset);
|
||||
point.y += int(pixelSize * vOffset);
|
||||
|
||||
fragColor = texelFetch(texture, point, 0);
|
||||
fragColor = texelFetch(sampler1, point, 0);
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#version 300 es
|
||||
#extension GL_OES_EGL_image_external_essl3 : enable
|
||||
|
||||
precision highp float;
|
||||
|
||||
#define PI 3.141592653589793
|
||||
@@ -6,7 +8,7 @@ precision highp float;
|
||||
in vec2 fragCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D sampler1;
|
||||
float sinc(float x)
|
||||
{
|
||||
return x == 0.0 ? 1.0 : sin(x * PI) / (x * PI);
|
||||
@@ -24,7 +26,7 @@ float lanczos(vec2 v)
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 size = vec2(textureSize(texture, 0));
|
||||
vec2 size = vec2(textureSize(sampler1, 0));
|
||||
vec2 pos = fragCoord * size;
|
||||
vec2 invSize = 1.0 / size;
|
||||
vec2 uvc = floor(pos) + vec2(0.5, 0.5);
|
||||
@@ -54,7 +56,7 @@ void main()
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
for (int i = 0; i < 9; ++i)
|
||||
color += texture2D(texture, uvs[i] * invSize).rgb * factors[i];
|
||||
color += texture(sampler1, uvs[i] * invSize).rgb * factors[i];
|
||||
|
||||
fragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
@@ -1,12 +1,14 @@
|
||||
#version 300 es
|
||||
#extension GL_OES_EGL_image_external_essl3 : enable
|
||||
|
||||
precision highp float;
|
||||
|
||||
in vec2 fragCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D sampler1;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = texture2D(texture, fragCoord);
|
||||
fragColor = texture(sampler1, fragCoord);
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#version 300 es
|
||||
#extension GL_OES_EGL_image_external_essl3 : enable
|
||||
|
||||
precision highp float;
|
||||
|
||||
#include "compat.h"
|
||||
@@ -6,7 +8,7 @@ precision highp float;
|
||||
in vec2 fragCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D sampler1;
|
||||
uniform uvec4 uConsts[2];
|
||||
|
||||
#define A_GPU 1
|
||||
@@ -16,7 +18,7 @@ uniform uvec4 uConsts[2];
|
||||
|
||||
vec3 imageLoad(ivec2 point)
|
||||
{
|
||||
return texelFetch(texture, point, 0).rgb;
|
||||
return texelFetch(sampler1, point, 0).rgb;
|
||||
}
|
||||
|
||||
AF3 CasLoad(ASU2 p)
|
||||
@@ -30,7 +32,7 @@ void CasInput(inout AF1 r,inout AF1 g,inout AF1 b) {}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 res = vec2(textureSize(texture, 0));
|
||||
vec2 res = vec2(textureSize(sampler1, 0));
|
||||
uvec2 point = uvec2(fragCoord * res);
|
||||
|
||||
CasFilter(
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#version 300 es
|
||||
#extension GL_OES_EGL_image_external_essl3 : enable
|
||||
|
||||
precision highp float;
|
||||
|
||||
#include "compat.h"
|
||||
@@ -6,7 +8,7 @@ precision highp float;
|
||||
in vec2 fragCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D sampler1;
|
||||
uniform vec2 uOutRes;
|
||||
uniform uvec4 uConsts[4];
|
||||
|
||||
@@ -18,20 +20,9 @@ uniform uvec4 uConsts[4];
|
||||
|
||||
#define FSR_EASU_F 1
|
||||
|
||||
vec4 _textureGather(sampler2D tex, vec2 uv, int comp)
|
||||
{
|
||||
vec2 res = vec2(textureSize(tex, 0));
|
||||
ivec2 p = ivec2((uv * res) - 0.5f);
|
||||
vec4 c0 = texelFetchOffset(tex, p, 0, ivec2(0,1));
|
||||
vec4 c1 = texelFetchOffset(tex, p, 0, ivec2(1,1));
|
||||
vec4 c2 = texelFetchOffset(tex, p, 0, ivec2(1,0));
|
||||
vec4 c3 = texelFetchOffset(tex, p, 0, ivec2(0,0));
|
||||
return vec4(c0[comp], c1[comp], c2[comp],c3[comp]);
|
||||
}
|
||||
|
||||
AF4 FsrEasuRF(AF2 p){return AF4(_textureGather(texture, p, 0));}
|
||||
AF4 FsrEasuGF(AF2 p){return AF4(_textureGather(texture, p, 1));}
|
||||
AF4 FsrEasuBF(AF2 p){return AF4(_textureGather(texture, p, 2));}
|
||||
AF4 FsrEasuRF(AF2 p){return AF4(textureGather(sampler1, p, 0));}
|
||||
AF4 FsrEasuGF(AF2 p){return AF4(textureGather(sampler1, p, 1));}
|
||||
AF4 FsrEasuBF(AF2 p){return AF4(textureGather(sampler1, p, 2));}
|
||||
|
||||
#include "ffx_fsr1.h"
|
||||
|
||||
|
@@ -6,7 +6,7 @@ precision highp float;
|
||||
in vec2 fragCoord;
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D sampler1;
|
||||
uniform uvec4 uConsts;
|
||||
|
||||
#define A_GPU 1
|
||||
@@ -15,7 +15,7 @@ uniform uvec4 uConsts;
|
||||
|
||||
#include "ffx_a.h"
|
||||
|
||||
AF4 FsrRcasLoadF(ASU2 p) { return texelFetch(texture, ASU2(p), 0); }
|
||||
AF4 FsrRcasLoadF(ASU2 p) { return texelFetch(sampler1, ASU2(p), 0); }
|
||||
void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b) {}
|
||||
|
||||
#define FSR_RCAS_F 1
|
||||
@@ -24,7 +24,7 @@ void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b) {}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 inRes = vec2(textureSize(texture, 0));
|
||||
vec2 inRes = vec2(textureSize(sampler1, 0));
|
||||
uvec2 point = uvec2(fragCoord * (inRes + 0.5f));
|
||||
|
||||
FsrRcasF(fragColor.r, fragColor.g, fragColor.b, point, uConsts);
|
||||
|
Reference in New Issue
Block a user