From: Jason Ekstrand Date: Thu, 20 Feb 2020 23:19:50 +0000 (-0600) Subject: nir/builder: Return an integer from nir_get_texture_size X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1598370aca6459ba54915a26683a75bb66f88161;p=mesa.git nir/builder: Return an integer from nir_get_texture_size It's convenient in a bunch of cases for nir_get_texture_size to return a float but it's very unexpected. This fixes a bug in the R600 NIR code. Fixes: f718ac62688b "r600/sfn: Add a basic nir shader backend" Reviewed-by: Eric Anholt Tested-by: Marge Bot Part-of: --- diff --git a/src/compiler/nir/nir_builtin_builder.c b/src/compiler/nir/nir_builtin_builder.c index d35542c50a9..3a66eba2c8c 100644 --- a/src/compiler/nir/nir_builtin_builder.c +++ b/src/compiler/nir/nir_builtin_builder.c @@ -375,7 +375,7 @@ nir_get_texture_size(nir_builder *b, nir_tex_instr *tex) nir_tex_instr_dest_size(txs), 32, NULL); nir_builder_instr_insert(b, &txs->instr); - return nir_i2f32(b, &txs->dest.ssa); + return &txs->dest.ssa; } nir_ssa_def * diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 6c8c6aa1164..18bbd1e39a8 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -126,7 +126,7 @@ lower_offset(nir_builder *b, nir_tex_instr *tex) if (tex->sampler_dim == GLSL_SAMPLER_DIM_RECT) { offset_coord = nir_fadd(b, coord, nir_i2f32(b, offset)); } else { - nir_ssa_def *txs = nir_get_texture_size(b, tex); + nir_ssa_def *txs = nir_i2f32(b, nir_get_texture_size(b, tex)); nir_ssa_def *scale = nir_frcp(b, txs); offset_coord = nir_fadd(b, coord, @@ -168,7 +168,7 @@ lower_rect(nir_builder *b, nir_tex_instr *tex) */ tex->sampler_dim = GLSL_SAMPLER_DIM_2D; - nir_ssa_def *txs = nir_get_texture_size(b, tex); + nir_ssa_def *txs = nir_i2f32(b, nir_get_texture_size(b, tex)); nir_ssa_def *scale = nir_frcp(b, txs); /* Walk through the sources normalizing the requested arguments. */ @@ -405,7 +405,7 @@ lower_gradient_cube_map(nir_builder *b, nir_tex_instr *tex) assert(tex->dest.is_ssa); /* Use textureSize() to get the width and height of LOD 0 */ - nir_ssa_def *size = nir_get_texture_size(b, tex); + nir_ssa_def *size = nir_i2f32(b, nir_get_texture_size(b, tex)); /* Cubemap texture lookups first generate a texture coordinate normalized * to [-1, 1] on the appropiate face. The appropiate face is determined @@ -572,7 +572,8 @@ lower_gradient(nir_builder *b, nir_tex_instr *tex) } nir_ssa_def *size = - nir_channels(b, nir_get_texture_size(b, tex), component_mask); + nir_channels(b, nir_i2f32(b, nir_get_texture_size(b, tex)), + component_mask); /* Scale the gradients by width and height. Effectively, the incoming * gradients are s'(x,y), t'(x,y), and r'(x,y) from equation 3.19 in the @@ -634,7 +635,7 @@ saturate_src(nir_builder *b, nir_tex_instr *tex, unsigned sat_mask) /* non-normalized texture coords, so clamp to texture * size rather than [0.0, 1.0] */ - nir_ssa_def *txs = nir_get_texture_size(b, tex); + nir_ssa_def *txs = nir_i2f32(b, nir_get_texture_size(b, tex)); comp[j] = nir_fmax(b, comp[j], nir_imm_float(b, 0.0)); comp[j] = nir_fmin(b, comp[j], nir_channel(b, txs, j)); } else { diff --git a/src/gallium/drivers/r600/sfn/sfn_instruction_tex.cpp b/src/gallium/drivers/r600/sfn/sfn_instruction_tex.cpp index 0e7b63db570..0f0de213429 100644 --- a/src/gallium/drivers/r600/sfn/sfn_instruction_tex.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_instruction_tex.cpp @@ -246,7 +246,7 @@ bool lower_txl_txf_array_or_cube(nir_builder *b, nir_tex_instr *tex) int min_lod_idx = nir_tex_instr_src_index(tex, nir_tex_src_min_lod); assert (lod_idx >= 0 || bias_idx >= 0); - nir_ssa_def *size = nir_get_texture_size(b, tex); + nir_ssa_def *size = nir_i2f32(b, nir_get_texture_size(b, tex)); nir_ssa_def *lod = (lod_idx >= 0) ? nir_ssa_for_src(b, tex->src[lod_idx].src, 1) : nir_get_texture_lod(b, tex);