From c5ae01dcf12b8b70d7ca181f82012e4c9d3fc8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 21 Sep 2020 07:54:12 -0400 Subject: [PATCH] ac,radeonsi: implement GL_NV_compute_shader_derivatives Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- docs/relnotes/new_features.txt | 1 + src/amd/llvm/ac_nir_to_llvm.c | 4 +++- src/gallium/drivers/radeonsi/si_get.c | 1 + src/gallium/drivers/radeonsi/si_shader_nir.c | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt index bfc0c458528..28107e365f5 100644 --- a/docs/relnotes/new_features.txt +++ b/docs/relnotes/new_features.txt @@ -1,4 +1,5 @@ GL_EXT_demote_to_helper_invocation on radeonsi +GL_NV_compute_shader_derivatives on radeonsi EGL_MESA_platform_xcb Removed GL_NV_point_sprite for classic swrast. driconf: remove glx_disable_oml_sync_control, glx_disable_sgi_video_sync, and glx_disable_ext_buffer_age diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index f6969eae9d9..4d5714f1192 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -1430,7 +1430,9 @@ static LLVMValueRef build_tex_intrinsic(struct ac_nir_context *ctx, const nir_te args->level_zero = false; break; case nir_texop_tex: - if (ctx->stage != MESA_SHADER_FRAGMENT) { + if (ctx->stage != MESA_SHADER_FRAGMENT && + (ctx->stage != MESA_SHADER_COMPUTE || + ctx->info->cs.derivative_group == DERIVATIVE_GROUP_NONE)) { assert(!args->lod); args->level_zero = true; } diff --git a/src/gallium/drivers/radeonsi/si_get.c b/src/gallium/drivers/radeonsi/si_get.c index cfc9340b4b5..469443bf7f1 100644 --- a/src/gallium/drivers/radeonsi/si_get.c +++ b/src/gallium/drivers/radeonsi/si_get.c @@ -166,6 +166,7 @@ static int si_get_param(struct pipe_screen *pscreen, enum pipe_cap param) case PIPE_CAP_DEMOTE_TO_HELPER_INVOCATION: case PIPE_CAP_MULTI_DRAW: case PIPE_CAP_PREFER_REAL_BUFFER_IN_CONSTBUF0: + case PIPE_CAP_COMPUTE_SHADER_DERIVATIVES: return 1; case PIPE_CAP_GLSL_ZERO_INIT: diff --git a/src/gallium/drivers/radeonsi/si_shader_nir.c b/src/gallium/drivers/radeonsi/si_shader_nir.c index 0624822b394..ae190b2de59 100644 --- a/src/gallium/drivers/radeonsi/si_shader_nir.c +++ b/src/gallium/drivers/radeonsi/si_shader_nir.c @@ -676,6 +676,24 @@ static void si_lower_nir(struct si_screen *sscreen, struct nir_shader *nir) NIR_PASS_V(nir, nir_lower_system_values); NIR_PASS_V(nir, nir_lower_compute_system_values, NULL); + if (nir->info.stage == MESA_SHADER_COMPUTE) { + if (nir->info.cs.derivative_group == DERIVATIVE_GROUP_QUADS) { + /* If we are shuffling local_invocation_id for quad derivatives, we + * need to derive local_invocation_index from local_invocation_id + * first, so that the value corresponds to the shuffled + * local_invocation_id. + */ + nir_lower_compute_system_values_options options = {0}; + options.lower_local_invocation_index = true; + NIR_PASS_V(nir, nir_lower_compute_system_values, &options); + } + + nir_opt_cse(nir); /* CSE load_local_invocation_id */ + nir_lower_compute_system_values_options options = {0}; + options.shuffle_local_ids_for_quad_derivatives = true; + NIR_PASS_V(nir, nir_lower_compute_system_values, &options); + } + if (nir->info.stage == MESA_SHADER_FRAGMENT && sscreen->info.has_packed_math_16bit && sscreen->b.get_shader_param(&sscreen->b, PIPE_SHADER_FRAGMENT, PIPE_SHADER_CAP_FP16))