2018-03-09 16:58:10 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2016 Red Hat.
|
|
|
|
|
* Copyright © 2016 Bas Nieuwenhuizen
|
|
|
|
|
*
|
|
|
|
|
* based in part on anv driver which is:
|
|
|
|
|
* Copyright © 2015 Intel Corporation
|
|
|
|
|
*
|
2024-04-05 16:28:39 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-03-09 16:58:10 +01:00
|
|
|
*/
|
|
|
|
|
|
2024-04-02 17:29:51 +02:00
|
|
|
#include "radv_nir_to_llvm.h"
|
2018-03-09 16:58:10 +01:00
|
|
|
#include "nir/nir.h"
|
2020-03-12 14:49:55 +01:00
|
|
|
#include "radv_debug.h"
|
2021-06-11 12:20:59 +02:00
|
|
|
#include "radv_llvm_helper.h"
|
2018-03-13 14:34:35 +01:00
|
|
|
#include "radv_shader.h"
|
2019-11-11 12:50:12 +01:00
|
|
|
#include "radv_shader_args.h"
|
2018-03-09 16:58:10 +01:00
|
|
|
|
|
|
|
|
#include "ac_binary.h"
|
|
|
|
|
#include "ac_llvm_build.h"
|
2021-12-12 20:20:36 -05:00
|
|
|
#include "ac_nir.h"
|
2021-04-22 15:59:22 +02:00
|
|
|
#include "ac_nir_to_llvm.h"
|
2018-03-09 16:58:10 +01:00
|
|
|
#include "ac_shader_abi.h"
|
|
|
|
|
#include "ac_shader_util.h"
|
|
|
|
|
#include "sid.h"
|
|
|
|
|
|
|
|
|
|
struct radv_shader_context {
|
|
|
|
|
struct ac_llvm_context ac;
|
2019-08-28 17:08:29 +02:00
|
|
|
const struct nir_shader *shader;
|
2018-03-09 16:58:10 +01:00
|
|
|
struct ac_shader_abi abi;
|
2021-10-08 16:14:15 +02:00
|
|
|
const struct radv_nir_compiler_options *options;
|
2021-10-27 11:20:15 +02:00
|
|
|
const struct radv_shader_info *shader_info;
|
2019-11-11 12:50:12 +01:00
|
|
|
const struct radv_shader_args *args;
|
|
|
|
|
|
|
|
|
|
gl_shader_stage stage;
|
2018-03-09 16:58:10 +01:00
|
|
|
|
|
|
|
|
unsigned max_workgroup_size;
|
|
|
|
|
LLVMContextRef context;
|
2022-10-04 15:15:54 +02:00
|
|
|
struct ac_llvm_pointer main_function;
|
2018-03-09 16:58:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static inline struct radv_shader_context *
|
|
|
|
|
radv_shader_context_from_abi(struct ac_shader_abi *abi)
|
|
|
|
|
{
|
2020-12-05 11:56:45 -08:00
|
|
|
return container_of(abi, struct radv_shader_context, abi);
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
2022-10-04 15:15:54 +02:00
|
|
|
static struct ac_llvm_pointer
|
2019-11-11 12:50:12 +01:00
|
|
|
create_llvm_function(struct ac_llvm_context *ctx, LLVMModuleRef module, LLVMBuilderRef builder,
|
|
|
|
|
const struct ac_shader_args *args, enum ac_llvm_calling_convention convention,
|
2018-05-18 10:43:06 +02:00
|
|
|
unsigned max_workgroup_size, const struct radv_nir_compiler_options *options)
|
2018-03-09 16:58:10 +01:00
|
|
|
{
|
2022-10-04 15:15:54 +02:00
|
|
|
struct ac_llvm_pointer main_function = ac_build_main(args, ctx, convention, "main", ctx->voidt, module);
|
2018-03-09 16:58:10 +01:00
|
|
|
|
2023-05-31 14:19:14 -04:00
|
|
|
if (options->info->address32_hi) {
|
2022-10-04 15:15:54 +02:00
|
|
|
ac_llvm_add_target_dep_function_attr(main_function.value, "amdgpu-32bit-address-high-bits",
|
2023-05-31 14:19:14 -04:00
|
|
|
options->info->address32_hi);
|
2018-05-16 16:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-04 15:15:54 +02:00
|
|
|
ac_llvm_set_workgroup_size(main_function.value, max_workgroup_size);
|
2023-06-10 23:04:30 +02:00
|
|
|
ac_llvm_set_target_features(main_function.value, ctx, true);
|
2019-05-31 15:38:39 -04:00
|
|
|
|
2018-03-09 16:58:10 +01:00
|
|
|
return main_function;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-11 12:50:12 +01:00
|
|
|
static enum ac_llvm_calling_convention
|
|
|
|
|
get_llvm_calling_convention(LLVMValueRef func, gl_shader_stage stage)
|
2018-03-09 16:58:10 +01:00
|
|
|
{
|
|
|
|
|
switch (stage) {
|
|
|
|
|
case MESA_SHADER_VERTEX:
|
|
|
|
|
case MESA_SHADER_TESS_EVAL:
|
2019-11-11 12:50:12 +01:00
|
|
|
return AC_LLVM_AMDGPU_VS;
|
2018-03-09 16:58:10 +01:00
|
|
|
break;
|
|
|
|
|
case MESA_SHADER_GEOMETRY:
|
2019-11-11 12:50:12 +01:00
|
|
|
return AC_LLVM_AMDGPU_GS;
|
2018-03-09 16:58:10 +01:00
|
|
|
break;
|
|
|
|
|
case MESA_SHADER_TESS_CTRL:
|
2019-11-11 12:50:12 +01:00
|
|
|
return AC_LLVM_AMDGPU_HS;
|
2018-03-09 16:58:10 +01:00
|
|
|
break;
|
|
|
|
|
case MESA_SHADER_FRAGMENT:
|
2019-11-11 12:50:12 +01:00
|
|
|
return AC_LLVM_AMDGPU_PS;
|
2018-03-09 16:58:10 +01:00
|
|
|
break;
|
|
|
|
|
case MESA_SHADER_COMPUTE:
|
2019-11-11 12:50:12 +01:00
|
|
|
return AC_LLVM_AMDGPU_CS;
|
2018-03-09 16:58:10 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
unreachable("Unhandle shader type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 08:33:06 +02:00
|
|
|
/* Returns whether the stage is a stage that can be directly before the GS */
|
|
|
|
|
static bool
|
|
|
|
|
is_pre_gs_stage(gl_shader_stage stage)
|
|
|
|
|
{
|
|
|
|
|
return stage == MESA_SHADER_VERTEX || stage == MESA_SHADER_TESS_EVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-11 12:50:12 +01:00
|
|
|
static void
|
|
|
|
|
create_function(struct radv_shader_context *ctx, gl_shader_stage stage, bool has_previous_stage)
|
|
|
|
|
{
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx->ac.gfx_level >= GFX10) {
|
2021-10-08 16:14:15 +02:00
|
|
|
if (is_pre_gs_stage(stage) && ctx->shader_info->is_ngg) {
|
2022-05-17 19:18:37 +02:00
|
|
|
/* On GFX10+, VS and TES are merged into GS for NGG. */
|
2019-11-11 12:50:12 +01:00
|
|
|
stage = MESA_SHADER_GEOMETRY;
|
|
|
|
|
has_previous_stage = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx->main_function = create_llvm_function(&ctx->ac, ctx->ac.module, ctx->ac.builder, &ctx->args->ac,
|
2022-10-04 15:15:54 +02:00
|
|
|
get_llvm_calling_convention(ctx->main_function.value, stage),
|
2021-10-08 16:14:15 +02:00
|
|
|
ctx->max_workgroup_size, ctx->options);
|
2019-11-11 12:50:12 +01:00
|
|
|
|
2021-10-08 16:14:15 +02:00
|
|
|
if (stage == MESA_SHADER_TESS_CTRL || (stage == MESA_SHADER_VERTEX && ctx->shader_info->vs.as_ls) ||
|
2022-05-17 19:18:37 +02:00
|
|
|
ctx->shader_info->is_ngg ||
|
2018-03-09 16:58:10 +01:00
|
|
|
/* GFX9 has the ESGS ring buffer in LDS. */
|
|
|
|
|
(stage == MESA_SHADER_GEOMETRY && has_previous_stage)) {
|
|
|
|
|
ac_declare_lds_as_pointer(&ctx->ac);
|
2021-04-10 03:24:05 +02:00
|
|
|
}
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-25 02:13:27 -05:00
|
|
|
static LLVMValueRef
|
|
|
|
|
radv_load_base_vertex(struct ac_shader_abi *abi, bool non_indexed_is_zero)
|
2018-03-09 16:58:10 +01:00
|
|
|
{
|
2019-11-11 12:50:12 +01:00
|
|
|
struct radv_shader_context *ctx = radv_shader_context_from_abi(abi);
|
|
|
|
|
return ac_get_arg(&ctx->ac, ctx->args->ac.base_vertex);
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-10 14:44:52 +00:00
|
|
|
static LLVMValueRef
|
radv,aco: lower buffer descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 75420 (46.47% of 162293) affected shaders:
MaxWaves: 1878200 -> 1879228 (+0.05%); split: +0.06%, -0.00%
Instrs: 54021103 -> 54141370 (+0.22%); split: -0.04%, +0.26%
CodeSize: 287813520 -> 288293352 (+0.17%); split: -0.04%, +0.21%
VGPRs: 3267576 -> 3266296 (-0.04%); split: -0.04%, +0.00%
SpillSGPRs: 10445 -> 10904 (+4.39%); split: -0.31%, +4.70%
SpillVGPRs: 1818 -> 1811 (-0.39%); split: -1.05%, +0.66%
Scratch: 955392 -> 954368 (-0.11%)
Latency: 563477854 -> 562131282 (-0.24%); split: -0.31%, +0.08%
InvThroughput: 111860104 -> 111553968 (-0.27%); split: -0.30%, +0.02%
VClause: 958432 -> 961415 (+0.31%); split: -0.34%, +0.65%
SClause: 1917415 -> 1926952 (+0.50%); split: -0.69%, +1.19%
Copies: 3812945 -> 3916758 (+2.72%); split: -0.27%, +2.99%
Branches: 1611235 -> 1612022 (+0.05%); split: -0.04%, +0.08%
PreSGPRs: 3095505 -> 3126580 (+1.00%); split: -0.06%, +1.07%
PreVGPRs: 2773011 -> 2773013 (+0.00%)
Most regressions seem to be because ACO's convert_pointer_to_64_bit()
can't be CSE'd with radv_nir_apply_pipeline_layout()'s
convert_pointer_to_64_bit(). This should be improved by later commits.
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-04 14:06:47 +01:00
|
|
|
radv_load_rsrc(struct radv_shader_context *ctx, LLVMValueRef ptr, LLVMTypeRef type)
|
2021-03-10 14:44:52 +00:00
|
|
|
{
|
radv,aco: lower buffer descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 75420 (46.47% of 162293) affected shaders:
MaxWaves: 1878200 -> 1879228 (+0.05%); split: +0.06%, -0.00%
Instrs: 54021103 -> 54141370 (+0.22%); split: -0.04%, +0.26%
CodeSize: 287813520 -> 288293352 (+0.17%); split: -0.04%, +0.21%
VGPRs: 3267576 -> 3266296 (-0.04%); split: -0.04%, +0.00%
SpillSGPRs: 10445 -> 10904 (+4.39%); split: -0.31%, +4.70%
SpillVGPRs: 1818 -> 1811 (-0.39%); split: -1.05%, +0.66%
Scratch: 955392 -> 954368 (-0.11%)
Latency: 563477854 -> 562131282 (-0.24%); split: -0.31%, +0.08%
InvThroughput: 111860104 -> 111553968 (-0.27%); split: -0.30%, +0.02%
VClause: 958432 -> 961415 (+0.31%); split: -0.34%, +0.65%
SClause: 1917415 -> 1926952 (+0.50%); split: -0.69%, +1.19%
Copies: 3812945 -> 3916758 (+2.72%); split: -0.27%, +2.99%
Branches: 1611235 -> 1612022 (+0.05%); split: -0.04%, +0.08%
PreSGPRs: 3095505 -> 3126580 (+1.00%); split: -0.06%, +1.07%
PreVGPRs: 2773011 -> 2773013 (+0.00%)
Most regressions seem to be because ACO's convert_pointer_to_64_bit()
can't be CSE'd with radv_nir_apply_pipeline_layout()'s
convert_pointer_to_64_bit(). This should be improved by later commits.
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-04 14:06:47 +01:00
|
|
|
if (ptr && LLVMTypeOf(ptr) == ctx->ac.i32) {
|
|
|
|
|
LLVMValueRef result;
|
|
|
|
|
|
|
|
|
|
LLVMTypeRef ptr_type = LLVMPointerType(type, AC_ADDR_SPACE_CONST_32BIT);
|
|
|
|
|
ptr = LLVMBuildIntToPtr(ctx->ac.builder, ptr, ptr_type, "");
|
|
|
|
|
LLVMSetMetadata(ptr, ctx->ac.uniform_md_kind, ctx->ac.empty_md);
|
|
|
|
|
|
2022-10-11 10:48:01 +02:00
|
|
|
result = LLVMBuildLoad2(ctx->ac.builder, type, ptr, "");
|
radv,aco: lower buffer descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 75420 (46.47% of 162293) affected shaders:
MaxWaves: 1878200 -> 1879228 (+0.05%); split: +0.06%, -0.00%
Instrs: 54021103 -> 54141370 (+0.22%); split: -0.04%, +0.26%
CodeSize: 287813520 -> 288293352 (+0.17%); split: -0.04%, +0.21%
VGPRs: 3267576 -> 3266296 (-0.04%); split: -0.04%, +0.00%
SpillSGPRs: 10445 -> 10904 (+4.39%); split: -0.31%, +4.70%
SpillVGPRs: 1818 -> 1811 (-0.39%); split: -1.05%, +0.66%
Scratch: 955392 -> 954368 (-0.11%)
Latency: 563477854 -> 562131282 (-0.24%); split: -0.31%, +0.08%
InvThroughput: 111860104 -> 111553968 (-0.27%); split: -0.30%, +0.02%
VClause: 958432 -> 961415 (+0.31%); split: -0.34%, +0.65%
SClause: 1917415 -> 1926952 (+0.50%); split: -0.69%, +1.19%
Copies: 3812945 -> 3916758 (+2.72%); split: -0.27%, +2.99%
Branches: 1611235 -> 1612022 (+0.05%); split: -0.04%, +0.08%
PreSGPRs: 3095505 -> 3126580 (+1.00%); split: -0.06%, +1.07%
PreVGPRs: 2773011 -> 2773013 (+0.00%)
Most regressions seem to be because ACO's convert_pointer_to_64_bit()
can't be CSE'd with radv_nir_apply_pipeline_layout()'s
convert_pointer_to_64_bit(). This should be improved by later commits.
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-04 14:06:47 +01:00
|
|
|
LLVMSetMetadata(result, ctx->ac.invariant_load_md_kind, ctx->ac.empty_md);
|
|
|
|
|
|
|
|
|
|
return result;
|
2021-03-10 14:44:52 +00:00
|
|
|
}
|
radv,aco: lower buffer descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 75420 (46.47% of 162293) affected shaders:
MaxWaves: 1878200 -> 1879228 (+0.05%); split: +0.06%, -0.00%
Instrs: 54021103 -> 54141370 (+0.22%); split: -0.04%, +0.26%
CodeSize: 287813520 -> 288293352 (+0.17%); split: -0.04%, +0.21%
VGPRs: 3267576 -> 3266296 (-0.04%); split: -0.04%, +0.00%
SpillSGPRs: 10445 -> 10904 (+4.39%); split: -0.31%, +4.70%
SpillVGPRs: 1818 -> 1811 (-0.39%); split: -1.05%, +0.66%
Scratch: 955392 -> 954368 (-0.11%)
Latency: 563477854 -> 562131282 (-0.24%); split: -0.31%, +0.08%
InvThroughput: 111860104 -> 111553968 (-0.27%); split: -0.30%, +0.02%
VClause: 958432 -> 961415 (+0.31%); split: -0.34%, +0.65%
SClause: 1917415 -> 1926952 (+0.50%); split: -0.69%, +1.19%
Copies: 3812945 -> 3916758 (+2.72%); split: -0.27%, +2.99%
Branches: 1611235 -> 1612022 (+0.05%); split: -0.04%, +0.08%
PreSGPRs: 3095505 -> 3126580 (+1.00%); split: -0.06%, +1.07%
PreVGPRs: 2773011 -> 2773013 (+0.00%)
Most regressions seem to be because ACO's convert_pointer_to_64_bit()
can't be CSE'd with radv_nir_apply_pipeline_layout()'s
convert_pointer_to_64_bit(). This should be improved by later commits.
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-04 14:06:47 +01:00
|
|
|
|
|
|
|
|
return ptr;
|
2021-03-10 14:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-09 16:58:10 +01:00
|
|
|
static LLVMValueRef
|
radv,aco: lower buffer descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 75420 (46.47% of 162293) affected shaders:
MaxWaves: 1878200 -> 1879228 (+0.05%); split: +0.06%, -0.00%
Instrs: 54021103 -> 54141370 (+0.22%); split: -0.04%, +0.26%
CodeSize: 287813520 -> 288293352 (+0.17%); split: -0.04%, +0.21%
VGPRs: 3267576 -> 3266296 (-0.04%); split: -0.04%, +0.00%
SpillSGPRs: 10445 -> 10904 (+4.39%); split: -0.31%, +4.70%
SpillVGPRs: 1818 -> 1811 (-0.39%); split: -1.05%, +0.66%
Scratch: 955392 -> 954368 (-0.11%)
Latency: 563477854 -> 562131282 (-0.24%); split: -0.31%, +0.08%
InvThroughput: 111860104 -> 111553968 (-0.27%); split: -0.30%, +0.02%
VClause: 958432 -> 961415 (+0.31%); split: -0.34%, +0.65%
SClause: 1917415 -> 1926952 (+0.50%); split: -0.69%, +1.19%
Copies: 3812945 -> 3916758 (+2.72%); split: -0.27%, +2.99%
Branches: 1611235 -> 1612022 (+0.05%); split: -0.04%, +0.08%
PreSGPRs: 3095505 -> 3126580 (+1.00%); split: -0.06%, +1.07%
PreVGPRs: 2773011 -> 2773013 (+0.00%)
Most regressions seem to be because ACO's convert_pointer_to_64_bit()
can't be CSE'd with radv_nir_apply_pipeline_layout()'s
convert_pointer_to_64_bit(). This should be improved by later commits.
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-04 14:06:47 +01:00
|
|
|
radv_load_ubo(struct ac_shader_abi *abi, LLVMValueRef buffer_ptr)
|
2018-03-09 16:58:10 +01:00
|
|
|
{
|
|
|
|
|
struct radv_shader_context *ctx = radv_shader_context_from_abi(abi);
|
radv,aco: lower buffer descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 75420 (46.47% of 162293) affected shaders:
MaxWaves: 1878200 -> 1879228 (+0.05%); split: +0.06%, -0.00%
Instrs: 54021103 -> 54141370 (+0.22%); split: -0.04%, +0.26%
CodeSize: 287813520 -> 288293352 (+0.17%); split: -0.04%, +0.21%
VGPRs: 3267576 -> 3266296 (-0.04%); split: -0.04%, +0.00%
SpillSGPRs: 10445 -> 10904 (+4.39%); split: -0.31%, +4.70%
SpillVGPRs: 1818 -> 1811 (-0.39%); split: -1.05%, +0.66%
Scratch: 955392 -> 954368 (-0.11%)
Latency: 563477854 -> 562131282 (-0.24%); split: -0.31%, +0.08%
InvThroughput: 111860104 -> 111553968 (-0.27%); split: -0.30%, +0.02%
VClause: 958432 -> 961415 (+0.31%); split: -0.34%, +0.65%
SClause: 1917415 -> 1926952 (+0.50%); split: -0.69%, +1.19%
Copies: 3812945 -> 3916758 (+2.72%); split: -0.27%, +2.99%
Branches: 1611235 -> 1612022 (+0.05%); split: -0.04%, +0.08%
PreSGPRs: 3095505 -> 3126580 (+1.00%); split: -0.06%, +1.07%
PreVGPRs: 2773011 -> 2773013 (+0.00%)
Most regressions seem to be because ACO's convert_pointer_to_64_bit()
can't be CSE'd with radv_nir_apply_pipeline_layout()'s
convert_pointer_to_64_bit(). This should be improved by later commits.
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-04 14:06:47 +01:00
|
|
|
return radv_load_rsrc(ctx, buffer_ptr, ctx->ac.v4i32);
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2020-09-28 15:47:38 +02:00
|
|
|
static LLVMValueRef
|
radv,aco: lower buffer descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 75420 (46.47% of 162293) affected shaders:
MaxWaves: 1878200 -> 1879228 (+0.05%); split: +0.06%, -0.00%
Instrs: 54021103 -> 54141370 (+0.22%); split: -0.04%, +0.26%
CodeSize: 287813520 -> 288293352 (+0.17%); split: -0.04%, +0.21%
VGPRs: 3267576 -> 3266296 (-0.04%); split: -0.04%, +0.00%
SpillSGPRs: 10445 -> 10904 (+4.39%); split: -0.31%, +4.70%
SpillVGPRs: 1818 -> 1811 (-0.39%); split: -1.05%, +0.66%
Scratch: 955392 -> 954368 (-0.11%)
Latency: 563477854 -> 562131282 (-0.24%); split: -0.31%, +0.08%
InvThroughput: 111860104 -> 111553968 (-0.27%); split: -0.30%, +0.02%
VClause: 958432 -> 961415 (+0.31%); split: -0.34%, +0.65%
SClause: 1917415 -> 1926952 (+0.50%); split: -0.69%, +1.19%
Copies: 3812945 -> 3916758 (+2.72%); split: -0.27%, +2.99%
Branches: 1611235 -> 1612022 (+0.05%); split: -0.04%, +0.08%
PreSGPRs: 3095505 -> 3126580 (+1.00%); split: -0.06%, +1.07%
PreVGPRs: 2773011 -> 2773013 (+0.00%)
Most regressions seem to be because ACO's convert_pointer_to_64_bit()
can't be CSE'd with radv_nir_apply_pipeline_layout()'s
convert_pointer_to_64_bit(). This should be improved by later commits.
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-04 14:06:47 +01:00
|
|
|
radv_load_ssbo(struct ac_shader_abi *abi, LLVMValueRef buffer_ptr, bool write, bool non_uniform)
|
2018-03-09 16:58:10 +01:00
|
|
|
{
|
|
|
|
|
struct radv_shader_context *ctx = radv_shader_context_from_abi(abi);
|
radv,aco: lower buffer descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 75420 (46.47% of 162293) affected shaders:
MaxWaves: 1878200 -> 1879228 (+0.05%); split: +0.06%, -0.00%
Instrs: 54021103 -> 54141370 (+0.22%); split: -0.04%, +0.26%
CodeSize: 287813520 -> 288293352 (+0.17%); split: -0.04%, +0.21%
VGPRs: 3267576 -> 3266296 (-0.04%); split: -0.04%, +0.00%
SpillSGPRs: 10445 -> 10904 (+4.39%); split: -0.31%, +4.70%
SpillVGPRs: 1818 -> 1811 (-0.39%); split: -1.05%, +0.66%
Scratch: 955392 -> 954368 (-0.11%)
Latency: 563477854 -> 562131282 (-0.24%); split: -0.31%, +0.08%
InvThroughput: 111860104 -> 111553968 (-0.27%); split: -0.30%, +0.02%
VClause: 958432 -> 961415 (+0.31%); split: -0.34%, +0.65%
SClause: 1917415 -> 1926952 (+0.50%); split: -0.69%, +1.19%
Copies: 3812945 -> 3916758 (+2.72%); split: -0.27%, +2.99%
Branches: 1611235 -> 1612022 (+0.05%); split: -0.04%, +0.08%
PreSGPRs: 3095505 -> 3126580 (+1.00%); split: -0.06%, +1.07%
PreVGPRs: 2773011 -> 2773013 (+0.00%)
Most regressions seem to be because ACO's convert_pointer_to_64_bit()
can't be CSE'd with radv_nir_apply_pipeline_layout()'s
convert_pointer_to_64_bit(). This should be improved by later commits.
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-04 14:06:47 +01:00
|
|
|
return radv_load_rsrc(ctx, buffer_ptr, ctx->ac.v4i32);
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2018-03-09 16:58:10 +01:00
|
|
|
static LLVMValueRef
|
2022-09-16 16:39:41 +08:00
|
|
|
radv_get_sampler_desc(struct ac_shader_abi *abi, LLVMValueRef index, enum ac_descriptor_type desc_type)
|
2018-03-09 16:58:10 +01:00
|
|
|
{
|
|
|
|
|
struct radv_shader_context *ctx = radv_shader_context_from_abi(abi);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-05-09 01:57:28 +02:00
|
|
|
/* 3 plane formats always have same size and format for plane 1 & 2, so
|
|
|
|
|
* use the tail from plane 1 so that we can store only the first 16 bytes
|
|
|
|
|
* of the last plane. */
|
radv,aco: lower texture descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 39445 (24.30% of 162293) affected shaders:
MaxWaves: 875988 -> 875972 (-0.00%)
Instrs: 35372561 -> 35234909 (-0.39%); split: -0.41%, +0.03%
CodeSize: 190237480 -> 189379240 (-0.45%); split: -0.47%, +0.02%
VGPRs: 1889856 -> 1889928 (+0.00%); split: -0.00%, +0.01%
SpillSGPRs: 10764 -> 10857 (+0.86%); split: -2.04%, +2.91%
SpillVGPRs: 1891 -> 1907 (+0.85%); split: -0.32%, +1.16%
Scratch: 260096 -> 261120 (+0.39%)
Latency: 477701150 -> 477578466 (-0.03%); split: -0.06%, +0.03%
InvThroughput: 87819847 -> 87830346 (+0.01%); split: -0.03%, +0.04%
VClause: 673353 -> 673829 (+0.07%); split: -0.04%, +0.11%
SClause: 1385396 -> 1366478 (-1.37%); split: -1.65%, +0.29%
Copies: 2327965 -> 2229134 (-4.25%); split: -4.58%, +0.34%
Branches: 906707 -> 906434 (-0.03%); split: -0.13%, +0.10%
PreSGPRs: 1874153 -> 1862698 (-0.61%); split: -1.34%, +0.73%
PreVGPRs: 1691382 -> 1691383 (+0.00%); split: -0.00%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-12 15:36:56 +01:00
|
|
|
if (desc_type == AC_DESC_PLANE_2 && index && LLVMTypeOf(index) == ctx->ac.i32) {
|
|
|
|
|
LLVMValueRef plane1_addr = LLVMBuildSub(ctx->ac.builder, index, LLVMConstInt(ctx->ac.i32, 32, false), "");
|
|
|
|
|
LLVMValueRef descriptor1 = radv_load_rsrc(ctx, plane1_addr, ctx->ac.v8i32);
|
|
|
|
|
LLVMValueRef descriptor2 = radv_load_rsrc(ctx, index, ctx->ac.v4i32);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-05-09 01:57:28 +02:00
|
|
|
LLVMValueRef components[8];
|
|
|
|
|
for (unsigned i = 0; i < 4; ++i)
|
|
|
|
|
components[i] = ac_llvm_extract_elem(&ctx->ac, descriptor2, i);
|
2021-04-23 15:06:10 +02:00
|
|
|
|
radv,aco: lower texture descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 39445 (24.30% of 162293) affected shaders:
MaxWaves: 875988 -> 875972 (-0.00%)
Instrs: 35372561 -> 35234909 (-0.39%); split: -0.41%, +0.03%
CodeSize: 190237480 -> 189379240 (-0.45%); split: -0.47%, +0.02%
VGPRs: 1889856 -> 1889928 (+0.00%); split: -0.00%, +0.01%
SpillSGPRs: 10764 -> 10857 (+0.86%); split: -2.04%, +2.91%
SpillVGPRs: 1891 -> 1907 (+0.85%); split: -0.32%, +1.16%
Scratch: 260096 -> 261120 (+0.39%)
Latency: 477701150 -> 477578466 (-0.03%); split: -0.06%, +0.03%
InvThroughput: 87819847 -> 87830346 (+0.01%); split: -0.03%, +0.04%
VClause: 673353 -> 673829 (+0.07%); split: -0.04%, +0.11%
SClause: 1385396 -> 1366478 (-1.37%); split: -1.65%, +0.29%
Copies: 2327965 -> 2229134 (-4.25%); split: -4.58%, +0.34%
Branches: 906707 -> 906434 (-0.03%); split: -0.13%, +0.10%
PreSGPRs: 1874153 -> 1862698 (-0.61%); split: -1.34%, +0.73%
PreVGPRs: 1691382 -> 1691383 (+0.00%); split: -0.00%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-12 15:36:56 +01:00
|
|
|
for (unsigned i = 4; i < 8; ++i)
|
|
|
|
|
components[i] = ac_llvm_extract_elem(&ctx->ac, descriptor1, i);
|
|
|
|
|
return ac_build_gather_values(&ctx->ac, components, 8);
|
2019-05-09 01:57:28 +02:00
|
|
|
}
|
2021-04-10 03:24:05 +02:00
|
|
|
|
radv,aco: lower texture descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 39445 (24.30% of 162293) affected shaders:
MaxWaves: 875988 -> 875972 (-0.00%)
Instrs: 35372561 -> 35234909 (-0.39%); split: -0.41%, +0.03%
CodeSize: 190237480 -> 189379240 (-0.45%); split: -0.47%, +0.02%
VGPRs: 1889856 -> 1889928 (+0.00%); split: -0.00%, +0.01%
SpillSGPRs: 10764 -> 10857 (+0.86%); split: -2.04%, +2.91%
SpillVGPRs: 1891 -> 1907 (+0.85%); split: -0.32%, +1.16%
Scratch: 260096 -> 261120 (+0.39%)
Latency: 477701150 -> 477578466 (-0.03%); split: -0.06%, +0.03%
InvThroughput: 87819847 -> 87830346 (+0.01%); split: -0.03%, +0.04%
VClause: 673353 -> 673829 (+0.07%); split: -0.04%, +0.11%
SClause: 1385396 -> 1366478 (-1.37%); split: -1.65%, +0.29%
Copies: 2327965 -> 2229134 (-4.25%); split: -4.58%, +0.34%
Branches: 906707 -> 906434 (-0.03%); split: -0.13%, +0.10%
PreSGPRs: 1874153 -> 1862698 (-0.61%); split: -1.34%, +0.73%
PreVGPRs: 1691382 -> 1691383 (+0.00%); split: -0.00%, +0.00%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2021-08-12 15:36:56 +01:00
|
|
|
bool v4 = desc_type == AC_DESC_BUFFER || desc_type == AC_DESC_SAMPLER;
|
|
|
|
|
return radv_load_rsrc(ctx, index, v4 ? ctx->ac.v4i32 : ctx->ac.v8i32);
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static LLVMValueRef
|
|
|
|
|
radv_load_output(struct radv_shader_context *ctx, unsigned index, unsigned chan)
|
|
|
|
|
{
|
2022-10-11 10:48:01 +02:00
|
|
|
int idx = ac_llvm_reg_index_soa(index, chan);
|
|
|
|
|
LLVMValueRef output = ctx->abi.outputs[idx];
|
|
|
|
|
LLVMTypeRef type = ctx->abi.is_16bit[idx] ? ctx->ac.f16 : ctx->ac.f32;
|
|
|
|
|
return LLVMBuildLoad2(ctx->ac.builder, type, output, "");
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
2018-06-14 14:28:58 +02:00
|
|
|
static void
|
2024-08-04 11:40:18 -05:00
|
|
|
ac_llvm_finalize_module(struct radv_shader_context *ctx, struct ac_midend_optimizer *meo)
|
2018-03-09 16:58:10 +01:00
|
|
|
{
|
2024-08-04 11:40:18 -05:00
|
|
|
ac_llvm_optimize_module(meo, ctx->ac.module);
|
2018-03-09 16:58:10 +01:00
|
|
|
ac_llvm_context_dispose(&ctx->ac);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 00:29:50 +02:00
|
|
|
/* Ensure that the esgs ring is declared.
|
|
|
|
|
*
|
|
|
|
|
* We declare it with 64KB alignment as a hint that the
|
|
|
|
|
* pointer value will always be 0.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
declare_esgs_ring(struct radv_shader_context *ctx)
|
|
|
|
|
{
|
|
|
|
|
assert(!LLVMGetNamedGlobal(ctx->ac.module, "esgs_ring"));
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2022-10-20 13:21:54 +01:00
|
|
|
LLVMValueRef esgs_ring =
|
|
|
|
|
LLVMAddGlobalInAddressSpace(ctx->ac.module, LLVMArrayType(ctx->ac.i32, 0), "esgs_ring", AC_ADDR_SPACE_LDS);
|
|
|
|
|
LLVMSetLinkage(esgs_ring, LLVMExternalLinkage);
|
|
|
|
|
LLVMSetAlignment(esgs_ring, 64 * 1024);
|
2019-07-11 00:29:50 +02:00
|
|
|
}
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2022-12-09 10:32:48 +08:00
|
|
|
static LLVMValueRef
|
|
|
|
|
radv_intrinsic_load(struct ac_shader_abi *abi, nir_intrinsic_instr *intrin)
|
2022-05-05 22:16:27 -04:00
|
|
|
{
|
2022-12-09 10:32:48 +08:00
|
|
|
switch (intrin->intrinsic) {
|
2022-05-05 22:16:27 -04:00
|
|
|
case nir_intrinsic_load_base_vertex:
|
|
|
|
|
case nir_intrinsic_load_first_vertex:
|
2022-12-09 10:32:48 +08:00
|
|
|
return radv_load_base_vertex(abi, intrin->intrinsic == nir_intrinsic_load_base_vertex);
|
2022-05-05 22:16:27 -04:00
|
|
|
default:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 09:27:03 +10:00
|
|
|
static LLVMModuleRef
|
2021-10-08 16:14:15 +02:00
|
|
|
ac_translate_nir_to_llvm(struct ac_llvm_compiler *ac_llvm, const struct radv_nir_compiler_options *options,
|
|
|
|
|
const struct radv_shader_info *info, struct nir_shader *const *shaders, int shader_count,
|
|
|
|
|
const struct radv_shader_args *args)
|
2018-03-09 16:58:10 +01:00
|
|
|
{
|
|
|
|
|
struct radv_shader_context ctx = {0};
|
2019-11-11 18:05:03 +01:00
|
|
|
ctx.args = args;
|
2021-10-08 16:14:15 +02:00
|
|
|
ctx.options = options;
|
|
|
|
|
ctx.shader_info = info;
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-10-14 11:27:32 +02:00
|
|
|
enum ac_float_mode float_mode = AC_FLOAT_MODE_DEFAULT;
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2021-09-23 10:07:38 +02:00
|
|
|
if (shaders[0]->info.float_controls_execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP32) {
|
2019-10-14 11:27:32 +02:00
|
|
|
float_mode = AC_FLOAT_MODE_DENORM_FLUSH_TO_ZERO;
|
|
|
|
|
}
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2023-01-02 18:05:14 +00:00
|
|
|
bool exports_mrtz = false;
|
|
|
|
|
bool exports_color_null = false;
|
|
|
|
|
if (shaders[0]->info.stage == MESA_SHADER_FRAGMENT) {
|
|
|
|
|
exports_mrtz = info->ps.writes_z || info->ps.writes_stencil || info->ps.writes_sample_mask;
|
|
|
|
|
exports_color_null = !exports_mrtz || (shaders[0]->info.outputs_written & (0xffu << FRAG_RESULT_DATA0));
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 14:19:14 -04:00
|
|
|
ac_llvm_context_init(&ctx.ac, ac_llvm, options->info, float_mode, info->wave_size, info->ballot_bit_size,
|
2023-01-02 18:05:14 +00:00
|
|
|
exports_color_null, exports_mrtz);
|
2023-01-04 16:48:29 +01:00
|
|
|
|
|
|
|
|
uint32_t length = 1;
|
|
|
|
|
for (uint32_t i = 0; i < shader_count; i++)
|
|
|
|
|
if (shaders[i]->info.name)
|
|
|
|
|
length += strlen(shaders[i]->info.name) + 1;
|
|
|
|
|
|
|
|
|
|
char *name = malloc(length);
|
|
|
|
|
if (name) {
|
|
|
|
|
uint32_t offset = 0;
|
|
|
|
|
for (uint32_t i = 0; i < shader_count; i++) {
|
|
|
|
|
if (!shaders[i]->info.name)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
strcpy(name + offset, shaders[i]->info.name);
|
|
|
|
|
offset += strlen(shaders[i]->info.name);
|
|
|
|
|
if (i != shader_count - 1)
|
|
|
|
|
name[offset++] = ',';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LLVMSetSourceFileName(ctx.ac.module, name, offset);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-12 17:35:39 -04:00
|
|
|
ctx.context = ctx.ac.context;
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2021-10-08 16:14:15 +02:00
|
|
|
ctx.max_workgroup_size = info->workgroup_size;
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-11-11 12:50:12 +01:00
|
|
|
create_function(&ctx, shaders[shader_count - 1]->info.stage, shader_count >= 2);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2022-05-05 22:16:27 -04:00
|
|
|
ctx.abi.intrinsic_load = radv_intrinsic_load;
|
2018-03-09 16:58:10 +01:00
|
|
|
ctx.abi.load_ubo = radv_load_ubo;
|
|
|
|
|
ctx.abi.load_ssbo = radv_load_ssbo;
|
|
|
|
|
ctx.abi.load_sampler_desc = radv_get_sampler_desc;
|
|
|
|
|
ctx.abi.clamp_shadow_reference = false;
|
2023-06-28 18:28:57 +01:00
|
|
|
ctx.abi.robust_buffer_access = options->robust_buffer_access_llvm;
|
2020-09-24 14:50:54 +01:00
|
|
|
ctx.abi.load_grid_size_from_user_sgpr = args->load_grid_size_from_user_sgpr;
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2021-10-08 16:14:15 +02:00
|
|
|
bool is_ngg = is_pre_gs_stage(shaders[0]->info.stage) && info->is_ngg;
|
2019-07-05 08:33:06 +02:00
|
|
|
if (shader_count >= 2 || is_ngg)
|
2018-03-09 16:58:10 +01:00
|
|
|
ac_init_exec_full_mask(&ctx.ac);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-11-11 18:05:03 +01:00
|
|
|
if (args->ac.vertex_id.used)
|
|
|
|
|
ctx.abi.vertex_id = ac_get_arg(&ctx.ac, args->ac.vertex_id);
|
2020-12-08 18:51:57 -05:00
|
|
|
if (args->ac.vs_rel_patch_id.used)
|
2023-03-20 11:49:20 +08:00
|
|
|
ctx.abi.vs_rel_patch_id = ac_get_arg(&ctx.ac, args->ac.vs_rel_patch_id);
|
2019-11-11 18:05:03 +01:00
|
|
|
if (args->ac.instance_id.used)
|
|
|
|
|
ctx.abi.instance_id = ac_get_arg(&ctx.ac, args->ac.instance_id);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2018-03-09 16:58:10 +01:00
|
|
|
if (options->info->has_ls_vgpr_init_bug && shaders[shader_count - 1]->info.stage == MESA_SHADER_TESS_CTRL)
|
2023-03-20 12:15:02 +08:00
|
|
|
ac_fixup_ls_hs_input_vgprs(&ctx.ac, &ctx.abi, &args->ac);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-10-28 14:41:13 +01:00
|
|
|
if (is_ngg) {
|
2021-10-08 16:14:15 +02:00
|
|
|
if (!info->is_ngg_passthrough)
|
2020-01-08 08:39:10 +01:00
|
|
|
declare_esgs_ring(&ctx);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2022-05-17 19:18:37 +02:00
|
|
|
if (ctx.stage == MESA_SHADER_GEOMETRY) {
|
|
|
|
|
/* Scratch space used by NGG GS for repacking vertices at the end. */
|
|
|
|
|
LLVMTypeRef ai32 = LLVMArrayType(ctx.ac.i32, 8);
|
|
|
|
|
LLVMValueRef gs_ngg_scratch =
|
|
|
|
|
LLVMAddGlobalInAddressSpace(ctx.ac.module, ai32, "ngg_scratch", AC_ADDR_SPACE_LDS);
|
|
|
|
|
LLVMSetInitializer(gs_ngg_scratch, LLVMGetUndef(ai32));
|
|
|
|
|
LLVMSetLinkage(gs_ngg_scratch, LLVMExternalLinkage);
|
|
|
|
|
LLVMSetAlignment(gs_ngg_scratch, 4);
|
|
|
|
|
|
|
|
|
|
/* Vertex emit space used by NGG GS for storing all vertex attributes. */
|
|
|
|
|
LLVMValueRef gs_ngg_emit =
|
|
|
|
|
LLVMAddGlobalInAddressSpace(ctx.ac.module, LLVMArrayType(ctx.ac.i32, 0), "ngg_emit", AC_ADDR_SPACE_LDS);
|
|
|
|
|
LLVMSetInitializer(gs_ngg_emit, LLVMGetUndef(ai32));
|
|
|
|
|
LLVMSetLinkage(gs_ngg_emit, LLVMExternalLinkage);
|
|
|
|
|
LLVMSetAlignment(gs_ngg_emit, 4);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 14:00:58 +02:00
|
|
|
/* GFX10 hang workaround - there needs to be an s_barrier before gs_alloc_req always */
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.ac.gfx_level == GFX10 && shader_count == 1)
|
2022-05-02 21:38:07 -04:00
|
|
|
ac_build_s_barrier(&ctx.ac, shaders[0]->info.stage);
|
2021-04-10 03:24:05 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-03 17:20:36 +01:00
|
|
|
for (int shader_idx = 0; shader_idx < shader_count; ++shader_idx) {
|
2019-07-11 08:44:16 +02:00
|
|
|
ctx.stage = shaders[shader_idx]->info.stage;
|
2020-11-03 17:20:36 +01:00
|
|
|
ctx.shader = shaders[shader_idx];
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2022-05-17 19:18:37 +02:00
|
|
|
if (shader_idx && !(shaders[shader_idx]->info.stage == MESA_SHADER_GEOMETRY && info->is_ngg)) {
|
2020-11-03 17:20:36 +01:00
|
|
|
/* Execute a barrier before the second shader in
|
2019-12-16 20:00:00 -08:00
|
|
|
* a merged shader.
|
2021-04-10 03:24:05 +02:00
|
|
|
*
|
2018-03-09 16:58:10 +01:00
|
|
|
* Execute the barrier inside the conditional block,
|
|
|
|
|
* so that empty waves can jump directly to s_endpgm,
|
|
|
|
|
* which will also signal the barrier.
|
2021-04-10 03:24:05 +02:00
|
|
|
*
|
2018-03-09 16:58:10 +01:00
|
|
|
* This is possible in gfx9, because an empty wave
|
|
|
|
|
* for the second shader does not participate in
|
|
|
|
|
* the epilogue. With NGG, empty waves may still
|
2020-12-08 18:51:57 -05:00
|
|
|
* be required to export data (e.g. GS output vertices),
|
|
|
|
|
* so we cannot let them exit early.
|
2021-04-10 03:24:05 +02:00
|
|
|
*
|
2020-11-03 17:20:36 +01:00
|
|
|
* If the shader is TCS and the TCS epilog is present
|
2018-03-09 16:58:10 +01:00
|
|
|
* and contains a barrier, it will wait there and then
|
|
|
|
|
* reach s_endpgm.
|
2021-04-10 03:24:05 +02:00
|
|
|
*/
|
2023-04-27 03:34:01 -04:00
|
|
|
ac_build_waitcnt(&ctx.ac, AC_WAIT_DS);
|
2022-05-02 21:38:07 -04:00
|
|
|
ac_build_s_barrier(&ctx.ac, shaders[shader_idx]->info.stage);
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2022-05-17 19:18:37 +02:00
|
|
|
bool check_merged_wave_info = shader_count >= 2 && !(is_ngg && shader_idx == 1);
|
2020-11-03 17:20:36 +01:00
|
|
|
LLVMBasicBlockRef merge_block = NULL;
|
2022-05-17 19:18:37 +02:00
|
|
|
|
|
|
|
|
if (check_merged_wave_info) {
|
2018-03-09 16:58:10 +01:00
|
|
|
LLVMValueRef fn = LLVMGetBasicBlockParent(LLVMGetInsertBlock(ctx.ac.builder));
|
2019-07-08 01:19:55 +02:00
|
|
|
LLVMBasicBlockRef then_block = LLVMAppendBasicBlockInContext(ctx.ac.context, fn, "");
|
|
|
|
|
merge_block = LLVMAppendBasicBlockInContext(ctx.ac.context, fn, "");
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2020-11-03 17:20:36 +01:00
|
|
|
LLVMValueRef count =
|
|
|
|
|
ac_unpack_param(&ctx.ac, ac_get_arg(&ctx.ac, args->ac.merged_wave_info), 8 * shader_idx, 8);
|
2019-11-11 18:05:03 +01:00
|
|
|
LLVMValueRef thread_id = ac_get_thread_id(&ctx.ac);
|
2020-11-03 17:20:36 +01:00
|
|
|
LLVMValueRef cond = LLVMBuildICmp(ctx.ac.builder, LLVMIntULT, thread_id, count, "");
|
2019-09-09 10:54:27 +02:00
|
|
|
LLVMBuildCondBr(ctx.ac.builder, cond, then_block, merge_block);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-09-09 10:54:27 +02:00
|
|
|
LLVMPositionBuilderAtEnd(ctx.ac.builder, then_block);
|
2020-11-03 17:20:36 +01:00
|
|
|
}
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2022-08-19 15:02:29 +02:00
|
|
|
if (!ac_nir_translate(&ctx.ac, &ctx.abi, &args->ac, shaders[shader_idx])) {
|
|
|
|
|
abort();
|
|
|
|
|
}
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2022-05-17 19:18:37 +02:00
|
|
|
if (check_merged_wave_info) {
|
2018-03-09 16:58:10 +01:00
|
|
|
LLVMBuildBr(ctx.ac.builder, merge_block);
|
|
|
|
|
LLVMPositionBuilderAtEnd(ctx.ac.builder, merge_block);
|
2021-04-10 03:24:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-09 16:58:10 +01:00
|
|
|
LLVMBuildRetVoid(ctx.ac.builder);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2021-10-08 16:14:15 +02:00
|
|
|
if (options->dump_preoptir) {
|
|
|
|
|
fprintf(stderr, "%s LLVM IR:\n\n", radv_get_shader_name(info, shaders[shader_count - 1]->info.stage));
|
2018-03-09 16:58:10 +01:00
|
|
|
ac_dump_module(ctx.ac.module);
|
|
|
|
|
fprintf(stderr, "\n");
|
2021-04-10 03:24:05 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-04 11:40:18 -05:00
|
|
|
ac_llvm_finalize_module(&ctx, ac_llvm->meo);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2023-01-04 16:48:29 +01:00
|
|
|
free(name);
|
|
|
|
|
|
2018-06-27 09:27:03 +10:00
|
|
|
return ctx.ac.module;
|
2021-04-10 03:24:05 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-27 09:27:03 +10:00
|
|
|
static void
|
|
|
|
|
ac_diagnostic_handler(LLVMDiagnosticInfoRef di, void *context)
|
2021-04-10 03:24:05 +02:00
|
|
|
{
|
2018-03-09 16:58:10 +01:00
|
|
|
unsigned *retval = (unsigned *)context;
|
|
|
|
|
LLVMDiagnosticSeverity severity = LLVMGetDiagInfoSeverity(di);
|
2019-07-01 03:21:58 +02:00
|
|
|
char *description = LLVMGetDiagInfoDescription(di);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-07-11 18:03:56 +02:00
|
|
|
if (severity == LLVMDSError) {
|
2018-03-09 16:58:10 +01:00
|
|
|
*retval = 1;
|
2019-07-11 18:03:56 +02:00
|
|
|
fprintf(stderr, "LLVM triggered Diagnostic Handler: %s\n", description);
|
|
|
|
|
}
|
2018-03-09 16:58:10 +01:00
|
|
|
|
2018-03-14 10:34:13 +01:00
|
|
|
LLVMDisposeMessage(description);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-01 03:21:58 +02:00
|
|
|
static unsigned
|
|
|
|
|
radv_llvm_compile(LLVMModuleRef M, char **pelf_buffer, size_t *pelf_size, struct ac_llvm_compiler *ac_llvm)
|
2021-04-10 03:24:05 +02:00
|
|
|
{
|
2019-07-01 03:21:58 +02:00
|
|
|
unsigned retval = 0;
|
2018-03-09 16:58:10 +01:00
|
|
|
LLVMContextRef llvm_ctx;
|
|
|
|
|
|
|
|
|
|
/* Setup Diagnostic Handler*/
|
|
|
|
|
llvm_ctx = LLVMGetModuleContext(M);
|
|
|
|
|
|
2019-07-01 03:21:58 +02:00
|
|
|
LLVMContextSetDiagnosticHandler(llvm_ctx, ac_diagnostic_handler, &retval);
|
|
|
|
|
|
|
|
|
|
/* Compile IR*/
|
|
|
|
|
if (!radv_compile_to_elf(ac_llvm, M, pelf_buffer, pelf_size))
|
|
|
|
|
retval = 1;
|
|
|
|
|
return retval;
|
2021-04-10 03:24:05 +02:00
|
|
|
}
|
2019-07-01 03:21:58 +02:00
|
|
|
|
2018-03-09 16:58:10 +01:00
|
|
|
static void
|
2019-07-26 14:48:23 +02:00
|
|
|
ac_compile_llvm_module(struct ac_llvm_compiler *ac_llvm, LLVMModuleRef llvm_module, struct radv_shader_binary **rbinary,
|
2018-03-14 10:23:22 +01:00
|
|
|
const char *name, const struct radv_nir_compiler_options *options)
|
2021-04-10 03:24:05 +02:00
|
|
|
{
|
2019-07-01 03:21:58 +02:00
|
|
|
char *elf_buffer = NULL;
|
|
|
|
|
size_t elf_size = 0;
|
2018-03-14 10:34:13 +01:00
|
|
|
char *llvm_ir_string = NULL;
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-11-11 18:05:03 +01:00
|
|
|
if (options->dump_shader) {
|
2019-07-11 18:03:56 +02:00
|
|
|
fprintf(stderr, "%s LLVM IR:\n\n", name);
|
2018-03-09 16:58:10 +01:00
|
|
|
ac_dump_module(llvm_module);
|
2019-07-11 18:03:56 +02:00
|
|
|
fprintf(stderr, "\n");
|
2021-04-10 03:24:05 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-25 11:48:04 +01:00
|
|
|
if (options->record_ir) {
|
2018-03-14 10:34:13 +01:00
|
|
|
char *llvm_ir = LLVMPrintModuleToString(llvm_module);
|
2019-07-01 03:21:58 +02:00
|
|
|
llvm_ir_string = strdup(llvm_ir);
|
2018-03-09 16:58:10 +01:00
|
|
|
LLVMDisposeMessage(llvm_ir);
|
2021-04-10 03:24:05 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-26 14:48:23 +02:00
|
|
|
int v = radv_llvm_compile(llvm_module, &elf_buffer, &elf_size, ac_llvm);
|
2021-04-10 03:24:05 +02:00
|
|
|
if (v) {
|
2018-03-09 16:58:10 +01:00
|
|
|
fprintf(stderr, "compile failed\n");
|
2021-04-10 03:24:05 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 10:34:13 +01:00
|
|
|
LLVMContextRef ctx = LLVMGetModuleContext(llvm_module);
|
2018-03-09 16:58:10 +01:00
|
|
|
LLVMDisposeModule(llvm_module);
|
|
|
|
|
LLVMContextDispose(ctx);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-07-01 03:21:58 +02:00
|
|
|
size_t llvm_ir_size = llvm_ir_string ? strlen(llvm_ir_string) : 0;
|
|
|
|
|
size_t alloc_size = sizeof(struct radv_shader_binary_rtld) + elf_size + llvm_ir_size + 1;
|
|
|
|
|
struct radv_shader_binary_rtld *rbin = calloc(1, alloc_size);
|
|
|
|
|
memcpy(rbin->data, elf_buffer, elf_size);
|
|
|
|
|
if (llvm_ir_string)
|
|
|
|
|
memcpy(rbin->data + elf_size, llvm_ir_string, llvm_ir_size + 1);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-07-01 03:21:58 +02:00
|
|
|
rbin->base.type = RADV_BINARY_TYPE_RTLD;
|
|
|
|
|
rbin->base.total_size = alloc_size;
|
|
|
|
|
rbin->elf_size = elf_size;
|
|
|
|
|
rbin->llvm_ir_size = llvm_ir_size;
|
|
|
|
|
*rbinary = &rbin->base;
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2019-07-01 03:21:58 +02:00
|
|
|
free(llvm_ir_string);
|
|
|
|
|
free(elf_buffer);
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-12 14:49:55 +01:00
|
|
|
static void
|
2021-10-08 16:14:15 +02:00
|
|
|
radv_compile_nir_shader(struct ac_llvm_compiler *ac_llvm, const struct radv_nir_compiler_options *options,
|
|
|
|
|
const struct radv_shader_info *info, struct radv_shader_binary **rbinary,
|
2019-11-11 18:05:03 +01:00
|
|
|
const struct radv_shader_args *args, struct nir_shader *const *nir, int nir_count)
|
2018-03-09 16:58:10 +01:00
|
|
|
{
|
|
|
|
|
|
2018-03-14 10:28:49 +01:00
|
|
|
LLVMModuleRef llvm_module;
|
|
|
|
|
|
2021-10-08 16:14:15 +02:00
|
|
|
llvm_module = ac_translate_nir_to_llvm(ac_llvm, options, info, nir, nir_count, args);
|
2018-03-09 16:58:10 +01:00
|
|
|
|
2023-03-17 00:49:44 +01:00
|
|
|
ac_compile_llvm_module(ac_llvm, llvm_module, rbinary, radv_get_shader_name(info, nir[nir_count - 1]->info.stage),
|
|
|
|
|
options);
|
2018-03-09 16:58:10 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-12 14:49:55 +01:00
|
|
|
void
|
2021-10-08 16:14:15 +02:00
|
|
|
llvm_compile_shader(const struct radv_nir_compiler_options *options, const struct radv_shader_info *info,
|
2020-03-12 14:49:55 +01:00
|
|
|
unsigned shader_count, struct nir_shader *const *shaders, struct radv_shader_binary **binary,
|
2021-10-08 16:14:15 +02:00
|
|
|
const struct radv_shader_args *args)
|
2020-03-12 14:49:55 +01:00
|
|
|
{
|
|
|
|
|
enum ac_target_machine_options tm_options = 0;
|
|
|
|
|
struct ac_llvm_compiler ac_llvm;
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2020-03-12 14:49:55 +01:00
|
|
|
tm_options |= AC_TM_SUPPORTS_SPILL;
|
2021-10-08 16:14:15 +02:00
|
|
|
if (options->check_ir)
|
2020-03-12 14:49:55 +01:00
|
|
|
tm_options |= AC_TM_CHECK_IR;
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2023-05-31 14:19:14 -04:00
|
|
|
radv_init_llvm_compiler(&ac_llvm, options->info->family, tm_options, info->wave_size);
|
2021-04-10 03:24:05 +02:00
|
|
|
|
2022-09-29 12:43:05 +01:00
|
|
|
radv_compile_nir_shader(&ac_llvm, options, info, binary, args, shaders, shader_count);
|
2020-03-12 14:49:55 +01:00
|
|
|
}
|