mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 09:39:58 -04:00
Reflect every location in vertex and fragment interface arrays.
This commit is contained in:
@@ -952,7 +952,7 @@ static void add_res(GfxShader *s, int kind, const char *o, const char *e) {
|
||||
|
||||
// SPIR-V opcodes and enumerants used below (SPIR-V 1.6 specification, section 3).
|
||||
enum { OP_ENTRY_POINT = 15, OP_EXECUTION_MODE = 16, OP_TYPE_INT = 21, OP_TYPE_FLOAT = 22, OP_TYPE_VECTOR = 23,
|
||||
OP_TYPE_ARRAY = 28, OP_TYPE_POINTER = 32, OP_VARIABLE = 59, OP_DECORATE = 71,
|
||||
OP_TYPE_ARRAY = 28, OP_TYPE_POINTER = 32, OP_CONSTANT = 43, OP_VARIABLE = 59, OP_DECORATE = 71,
|
||||
DEC_BUILTIN = 11, DEC_LOCATION = 30, DEC_COMPONENT = 31, SC_INPUT = 1, SC_OUTPUT = 3, EM_LOCAL_SIZE = 17 };
|
||||
|
||||
// Interface Locations and the compute workgroup size from the module. Ids beyond 2^20 are ignored (translated modules stay
|
||||
@@ -963,11 +963,11 @@ static void reflect_spirv(GfxShader *s) {
|
||||
s->local[0] = s->local[1] = s->local[2] = 1;
|
||||
if (n < 5) return;
|
||||
uint32_t bound = w[3] < (1u << 20) ? w[3] : (1u << 20);
|
||||
// per id: location + 1 (0 = none), component flag, scalar/vector description of types, pointee of pointers
|
||||
// per id: location + 1 (0 = none), component flag, scalar/vector type and array span, pointer target, constant value
|
||||
int32_t *loc = calloc(bound, sizeof *loc);
|
||||
uint8_t *packed = calloc(bound, 1), *ttype = calloc(bound, 1), *tcomps = calloc(bound, 1);
|
||||
uint32_t *pointee = calloc(bound, sizeof *pointee);
|
||||
if (!loc || !packed || !ttype || !tcomps || !pointee) goto out;
|
||||
uint8_t *packed = calloc(bound, 1), *ttype = calloc(bound, 1), *tcomps = calloc(bound, 1), *tlocs = calloc(bound, 1);
|
||||
uint32_t *pointee = calloc(bound, sizeof *pointee), *value = calloc(bound, sizeof *value);
|
||||
if (!loc || !packed || !ttype || !tcomps || !tlocs || !pointee || !value) goto out;
|
||||
for (uint64_t i = 5; i < n;) {
|
||||
uint32_t op = w[i] & 0xffff, len = w[i] >> 16;
|
||||
if (!len || i + len > n) break;
|
||||
@@ -979,13 +979,17 @@ static void reflect_spirv(GfxShader *s) {
|
||||
if (a[1] == DEC_LOCATION) loc[id] = (int32_t)a[2] + 1;
|
||||
else if (a[1] == DEC_COMPONENT) packed[id] = 1;
|
||||
} else if (op == OP_TYPE_INT && len >= 4 && id < bound) {
|
||||
ttype[id] = a[2] ? GFX_TYPE_SINT : GFX_TYPE_UINT, tcomps[id] = 1;
|
||||
ttype[id] = a[2] ? GFX_TYPE_SINT : GFX_TYPE_UINT, tcomps[id] = 1, tlocs[id] = 1;
|
||||
} else if (op == OP_TYPE_FLOAT && len >= 3 && id < bound) {
|
||||
ttype[id] = GFX_TYPE_FLOAT, tcomps[id] = 1;
|
||||
ttype[id] = GFX_TYPE_FLOAT, tcomps[id] = 1, tlocs[id] = 1;
|
||||
} else if (op == OP_TYPE_VECTOR && len >= 4 && id < bound && a[1] < bound) {
|
||||
ttype[id] = ttype[a[1]], tcomps[id] = (uint8_t)a[2];
|
||||
} else if (op == OP_TYPE_ARRAY && len >= 4 && id < bound && a[1] < bound) {
|
||||
ttype[id] = ttype[a[1]], tcomps[id] = tcomps[a[1]]; // element type (arrayed interface blocks)
|
||||
ttype[id] = ttype[a[1]], tcomps[id] = (uint8_t)a[2], tlocs[id] = 1;
|
||||
} else if (op == OP_CONSTANT && len == 4 && a[1] < bound) {
|
||||
value[a[1]] = a[2];
|
||||
} else if (op == OP_TYPE_ARRAY && len >= 4 && id < bound && a[1] < bound && a[2] < bound) {
|
||||
ttype[id] = ttype[a[1]], tcomps[id] = tcomps[a[1]];
|
||||
uint64_t slots = (uint64_t)tlocs[a[1]] * value[a[2]];
|
||||
tlocs[id] = (uint8_t)(slots < 32 ? slots : 32); // the interface masks cover 32 locations
|
||||
} else if (op == OP_TYPE_POINTER && len >= 4 && id < bound) {
|
||||
pointee[id] = a[2];
|
||||
} else if (op == OP_VARIABLE && len >= 4) {
|
||||
@@ -994,14 +998,20 @@ static void reflect_spirv(GfxShader *s) {
|
||||
int l = loc[var] - 1;
|
||||
uint32_t t = pointee[type] < bound ? pointee[type] : 0;
|
||||
GfxShaderIo io = {ttype[t], tcomps[t] ? tcomps[t] : 4, packed[var]};
|
||||
if (sc == SC_INPUT) s->in_mask |= 1u << l, s->in[l] = io;
|
||||
else s->out_mask |= 1u << l, s->out[l] = io;
|
||||
// VS -> FS arrays occupy every element's locations, even if only some elements are accessed.
|
||||
// Other stages retain their existing reflection: mesh outputs have an outer per-vertex array.
|
||||
uint32_t slots = ((s->stage == GFX_STAGE_VS && sc == SC_OUTPUT) ||
|
||||
(s->stage == GFX_STAGE_FS && sc == SC_INPUT)) && tlocs[t] ? tlocs[t] : 1;
|
||||
for (uint32_t j = 0; j < slots && l + j < 32; j++) {
|
||||
if (sc == SC_INPUT) s->in_mask |= 1u << (l + j), s->in[l + j] = io;
|
||||
else s->out_mask |= 1u << (l + j), s->out[l + j] = io;
|
||||
}
|
||||
}
|
||||
}
|
||||
i += len;
|
||||
}
|
||||
out:
|
||||
free(loc), free(packed), free(ttype), free(tcomps), free(pointee);
|
||||
free(loc), free(packed), free(ttype), free(tcomps), free(tlocs), free(pointee), free(value);
|
||||
}
|
||||
|
||||
// Every gradient sample (OpImageSampleExplicitLod with Grad) whose two gradients are each built from two components gets
|
||||
|
||||
Reference in New Issue
Block a user