2018-01-10 12:51:08 -08:00
|
|
|
/*
|
|
|
|
* Copyright © 2016-2018 Broadcom
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "v3d_compiler.h"
|
|
|
|
|
|
|
|
/* We don't do any address packing. */
|
|
|
|
#define __gen_user_data void
|
|
|
|
#define __gen_address_type uint32_t
|
|
|
|
#define __gen_address_offset(reloc) (*reloc)
|
|
|
|
#define __gen_emit_reloc(cl, reloc)
|
|
|
|
#include "cle/v3d_packet_v41_pack.h"
|
|
|
|
|
2023-03-20 11:15:40 +01:00
|
|
|
static inline struct qinst *
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_TMU_WRITE(struct v3d_compile *c, enum v3d_qpu_waddr waddr, struct qreg val)
|
2018-01-10 12:51:08 -08:00
|
|
|
{
|
2018-12-14 14:46:48 -08:00
|
|
|
/* XXX perf: We should figure out how to merge ALU operations
|
|
|
|
* producing the val with this MOV, when possible.
|
|
|
|
*/
|
2023-03-20 11:15:40 +01:00
|
|
|
return vir_MOV_dest(c, vir_reg(QFILE_MAGIC, waddr), val);
|
2021-01-28 09:27:09 +01:00
|
|
|
}
|
2018-06-14 11:17:11 -07:00
|
|
|
|
2023-03-20 11:15:40 +01:00
|
|
|
static inline struct qinst *
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_TMU_WRITE_or_count(struct v3d_compile *c,
|
|
|
|
enum v3d_qpu_waddr waddr,
|
|
|
|
struct qreg val,
|
|
|
|
uint32_t *tmu_writes)
|
|
|
|
{
|
2023-03-20 11:15:40 +01:00
|
|
|
if (tmu_writes) {
|
2021-01-27 09:45:52 +01:00
|
|
|
(*tmu_writes)++;
|
2023-03-20 11:15:40 +01:00
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return vir_TMU_WRITE(c, waddr, val);
|
|
|
|
}
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vir_WRTMUC(struct v3d_compile *c, enum quniform_contents contents, uint32_t data)
|
|
|
|
{
|
|
|
|
struct qinst *inst = vir_NOP(c);
|
|
|
|
inst->qpu.sig.wrtmuc = true;
|
2019-02-26 18:36:05 -08:00
|
|
|
inst->uniform = vir_get_uniform_index(c, contents, data);
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
|
|
|
|
2017-12-11 12:52:27 -08:00
|
|
|
static const struct V3D41_TMU_CONFIG_PARAMETER_1 p1_unpacked_default = {
|
|
|
|
.per_pixel_mask_enable = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct V3D41_TMU_CONFIG_PARAMETER_2 p2_unpacked_default = {
|
|
|
|
.op = V3D_TMU_OP_REGULAR,
|
|
|
|
};
|
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
/**
|
|
|
|
* If 'tmu_writes' is not NULL, then it just counts required register writes,
|
|
|
|
* otherwise, it emits the actual register writes.
|
|
|
|
*
|
|
|
|
* It is important to notice that emitting register writes for the current
|
|
|
|
* TMU operation may trigger a TMU flush, since it is possible that any
|
|
|
|
* of the inputs required for the register writes is the result of a pending
|
|
|
|
* TMU operation. If that happens we need to make sure that it doesn't happen
|
|
|
|
* in the middle of the TMU register writes for the current TMU operation,
|
|
|
|
* which is why we always call ntq_get_src() even if we are only interested in
|
|
|
|
* register write counts.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
handle_tex_src(struct v3d_compile *c,
|
|
|
|
nir_tex_instr *instr,
|
|
|
|
unsigned src_idx,
|
|
|
|
unsigned non_array_components,
|
|
|
|
struct V3D41_TMU_CONFIG_PARAMETER_2 *p2_unpacked,
|
|
|
|
struct qreg *s_out,
|
|
|
|
unsigned *tmu_writes)
|
2018-01-10 12:51:08 -08:00
|
|
|
{
|
2021-01-27 09:45:52 +01:00
|
|
|
/* Either we are calling this just to count required TMU writes, or we
|
|
|
|
* are calling this to emit the actual TMU writes.
|
|
|
|
*/
|
|
|
|
assert(tmu_writes || (s_out && p2_unpacked));
|
2020-04-17 01:57:18 +02:00
|
|
|
|
2018-01-10 12:51:08 -08:00
|
|
|
struct qreg s;
|
2021-01-27 09:45:52 +01:00
|
|
|
switch (instr->src[src_idx].src_type) {
|
|
|
|
case nir_tex_src_coord:
|
|
|
|
/* S triggers the lookup, so save it for the end. */
|
|
|
|
s = ntq_get_src(c, instr->src[src_idx].src, 0);
|
|
|
|
if (tmu_writes)
|
|
|
|
(*tmu_writes)++;
|
|
|
|
else
|
|
|
|
*s_out = s;
|
|
|
|
|
|
|
|
if (non_array_components > 1) {
|
|
|
|
struct qreg src =
|
|
|
|
ntq_get_src(c, instr->src[src_idx].src, 1);
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUT, src,
|
|
|
|
tmu_writes);
|
2021-01-27 09:45:52 +01:00
|
|
|
}
|
2018-01-10 12:51:08 -08:00
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
if (non_array_components > 2) {
|
|
|
|
struct qreg src =
|
|
|
|
ntq_get_src(c, instr->src[src_idx].src, 2);
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUR, src,
|
|
|
|
tmu_writes);
|
2021-01-27 09:45:52 +01:00
|
|
|
}
|
2018-01-10 12:51:08 -08:00
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
if (instr->is_array) {
|
|
|
|
struct qreg src =
|
|
|
|
ntq_get_src(c, instr->src[src_idx].src,
|
|
|
|
instr->coord_components - 1);
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUI, src,
|
|
|
|
tmu_writes);
|
2021-01-27 09:45:52 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nir_tex_src_bias: {
|
|
|
|
struct qreg src = ntq_get_src(c, instr->src[src_idx].src, 0);
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUB, src, tmu_writes);
|
2021-01-27 09:45:52 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case nir_tex_src_lod: {
|
|
|
|
struct qreg src = ntq_get_src(c, instr->src[src_idx].src, 0);
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUB, src, tmu_writes);
|
|
|
|
if (!tmu_writes) {
|
|
|
|
/* With texel fetch automatic LOD is already disabled,
|
|
|
|
* and disable_autolod must not be enabled. For
|
|
|
|
* non-cubes we can use the register TMUSLOD, that
|
|
|
|
* implicitly sets disable_autolod.
|
|
|
|
*/
|
|
|
|
assert(p2_unpacked);
|
|
|
|
if (instr->op != nir_texop_txf &&
|
|
|
|
instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE) {
|
|
|
|
p2_unpacked->disable_autolod = true;
|
|
|
|
}
|
2021-01-27 09:45:52 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-01-10 12:51:08 -08:00
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
case nir_tex_src_comparator: {
|
|
|
|
struct qreg src = ntq_get_src(c, instr->src[src_idx].src, 0);
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUDREF, src, tmu_writes);
|
2021-01-27 09:45:52 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-01-10 12:51:08 -08:00
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
case nir_tex_src_offset: {
|
|
|
|
bool is_const_offset = nir_src_is_const(instr->src[src_idx].src);
|
|
|
|
if (is_const_offset) {
|
|
|
|
if (!tmu_writes) {
|
|
|
|
p2_unpacked->offset_s =
|
|
|
|
nir_src_comp_as_int(instr->src[src_idx].src, 0);
|
2020-04-29 00:33:47 +02:00
|
|
|
if (non_array_components >= 2)
|
2021-01-27 09:45:52 +01:00
|
|
|
p2_unpacked->offset_t =
|
|
|
|
nir_src_comp_as_int(instr->src[src_idx].src, 1);
|
2019-04-12 09:38:03 -07:00
|
|
|
if (non_array_components >= 3)
|
2021-01-27 09:45:52 +01:00
|
|
|
p2_unpacked->offset_r =
|
|
|
|
nir_src_comp_as_int(instr->src[src_idx].src, 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct qreg src_0 =
|
|
|
|
ntq_get_src(c, instr->src[src_idx].src, 0);
|
|
|
|
struct qreg src_1 =
|
|
|
|
ntq_get_src(c, instr->src[src_idx].src, 1);
|
|
|
|
if (!tmu_writes) {
|
2018-12-26 23:35:22 -08:00
|
|
|
struct qreg mask = vir_uniform_ui(c, 0xf);
|
|
|
|
struct qreg x, y, offset;
|
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
x = vir_AND(c, src_0, mask);
|
|
|
|
y = vir_AND(c, src_1, mask);
|
2018-12-26 23:35:22 -08:00
|
|
|
offset = vir_OR(c, x,
|
2021-01-27 09:45:52 +01:00
|
|
|
vir_SHL(c, y, vir_uniform_ui(c, 4)));
|
2018-12-26 23:35:22 -08:00
|
|
|
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUOFF, offset);
|
2021-01-27 09:45:52 +01:00
|
|
|
} else {
|
|
|
|
(*tmu_writes)++;
|
2018-12-26 23:35:22 -08:00
|
|
|
}
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
2021-01-27 09:45:52 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-01-10 12:51:08 -08:00
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
default:
|
|
|
|
unreachable("unknown texture source");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vir_tex_handle_srcs(struct v3d_compile *c,
|
|
|
|
nir_tex_instr *instr,
|
|
|
|
struct V3D41_TMU_CONFIG_PARAMETER_2 *p2_unpacked,
|
|
|
|
struct qreg *s,
|
|
|
|
unsigned *tmu_writes)
|
|
|
|
{
|
|
|
|
unsigned non_array_components = instr->op != nir_texop_lod ?
|
|
|
|
instr->coord_components - instr->is_array :
|
|
|
|
instr->coord_components;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < instr->num_srcs; i++) {
|
|
|
|
handle_tex_src(c, instr, i, non_array_components,
|
|
|
|
p2_unpacked, s, tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
2021-01-27 09:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
2021-01-28 09:27:09 +01:00
|
|
|
get_required_tex_tmu_writes(struct v3d_compile *c, nir_tex_instr *instr)
|
2021-01-27 09:45:52 +01:00
|
|
|
{
|
|
|
|
unsigned tmu_writes = 0;
|
|
|
|
vir_tex_handle_srcs(c, instr, NULL, NULL, &tmu_writes);
|
|
|
|
return tmu_writes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
v3d40_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr)
|
|
|
|
{
|
|
|
|
assert(instr->op != nir_texop_lod || c->devinfo->ver >= 42);
|
|
|
|
|
|
|
|
unsigned texture_idx = instr->texture_index;
|
|
|
|
unsigned sampler_idx = instr->sampler_index;
|
|
|
|
|
broadcom/compiler: update how we compute return_words_of_texture_data on non-ssa
For the non-ssa case, we were trying to use reg->num_components. But
this is not the same that nir_ssa_def_components_read. It is the
number of components of the destination register. And in the 16bit
case, even if nir_lower_tex packs the outcome, it doesn't update the
number of components, as nir_tex_instr_dest_size would still return
4. And nir validate would check that those values are the same.
So this change focuses on the last part of this comment at
nir_lower_tex:
* Note that we don't change the destination num_components, because
* nir_tex_instr_dest_size() will still return 4. The driver is just
* expected to not store the other channels, given that nothing at the
* NIR level will read them.
We just limit how many channels we would use for the f16 case.
It is also worth to note, based on the CTS and different applications
we test, that this is a corner case.
This was detected when we experimented to enable nir_opt_gcm for v3d,
that lead to raise an assertion slightly below with some shaderdb
tests, but technically it could happen without it.
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17185>
2022-06-16 23:26:22 +02:00
|
|
|
/* Even if the texture operation doesn't need a sampler by
|
|
|
|
* itself, we still need to add the sampler configuration
|
|
|
|
* parameter if the output is 32 bit
|
|
|
|
*/
|
|
|
|
bool output_type_32_bit =
|
|
|
|
c->key->sampler[sampler_idx].return_size == 32 &&
|
|
|
|
!instr->is_shadow;
|
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
struct V3D41_TMU_CONFIG_PARAMETER_0 p0_unpacked = {
|
|
|
|
};
|
2018-01-10 12:51:08 -08:00
|
|
|
|
|
|
|
/* Limit the number of channels returned to both how many the NIR
|
|
|
|
* instruction writes and how many the instruction could produce.
|
|
|
|
*/
|
broadcom/compiler: update how we compute return_words_of_texture_data on non-ssa
For the non-ssa case, we were trying to use reg->num_components. But
this is not the same that nir_ssa_def_components_read. It is the
number of components of the destination register. And in the 16bit
case, even if nir_lower_tex packs the outcome, it doesn't update the
number of components, as nir_tex_instr_dest_size would still return
4. And nir validate would check that those values are the same.
So this change focuses on the last part of this comment at
nir_lower_tex:
* Note that we don't change the destination num_components, because
* nir_tex_instr_dest_size() will still return 4. The driver is just
* expected to not store the other channels, given that nothing at the
* NIR level will read them.
We just limit how many channels we would use for the f16 case.
It is also worth to note, based on the CTS and different applications
we test, that this is a corner case.
This was detected when we experimented to enable nir_opt_gcm for v3d,
that lead to raise an assertion slightly below with some shaderdb
tests, but technically it could happen without it.
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17185>
2022-06-16 23:26:22 +02:00
|
|
|
if (instr->dest.is_ssa) {
|
|
|
|
p0_unpacked.return_words_of_texture_data =
|
|
|
|
nir_ssa_def_components_read(&instr->dest.ssa);
|
|
|
|
} else {
|
|
|
|
/* For the non-ssa case we don't have a full equivalent to
|
|
|
|
* nir_ssa_def_components_read. This is a problem for the 16
|
|
|
|
* bit case. nir_lower_tex will not change the destination as
|
|
|
|
* nir_tex_instr_dest_size will still return 4. The driver is
|
|
|
|
* just expected to not store on other channels, so we
|
|
|
|
* manually ensure that here.
|
|
|
|
*/
|
|
|
|
uint32_t num_components = output_type_32_bit ?
|
|
|
|
MIN2(instr->dest.reg.reg->num_components, 4) :
|
|
|
|
MIN2(instr->dest.reg.reg->num_components, 2);
|
|
|
|
|
|
|
|
p0_unpacked.return_words_of_texture_data = (1 << num_components) - 1;
|
|
|
|
}
|
2019-04-25 11:23:55 -07:00
|
|
|
assert(p0_unpacked.return_words_of_texture_data != 0);
|
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
struct V3D41_TMU_CONFIG_PARAMETER_2 p2_unpacked = {
|
|
|
|
.op = V3D_TMU_OP_REGULAR,
|
|
|
|
.gather_mode = instr->op == nir_texop_tg4,
|
|
|
|
.gather_component = instr->component,
|
|
|
|
.coefficient_mode = instr->op == nir_texop_txd,
|
|
|
|
.disable_autolod = instr->op == nir_texop_tg4
|
|
|
|
};
|
|
|
|
|
2021-01-28 09:27:09 +01:00
|
|
|
const unsigned tmu_writes = get_required_tex_tmu_writes(c, instr);
|
2021-01-27 09:45:52 +01:00
|
|
|
|
|
|
|
/* The input FIFO has 16 slots across all threads so if we require
|
|
|
|
* more than that we need to lower thread count.
|
|
|
|
*/
|
|
|
|
while (tmu_writes > 16 / c->threads)
|
|
|
|
c->threads /= 2;
|
|
|
|
|
|
|
|
/* If pipelining this TMU operation would overflow TMU fifos, we need
|
|
|
|
* to flush any outstanding TMU operations.
|
|
|
|
*/
|
|
|
|
const unsigned dest_components =
|
|
|
|
util_bitcount(p0_unpacked.return_words_of_texture_data);
|
2021-02-03 09:14:00 +01:00
|
|
|
if (ntq_tmu_fifo_overflow(c, dest_components))
|
2021-01-27 09:45:52 +01:00
|
|
|
ntq_flush_tmu(c);
|
|
|
|
|
|
|
|
/* Process tex sources emitting corresponding TMU writes */
|
|
|
|
struct qreg s = { };
|
|
|
|
vir_tex_handle_srcs(c, instr, &p2_unpacked, &s, NULL);
|
|
|
|
|
2018-01-10 12:51:08 -08:00
|
|
|
uint32_t p0_packed;
|
|
|
|
V3D41_TMU_CONFIG_PARAMETER_0_pack(NULL,
|
|
|
|
(uint8_t *)&p0_packed,
|
|
|
|
&p0_unpacked);
|
|
|
|
|
|
|
|
uint32_t p2_packed;
|
|
|
|
V3D41_TMU_CONFIG_PARAMETER_2_pack(NULL,
|
|
|
|
(uint8_t *)&p2_packed,
|
|
|
|
&p2_unpacked);
|
|
|
|
|
2020-04-17 01:57:18 +02:00
|
|
|
/* We manually set the LOD Query bit (see
|
|
|
|
* V3D42_TMU_CONFIG_PARAMETER_2) as right now is the only V42 specific
|
|
|
|
* feature over V41 we are using
|
|
|
|
*/
|
|
|
|
if (instr->op == nir_texop_lod)
|
|
|
|
p2_packed |= 1UL << 24;
|
|
|
|
|
2020-11-10 22:05:10 +01:00
|
|
|
/* Load texture_idx number into the high bits of the texture address field,
|
2020-04-13 11:45:27 +02:00
|
|
|
* which will be be used by the driver to decide which texture to put
|
|
|
|
* in the actual address field.
|
2018-01-10 12:51:08 -08:00
|
|
|
*/
|
2020-11-10 22:05:10 +01:00
|
|
|
p0_packed |= texture_idx << 24;
|
2018-01-10 12:51:08 -08:00
|
|
|
|
|
|
|
vir_WRTMUC(c, QUNIFORM_TMU_CONFIG_P0, p0_packed);
|
2020-04-13 11:45:27 +02:00
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
/* p1 is optional, but we can skip it only if p2 can be skipped too */
|
2020-04-21 01:09:00 +02:00
|
|
|
bool needs_p2_config =
|
2020-04-17 01:57:18 +02:00
|
|
|
(instr->op == nir_texop_lod ||
|
2021-01-27 09:45:52 +01:00
|
|
|
memcmp(&p2_unpacked, &p2_unpacked_default,
|
|
|
|
sizeof(p2_unpacked)) != 0);
|
2020-04-21 01:09:00 +02:00
|
|
|
|
2020-06-23 01:52:48 +02:00
|
|
|
/* To handle the cases were we can't just use p1_unpacked_default */
|
|
|
|
bool non_default_p1_config = nir_tex_instr_need_sampler(instr) ||
|
|
|
|
output_type_32_bit;
|
|
|
|
|
|
|
|
if (non_default_p1_config) {
|
2020-04-13 11:45:27 +02:00
|
|
|
struct V3D41_TMU_CONFIG_PARAMETER_1 p1_unpacked = {
|
|
|
|
.output_type_32_bit = output_type_32_bit,
|
|
|
|
|
|
|
|
.unnormalized_coordinates = (instr->sampler_dim ==
|
|
|
|
GLSL_SAMPLER_DIM_RECT),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Word enables can't ask for more channels than the
|
|
|
|
* output type could provide (2 for f16, 4 for
|
|
|
|
* 32-bit).
|
|
|
|
*/
|
|
|
|
assert(!p1_unpacked.output_type_32_bit ||
|
|
|
|
p0_unpacked.return_words_of_texture_data < (1 << 4));
|
|
|
|
assert(p1_unpacked.output_type_32_bit ||
|
|
|
|
p0_unpacked.return_words_of_texture_data < (1 << 2));
|
|
|
|
|
|
|
|
uint32_t p1_packed;
|
|
|
|
V3D41_TMU_CONFIG_PARAMETER_1_pack(NULL,
|
|
|
|
(uint8_t *)&p1_packed,
|
|
|
|
&p1_unpacked);
|
|
|
|
|
2020-06-23 01:52:48 +02:00
|
|
|
if (nir_tex_instr_need_sampler(instr)) {
|
2020-11-10 22:05:10 +01:00
|
|
|
/* Load sampler_idx number into the high bits of the
|
|
|
|
* sampler address field, which will be be used by the
|
|
|
|
* driver to decide which sampler to put in the actual
|
2020-06-23 01:52:48 +02:00
|
|
|
* address field.
|
|
|
|
*/
|
2020-11-10 22:05:10 +01:00
|
|
|
p1_packed |= sampler_idx << 24;
|
2020-06-23 01:52:48 +02:00
|
|
|
|
|
|
|
vir_WRTMUC(c, QUNIFORM_TMU_CONFIG_P1, p1_packed);
|
|
|
|
} else {
|
|
|
|
/* In this case, we don't need to merge in any
|
|
|
|
* sampler state from the API and can just use
|
|
|
|
* our packed bits */
|
|
|
|
vir_WRTMUC(c, QUNIFORM_CONSTANT, p1_packed);
|
|
|
|
}
|
2020-04-29 10:29:50 +02:00
|
|
|
} else if (needs_p2_config) {
|
|
|
|
/* Configuration parameters need to be set up in
|
|
|
|
* order, and if P2 is needed, you need to set up P1
|
|
|
|
* too even if sampler info is not needed by the
|
|
|
|
* texture operation. But we can set up default info,
|
|
|
|
* and avoid asking the driver for the sampler state
|
|
|
|
* address
|
|
|
|
*/
|
|
|
|
uint32_t p1_packed_default;
|
|
|
|
V3D41_TMU_CONFIG_PARAMETER_1_pack(NULL,
|
|
|
|
(uint8_t *)&p1_packed_default,
|
|
|
|
&p1_unpacked_default);
|
|
|
|
vir_WRTMUC(c, QUNIFORM_CONSTANT, p1_packed_default);
|
2020-04-13 11:45:27 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 01:09:00 +02:00
|
|
|
if (needs_p2_config)
|
2018-07-20 13:31:49 -07:00
|
|
|
vir_WRTMUC(c, QUNIFORM_CONSTANT, p2_packed);
|
2018-01-10 12:51:08 -08:00
|
|
|
|
2021-01-27 09:45:52 +01:00
|
|
|
/* Emit retiring TMU write */
|
2023-03-20 11:15:40 +01:00
|
|
|
struct qinst *retiring;
|
2018-01-10 12:51:08 -08:00
|
|
|
if (instr->op == nir_texop_txf) {
|
|
|
|
assert(instr->sampler_dim != GLSL_SAMPLER_DIM_CUBE);
|
2023-03-20 11:15:40 +01:00
|
|
|
retiring = vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUSF, s);
|
2018-01-10 12:51:08 -08:00
|
|
|
} else if (instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE) {
|
2023-03-20 11:15:40 +01:00
|
|
|
retiring = vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUSCM, s);
|
2020-05-07 11:46:25 +02:00
|
|
|
} else if (instr->op == nir_texop_txl) {
|
2023-03-20 11:15:40 +01:00
|
|
|
retiring = vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUSLOD, s);
|
2018-01-10 12:51:08 -08:00
|
|
|
} else {
|
2023-03-20 11:15:40 +01:00
|
|
|
retiring = vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUS, s);
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
|
|
|
|
2023-03-20 11:15:40 +01:00
|
|
|
retiring->ldtmu_count = p0_unpacked.return_words_of_texture_data;
|
2021-01-27 09:45:52 +01:00
|
|
|
ntq_add_pending_tmu_flush(c, &instr->dest,
|
2021-02-03 09:14:00 +01:00
|
|
|
p0_unpacked.return_words_of_texture_data);
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
2017-12-11 12:52:27 -08:00
|
|
|
|
2019-06-27 14:16:15 +02:00
|
|
|
static uint32_t
|
|
|
|
v3d40_image_load_store_tmu_op(nir_intrinsic_instr *instr)
|
|
|
|
{
|
|
|
|
switch (instr->intrinsic) {
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_load:
|
|
|
|
case nir_intrinsic_image_store:
|
2019-06-27 14:16:15 +02:00
|
|
|
return V3D_TMU_OP_REGULAR;
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_add:
|
2019-06-25 15:02:56 +02:00
|
|
|
return v3d_get_op_for_atomic_add(instr, 3);
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_imin:
|
2019-08-21 11:47:55 -05:00
|
|
|
return V3D_TMU_OP_WRITE_SMIN;
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_umin:
|
2019-06-27 14:16:15 +02:00
|
|
|
return V3D_TMU_OP_WRITE_UMIN_FULL_L1_CLEAR;
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_imax:
|
2019-08-21 11:47:55 -05:00
|
|
|
return V3D_TMU_OP_WRITE_SMAX;
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_umax:
|
2019-06-27 14:16:15 +02:00
|
|
|
return V3D_TMU_OP_WRITE_UMAX;
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_and:
|
2019-06-27 14:16:15 +02:00
|
|
|
return V3D_TMU_OP_WRITE_AND_READ_INC;
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_or:
|
2019-06-27 14:16:15 +02:00
|
|
|
return V3D_TMU_OP_WRITE_OR_READ_DEC;
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_xor:
|
2019-06-27 14:16:15 +02:00
|
|
|
return V3D_TMU_OP_WRITE_XOR_READ_NOT;
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_exchange:
|
2019-06-27 14:16:15 +02:00
|
|
|
return V3D_TMU_OP_WRITE_XCHG_READ_FLUSH;
|
2020-01-23 16:33:24 -08:00
|
|
|
case nir_intrinsic_image_atomic_comp_swap:
|
2019-06-27 14:16:15 +02:00
|
|
|
return V3D_TMU_OP_WRITE_CMPXCHG_READ_FLUSH;
|
|
|
|
default:
|
|
|
|
unreachable("unknown image intrinsic");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-28 09:27:09 +01:00
|
|
|
/**
|
|
|
|
* If 'tmu_writes' is not NULL, then it just counts required register writes,
|
|
|
|
* otherwise, it emits the actual register writes.
|
|
|
|
*
|
|
|
|
* It is important to notice that emitting register writes for the current
|
|
|
|
* TMU operation may trigger a TMU flush, since it is possible that any
|
|
|
|
* of the inputs required for the register writes is the result of a pending
|
|
|
|
* TMU operation. If that happens we need to make sure that it doesn't happen
|
|
|
|
* in the middle of the TMU register writes for the current TMU operation,
|
|
|
|
* which is why we always call ntq_get_src() even if we are only interested in
|
|
|
|
* register write counts.
|
|
|
|
*/
|
2023-03-20 11:15:40 +01:00
|
|
|
static struct qinst *
|
2021-01-28 09:27:09 +01:00
|
|
|
vir_image_emit_register_writes(struct v3d_compile *c,
|
|
|
|
nir_intrinsic_instr *instr,
|
|
|
|
bool atomic_add_replaced,
|
|
|
|
uint32_t *tmu_writes)
|
|
|
|
{
|
|
|
|
if (tmu_writes)
|
|
|
|
*tmu_writes = 0;
|
|
|
|
|
|
|
|
bool is_1d = false;
|
|
|
|
switch (nir_intrinsic_image_dim(instr)) {
|
|
|
|
case GLSL_SAMPLER_DIM_1D:
|
|
|
|
is_1d = true;
|
|
|
|
break;
|
|
|
|
case GLSL_SAMPLER_DIM_BUF:
|
|
|
|
break;
|
|
|
|
case GLSL_SAMPLER_DIM_2D:
|
|
|
|
case GLSL_SAMPLER_DIM_RECT:
|
|
|
|
case GLSL_SAMPLER_DIM_CUBE: {
|
|
|
|
struct qreg src = ntq_get_src(c, instr->src[1], 1);
|
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUT, src, tmu_writes);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GLSL_SAMPLER_DIM_3D: {
|
|
|
|
struct qreg src_1_1 = ntq_get_src(c, instr->src[1], 1);
|
|
|
|
struct qreg src_1_2 = ntq_get_src(c, instr->src[1], 2);
|
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUT, src_1_1, tmu_writes);
|
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUR, src_1_2, tmu_writes);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
unreachable("bad image sampler dim");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In order to fetch on a cube map, we need to interpret it as
|
|
|
|
* 2D arrays, where the third coord would be the face index.
|
|
|
|
*/
|
|
|
|
if (nir_intrinsic_image_dim(instr) == GLSL_SAMPLER_DIM_CUBE ||
|
|
|
|
nir_intrinsic_image_array(instr)) {
|
|
|
|
struct qreg src = ntq_get_src(c, instr->src[1], is_1d ? 1 : 2);
|
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUI, src, tmu_writes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit the data writes for atomics or image store. */
|
|
|
|
if (instr->intrinsic != nir_intrinsic_image_load &&
|
|
|
|
!atomic_add_replaced) {
|
|
|
|
for (int i = 0; i < nir_intrinsic_src_components(instr, 3); i++) {
|
|
|
|
struct qreg src_3_i = ntq_get_src(c, instr->src[3], i);
|
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUD, src_3_i,
|
|
|
|
tmu_writes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Second atomic argument */
|
|
|
|
if (instr->intrinsic == nir_intrinsic_image_atomic_comp_swap) {
|
|
|
|
struct qreg src_4_0 = ntq_get_src(c, instr->src[4], 0);
|
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUD, src_4_0,
|
|
|
|
tmu_writes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct qreg src_1_0 = ntq_get_src(c, instr->src[1], 0);
|
|
|
|
if (!tmu_writes && vir_in_nonuniform_control_flow(c) &&
|
|
|
|
instr->intrinsic != nir_intrinsic_image_load) {
|
2021-02-08 16:41:35 -05:00
|
|
|
vir_set_pf(c, vir_MOV_dest(c, vir_nop_reg(), c->execute),
|
|
|
|
V3D_QPU_PF_PUSHZ);
|
2021-01-28 09:27:09 +01:00
|
|
|
}
|
|
|
|
|
2023-03-20 11:15:40 +01:00
|
|
|
struct qinst *retiring =
|
|
|
|
vir_TMU_WRITE_or_count(c, V3D_QPU_WADDR_TMUSF, src_1_0, tmu_writes);
|
2021-01-28 09:27:09 +01:00
|
|
|
|
|
|
|
if (!tmu_writes && vir_in_nonuniform_control_flow(c) &&
|
|
|
|
instr->intrinsic != nir_intrinsic_image_load) {
|
|
|
|
struct qinst *last_inst =
|
|
|
|
(struct qinst *)c->cur_block->instructions.prev;
|
|
|
|
vir_set_cond(last_inst, V3D_QPU_COND_IFA);
|
|
|
|
}
|
2023-03-20 11:15:40 +01:00
|
|
|
|
|
|
|
return retiring;
|
2021-01-28 09:27:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
|
|
|
get_required_image_tmu_writes(struct v3d_compile *c,
|
|
|
|
nir_intrinsic_instr *instr,
|
|
|
|
bool atomic_add_replaced)
|
|
|
|
{
|
|
|
|
unsigned tmu_writes;
|
|
|
|
vir_image_emit_register_writes(c, instr, atomic_add_replaced,
|
|
|
|
&tmu_writes);
|
|
|
|
return tmu_writes;
|
|
|
|
}
|
|
|
|
|
2017-12-11 12:52:27 -08:00
|
|
|
void
|
|
|
|
v3d40_vir_emit_image_load_store(struct v3d_compile *c,
|
|
|
|
nir_intrinsic_instr *instr)
|
|
|
|
{
|
2020-01-23 16:33:24 -08:00
|
|
|
unsigned format = nir_intrinsic_format(instr);
|
|
|
|
unsigned unit = nir_src_as_uint(instr->src[0]);
|
2017-12-11 12:52:27 -08:00
|
|
|
|
|
|
|
struct V3D41_TMU_CONFIG_PARAMETER_0 p0_unpacked = {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct V3D41_TMU_CONFIG_PARAMETER_1 p1_unpacked = {
|
|
|
|
.per_pixel_mask_enable = true,
|
2020-01-23 16:33:24 -08:00
|
|
|
.output_type_32_bit = v3d_gl_format_is_return_32(format),
|
2017-12-11 12:52:27 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct V3D41_TMU_CONFIG_PARAMETER_2 p2_unpacked = { 0 };
|
|
|
|
|
2021-01-28 09:29:11 +01:00
|
|
|
/* Limit the number of channels returned to both how many the NIR
|
|
|
|
* instruction writes and how many the instruction could produce.
|
|
|
|
*/
|
|
|
|
uint32_t instr_return_channels = nir_intrinsic_dest_components(instr);
|
|
|
|
if (!p1_unpacked.output_type_32_bit)
|
|
|
|
instr_return_channels = (instr_return_channels + 1) / 2;
|
|
|
|
|
|
|
|
p0_unpacked.return_words_of_texture_data =
|
|
|
|
(1 << instr_return_channels) - 1;
|
|
|
|
|
2019-06-27 14:16:15 +02:00
|
|
|
p2_unpacked.op = v3d40_image_load_store_tmu_op(instr);
|
2017-12-11 12:52:27 -08:00
|
|
|
|
2019-06-25 15:02:56 +02:00
|
|
|
/* If we were able to replace atomic_add for an inc/dec, then we
|
|
|
|
* need/can to do things slightly different, like not loading the
|
|
|
|
* amount to add/sub, as that is implicit.
|
|
|
|
*/
|
2021-01-28 09:29:11 +01:00
|
|
|
bool atomic_add_replaced =
|
|
|
|
(instr->intrinsic == nir_intrinsic_image_atomic_add &&
|
|
|
|
(p2_unpacked.op == V3D_TMU_OP_WRITE_AND_READ_INC ||
|
|
|
|
p2_unpacked.op == V3D_TMU_OP_WRITE_OR_READ_DEC));
|
|
|
|
|
|
|
|
uint32_t p0_packed;
|
|
|
|
V3D41_TMU_CONFIG_PARAMETER_0_pack(NULL,
|
|
|
|
(uint8_t *)&p0_packed,
|
|
|
|
&p0_unpacked);
|
|
|
|
|
|
|
|
/* Load unit number into the high bits of the texture or sampler
|
|
|
|
* address field, which will be be used by the driver to decide which
|
|
|
|
* texture to put in the actual address field.
|
|
|
|
*/
|
|
|
|
p0_packed |= unit << 24;
|
|
|
|
|
|
|
|
uint32_t p1_packed;
|
|
|
|
V3D41_TMU_CONFIG_PARAMETER_1_pack(NULL,
|
|
|
|
(uint8_t *)&p1_packed,
|
|
|
|
&p1_unpacked);
|
|
|
|
|
|
|
|
uint32_t p2_packed;
|
|
|
|
V3D41_TMU_CONFIG_PARAMETER_2_pack(NULL,
|
|
|
|
(uint8_t *)&p2_packed,
|
|
|
|
&p2_unpacked);
|
|
|
|
|
|
|
|
if (instr->intrinsic != nir_intrinsic_image_load)
|
|
|
|
c->tmu_dirty_rcl = true;
|
|
|
|
|
2019-06-25 15:02:56 +02:00
|
|
|
|
2021-01-28 09:27:09 +01:00
|
|
|
const uint32_t tmu_writes =
|
|
|
|
get_required_image_tmu_writes(c, instr, atomic_add_replaced);
|
2017-12-11 12:52:27 -08:00
|
|
|
|
2021-01-28 09:27:09 +01:00
|
|
|
/* The input FIFO has 16 slots across all threads so if we require
|
|
|
|
* more than that we need to lower thread count.
|
2017-12-11 12:52:27 -08:00
|
|
|
*/
|
|
|
|
while (tmu_writes > 16 / c->threads)
|
|
|
|
c->threads /= 2;
|
|
|
|
|
2021-01-28 09:27:09 +01:00
|
|
|
/* If pipelining this TMU operation would overflow TMU fifos, we need
|
|
|
|
* to flush any outstanding TMU operations.
|
|
|
|
*/
|
2021-02-03 09:14:00 +01:00
|
|
|
if (ntq_tmu_fifo_overflow(c, instr_return_channels))
|
2021-01-28 09:27:09 +01:00
|
|
|
ntq_flush_tmu(c);
|
|
|
|
|
|
|
|
vir_WRTMUC(c, QUNIFORM_IMAGE_TMU_CONFIG_P0, p0_packed);
|
|
|
|
if (memcmp(&p1_unpacked, &p1_unpacked_default, sizeof(p1_unpacked)))
|
|
|
|
vir_WRTMUC(c, QUNIFORM_CONSTANT, p1_packed);
|
|
|
|
if (memcmp(&p2_unpacked, &p2_unpacked_default, sizeof(p2_unpacked)))
|
|
|
|
vir_WRTMUC(c, QUNIFORM_CONSTANT, p2_packed);
|
2017-12-11 12:52:27 -08:00
|
|
|
|
2023-03-20 11:15:40 +01:00
|
|
|
struct qinst *retiring =
|
|
|
|
vir_image_emit_register_writes(c, instr, atomic_add_replaced, NULL);
|
|
|
|
retiring->ldtmu_count = p0_unpacked.return_words_of_texture_data;
|
2021-01-28 09:27:09 +01:00
|
|
|
ntq_add_pending_tmu_flush(c, &instr->dest,
|
2021-02-03 09:14:00 +01:00
|
|
|
p0_unpacked.return_words_of_texture_data);
|
2017-12-11 12:52:27 -08:00
|
|
|
}
|