From a03e24aa7faafe2dca77150e709727d4276b08cb Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Sat, 27 Jun 2020 22:40:56 +0200 Subject: [PATCH] gallium + mesa/st: Add PIPE_CAP_NIR_ATOMICS_AS_DEREF and use it This cap is useful for drivers that support hardware atomics and need special handling to resolve their addresses. Signed-off-by: Gert Wollny Part-of: --- docs/gallium/screen.rst | 1 + src/gallium/auxiliary/util/u_screen.c | 1 + src/gallium/include/pipe/p_defines.h | 1 + src/mesa/state_tracker/st_glsl_to_nir.cpp | 7 +++++-- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/gallium/screen.rst b/docs/gallium/screen.rst index 2f0b4bf0d88..45c82802cc9 100644 --- a/docs/gallium/screen.rst +++ b/docs/gallium/screen.rst @@ -589,6 +589,7 @@ The integer capabilities: * ``PIPE_CAP_MAP_UNSYNCHRONIZED_THREAD_SAFE``: Whether mapping a buffer as unsynchronized from any thread is safe. * ``PIPE_CAP_GLSL_ZERO_INIT``: Choose a default zero initialization some glsl variables. If `1`, then all glsl shader variables and gl_FragColor are initialized to zero. If `2`, then shader out variables are not initialized but function out variables are. * ``PIPE_CAP_BLEND_EQUATION_ADVANCED``: Driver supports blend equation advanced without necessarily supporting FBFETCH. +* ``PIPE_CAP_NIR_ATOMICS_AS_DEREF``: Whether NIR atomics instructions should reference atomics as NIR derefs instead of by indices. .. _pipe_capf: diff --git a/src/gallium/auxiliary/util/u_screen.c b/src/gallium/auxiliary/util/u_screen.c index ccf2fa8c75d..9f174c58701 100644 --- a/src/gallium/auxiliary/util/u_screen.c +++ b/src/gallium/auxiliary/util/u_screen.c @@ -294,6 +294,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen, case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT: case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX: case PIPE_CAP_TGSI_DIV: + case PIPE_CAP_NIR_ATOMICS_AS_DEREF: return 0; case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION: diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index ddeac139f93..d82ffcd14dc 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -954,6 +954,7 @@ enum pipe_cap PIPE_CAP_MAP_UNSYNCHRONIZED_THREAD_SAFE, PIPE_CAP_GLSL_ZERO_INIT, PIPE_CAP_BLEND_EQUATION_ADVANCED, + PIPE_CAP_NIR_ATOMICS_AS_DEREF, }; /** diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index 17237a62091..99bbbef79db 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -432,6 +432,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog, struct gl_shader_program *shader_program) { nir_shader *nir = prog->nir; + struct pipe_screen *screen = st->pipe->screen; /* Make a pass over the IR to add state references for any built-in * uniforms that are used. This has to be done now (during linking). @@ -486,7 +487,9 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog, !st->ctx->Const.PackedDriverUniformStorage) NIR_PASS_V(nir, st_nir_lower_builtin); - NIR_PASS_V(nir, gl_nir_lower_atomics, shader_program, true); + if (!screen->get_param(screen, PIPE_CAP_NIR_ATOMICS_AS_DEREF)) + NIR_PASS_V(nir, gl_nir_lower_atomics, shader_program, true); + NIR_PASS_V(nir, nir_opt_intrinsics); /* Lower 64-bit ops. */ @@ -508,7 +511,7 @@ st_glsl_to_nir_post_opts(struct st_context *st, struct gl_program *prog, (nir_var_shader_in | nir_var_shader_out | nir_var_function_temp ); nir_remove_dead_variables(nir, mask, NULL); - if (!st->has_hw_atomics) + if (!st->has_hw_atomics && !screen->get_param(screen, PIPE_CAP_NIR_ATOMICS_AS_DEREF)) NIR_PASS_V(nir, nir_lower_atomics_to_ssbo); st_finalize_nir_before_variants(nir); -- 2.30.2