intel/nir: Take a nir_tex_instr and src index in brw_texture_offset
This makes things a bit simpler and it's also more robust because it no longer has a hard dependency on the offset being a 32-bit value.
This commit is contained in:
parent
2a36699ed3
commit
6b1c398bcb
|
@ -5062,14 +5062,8 @@ fs_visitor::nir_emit_texture(const fs_builder &bld, nir_tex_instr *instr)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nir_tex_src_offset: {
|
case nir_tex_src_offset: {
|
||||||
nir_const_value *const_offset =
|
uint32_t offset_bits = 0;
|
||||||
nir_src_as_const_value(instr->src[i].src);
|
if (brw_texture_offset(instr, i, &offset_bits)) {
|
||||||
assert(nir_src_bit_size(instr->src[i].src) == 32);
|
|
||||||
unsigned offset_bits = 0;
|
|
||||||
if (const_offset &&
|
|
||||||
brw_texture_offset(const_offset->i32,
|
|
||||||
nir_tex_instr_src_size(instr, i),
|
|
||||||
&offset_bits)) {
|
|
||||||
header_bits |= offset_bits;
|
header_bits |= offset_bits;
|
||||||
} else {
|
} else {
|
||||||
srcs[TEX_LOGICAL_SRC_TG4_OFFSET] =
|
srcs[TEX_LOGICAL_SRC_TG4_OFFSET] =
|
||||||
|
|
|
@ -129,26 +129,34 @@ brw_math_function(enum opcode op)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
brw_texture_offset(int *offsets, unsigned num_components, uint32_t *offset_bits)
|
brw_texture_offset(const nir_tex_instr *tex, unsigned src,
|
||||||
|
uint32_t *offset_bits_out)
|
||||||
{
|
{
|
||||||
if (!offsets) return false; /* nonconstant offset; caller will handle it. */
|
if (!nir_src_is_const(tex->src[src].src))
|
||||||
|
|
||||||
/* offset out of bounds; caller will handle it. */
|
|
||||||
for (unsigned i = 0; i < num_components; i++)
|
|
||||||
if (offsets[i] > 7 || offsets[i] < -8)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
const unsigned num_components = nir_tex_instr_src_size(tex, src);
|
||||||
|
|
||||||
/* Combine all three offsets into a single unsigned dword:
|
/* Combine all three offsets into a single unsigned dword:
|
||||||
*
|
*
|
||||||
* bits 11:8 - U Offset (X component)
|
* bits 11:8 - U Offset (X component)
|
||||||
* bits 7:4 - V Offset (Y component)
|
* bits 7:4 - V Offset (Y component)
|
||||||
* bits 3:0 - R Offset (Z component)
|
* bits 3:0 - R Offset (Z component)
|
||||||
*/
|
*/
|
||||||
*offset_bits = 0;
|
uint32_t offset_bits = 0;
|
||||||
for (unsigned i = 0; i < num_components; i++) {
|
for (unsigned i = 0; i < num_components; i++) {
|
||||||
|
int offset = nir_src_comp_as_int(tex->src[src].src, i);
|
||||||
|
|
||||||
|
/* offset out of bounds; caller will handle it. */
|
||||||
|
if (offset > 7 || offset < -8)
|
||||||
|
return false;
|
||||||
|
|
||||||
const unsigned shift = 4 * (2 - i);
|
const unsigned shift = 4 * (2 - i);
|
||||||
*offset_bits |= (offsets[i] << shift) & (0xF << shift);
|
offset_bits |= (offset << shift) & (0xF << shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*offset_bits_out = offset_bits;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,8 +243,7 @@ public:
|
||||||
virtual void invalidate_live_intervals() = 0;
|
virtual void invalidate_live_intervals() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool brw_texture_offset(int *offsets,
|
bool brw_texture_offset(const nir_tex_instr *tex, unsigned src,
|
||||||
unsigned num_components,
|
|
||||||
uint32_t *offset_bits);
|
uint32_t *offset_bits);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -2061,19 +2061,12 @@ vec4_visitor::nir_emit_texture(nir_tex_instr *instr)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case nir_tex_src_offset: {
|
case nir_tex_src_offset:
|
||||||
nir_const_value *const_offset =
|
if (!brw_texture_offset(instr, i, &constant_offset)) {
|
||||||
nir_src_as_const_value(instr->src[i].src);
|
|
||||||
assert(nir_src_bit_size(instr->src[i].src) == 32);
|
|
||||||
if (!const_offset ||
|
|
||||||
!brw_texture_offset(const_offset->i32,
|
|
||||||
nir_tex_instr_src_size(instr, i),
|
|
||||||
&constant_offset)) {
|
|
||||||
offset_value =
|
offset_value =
|
||||||
get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_D, 2);
|
get_nir_src(instr->src[i].src, BRW_REGISTER_TYPE_D, 2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case nir_tex_src_texture_offset: {
|
case nir_tex_src_texture_offset: {
|
||||||
/* Emit code to evaluate the actual indexing expression */
|
/* Emit code to evaluate the actual indexing expression */
|
||||||
|
|
Loading…
Reference in New Issue