[Mesa-dev] [PATCH 4/8] st/mesa: determine states used or affected by shaders at compile time
Marek Olšák
maraeo at gmail.com
Wed Aug 10 11:05:12 UTC 2016
On Tue, Aug 9, 2016 at 12:56 PM, Nicolai Hähnle <nhaehnle at gmail.com> wrote:
> On 07.08.2016 03:12, Marek Olšák wrote:
>>
>> From: Marek Olšák <marek.olsak at amd.com>
>>
>> At compile time, each shader determines which ST_NEW flags should be set
>> at shader bind time.
>>
>> This just sets the new field for all shaders. The next commit will use it.
>> ---
>> src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 175
>> ++++++++++++++++++++++++++++-
>> src/mesa/state_tracker/st_program.c | 37 +++++-
>> src/mesa/state_tracker/st_program.h | 6 +
>> 3 files changed, 215 insertions(+), 3 deletions(-)
>>
>> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> index 362559f..fd14766 100644
>> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
>> @@ -6666,31 +6666,202 @@ get_mesa_program_tgsi(struct gl_context *ctx,
>>
>> static struct gl_program *
>> get_mesa_program(struct gl_context *ctx,
>> struct gl_shader_program *shader_program,
>> struct gl_linked_shader *shader)
>> {
>> struct pipe_screen *pscreen = ctx->st->pipe->screen;
>> unsigned ptarget = st_shader_stage_to_ptarget(shader->Stage);
>> enum pipe_shader_ir preferred_ir = (enum pipe_shader_ir)
>> pscreen->get_shader_param(pscreen, ptarget,
>> PIPE_SHADER_CAP_PREFERRED_IR);
>> + struct gl_program *prog = NULL;
>> +
>> if (preferred_ir == PIPE_SHADER_IR_NIR) {
>> /* TODO only for GLSL VS/FS for now: */
>> switch (shader->Stage) {
>> case MESA_SHADER_VERTEX:
>> case MESA_SHADER_FRAGMENT:
>> - return st_nir_get_mesa_program(ctx, shader_program, shader);
>> + prog = st_nir_get_mesa_program(ctx, shader_program, shader);
>> default:
>> break;
>> }
>> + } else {
>> + prog = get_mesa_program_tgsi(ctx, shader_program, shader);
>> + }
>> +
>> + if (prog) {
>> + uint64_t *states;
>> +
>> + /* This determines which states will be updated when the shader is
>> + * bound.
>> + */
>> + switch (shader->Stage) {
>> + case MESA_SHADER_VERTEX:
>> + states = &((struct st_vertex_program*)prog)->affected_states;
>> +
>> + *states = ST_NEW_VS_STATE |
>> + ST_NEW_RASTERIZER |
>> + ST_NEW_VERTEX_ARRAYS;
>> +
>> + if (prog->Parameters->NumParameters)
>> + *states |= ST_NEW_VS_CONSTANTS;
>> +
>> + if (shader->num_samplers)
>> + *states |= ST_NEW_VS_SAMPLER_VIEWS |
>> + ST_NEW_RENDER_SAMPLERS;
>> +
>> + if (shader->NumImages)
>> + *states |= ST_NEW_VS_IMAGES;
>> +
>> + if (shader->NumUniformBlocks)
>> + *states |= ST_NEW_VS_UBOS;
>> +
>> + if (shader->NumShaderStorageBlocks)
>> + *states |= ST_NEW_VS_SSBOS;
>> +
>> + if (shader->NumAtomicBuffers)
>> + *states |= ST_NEW_VS_ATOMICS;
>
>
> I'm not overly fond of the code duplication here. Perhaps these could all be
> expressed relative to a stage-specific base flag?
Not really. It shouldn't rely on the order the flags are declared. I
can't make it better than this:
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index fd14766..3e5b322 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -6664,6 +6664,37 @@ get_mesa_program_tgsi(struct gl_context *ctx,
return prog;
}
+static void
+set_affected_state_flags(uint64_t *states,
+ struct gl_program *prog,
+ struct gl_linked_shader *shader,
+ uint64_t new_constants,
+ uint64_t new_sampler_views,
+ uint64_t new_samplers,
+ uint64_t new_images,
+ uint64_t new_ubos,
+ uint64_t new_ssbos,
+ uint64_t new_atomics)
+{
+ if (prog->Parameters->NumParameters)
+ *states |= new_constants;
+
+ if (shader->num_samplers)
+ *states |= new_sampler_views | new_samplers;
+
+ if (shader->NumImages)
+ *states |= new_images;
+
+ if (shader->NumUniformBlocks)
+ *states |= new_ubos;
+
+ if (shader->NumShaderStorageBlocks)
+ *states |= new_ssbos;
+
+ if (shader->NumAtomicBuffers)
+ *states |= new_atomics;
+}
+
static struct gl_program *
get_mesa_program(struct gl_context *ctx,
struct gl_shader_program *shader_program,
@@ -6702,24 +6733,14 @@ get_mesa_program(struct gl_context *ctx,
ST_NEW_RASTERIZER |
ST_NEW_VERTEX_ARRAYS;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_VS_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_VS_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_VS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_VS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_VS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_VS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ ST_NEW_VS_CONSTANTS,
+ ST_NEW_VS_SAMPLER_VIEWS,
+ ST_NEW_RENDER_SAMPLERS,
+ ST_NEW_VS_IMAGES,
+ ST_NEW_VS_UBOS,
+ ST_NEW_VS_SSBOS,
+ ST_NEW_VS_ATOMICS);
break;
case MESA_SHADER_TESS_CTRL:
@@ -6727,24 +6748,14 @@ get_mesa_program(struct gl_context *ctx,
*states = ST_NEW_TCS_STATE;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_TCS_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_TCS_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_TCS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_TCS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_TCS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_TCS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ ST_NEW_TCS_CONSTANTS,
+ ST_NEW_TCS_SAMPLER_VIEWS,
+ ST_NEW_RENDER_SAMPLERS,
+ ST_NEW_TCS_IMAGES,
+ ST_NEW_TCS_UBOS,
+ ST_NEW_TCS_SSBOS,
+ ST_NEW_TCS_ATOMICS);
break;
case MESA_SHADER_TESS_EVAL:
@@ -6753,24 +6764,14 @@ get_mesa_program(struct gl_context *ctx,
*states = ST_NEW_TES_STATE |
ST_NEW_RASTERIZER;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_TES_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_TES_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_TES_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_TES_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_TES_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_TES_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ ST_NEW_TES_CONSTANTS,
+ ST_NEW_TES_SAMPLER_VIEWS,
+ ST_NEW_RENDER_SAMPLERS,
+ ST_NEW_TES_IMAGES,
+ ST_NEW_TES_UBOS,
+ ST_NEW_TES_SSBOS,
+ ST_NEW_TES_ATOMICS);
break;
case MESA_SHADER_GEOMETRY:
@@ -6779,24 +6780,14 @@ get_mesa_program(struct gl_context *ctx,
*states = ST_NEW_GS_STATE |
ST_NEW_RASTERIZER;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_GS_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_GS_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_GS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_GS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_GS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_GS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ ST_NEW_GS_CONSTANTS,
+ ST_NEW_GS_SAMPLER_VIEWS,
+ ST_NEW_RENDER_SAMPLERS,
+ ST_NEW_GS_IMAGES,
+ ST_NEW_GS_UBOS,
+ ST_NEW_GS_SSBOS,
+ ST_NEW_GS_ATOMICS);
break;
case MESA_SHADER_FRAGMENT:
@@ -6807,21 +6798,14 @@ get_mesa_program(struct gl_context *ctx,
ST_NEW_SAMPLE_SHADING |
ST_NEW_FS_CONSTANTS;
- if (shader->num_samplers)
- *states |= ST_NEW_FS_SAMPLER_VIEWS |
- ST_NEW_RENDER_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_FS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_FS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_FS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_FS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ ST_NEW_FS_CONSTANTS,
+ ST_NEW_FS_SAMPLER_VIEWS,
+ ST_NEW_RENDER_SAMPLERS,
+ ST_NEW_FS_IMAGES,
+ ST_NEW_FS_UBOS,
+ ST_NEW_FS_SSBOS,
+ ST_NEW_FS_ATOMICS);
break;
case MESA_SHADER_COMPUTE:
@@ -6829,24 +6813,14 @@ get_mesa_program(struct gl_context *ctx,
*states = ST_NEW_CS_STATE;
- if (prog->Parameters->NumParameters)
- *states |= ST_NEW_CS_CONSTANTS;
-
- if (shader->num_samplers)
- *states |= ST_NEW_CS_SAMPLER_VIEWS |
- ST_NEW_CS_SAMPLERS;
-
- if (shader->NumImages)
- *states |= ST_NEW_CS_IMAGES;
-
- if (shader->NumUniformBlocks)
- *states |= ST_NEW_CS_UBOS;
-
- if (shader->NumShaderStorageBlocks)
- *states |= ST_NEW_CS_SSBOS;
-
- if (shader->NumAtomicBuffers)
- *states |= ST_NEW_CS_ATOMICS;
+ set_affected_state_flags(states, prog, shader,
+ ST_NEW_CS_CONSTANTS,
+ ST_NEW_CS_SAMPLER_VIEWS,
+ ST_NEW_CS_SAMPLERS,
+ ST_NEW_CS_IMAGES,
+ ST_NEW_CS_UBOS,
+ ST_NEW_CS_SSBOS,
+ ST_NEW_CS_ATOMICS);
break;
default:
Marek
More information about the mesa-dev
mailing list