Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/imagination/g5p/g5p_mrt_programs.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,28 @@ static inline uint32_t g5p_mrt_restore1(unsigned n)
* halves: output halves per target, 4 for an 8-bit RGBA target (two packed
* f16x2 dwords), 8 for a 32-bit integer target of the raw32 output (four
* raw words, so target 1 starts at output dword 4). */
static inline unsigned g5p_mrt_pbe_block_halves(uint32_t *out, unsigned n, const uint64_t pbe[][3], unsigned halves)
static inline unsigned g5p_mrt_pbe_block_offsets(uint32_t *out, unsigned n, const uint64_t pbe[][3],
const uint32_t *halves)
{
for (unsigned t = 0; t < n; t++) {
uint32_t *w = out + G5P_MRT_PBE_STRIDE * t;
for (unsigned q = 0; q < 3; q++) {
w[2 * q] = (uint32_t)pbe[t][q];
w[2 * q + 1] = (uint32_t)(pbe[t][q] >> 32);
}
w[6] = halves * t;
w[6] = halves[t];
if (t + 1 < n)
w[7] = 0xffffffff;
}
return g5p_mrt_pbe_dwords(n);
}
static inline unsigned g5p_mrt_pbe_block_halves(uint32_t *out, unsigned n, const uint64_t pbe[][3], unsigned halves)
{
uint32_t offs[G5P_MRT_MAX];
for (unsigned t = 0; t < n; t++)
offs[t] = halves * t;
return g5p_mrt_pbe_block_offsets(out, n, pbe, offs);
}
static inline unsigned g5p_mrt_pbe_block(uint32_t *out, unsigned n, const uint64_t pbe[][3])
{
return g5p_mrt_pbe_block_halves(out, n, pbe, 4);
Expand Down
27 changes: 19 additions & 8 deletions src/imagination/g5p/pco_g5p_general.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ struct gctx {
/* common store */
struct tex_bind tex[16];
unsigned ntex, fetch_sampler_common;
bool fs_fetch_shared; /* compact FS uses shared fetch_sampler_common for txf */
int vtx_lod_common; /* the A8 vertex sample's level 0.0 in the common store (PCO_G5P_UPLOAD_ZERO), -1 without */
bool cube_gradient; /* fixed native bank0 r0..r8 operand tuple */
struct { unsigned set, binding, element, lod, common; } tsize[4]; /* textureSize/QueryLevels */
Expand Down Expand Up @@ -2379,11 +2380,13 @@ static void plan_common(struct gctx *c)
if (g5p_usc_g4p && !g5p_usc_g4p_a9_forms && compact && c->ntex && !(c->vs && g5p_usc_g4p_vtex))
refuse(c, "the A8 samples one image slot (common dword 0); more than four textures or vertex textures are "
"not captured");
const bool fs_fetch = !c->vs && !g5p_usc_g4p && !c->key->txf_own_sampler;
const bool use_fetch = qualified || fs_fetch;
unsigned sampler_count = 0;
bool fetch_sampler = false;
for (unsigned i = 0; i < c->ntex; i++) {
sampler_count += !qualified || c->tex[i].needs_sampler;
fetch_sampler |= qualified && c->tex[i].needs_fetch_sampler;
sampler_count += !use_fetch || c->tex[i].needs_sampler;
fetch_sampler |= use_fetch && c->tex[i].needs_fetch_sampler;
}
/* the samplerless read's sampler policy is the A9's one-qword word (pvr_g5p_fetch_sampler_word()); the A8's,
* with vertex textures, four dwords of Rogue sampler words (point, non-normalized, clamped) */
Expand Down Expand Up @@ -2466,6 +2469,7 @@ static void plan_common(struct gctx *c)
c->a8_one_sampler = c->a8_slots && (c->ntex == 1 || (one_sampler && !a8_each));
c->a8_sampler_each = c->a8_slots && a8_each;
c->fetch_sampler_common = sampler_base + sdw * sampler_count;
c->fs_fetch_shared = fs_fetch && compact && fetch_sampler;
for (unsigned i = 0; c->a8_slots && i < c->ntex; i++) {
struct tex_bind *t = &c->tex[i];
t->image = slot_base + 4 * i;
Expand All @@ -2483,22 +2487,27 @@ static void plan_common(struct gctx *c)
for (unsigned i = 0; !c->a8_slots && i < c->ntex; i++) {
struct tex_bind *t = &c->tex[i];
t->image = compact ? image_base + istride * i : align(next, 8);
t->sampler = compact ? ((!qualified || t->needs_sampler) ? sampler_cursor : c->fetch_sampler_common) : t->image + idw;
sampler_cursor += compact && (!qualified || t->needs_sampler) ? sdw : 0;
next = compact ? c->fetch_sampler_common + (g5p_usc_g4p ? sdw : 2) * (qualified && fetch_sampler)
t->sampler = compact ? ((!use_fetch || t->needs_sampler) ? sampler_cursor : c->fetch_sampler_common) : t->image + idw;
sampler_cursor += compact && (!use_fetch || t->needs_sampler) ? sdw : 0;
next = compact ? c->fetch_sampler_common + (g5p_usc_g4p ? sdw : 2) * (use_fetch && fetch_sampler)
: t->image + idw + sdw;
if (t->image / 2 > (compact ? 120 : 28) || t->sampler / 2 > (compact ? 124 : 32))
refuse(c, "texture descriptors beyond the bounded qualified selectors");
add_upload(c, PCO_G5P_UPLOAD_IMAGE, t->set, t->binding, t->element, t->image_flags, idw, t->image);
if (!qualified || t->needs_sampler)
if (!use_fetch || t->needs_sampler)
add_upload(c, PCO_G5P_UPLOAD_SAMPLER, t->sset, t->sbinding, t->selement,
32 | (t->fetch ? PCO_G5P_UPLOAD_SAMPLER_FETCH |
t->fetch_level << PCO_G5P_UPLOAD_SAMPLER_FETCH_LEVEL_SHIFT |
(t->fetch_read ? PCO_G5P_UPLOAD_SAMPLER_READ : 0) : 0),
sdw, t->sampler);
else if (!compact && fs_fetch)
add_upload(c, PCO_G5P_UPLOAD_FETCH_SAMPLER, 0, 0, 0, 0, 2, t->sampler);
}
if (qualified && fetch_sampler)
if (compact && use_fetch && fetch_sampler) {
if (c->fetch_sampler_common / 2 > 124)
refuse(c, "texture descriptors beyond the bounded qualified selectors");
add_upload(c, PCO_G5P_UPLOAD_FETCH_SAMPLER, 0, 0, 0, 0, g5p_usc_g4p ? sdw : 2, c->fetch_sampler_common);
}
/* Pointer pairs of register-indexed UBO arrays: even dwords below 32 (the
* addr.add_shift base field, 0x81 | 4 * dword). */
for (unsigned i = 0; i < c->nuptr; i++) {
Expand Down Expand Up @@ -5199,7 +5208,9 @@ static void emit_tex_ext(struct gctx *c, nir_tex_instr *t)
bool third = array || sd == GLSL_SAMPLER_DIM_3D || sd == GLSL_SAMPLER_DIM_CUBE;
int packed = packed_offset_components(t, sd == GLSL_SAMPLER_DIM_3D ? 3 : 2);
struct g5p_tex_ext x = {
.image_qword = b->image / 2, .sampler_qword = g5p_usc_g4p ? b->sampler : b->sampler / 2, .read = read,
.image_qword = b->image / 2,
.sampler_qword = g5p_usc_g4p ? b->sampler : (read && c->fs_fetch_shared ? c->fetch_sampler_common : b->sampler) / 2,
.read = read,
.dim = sd == GLSL_SAMPLER_DIM_CUBE ? G5P_TEX_CUBE : sd == GLSL_SAMPLER_DIM_3D ? G5P_TEX_3D :
array ? G5P_TEX_2D_ARRAY : G5P_TEX_2D,
.mask = t->is_shadow ? 1 : 0xf, .compare = t->is_shadow, .offset = packed >= 0,
Expand Down
4 changes: 4 additions & 0 deletions src/imagination/g5p/pco_g5p_general.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ struct pco_g5p_fs_key {
* Apple's 4x form); several discards keep the one-sample test (Apple's several-discard 4x form is not
* ported: such draws are refused at 4x) */
bool ms4_kill;
/* The driver's own background programs (the colour LOAD programs): the driver supplies each texture's
* sampler (g5p_load_background()), so a samplerless texelFetch keeps a PCO_G5P_UPLOAD_SAMPLER slot per
* texture instead of the shared PCO_G5P_UPLOAD_FETCH_SAMPLER of application fragment programs. */
bool txf_own_sampler;
};
#define PCO_G5P_HAS_MASK_UPASS 1
#define PCO_G5P_FS_KEY_DEFAULT ((struct pco_g5p_fs_key){.write_mask = 0xf})
Expand Down
2 changes: 1 addition & 1 deletion src/imagination/g9p/g9p_a9.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct g9p_a9_upload {
/* Keep main's G9P numbering; only the A9 backend uses NIR-order breaks. */
#define G9P_A9_EMPTY_BREAK_BEFORE(ctx, side) do { if (!(ctx)->out->a9 || !(side)) (ctx)->ip++; } while (0)
#define G9P_A9_EMPTY_BREAK_AFTER(ctx, side) do { if ((ctx)->out->a9 && (side)) (ctx)->ip++; } while (0)
#define G9P_A9_CTX_FIELDS unsigned a9_barriers_remaining;
#define G9P_A9_CTX_FIELDS unsigned a9_barriers_remaining; uint8_t a9_storage_images, a9_sampled_images;
#define G9P_A9_GENERATE_INIT a9_generate_init(ctx, impl)
#define G9P_A9_SET_BODYLESS(ctx, n) do { \
if ((ctx)->out->a9 && (ctx)->stage == MESA_SHADER_COMPUTE) \
Expand Down
20 changes: 11 additions & 9 deletions src/imagination/g9p/g9p_a9_compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,9 @@ bool g9p_a9_compile_compute(nir_shader *nir, struct g9p_shader *out, void *mem_c
}
}
/* the fixed common-store places of texture words (g9p_a9_tex.h) */
bool sizes = false, lods = false;
for (unsigned i = 0; i < out->a9_num_uploads; i++) {
sizes |= out->a9_uploads[i].kind == G9P_A9_UP_SIZE;
bool lods = false;
for (unsigned i = 0; i < out->a9_num_uploads; i++)
lods |= out->a9_uploads[i].kind == G9P_A9_UP_LOD;
}
if (lods && out->num_buffers > 13) {
if (!out->a9_refusal[0])
snprintf(out->a9_refusal, sizeof(out->a9_refusal),
Expand All @@ -389,11 +387,15 @@ bool g9p_a9_compile_compute(nir_shader *nir, struct g9p_shader *out, void *mem_c
out->num_buffers);
return backend_failure(out, &(struct g9p_ctx){0});
}
if (sizes && out->num_textures) {
if (!out->a9_refusal[0])
snprintf(out->a9_refusal, sizeof(out->a9_refusal),
"a texture size query together with a storage image (both at common 40-47)");
return backend_failure(out, &(struct g9p_ctx){0});
for (unsigned i = 0; i < out->a9_num_uploads && out->num_textures; i++) {
const struct g9p_a9_upload *u = &out->a9_uploads[i];
if (u->common < 40 + 8 * out->num_textures && u->common + u->dwords > 40) {
if (!out->a9_refusal[0])
snprintf(out->a9_refusal, sizeof(out->a9_refusal),
"compute texture upload at common %u..%u overlaps storage image slots 40..%u",
u->common, u->common + u->dwords - 1, 40 + 8 * out->num_textures - 1);
return backend_failure(out, &(struct g9p_ctx){0});
}
}
return true;
}
92 changes: 92 additions & 0 deletions src/imagination/g9p/g9p_a9_intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,44 @@ static bool a9_shared(struct g9p_ctx *ctx, nir_intrinsic_instr *in)
static void a9_generate_init(struct g9p_ctx *ctx, nir_function_impl *impl)
{
ctx->a9_barriers_remaining = 0;
ctx->a9_storage_images = 0;
ctx->a9_sampled_images = 0;
ctx->out->a9_device_fence = false;
if (!ctx->out->a9) return;
unsigned n = ctx->out->local_size[0] * ctx->out->local_size[1] * ctx->out->local_size[2];
uint32_t st_keys[4], sm_keys[4];
unsigned nst = 0, nsm = 0;
nir_foreach_block(block, impl) {
nir_foreach_instr(instr, block) {
if (instr->type == nir_instr_type_tex) {
nir_tex_instr *tex = nir_instr_as_tex(instr);
unsigned set, binding, element;
if (tex->op != nir_texop_txs && tex->op != nir_texop_query_levels &&
a9_tex_var(tex, nir_tex_src_texture_deref, &set, &binding, &element)) {
const uint32_t k = (set << 16) | (binding << 8) | (element & 0xff);
bool seen = false;
for (unsigned i = 0; i < nsm; i++)
seen |= sm_keys[i] == k;
if (!seen && nsm < ARRAY_SIZE(sm_keys))
sm_keys[nsm++] = k;
}
continue;
}
if (instr->type != nir_instr_type_intrinsic) continue;
nir_intrinsic_instr *in = nir_instr_as_intrinsic(instr);
if (in->intrinsic == nir_intrinsic_image_deref_load ||
in->intrinsic == nir_intrinsic_image_deref_store) {
nir_deref_instr *deref = nir_src_as_deref(in->src[0]);
nir_variable *v = deref ? nir_deref_instr_get_variable(deref) : NULL;
if (v) {
const uint32_t k = (v->data.descriptor_set << 16) | v->data.binding;
bool seen = false;
for (unsigned i = 0; i < nst; i++)
seen |= st_keys[i] == k;
if (!seen && nst < ARRAY_SIZE(st_keys))
st_keys[nst++] = k;
}
}
if (in->intrinsic == nir_intrinsic_barrier &&
(nir_intrinsic_memory_modes(in) & (nir_var_mem_ssbo | nir_var_mem_global | nir_var_image)))
ctx->out->a9_device_fence = true;
Expand All @@ -82,6 +113,8 @@ static void a9_generate_init(struct g9p_ctx *ctx, nir_function_impl *impl)
ctx->a9_barriers_remaining++;
}
}
ctx->a9_storage_images = (uint8_t)nst;
ctx->a9_sampled_images = (uint8_t)nsm;
ctx->out->a9_has_barriers = n > 32 && ctx->a9_barriers_remaining;
if (ctx->out->a9_has_barriers) ctx->busy |= ctx->pinned |= BITFIELD64_BIT(0);
}
Expand Down Expand Up @@ -344,10 +377,69 @@ static bool a9_image(struct g9p_ctx *ctx, nir_intrinsic_instr *in)
}
return true;
}
/* textureDimensions() on a storage image (nir_intrinsic_image_deref_size):
* reuses the CPU-computed G9P_A9_UP_SIZE block (pvr_g5p_image_size() reads the
* storage descriptor's A9 image state), placed in common slots not occupied by
* storage or sampled images. */
static bool a9_image_size(struct g9p_ctx *ctx, nir_intrinsic_instr *in)
{
if (!ctx->out->a9 || ctx->stage != MESA_SHADER_COMPUTE)
return false;
if (nir_intrinsic_image_dim(in) == GLSL_SAMPLER_DIM_BUF) {
a9_tex_refuse(ctx, "storage texel-buffer size query in a compute shader");
return false;
}
nir_deref_instr *deref = nir_src_as_deref(in->src[0]);
nir_variable *v = deref ? nir_deref_instr_get_variable(deref) : NULL;
unsigned element = 0;
if (!v) {
a9_tex_refuse(ctx, "storage image size query without a constant binding");
return false;
}
if (deref->deref_type == nir_deref_type_array) {
if (!nir_src_is_const(deref->arr.index)) {
a9_tex_refuse(ctx, "storage image size query with a non-constant array index");
return false;
}
element = nir_src_as_uint(deref->arr.index);
} else if (deref->deref_type != nir_deref_type_var) {
a9_tex_refuse(ctx, "storage image size query without a constant binding");
return false;
}
if (!nir_src_is_const(in->src[1])) {
a9_tex_refuse(ctx, "storage image size query at a non-constant level");
return false;
}
const unsigned level = nir_src_as_uint(in->src[1]);
const int common = a9_tex_upload(ctx, G9P_A9_UP_SIZE, v->data.descriptor_set, v->data.binding, element, 0, level);
if (common < 0)
return false;
int zero = const_reg(ctx, 0);
if (zero < 0 || (zero = low_reg(ctx, zero)) < 0)
return false;
const bool array_1d = nir_intrinsic_image_dim(in) == GLSL_SAMPLER_DIM_1D && nir_intrinsic_image_array(in);
const unsigned n = in->def.num_components;
int dst[4];
for (unsigned c = 0; c < n; c++) {
if (!ctx->last_use[key(&in->def, c)]) {
dst[c] = -1;
continue;
}
dst[c] = alloc_reg(ctx);
if (dst[c] < 0)
return false;
g9p_mov_uniform(ctx->c, dst[c], common + (array_1d && c == 1 ? 2 : c), zero);
}
release(ctx, &in->instr);
for (unsigned c = 0; c < n; c++)
ctx->reg[key(&in->def, c)] = dst[c];
return true;
}
#define G9P_A9_INTRINSICS \
if (ctx->out->a9) { switch (intr->intrinsic) { \
case nir_intrinsic_image_deref_atomic: case nir_intrinsic_image_deref_atomic_swap: \
a9_tex_refuse(ctx, "image atomics unsupported on A9"); return false; \
case nir_intrinsic_image_deref_size: return a9_image_size(ctx, intr); \
case nir_intrinsic_image_deref_store: case nir_intrinsic_image_deref_load: return a9_image(ctx, intr); \
case nir_intrinsic_shared_atomic: case nir_intrinsic_shared_atomic_swap: return a9_shared_atomic(ctx, intr); \
case nir_intrinsic_ssbo_atomic_swap: return a9_ssbo_cas(ctx, intr); \
Expand Down
29 changes: 23 additions & 6 deletions src/imagination/g9p/g9p_a9_tex.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
static const uint8_t a9_tex_image_dw[] = { 32, 48 };
static const uint8_t a9_tex_sampler_dw[] = { 58, 60, 62 };
static const uint8_t a9_tex_size_dw[] = { 40, 44 };

static void
a9_tex_refuse(struct g9p_ctx *ctx, const char *why)
Expand All @@ -36,10 +35,27 @@ a9_tex_upload(struct g9p_ctx *ctx, unsigned kind, unsigned set, unsigned binding
unsigned combined, unsigned level)
{
struct g9p_shader *out = ctx->out;
uint8_t size_dw[4];
unsigned nsize = 0;
if (kind == G9P_A9_UP_SIZE) {
if (!ctx->a9_storage_images) {
size_dw[nsize++] = 40;
size_dw[nsize++] = 44;
} else {
if (!ctx->a9_sampled_images) {
size_dw[nsize++] = 32;
size_dw[nsize++] = 36;
}
if (ctx->a9_storage_images < 2 && ctx->a9_sampled_images < 2) {
size_dw[nsize++] = 48;
size_dw[nsize++] = 52;
}
}
}
const uint8_t *slots = kind == G9P_A9_UP_IMAGE ? a9_tex_image_dw :
kind == G9P_A9_UP_SIZE ? a9_tex_size_dw : a9_tex_sampler_dw;
kind == G9P_A9_UP_SIZE ? size_dw : a9_tex_sampler_dw;
const unsigned nslots = kind == G9P_A9_UP_IMAGE ? ARRAY_SIZE(a9_tex_image_dw) :
kind == G9P_A9_UP_SIZE ? ARRAY_SIZE(a9_tex_size_dw) : ARRAY_SIZE(a9_tex_sampler_dw);
kind == G9P_A9_UP_SIZE ? nsize : ARRAY_SIZE(a9_tex_sampler_dw);
unsigned used = 0;

for (unsigned i = 0; i < out->a9_num_uploads; i++) {
Expand All @@ -52,14 +68,15 @@ a9_tex_upload(struct g9p_ctx *ctx, unsigned kind, unsigned set, unsigned binding
return u->common;
used += same_class;
}
if (kind == G9P_A9_UP_IMAGE && slots[used < nslots ? used : 0] == 48 && out->num_textures >= 2) {
if (kind == G9P_A9_UP_IMAGE && nslots && slots[used < nslots ? used : 0] == 48 && out->num_textures >= 2) {
a9_tex_refuse(ctx, "a second sampled texture with two storage images (both at common 48)");
return -1;
}
if (used == nslots || out->a9_num_uploads == G9P_A9_MAX_UPLOADS || set > 255 || binding > 255 ||
if (used >= nslots || out->a9_num_uploads == G9P_A9_MAX_UPLOADS || set > 255 || binding > 255 ||
element > 255 || level > 255) {
a9_tex_refuse(ctx, kind == G9P_A9_UP_IMAGE ? "more than 2 sampled textures in a compute shader" :
kind == G9P_A9_UP_SIZE ? "more than 2 texture size queries in a compute shader" :
kind == G9P_A9_UP_SIZE ? (nslots ? "too many texture size queries in a compute shader"
: "no free common-store slot for texture size query") :
"more than 3 samplers in a compute shader");
return -1;
}
Expand Down
Loading
Loading