summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Pitoiset <[email protected]>2017-05-10 13:24:01 +0200
committerSamuel Pitoiset <[email protected]>2017-06-14 10:04:36 +0200
commitbf60db5a4ba3893d57e59c8a69516b6519ac0972 (patch)
tree2c53f56a7322389295772bd2e0ced0f48b00ad67
parent064d6263c54cd9a3b0f5954538fa74b5022f22de (diff)
mesa: add update_single_shader_texture_used() helper
This will also be used for looping over bindless samplers bound to texture units. Signed-off-by: Samuel Pitoiset <[email protected]> Reviewed-by: Nicolai Hähnle <[email protected]>
-rw-r--r--src/mesa/main/uniforms.c67
1 files changed, 38 insertions, 29 deletions
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index 67c238e4f37..6706f794d7e 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -63,6 +63,40 @@
* TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
* We'll use that info for state validation before rendering.
*/
+static inline void
+update_single_shader_texture_used(struct gl_shader_program *shProg,
+ struct gl_program *prog,
+ GLuint unit, GLuint target)
+{
+ gl_shader_stage prog_stage =
+ _mesa_program_enum_to_shader_stage(prog->Target);
+
+ assert(unit < ARRAY_SIZE(prog->TexturesUsed));
+ assert(target < NUM_TEXTURE_TARGETS);
+
+ /* From section 7.10 (Samplers) of the OpenGL 4.5 spec:
+ *
+ * "It is not allowed to have variables of different sampler types pointing
+ * to the same texture image unit within a program object."
+ */
+ unsigned stages_mask = shProg->data->linked_stages;
+ while (stages_mask) {
+ const int stage = u_bit_scan(&stages_mask);
+
+ /* Skip validation if we are yet to update textures used in this
+ * stage.
+ */
+ if (prog_stage < stage)
+ break;
+
+ struct gl_program *glprog = shProg->_LinkedShaders[stage]->Program;
+ if (glprog->TexturesUsed[unit] & ~(1 << target))
+ shProg->SamplersValidated = GL_FALSE;
+ }
+
+ prog->TexturesUsed[unit] |= (1 << target);
+}
+
void
_mesa_update_shader_textures_used(struct gl_shader_program *shProg,
struct gl_program *prog)
@@ -78,35 +112,10 @@ _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
while (mask) {
const int s = u_bit_scan(&mask);
- GLuint unit = prog->SamplerUnits[s];
- GLuint tgt = prog->sh.SamplerTargets[s];
- assert(unit < ARRAY_SIZE(prog->TexturesUsed));
- assert(tgt < NUM_TEXTURE_TARGETS);
-
- /* The types of the samplers associated with a particular texture
- * unit must be an exact match. Page 74 (page 89 of the PDF) of the
- * OpenGL 3.3 core spec says:
- *
- * "It is not allowed to have variables of different sampler
- * types pointing to the same texture image unit within a program
- * object."
- */
- unsigned stages_mask = shProg->data->linked_stages;
- while (stages_mask) {
- const int stage = u_bit_scan(&stages_mask);
-
- /* Skip validation if we are yet to update textures used in this
- * stage.
- */
- if (prog_stage < stage)
- break;
-
- struct gl_program *glprog = shProg->_LinkedShaders[stage]->Program;
- if (glprog->TexturesUsed[unit] & ~(1 << tgt))
- shProg->SamplersValidated = GL_FALSE;
- }
-
- prog->TexturesUsed[unit] |= (1 << tgt);
+
+ update_single_shader_texture_used(shProg, prog,
+ prog->SamplerUnits[s],
+ prog->sh.SamplerTargets[s]);
}
}