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"
|
|
|
|
|
|
|
|
static void
|
2018-06-14 11:17:11 -07:00
|
|
|
vir_TMU_WRITE(struct v3d_compile *c, enum v3d_qpu_waddr waddr, struct qreg val,
|
|
|
|
int *tmu_writes)
|
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.
|
|
|
|
*/
|
2018-01-10 12:51:08 -08:00
|
|
|
vir_MOV_dest(c, vir_reg(QFILE_MAGIC, waddr), val);
|
2018-06-14 11:17:11 -07:00
|
|
|
|
|
|
|
(*tmu_writes)++;
|
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,
|
|
|
|
};
|
|
|
|
|
2018-01-10 12:51:08 -08:00
|
|
|
void
|
|
|
|
v3d40_vir_emit_tex(struct v3d_compile *c, nir_tex_instr *instr)
|
|
|
|
{
|
broadcom/compiler: implement pipelining for general TMU operations
This creates the basic infrastructure to implement TMU pipelining and
applies it to general TMU. Follow-up patches will expand this
to texture and image/load store operations.
TMU pipelining means that we don't immediately end TMU sequences,
and instead, we postpone the thread switch and LDTMU (for loads)
or TMUWT (for stores) until we really need to do them.
For loads, we may need to flush them if another instruction reads
the result of a load operation. We can detect this because in that
case ntq_get_src() will not find the definition for that ssa/reg
(since we have not emitted the LDTMU instructions for it yet), so
when that happens, we flush all pending TMU operations and then
try again to find the definition for the source.
We also need to flush pending TMU operations when we reach the end
of a control flow block, to prevent the case where we emit a TMU
operation in a block, but then we read the result in another block
possibly under control flow.
It is also required to flush across barriers and discards to honor
their semantics.
Since this change doesn't implement pipelining for texture and
image load/store, we also need to flush outstanding TMU operations
if we ever have to emit one of these. This will be corrected with
follow-up patches.
Finally, the TMU has 3 fifos where it can queue TMU operations.
These fifos have limited capacity, depending on the number of threads
used to compile the shader, so we also need to ensure that we
don't have too many outstanding TMU requests and flush pending
TMU operations if a new TMU operation would overflow any of these
fifos. While overflowing the Input and Config fifos only leads
to stalls (which we want to avoid anyway), overflowing the Output
fifo is incorrect and would end up with a broken shader. This means
that we need to know how many TMU register writes are required
to emit a TMU operation and use that information to decide if we need
to flush pending TMU operations before we emit any register
writes for the new TMU operation.
v2: fix TMU flushing for NIR registers reads (jasuarez)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8825>
2021-01-26 12:18:43 +01:00
|
|
|
/* FIXME: allow tex pipelining */
|
|
|
|
ntq_flush_tmu(c);
|
|
|
|
|
2020-11-10 22:05:10 +01:00
|
|
|
unsigned texture_idx = instr->texture_index;
|
|
|
|
unsigned sampler_idx = instr->sampler_index;
|
|
|
|
|
2018-06-14 11:17:11 -07:00
|
|
|
int tmu_writes = 0;
|
2018-01-10 12:51:08 -08:00
|
|
|
|
|
|
|
struct V3D41_TMU_CONFIG_PARAMETER_0 p0_unpacked = {
|
|
|
|
};
|
|
|
|
|
2020-04-17 01:57:18 +02:00
|
|
|
assert(instr->op != nir_texop_lod || c->devinfo->ver >= 42);
|
|
|
|
|
2018-01-10 12:51:08 -08: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,
|
2018-12-26 23:15:30 -08:00
|
|
|
|
|
|
|
.disable_autolod = instr->op == nir_texop_tg4
|
2018-01-10 12:51:08 -08:00
|
|
|
};
|
|
|
|
|
2020-04-17 01:57:18 +02:00
|
|
|
int non_array_components =
|
|
|
|
instr->op != nir_texop_lod ?
|
|
|
|
instr->coord_components - instr->is_array :
|
|
|
|
instr->coord_components;
|
|
|
|
|
2018-01-10 12:51:08 -08:00
|
|
|
struct qreg s;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < instr->num_srcs; i++) {
|
|
|
|
switch (instr->src[i].src_type) {
|
|
|
|
case nir_tex_src_coord:
|
|
|
|
/* S triggers the lookup, so save it for the end. */
|
|
|
|
s = ntq_get_src(c, instr->src[i].src, 0);
|
|
|
|
|
|
|
|
if (non_array_components > 1) {
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUT,
|
|
|
|
ntq_get_src(c, instr->src[i].src,
|
2018-06-14 11:17:11 -07:00
|
|
|
1), &tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
|
|
|
if (non_array_components > 2) {
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUR,
|
|
|
|
ntq_get_src(c, instr->src[i].src,
|
2018-06-14 11:17:11 -07:00
|
|
|
2), &tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (instr->is_array) {
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUI,
|
|
|
|
ntq_get_src(c, instr->src[i].src,
|
2018-06-14 11:17:11 -07:00
|
|
|
instr->coord_components - 1),
|
|
|
|
&tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nir_tex_src_bias:
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUB,
|
2018-06-14 11:17:11 -07:00
|
|
|
ntq_get_src(c, instr->src[i].src, 0),
|
|
|
|
&tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nir_tex_src_lod:
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUB,
|
2018-06-14 11:17:11 -07:00
|
|
|
ntq_get_src(c, instr->src[i].src, 0),
|
|
|
|
&tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
|
2020-05-07 11:46:25 +02:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
if (instr->op != nir_texop_txf &&
|
|
|
|
instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE) {
|
2018-01-10 12:51:08 -08:00
|
|
|
p2_unpacked.disable_autolod = true;
|
2020-05-07 11:46:25 +02:00
|
|
|
}
|
2018-01-10 12:51:08 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nir_tex_src_comparator:
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUDREF,
|
2018-06-14 11:17:11 -07:00
|
|
|
ntq_get_src(c, instr->src[i].src, 0),
|
|
|
|
&tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nir_tex_src_offset: {
|
2018-12-26 23:35:22 -08:00
|
|
|
if (nir_src_is_const(instr->src[i].src)) {
|
2019-03-28 17:53:30 +01:00
|
|
|
p2_unpacked.offset_s = nir_src_comp_as_int(instr->src[i].src, 0);
|
2020-04-29 00:33:47 +02:00
|
|
|
if (non_array_components >= 2)
|
2019-03-28 17:53:30 +01:00
|
|
|
p2_unpacked.offset_t =
|
|
|
|
nir_src_comp_as_int(instr->src[i].src, 1);
|
2019-04-12 09:38:03 -07:00
|
|
|
if (non_array_components >= 3)
|
2019-03-28 17:53:30 +01:00
|
|
|
p2_unpacked.offset_r =
|
|
|
|
nir_src_comp_as_int(instr->src[i].src, 2);
|
2018-12-26 23:35:22 -08:00
|
|
|
} else {
|
|
|
|
struct qreg mask = vir_uniform_ui(c, 0xf);
|
|
|
|
struct qreg x, y, offset;
|
|
|
|
|
|
|
|
x = vir_AND(c, ntq_get_src(c, instr->src[i].src,
|
|
|
|
0), mask);
|
|
|
|
y = vir_AND(c, ntq_get_src(c, instr->src[i].src,
|
|
|
|
1), mask);
|
|
|
|
offset = vir_OR(c, x,
|
|
|
|
vir_SHL(c, y,
|
|
|
|
vir_uniform_ui(c, 4)));
|
|
|
|
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUOFF,
|
|
|
|
offset, &tmu_writes);
|
|
|
|
}
|
2018-01-10 12:51:08 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("unknown texture source");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Limit the number of channels returned to both how many the NIR
|
|
|
|
* instruction writes and how many the instruction could produce.
|
|
|
|
*/
|
|
|
|
p0_unpacked.return_words_of_texture_data =
|
2020-10-26 11:57:32 -04:00
|
|
|
instr->dest.is_ssa ?
|
|
|
|
nir_ssa_def_components_read(&instr->dest.ssa) :
|
|
|
|
(1 << instr->dest.reg.reg->num_components) - 1;
|
2018-01-10 12:51:08 -08:00
|
|
|
|
2019-04-25 11:23:55 -07:00
|
|
|
assert(p0_unpacked.return_words_of_texture_data != 0);
|
|
|
|
|
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
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
2020-11-10 22:05:10 +01:00
|
|
|
bool output_type_32_bit = (c->key->sampler[sampler_idx].return_size == 32 &&
|
2020-04-13 11:45:27 +02:00
|
|
|
!instr->is_shadow);
|
|
|
|
|
2020-04-21 01:09:00 +02:00
|
|
|
/*
|
|
|
|
* p1 is optional, but we can skip it only if p2 can be skipped too
|
|
|
|
*/
|
|
|
|
bool needs_p2_config =
|
2020-04-17 01:57:18 +02:00
|
|
|
(instr->op == nir_texop_lod ||
|
|
|
|
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
|
|
|
|
|
|
|
if (instr->op == nir_texop_txf) {
|
|
|
|
assert(instr->sampler_dim != GLSL_SAMPLER_DIM_CUBE);
|
2018-06-14 11:17:11 -07:00
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUSF, s, &tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
} else if (instr->sampler_dim == GLSL_SAMPLER_DIM_CUBE) {
|
2018-06-14 11:17:11 -07:00
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUSCM, s, &tmu_writes);
|
2020-05-07 11:46:25 +02:00
|
|
|
} else if (instr->op == nir_texop_txl) {
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUSLOD, s, &tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
} else {
|
2018-06-14 11:17:11 -07:00
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUS, s, &tmu_writes);
|
2018-01-10 12:51:08 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
vir_emit_thrsw(c);
|
|
|
|
|
2018-06-14 11:17:11 -07:00
|
|
|
/* The input FIFO has 16 slots across all threads, so make sure we
|
|
|
|
* don't overfill our allocation.
|
|
|
|
*/
|
|
|
|
while (tmu_writes > 16 / c->threads)
|
|
|
|
c->threads /= 2;
|
|
|
|
|
2018-01-10 12:51:08 -08:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (p0_unpacked.return_words_of_texture_data & (1 << i))
|
2018-12-20 09:43:43 -08:00
|
|
|
ntq_store_dest(c, &instr->dest, i, vir_LDTMU(c));
|
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");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-11 12:52:27 -08:00
|
|
|
void
|
|
|
|
v3d40_vir_emit_image_load_store(struct v3d_compile *c,
|
|
|
|
nir_intrinsic_instr *instr)
|
|
|
|
{
|
broadcom/compiler: implement pipelining for general TMU operations
This creates the basic infrastructure to implement TMU pipelining and
applies it to general TMU. Follow-up patches will expand this
to texture and image/load store operations.
TMU pipelining means that we don't immediately end TMU sequences,
and instead, we postpone the thread switch and LDTMU (for loads)
or TMUWT (for stores) until we really need to do them.
For loads, we may need to flush them if another instruction reads
the result of a load operation. We can detect this because in that
case ntq_get_src() will not find the definition for that ssa/reg
(since we have not emitted the LDTMU instructions for it yet), so
when that happens, we flush all pending TMU operations and then
try again to find the definition for the source.
We also need to flush pending TMU operations when we reach the end
of a control flow block, to prevent the case where we emit a TMU
operation in a block, but then we read the result in another block
possibly under control flow.
It is also required to flush across barriers and discards to honor
their semantics.
Since this change doesn't implement pipelining for texture and
image load/store, we also need to flush outstanding TMU operations
if we ever have to emit one of these. This will be corrected with
follow-up patches.
Finally, the TMU has 3 fifos where it can queue TMU operations.
These fifos have limited capacity, depending on the number of threads
used to compile the shader, so we also need to ensure that we
don't have too many outstanding TMU requests and flush pending
TMU operations if a new TMU operation would overflow any of these
fifos. While overflowing the Input and Config fifos only leads
to stalls (which we want to avoid anyway), overflowing the Output
fifo is incorrect and would end up with a broken shader. This means
that we need to know how many TMU register writes are required
to emit a TMU operation and use that information to decide if we need
to flush pending TMU operations before we emit any register
writes for the new TMU operation.
v2: fix TMU flushing for NIR registers reads (jasuarez)
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8825>
2021-01-26 12:18:43 +01:00
|
|
|
/* FIXME: allow image load/store pipelining */
|
|
|
|
ntq_flush_tmu(c);
|
|
|
|
|
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
|
|
|
int tmu_writes = 0;
|
|
|
|
|
|
|
|
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 };
|
|
|
|
|
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.
|
|
|
|
*/
|
2020-01-23 16:33:24 -08:00
|
|
|
bool atomic_add_replaced = (instr->intrinsic == nir_intrinsic_image_atomic_add &&
|
2019-06-25 15:02:56 +02:00
|
|
|
(p2_unpacked.op == V3D_TMU_OP_WRITE_AND_READ_INC ||
|
|
|
|
p2_unpacked.op == V3D_TMU_OP_WRITE_OR_READ_DEC));
|
|
|
|
|
2017-12-11 12:52:27 -08:00
|
|
|
bool is_1d = false;
|
2020-01-23 16:33:24 -08:00
|
|
|
switch (nir_intrinsic_image_dim(instr)) {
|
2017-12-11 12:52:27 -08:00
|
|
|
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:
|
2020-06-26 15:32:31 +02:00
|
|
|
case GLSL_SAMPLER_DIM_CUBE:
|
2017-12-11 12:52:27 -08:00
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUT,
|
|
|
|
ntq_get_src(c, instr->src[1], 1), &tmu_writes);
|
|
|
|
break;
|
|
|
|
case GLSL_SAMPLER_DIM_3D:
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUT,
|
|
|
|
ntq_get_src(c, instr->src[1], 1), &tmu_writes);
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUR,
|
|
|
|
ntq_get_src(c, instr->src[1], 2), &tmu_writes);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unreachable("bad image sampler dim");
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:32:31 +02:00
|
|
|
/* 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)) {
|
2017-12-11 12:52:27 -08:00
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUI,
|
|
|
|
ntq_get_src(c, instr->src[1],
|
|
|
|
is_1d ? 1 : 2), &tmu_writes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
uint32_t p0_packed;
|
|
|
|
V3D41_TMU_CONFIG_PARAMETER_0_pack(NULL,
|
|
|
|
(uint8_t *)&p0_packed,
|
|
|
|
&p0_unpacked);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
vir_WRTMUC(c, QUNIFORM_IMAGE_TMU_CONFIG_P0, p0_packed);
|
|
|
|
if (memcmp(&p1_unpacked, &p1_unpacked_default, sizeof(p1_unpacked)) != 0)
|
|
|
|
vir_WRTMUC(c, QUNIFORM_CONSTANT, p1_packed);
|
|
|
|
if (memcmp(&p2_unpacked, &p2_unpacked_default, sizeof(p2_unpacked)) != 0)
|
|
|
|
vir_WRTMUC(c, QUNIFORM_CONSTANT, p2_packed);
|
|
|
|
|
|
|
|
/* Emit the data writes for atomics or image store. */
|
2020-01-23 16:33:24 -08:00
|
|
|
if (instr->intrinsic != nir_intrinsic_image_load &&
|
2019-06-25 15:02:56 +02:00
|
|
|
!atomic_add_replaced) {
|
2017-12-11 12:52:27 -08:00
|
|
|
/* Vector for stores, or first atomic argument */
|
|
|
|
struct qreg src[4];
|
|
|
|
for (int i = 0; i < nir_intrinsic_src_components(instr, 3); i++) {
|
|
|
|
src[i] = ntq_get_src(c, instr->src[3], i);
|
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUD, src[i],
|
|
|
|
&tmu_writes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Second atomic argument */
|
|
|
|
if (instr->intrinsic ==
|
2020-01-23 16:33:24 -08:00
|
|
|
nir_intrinsic_image_atomic_comp_swap) {
|
2017-12-11 12:52:27 -08:00
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUD,
|
|
|
|
ntq_get_src(c, instr->src[4], 0),
|
|
|
|
&tmu_writes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-15 14:46:30 +01:00
|
|
|
if (vir_in_nonuniform_control_flow(c) &&
|
2020-01-23 16:33:24 -08:00
|
|
|
instr->intrinsic != nir_intrinsic_image_load) {
|
2019-11-15 14:46:30 +01:00
|
|
|
vir_set_pf(vir_MOV_dest(c, vir_nop_reg(), c->execute),
|
|
|
|
V3D_QPU_PF_PUSHZ);
|
|
|
|
}
|
|
|
|
|
2017-12-11 12:52:27 -08:00
|
|
|
vir_TMU_WRITE(c, V3D_QPU_WADDR_TMUSF, ntq_get_src(c, instr->src[1], 0),
|
|
|
|
&tmu_writes);
|
|
|
|
|
2019-11-15 14:46:30 +01:00
|
|
|
if (vir_in_nonuniform_control_flow(c) &&
|
2020-01-23 16:33:24 -08:00
|
|
|
instr->intrinsic != nir_intrinsic_image_load) {
|
2019-11-15 14:46:30 +01:00
|
|
|
struct qinst *last_inst= (struct qinst *)c->cur_block->instructions.prev;
|
|
|
|
vir_set_cond(last_inst, V3D_QPU_COND_IFA);
|
|
|
|
}
|
|
|
|
|
2017-12-11 12:52:27 -08:00
|
|
|
vir_emit_thrsw(c);
|
|
|
|
|
|
|
|
/* The input FIFO has 16 slots across all threads, so make sure we
|
|
|
|
* don't overfill our allocation.
|
|
|
|
*/
|
|
|
|
while (tmu_writes > 16 / c->threads)
|
|
|
|
c->threads /= 2;
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
if (p0_unpacked.return_words_of_texture_data & (1 << i))
|
|
|
|
ntq_store_dest(c, &instr->dest, i, vir_LDTMU(c));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nir_intrinsic_dest_components(instr) == 0)
|
|
|
|
vir_TMUWT(c);
|
2019-08-14 09:27:13 +02:00
|
|
|
|
2020-01-23 16:33:24 -08:00
|
|
|
if (instr->intrinsic != nir_intrinsic_image_load)
|
2019-08-14 09:27:13 +02:00
|
|
|
c->tmu_dirty_rcl = true;
|
2017-12-11 12:52:27 -08:00
|
|
|
}
|