| 1 |
/* |
| 2 |
* Copyright 2023 Alyssa Rosenzweig |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
#include "agx_builder.h" |
| 6 |
#include "agx_compiler.h" |
| 7 |
|
| 8 |
/* |
| 9 |
* Not all instructions can take uniforms. Memory instructions can take |
| 10 |
* uniforms, but only for their base (first) source and only in the |
| 11 |
* low-half of the uniform file. |
| 12 |
* |
| 13 |
* This pass lowers invalid uniforms. |
| 14 |
*/ |
| 15 |
bool |
| 16 |
agx_instr_accepts_uniform(enum agx_opcode op, unsigned src_index, |
| 17 |
unsigned value, enum agx_size size) |
| 18 |
{ |
| 19 |
/* Some instructions only seem able to access uniforms in the low half */ |
| 20 |
bool high = value >= 256; |
| 21 |
|
| 22 |
/* ALU cannot access 64-bit uniforms */ |
| 23 |
bool is_64 = size == AGX_SIZE_64; |
| 24 |
|
| 25 |
switch (op) { |
| 26 |
case AGX_OPCODE_IMAGE_LOAD: |
| 27 |
case AGX_OPCODE_TEXTURE_LOAD: |
| 28 |
case AGX_OPCODE_TEXTURE_SAMPLE: |
| 29 |
/* Unknown if this works, but the driver will never hit this. */ |
| 30 |
assert(!(src_index == 2 && high) && "texture heap always low"); |
| 31 |
return !high && (src_index == 1 || src_index == 2); |
| 32 |
|
| 33 |
case AGX_OPCODE_TEX_STATE_STORE: |
| 34 |
case AGX_OPCODE_SAMPLER_STATE_STORE: |
| 35 |
assert(!high && "texture heap always low"); |
| 36 |
return !high && src_index == 0; |
| 37 |
|
| 38 |
case AGX_OPCODE_DEVICE_LOAD: |
| 39 |
return src_index == 0 && !high; |
| 40 |
case AGX_OPCODE_DEVICE_STORE: |
| 41 |
case AGX_OPCODE_ATOMIC: |
| 42 |
return src_index == 1 && !high; |
| 43 |
case AGX_OPCODE_LOCAL_LOAD: |
| 44 |
return src_index == 0; |
| 45 |
case AGX_OPCODE_LOCAL_STORE: |
| 46 |
return src_index == 1; |
| 47 |
case AGX_OPCODE_IMAGE_WRITE: |
| 48 |
return src_index == 3; |
| 49 |
case AGX_OPCODE_BLOCK_IMAGE_STORE: |
| 50 |
case AGX_OPCODE_ZS_EMIT: |
| 51 |
case AGX_OPCODE_ST_TILE: |
| 52 |
case AGX_OPCODE_LD_TILE: |
| 53 |
case AGX_OPCODE_UNIFORM_STORE: |
| 54 |
case AGX_OPCODE_ST_VARY: |
| 55 |
case AGX_OPCODE_LOCAL_ATOMIC: |
| 56 |
case AGX_OPCODE_SAMPLE_MASK: |
| 57 |
case AGX_OPCODE_ITER: |
| 58 |
case AGX_OPCODE_ITERPROJ: |
| 59 |
case AGX_OPCODE_STACK_LOAD: |
| 60 |
case AGX_OPCODE_STACK_STORE: |
| 61 |
case AGX_OPCODE_BALLOT: |
| 62 |
case AGX_OPCODE_FCMP_BALLOT: |
| 63 |
case AGX_OPCODE_ICMP_BALLOT: |
| 64 |
case AGX_OPCODE_QUAD_BALLOT: |
| 65 |
case AGX_OPCODE_FCMP_QUAD_BALLOT: |
| 66 |
case AGX_OPCODE_ICMP_QUAD_BALLOT: |
| 67 |
return false; |
| 68 |
case AGX_OPCODE_EXPORT: |
| 69 |
case AGX_OPCODE_PHI: |
| 70 |
/* We would fail validation otherwise */ |
| 71 |
return true; |
| 72 |
default: |
| 73 |
return !is_64; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
void |
| 78 |
agx_lower_uniform_sources(agx_context *ctx) |
| 79 |
{ |
| 80 |
agx_foreach_instr_global_safe(ctx, I) { |
| 81 |
agx_builder b = agx_init_builder(ctx, agx_before_instr(I)); |
| 82 |
|
| 83 |
agx_foreach_src(I, s) { |
| 84 |
if (I->src[s].type == AGX_INDEX_UNIFORM && |
| 85 |
!agx_instr_accepts_uniform(I->op, s, I->src[s].value, |
| 86 |
I->src[s].size)) { |
| 87 |
|
| 88 |
agx_index idx = I->src[s]; |
| 89 |
idx.abs = idx.neg = false; |
| 90 |
agx_replace_src(I, s, agx_mov(&b, idx)); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
} |