radv/llvm,aco/ngg: fix large shift exponent in ngg_gs_vertex_lds_addr
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 18 Nov 2020 19:13:19 +0000 (19:13 +0000)
committerMarge Bot <eric+marge@anholt.net>
Wed, 25 Nov 2020 13:41:04 +0000 (13:41 +0000)
When vertices_out=0, we will try to shift 1u by UINT32_MAX.

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7576>

src/amd/compiler/aco_instruction_selection.cpp
src/amd/vulkan/radv_nir_to_llvm.c

index 556e4ef..e727c6e 100644 (file)
@@ -4062,7 +4062,7 @@ Temp wave_count_in_threadgroup(isel_context *ctx)
 Temp ngg_gs_vertex_lds_addr(isel_context *ctx, Temp vertex_idx)
 {
    Builder bld(ctx->program, ctx->block);
-   unsigned write_stride_2exp = ffs(ctx->shader->info.gs.vertices_out) - 1;
+   unsigned write_stride_2exp = ffs(MAX2(ctx->shader->info.gs.vertices_out, 1)) - 1;
 
    /* gs_max_out_vertices = 2^(write_stride_2exp) * some odd number */
    if (write_stride_2exp) {
index 65bc0d3..1b982e8 100644 (file)
@@ -2147,7 +2147,7 @@ ngg_gs_vertex_ptr(struct radv_shader_context *ctx, LLVMValueRef vertexidx)
        LLVMValueRef storage = ngg_gs_get_vertex_storage(ctx);
 
        /* gs_max_out_vertices = 2^(write_stride_2exp) * some odd number */
-       unsigned write_stride_2exp = ffs(ctx->shader->info.gs.vertices_out) - 1;
+       unsigned write_stride_2exp = ffs(MAX2(ctx->shader->info.gs.vertices_out, 1)) - 1;
        if (write_stride_2exp) {
                LLVMValueRef row =
                        LLVMBuildLShr(builder, vertexidx,