mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-08 17:50:10 +00:00
gpu: Encode number of textures use in every shader
Just define GSK_N_TEXTURES in every glsl file, extract that #define in the python parser and emit a static const uint variable "{shader_name}_n_textures" in the generated header.
This commit is contained in:
parent
68baa93460
commit
b481fd854f
@ -7,6 +7,7 @@ import os
|
||||
name = os.path.splitext(os.path.splitext(os.path.basename(sys.argv[1]))[0])[0][6:]
|
||||
var_name = "gsk_gpu_" + name.replace('-', '_')
|
||||
struct_name = "GskGpu" + name.title().replace('-', '') + "Instance"
|
||||
n_textures = -1
|
||||
filename = sys.argv[1]
|
||||
|
||||
with open(filename) as f:
|
||||
@ -14,6 +15,10 @@ with open(filename) as f:
|
||||
matches = []
|
||||
|
||||
for pos, line in enumerate (lines):
|
||||
match = re.search(r"^#define GSK_N_TEXTURES ([0-9]+)$", line)
|
||||
if match:
|
||||
n_textures = int(match.group(1))
|
||||
|
||||
match = re.search(r"^IN\(([0-9]+)\) ([a-z0-9]+) ([a-zA-Z0-9_]+);$", line)
|
||||
if not match:
|
||||
if re.search(r"layout.*\sin\s.*", line):
|
||||
@ -26,9 +31,16 @@ with open(filename) as f:
|
||||
'location': int(match.group(1)),
|
||||
'type': match.group(2)})
|
||||
|
||||
if n_textures < 0:
|
||||
raise Exception(f'''{filename}: GSK_N_TEXTURES not defined''')
|
||||
if n_textures > 2:
|
||||
raise Exception(f'''{filename}: GSK_N_TEXTURES must be <= 2''')
|
||||
|
||||
print(f'''/* This file is auto-generated; any change will not be preserved */
|
||||
#pragma once
|
||||
|
||||
#define {var_name}_n_textures {n_textures}
|
||||
|
||||
typedef struct _{struct_name} {struct_name};
|
||||
|
||||
struct _{struct_name} {{''')
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 2
|
||||
|
||||
#include "common.glsl"
|
||||
#include "blendmode.glsl"
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 1
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
/* blur radius (aka in_blur_direction) 0 is NOT supported and MUST be caught before */
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 0
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
PASS(0) vec2 _pos;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 0
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
/* blur radius (aka in_blur_direction) 0 is NOT supported and MUST be caught before */
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 0
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
PASS(0) vec2 _pos;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 1
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
PASS(0) vec2 _pos;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 1
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
PASS_FLAT(0) mat4 _color_matrix;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 0
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
#define VARIATION_SUPERSAMPLING ((GSK_VARIATION & (1u << 0)) == (1u << 0))
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 1
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
#define VARIATION_OPACITY (1u << 0)
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 2
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
PASS(0) vec2 _pos;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 0
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
#define VARIATION_SUPERSAMPLING ((GSK_VARIATION & (1u << 0)) == (1u << 0))
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 2
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
#define VARIATION_MASK_MODE GSK_VARIATION
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 0
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
#define VARIATION_SUPERSAMPLING ((GSK_VARIATION & (1u << 0)) == (1u << 0))
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 0
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
PASS(0) vec2 _pos;
|
||||
|
@ -1,3 +1,5 @@
|
||||
#define GSK_N_TEXTURES 1
|
||||
|
||||
#include "common.glsl"
|
||||
|
||||
PASS(0) vec2 _pos;
|
||||
|
Loading…
Reference in New Issue
Block a user