feat(compiler): bind render constant buffers as plain buffers with descriptive reflection
This commit is contained in:
1 parent
6741f99ad3
commit
2ffceeaccc
4 files changed
+52
-234
No files matched your search
@@ -817,109 +817,12 @@ stage_type_matches(LLVMTypeRef type, enum stela_air_primitive p, unsigned n)
|
||||
LLVMGetIntTypeWidth(type) == primitive_bytes(p) * 8;
|
||||
}
|
||||
|
||||
/* These types are fixed, sized builtin leaves selected from validated metadata.
|
||||
* Never ask DataLayout to size an unvalidated source/scalable/opaque type. */
|
||||
static bool
|
||||
stage_primitive_layout(struct stela_air_metadata *m, enum stela_air_primitive p,
|
||||
unsigned components, unsigned size, unsigned alignment)
|
||||
{
|
||||
unsigned bytes = primitive_bytes(p);
|
||||
if (!bytes || !components || components > 4)
|
||||
return fail(m, STELA_AIR_TYPE, "unsupported reflected primitive storage");
|
||||
LLVMContextRef context = LLVMGetModuleContext(m->module);
|
||||
LLVMTypeRef type = p == STELA_AIR_FLOAT ? LLVMFloatTypeInContext(context) :
|
||||
p == STELA_AIR_HALF ? LLVMHalfTypeInContext(context) : LLVMIntTypeInContext(context, bytes * 8);
|
||||
if (components > 1) type = LLVMVectorType(type, components);
|
||||
return (LLVMABISizeOfType(m->layout, type) == size &&
|
||||
LLVMABIAlignmentOfType(m->layout, type) == alignment) ||
|
||||
fail(m, STELA_AIR_TYPE, "reflected primitive storage differs from IR DataLayout");
|
||||
}
|
||||
|
||||
static bool
|
||||
stage_struct(struct stela_air_metadata *m, struct stela_air_render *r,
|
||||
struct stela_air_stage_io *io, LLVMValueRef node)
|
||||
{
|
||||
if (!node) {
|
||||
unsigned bytes = primitive_bytes(io->primitive) * (io->components == 3 ? 4 : io->components);
|
||||
if (!bytes || bytes != io->buffer.type_size || bytes != io->buffer.type_alignment)
|
||||
return fail(m, STELA_AIR_ARGUMENT, "constant buffer reflection requires exact primitive or understood structure");
|
||||
return stage_primitive_layout(m, io->primitive, io->components,
|
||||
io->buffer.type_size, io->buffer.type_alignment);
|
||||
}
|
||||
if (io->primitive != STELA_AIR_PRIMITIVE_UNKNOWN)
|
||||
return fail(m, STELA_AIR_METADATA, "primitive buffer has structure metadata");
|
||||
LLVMValueRef fields[AIR_MAX_METADATA_OPERANDS];
|
||||
unsigned count;
|
||||
if (!stela_air_md_node(m, node, fields, &count) || !count || count % 5 ||
|
||||
count / 5 > AIR_MAX_ARGUMENTS - r->member_count)
|
||||
return fail(m, STELA_AIR_LIMIT, "structure reflection member budget/shape exceeded");
|
||||
io->members = &r->members[r->member_count];
|
||||
unsigned end = 0, align = 1;
|
||||
for (unsigned i = 0; i < count; i += 5) {
|
||||
struct stela_air_struct_member *member = &r->members[r->member_count++];
|
||||
unsigned flags;
|
||||
if (!stela_air_md_uint(fields[i], &member->offset) ||
|
||||
!stela_air_md_uint(fields[i + 1], &member->size) ||
|
||||
!stela_air_md_uint(fields[i + 2], &flags) || flags ||
|
||||
!metadata_text(m, fields[i + 3], &member->type_name, &member->type_name_bytes) ||
|
||||
!metadata_text(m, fields[i + 4], &member->name, &member->name_bytes))
|
||||
return fail(m, STELA_AIR_METADATA, "unsupported structure reflection member");
|
||||
member->primitive = primitive_type(fields[i + 3], &member->components);
|
||||
unsigned bytes = primitive_bytes(member->primitive) * (member->components == 3 ? 4 : member->components);
|
||||
if (!bytes || member->size != bytes || member->offset < end || member->offset % bytes ||
|
||||
member->offset > io->buffer.type_size || bytes > io->buffer.type_size - member->offset)
|
||||
return fail(m, STELA_AIR_TYPE, "structure reflection layout is inconsistent");
|
||||
if (!stage_primitive_layout(m, member->primitive, member->components, bytes, bytes))
|
||||
return false;
|
||||
unsigned expected = (end + bytes - 1) & ~(bytes - 1);
|
||||
if (expected != member->offset)
|
||||
return fail(m, STELA_AIR_TYPE, "unsupported explicit structure padding");
|
||||
end = member->offset + bytes;
|
||||
if (bytes > align) align = bytes;
|
||||
io->member_count++;
|
||||
}
|
||||
return (io->buffer.type_alignment == align &&
|
||||
((end + align - 1) & ~(align - 1)) == io->buffer.type_size) ||
|
||||
fail(m, STELA_AIR_TYPE, "structure reflection extent/alignment mismatch");
|
||||
}
|
||||
|
||||
bool
|
||||
stela_air_metadata_output_type(const struct stela_air_stage_io *io, LLVMTypeRef type)
|
||||
{
|
||||
return stage_type_matches(type, io->primitive, io->components);
|
||||
}
|
||||
|
||||
bool
|
||||
stela_air_metadata_stage_buffer_type(struct stela_air_metadata *m,
|
||||
const struct stela_air_stage_io *io, LLVMTypeRef type)
|
||||
{
|
||||
if (!io->member_count) {
|
||||
if (!stage_type_matches(type, io->primitive, io->components))
|
||||
return fail(m, STELA_AIR_TYPE, "constant view source type differs from reflection");
|
||||
return (LLVMABISizeOfType(m->layout, type) == io->buffer.type_size &&
|
||||
LLVMABIAlignmentOfType(m->layout, type) == io->buffer.type_alignment) ||
|
||||
fail(m, STELA_AIR_TYPE, "constant-view IR allocation differs from reflection");
|
||||
}
|
||||
/* Every leaf is checked before ANY fixed-size DataLayout query; opaque,
|
||||
* scalable, target-extension, nested and unsized storage are refused. */
|
||||
if (LLVMGetTypeKind(type) != LLVMStructTypeKind || LLVMIsOpaqueStruct(type) ||
|
||||
LLVMIsPackedStruct(type) || LLVMCountStructElementTypes(type) != io->member_count)
|
||||
return fail(m, STELA_AIR_TYPE, "unsupported constant-view structure type");
|
||||
for (unsigned i = 0; i < io->member_count; i++) {
|
||||
const struct stela_air_struct_member *a = &io->members[i];
|
||||
if (!stage_type_matches(LLVMStructGetTypeAtIndex(type, i), a->primitive, a->components))
|
||||
return fail(m, STELA_AIR_TYPE, "constant-view member type differs from reflection");
|
||||
}
|
||||
if (LLVMABISizeOfType(m->layout, type) != io->buffer.type_size ||
|
||||
LLVMABIAlignmentOfType(m->layout, type) != io->buffer.type_alignment)
|
||||
return fail(m, STELA_AIR_TYPE, "constant-view IR allocation differs from reflection");
|
||||
for (unsigned i = 0; i < io->member_count; i++) {
|
||||
if (LLVMOffsetOfElement(m->layout, type, i) != io->members[i].offset)
|
||||
return fail(m, STELA_AIR_TYPE, "constant-view IR member offset differs from reflection");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* The builtin input an argument descriptor's kind names, when the stage has
|
||||
* it. Positions and sizes have up to three lanes; the rest are scalars.
|
||||
* PATCH is a post-tessellation vertex function. */
|
||||
@@ -1595,12 +1498,15 @@ metadata_arguments(struct stela_air_metadata *t, LLVMValueRef fn, LLVMValueRef a
|
||||
}
|
||||
f++;
|
||||
*present = true;
|
||||
} else if (indirect && stela_air_md_string(key, "air.buffer_size")) {
|
||||
} else if (buffer && stela_air_md_string(key, "air.buffer_size")) {
|
||||
/* A reference's referenced bytes. */
|
||||
if (has_buffer_size || f == fields_count || !stela_air_md_uint(fields[f++], &buffer_size))
|
||||
return fail(t, STELA_AIR_METADATA, "invalid argument buffer size");
|
||||
return fail(t, STELA_AIR_METADATA, "invalid buffer size");
|
||||
has_buffer_size = true;
|
||||
} else if ((io || indirect) && stela_air_md_string(key, "air.struct_type_info")) {
|
||||
if (!buffer || struct_info || f == fields_count)
|
||||
} else if ((buffer || payload) && stela_air_md_string(key, "air.struct_type_info")) {
|
||||
/* The layout of a structure; only an argument buffer's is
|
||||
* interpreted, since its fields are bound resources. */
|
||||
if (struct_info || f == fields_count)
|
||||
return fail(t, STELA_AIR_METADATA, "invalid structure reflection");
|
||||
struct_info = fields[f++];
|
||||
} else if (io && interpolated &&
|
||||
@@ -1616,8 +1522,7 @@ metadata_arguments(struct stela_air_metadata *t, LLVMValueRef fn, LLVMValueRef a
|
||||
io->interpolation = stela_air_md_string(key, "air.perspective") ? STELA_AIR_PERSPECTIVE :
|
||||
stela_air_md_string(key, "air.no_perspective") ? STELA_AIR_NO_PERSPECTIVE :
|
||||
STELA_AIR_FLAT;
|
||||
} else if (((io && interpolated) || vertex_input) &&
|
||||
stela_air_md_string(key, "air.arg_unused")) {
|
||||
} else if (stela_air_md_string(key, "air.arg_unused")) {
|
||||
if (unused) return fail(t, STELA_AIR_METADATA, "duplicate unused qualifier");
|
||||
unused = true;
|
||||
} else if (varying && stela_air_md_string(key, "air.interpolation_function")) {
|
||||
@@ -1684,15 +1589,13 @@ metadata_arguments(struct stela_air_metadata *t, LLVMValueRef fn, LLVMValueRef a
|
||||
if (indices[desc.index] || (limit && desc.index >= limit))
|
||||
return fail(t, STELA_AIR_METADATA, "duplicate buffer or location exceeds AIR module limit");
|
||||
indices[desc.index] = true;
|
||||
if (indirect && (shared || !struct_info || !desc.type_size ||
|
||||
(has_buffer_size && buffer_size != desc.type_size)))
|
||||
if (has_buffer_size && buffer_size != desc.type_size)
|
||||
return fail(t, STELA_AIR_ARGUMENT, "buffer size differs from its type at %u", index);
|
||||
if (indirect && (shared || !struct_info || !desc.type_size))
|
||||
return fail(t, STELA_AIR_ARGUMENT, "unsupported argument buffer %u", index);
|
||||
if (indirect && !argument_fields(t, kernel, struct_info, desc.type_size, index, 0,
|
||||
&argument_buffer))
|
||||
return false;
|
||||
if (render && !indirect && desc.address_space == 2 &&
|
||||
(!has_size || !has_align || !desc.type_size || !desc.type_alignment))
|
||||
return fail(t, STELA_AIR_ARGUMENT, "render constant view must be reflected and readonly");
|
||||
if (shared && (!has_size || !has_align || !desc.type_size || !desc.type_alignment))
|
||||
return fail(t, STELA_AIR_ARGUMENT, "invalid/unbound threadgroup buffer %u", index);
|
||||
} else if (payload) {
|
||||
@@ -1772,9 +1675,7 @@ metadata_arguments(struct stela_air_metadata *t, LLVMValueRef fn, LLVMValueRef a
|
||||
io->type_name = type_name; io->type_name_bytes = type_name_bytes;
|
||||
io->used = LLVMGetFirstUse(param) != NULL;
|
||||
if (unused && io->used)
|
||||
return fail(t, STELA_AIR_METADATA, "used fragment input marked unused");
|
||||
if (buffer && !indirect && desc.address_space == 2 && !stage_struct(t, render, io, struct_info))
|
||||
return false;
|
||||
return fail(t, STELA_AIR_METADATA, "used stage argument marked unused");
|
||||
}
|
||||
kernel->arguments[a] = (struct stela_air_argument) {
|
||||
.value = param, .buffer = desc, .is_buffer = buffer, .components = components,
|
||||
|
||||
@@ -520,8 +520,6 @@ bool stela_air_metadata_stage(struct stela_air_metadata *, LLVMValueRef,
|
||||
enum stela_air_stage, struct stela_air_render *);
|
||||
bool stela_air_metadata_stage_map(struct stela_air_metadata *, const struct stela_air_render *,
|
||||
const struct stela_air_varying_slot *, unsigned count, unsigned max_slots);
|
||||
bool stela_air_metadata_stage_buffer_type(struct stela_air_metadata *,
|
||||
const struct stela_air_stage_io *, LLVMTypeRef);
|
||||
/* Whether type is an output's reflected scalar or vector type. */
|
||||
bool stela_air_metadata_output_type(const struct stela_air_stage_io *io, LLVMTypeRef type);
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ struct value {
|
||||
nir_variable *storage;
|
||||
bool constant_data;
|
||||
unsigned storage_size, constant_base;
|
||||
const struct stela_air_stage_io *constant_view; /* Borrowed only during translation. */
|
||||
bool view_root;
|
||||
/* A pointer into an argument buffer: the buffer's fields, the constant
|
||||
* part of the pointer's offset and the greatest common divisor of the
|
||||
* steps its dynamic indices add (zero without one). PHIs lose the
|
||||
@@ -86,7 +84,7 @@ stela_air_ssbo_view_valid(const struct stela_air_ssbo_view *view,
|
||||
struct pointer_node {
|
||||
LLVMValueRef llvm, root;
|
||||
unsigned index, low, next, component;
|
||||
bool active, view_root;
|
||||
bool active;
|
||||
};
|
||||
|
||||
struct translator {
|
||||
@@ -329,7 +327,7 @@ static nir_def *stage_narrow(nir_builder *b, nir_def *def, enum stela_air_primit
|
||||
|
||||
/* Static pointer authority is separate from the offset/VA in def. */
|
||||
static void
|
||||
pointer_authority(struct value *target, const struct value *root, bool view_root)
|
||||
pointer_authority(struct value *target, const struct value *root)
|
||||
{
|
||||
target->pointer_root = root->pointer_root;
|
||||
target->access = root->access;
|
||||
@@ -339,8 +337,6 @@ pointer_authority(struct value *target, const struct value *root, bool view_root
|
||||
target->constant_data = root->constant_data;
|
||||
target->storage_size = root->storage_size;
|
||||
target->constant_base = root->constant_base;
|
||||
target->constant_view = root->constant_view;
|
||||
target->view_root = view_root;
|
||||
target->fields = root->fields;
|
||||
target->array = root->array;
|
||||
target->texture = root->texture;
|
||||
@@ -1130,8 +1126,6 @@ gep(struct translator *t, LLVMValueRef inst, const struct value **origin, uint64
|
||||
return NULL;
|
||||
}
|
||||
LLVMTypeRef type = LLVMGetGEPSourceElementType(inst);
|
||||
if (base->view_root && !stela_air_metadata_stage_buffer_type(&t->metadata, base->constant_view, type))
|
||||
return NULL;
|
||||
unsigned type_budget = 4096;
|
||||
if (!fixed_storage_type(t, type, 0, &type_budget))
|
||||
return NULL;
|
||||
@@ -2073,10 +2067,6 @@ stage_arguments(struct translator *t, LLVMValueRef fn)
|
||||
if (!put_value(t, param, def, io->buffer.access)) return false;
|
||||
if (io->semantic == STELA_AIR_STAGE_BUFFER) {
|
||||
struct value *v = find_value(t, param);
|
||||
if (io->buffer.address_space == 2 && !argument->is_argument_buffer) {
|
||||
v->constant_view = io;
|
||||
v->view_root = true;
|
||||
}
|
||||
if (!argument_root(t, v, param, argument))
|
||||
return false;
|
||||
v->ssbo = t->options->bind_ssbo != NULL; v->ssbo_slot = slot;
|
||||
@@ -2857,9 +2847,8 @@ memory_intrinsic(struct translator *t, LLVMValueRef inst, unsigned intrinsic, bo
|
||||
nir_def *fill = operation == SET ? get_value(t, LLVMGetOperand(inst, 1)) : NULL;
|
||||
if (t->error->kind != STELA_AIR_OK)
|
||||
return false;
|
||||
/* A render constant view's root takes only loads of its reflected type. */
|
||||
if (!destination || !(destination->access & STELA_AIR_WRITE) ||
|
||||
(operation != SET && (!source || !(source->access & STELA_AIR_READ) || source->view_root)))
|
||||
(operation != SET && (!source || !(source->access & STELA_AIR_READ))))
|
||||
return fail(t, STELA_AIR_MEMORY, "memory intrinsic lacks a bound writable/readable pointer");
|
||||
unsigned alignment = argument_alignment(inst, 0);
|
||||
if (source)
|
||||
@@ -3230,7 +3219,7 @@ instruction(struct translator *t, LLVMValueRef inst)
|
||||
nir_def *def = gep(t, inst, &origin, &constant, &steps);
|
||||
if (!def || !put_value(t, inst, def, origin->access))
|
||||
return false;
|
||||
pointer_authority(find_value(t, inst), origin, false);
|
||||
pointer_authority(find_value(t, inst), origin);
|
||||
pointer_offset(find_value(t, inst), origin, constant, steps);
|
||||
return true;
|
||||
}
|
||||
@@ -3241,7 +3230,7 @@ instruction(struct translator *t, LLVMValueRef inst)
|
||||
const struct value *origin = pointer_value(t, LLVMGetOperand(inst, 0));
|
||||
if (!origin || !origin->access || !put_value(t, inst, origin->def, origin->access))
|
||||
return fail(t, STELA_AIR_MEMORY, "pointer identity cast lacks buffer provenance");
|
||||
pointer_authority(find_value(t, inst), origin, origin->view_root);
|
||||
pointer_authority(find_value(t, inst), origin);
|
||||
pointer_offset(find_value(t, inst), origin, 0, 0);
|
||||
return true;
|
||||
}
|
||||
@@ -3477,8 +3466,7 @@ instruction(struct translator *t, LLVMValueRef inst)
|
||||
a->def->num_components != 1 || b->def->num_components != 1 ||
|
||||
a->def->bit_size != 64 || b->def->bit_size != 64)
|
||||
return fail(t, STELA_AIR_MEMORY, "pointer equality requires one validated resource origin");
|
||||
/* Equality is invariant under the same unknown base modulo 2^64.
|
||||
* AS2 root reflection affects typing, not the pointer's address. */
|
||||
/* Equality is invariant under the same unknown base modulo 2^64. */
|
||||
return put_value(t, inst, predicate == LLVMIntEQ ?
|
||||
nir_ieq(&t->b, a->def, b->def) : nir_ine(&t->b, a->def, b->def), 0);
|
||||
}
|
||||
@@ -3500,9 +3488,6 @@ instruction(struct translator *t, LLVMValueRef inst)
|
||||
return fail(t, STELA_AIR_MEMORY, "relaxed atomic loads and stores take aligned 32- or 64-bit scalars");
|
||||
/* Relaxed atomic loads and stores are single, coherent accesses. */
|
||||
enum gl_access_qualifier access = atomic ? ACCESS_ATOMIC | ACCESS_COHERENT : 0;
|
||||
if (address->view_root && op == LLVMLoad &&
|
||||
!stela_air_metadata_stage_buffer_type(&t->metadata, address->constant_view, LLVMTypeOf(inst)))
|
||||
return false;
|
||||
unsigned alignment = LLVMGetAlignment(inst);
|
||||
if (!alignment)
|
||||
return fail(t, STELA_AIR_MEMORY, "memory access lacks explicit alignment");
|
||||
@@ -3714,14 +3699,7 @@ same_pointer_resource(const struct value *a, const struct value *b)
|
||||
a->access == b->access && a->ssbo == b->ssbo && a->ssbo_slot == b->ssbo_slot &&
|
||||
a->fields.first == b->fields.first && a->fields.count == b->fields.count &&
|
||||
a->storage == b->storage && a->constant_data == b->constant_data &&
|
||||
a->storage_size == b->storage_size && a->constant_base == b->constant_base &&
|
||||
a->constant_view == b->constant_view;
|
||||
}
|
||||
|
||||
static bool
|
||||
same_pointer_authority(const struct value *a, const struct value *b)
|
||||
{
|
||||
return same_pointer_resource(a, b) && a->view_root == b->view_root;
|
||||
a->storage_size == b->storage_size && a->constant_base == b->constant_base;
|
||||
}
|
||||
|
||||
static struct pointer_node *
|
||||
@@ -3731,13 +3709,11 @@ pointer_node(struct translator *t, LLVMValueRef llvm)
|
||||
return entry ? entry->data : NULL;
|
||||
}
|
||||
|
||||
/* Validates a provenance root and reports whether it is a reflected AS2
|
||||
* view. An address loaded from an argument buffer is a root its load
|
||||
* validates when translated; no reflection describes it. */
|
||||
/* Validates a provenance root. An address loaded from an argument buffer is
|
||||
* a root its load validates when translated. */
|
||||
static bool
|
||||
pointer_anchor(struct translator *t, LLVMValueRef llvm, bool *view_root)
|
||||
pointer_anchor(struct translator *t, LLVMValueRef llvm)
|
||||
{
|
||||
*view_root = false;
|
||||
if (LLVMIsALoadInst(llvm))
|
||||
return true;
|
||||
struct value *value = find_value(t, llvm);
|
||||
@@ -3745,21 +3721,16 @@ pointer_anchor(struct translator *t, LLVMValueRef llvm, bool *view_root)
|
||||
value = private_allocation(t, llvm);
|
||||
else if (!value && LLVMIsAGlobalVariable(llvm))
|
||||
value = pointer_value(t, llvm);
|
||||
if (!value || !value->access || value->pointer_root != llvm ||
|
||||
!pointer_space(LLVMTypeOf(llvm)) || !value->def ||
|
||||
value->def->num_components != 1 || value->def->bit_size != 64)
|
||||
return fail(t, STELA_AIR_MEMORY, "pointer PHI dependency lacks validated resource origin");
|
||||
*view_root = value->view_root;
|
||||
return true;
|
||||
return (value && value->access && value->pointer_root == llvm &&
|
||||
pointer_space(LLVMTypeOf(llvm)) && value->def &&
|
||||
value->def->num_components == 1 && value->def->bit_size == 64) ||
|
||||
fail(t, STELA_AIR_MEMORY, "pointer PHI dependency lacks validated resource origin");
|
||||
}
|
||||
|
||||
static unsigned
|
||||
pointer_dependencies(const struct pointer_node *node, bool reflection)
|
||||
pointer_dependencies(const struct pointer_node *node)
|
||||
{
|
||||
LLVMOpcode op = LLVMGetInstructionOpcode(node->llvm);
|
||||
if (reflection && op == LLVMGetElementPtr)
|
||||
return 0; /* A GEP is a non-root reflection anchor, even in a cycle. */
|
||||
return op == LLVMPHI ? LLVMCountIncoming(node->llvm) : 1;
|
||||
return LLVMGetInstructionOpcode(node->llvm) == LLVMPHI ? LLVMCountIncoming(node->llvm) : 1;
|
||||
}
|
||||
|
||||
static LLVMValueRef
|
||||
@@ -3773,67 +3744,48 @@ pointer_dependency(struct translator *t, const struct pointer_node *node, unsign
|
||||
}
|
||||
|
||||
/* Resolve one SCC only from already-proven outgoing dependencies. In
|
||||
* particular, a rooted user cannot lend authority backward to a rootless cycle.
|
||||
* Reflection uses the same solver with GEP as a terminal false anchor. */
|
||||
* particular, a rooted user cannot lend authority backward to a rootless cycle. */
|
||||
static bool
|
||||
pointer_component(struct translator *t, struct pointer_node **stack,
|
||||
unsigned begin, unsigned end, unsigned component, bool reflection)
|
||||
unsigned begin, unsigned end, unsigned component)
|
||||
{
|
||||
LLVMValueRef root = NULL;
|
||||
bool state = false, anchored = false;
|
||||
for (unsigned i = begin; i < end; i++)
|
||||
stack[i]->component = component;
|
||||
for (unsigned i = begin; i < end; i++) {
|
||||
struct pointer_node *node = stack[i];
|
||||
if (reflection && LLVMGetInstructionOpcode(node->llvm) == LLVMGetElementPtr) {
|
||||
if (anchored && state)
|
||||
return fail(t, STELA_AIR_MEMORY, "pointer PHI mixes AS2 root reflection states");
|
||||
anchored = true;
|
||||
state = false;
|
||||
}
|
||||
unsigned count = pointer_dependencies(node, reflection);
|
||||
unsigned count = pointer_dependencies(node);
|
||||
for (unsigned j = 0; j < count; j++) {
|
||||
LLVMValueRef dependency = pointer_dependency(t, node, j);
|
||||
if (!dependency)
|
||||
continue;
|
||||
struct pointer_node *dep = pointer_node(t, dependency);
|
||||
LLVMValueRef candidate;
|
||||
bool candidate_state;
|
||||
if (dep) {
|
||||
if (dep->component == component)
|
||||
continue;
|
||||
if (dep->component == UINT_MAX)
|
||||
return fail(t, STELA_AIR_MEMORY, "unresolved pointer provenance component");
|
||||
candidate = dep->root;
|
||||
candidate_state = dep->view_root;
|
||||
} else {
|
||||
if (!pointer_anchor(t, dependency, &candidate_state))
|
||||
if (!pointer_anchor(t, dependency))
|
||||
return false;
|
||||
candidate = dependency;
|
||||
}
|
||||
if (anchored && (reflection ? state != candidate_state : root != candidate))
|
||||
return fail(t, STELA_AIR_MEMORY, reflection ?
|
||||
"pointer PHI mixes AS2 root reflection states" :
|
||||
"pointer PHI joins distinct resource origins");
|
||||
anchored = true;
|
||||
if (root && root != candidate)
|
||||
return fail(t, STELA_AIR_MEMORY, "pointer PHI joins distinct resource origins");
|
||||
root = candidate;
|
||||
state = candidate_state;
|
||||
}
|
||||
}
|
||||
if (!anchored)
|
||||
if (!root)
|
||||
return fail(t, STELA_AIR_MEMORY, "pointer PHI has a rootless dependency cycle");
|
||||
for (unsigned i = begin; i < end; i++) {
|
||||
if (reflection)
|
||||
stack[i]->view_root = state;
|
||||
else
|
||||
stack[i]->root = root;
|
||||
}
|
||||
for (unsigned i = begin; i < end; i++)
|
||||
stack[i]->root = root;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
pointer_solve(struct translator *t, struct pointer_node **dfs,
|
||||
struct pointer_node **stack, bool reflection)
|
||||
pointer_solve(struct translator *t, struct pointer_node **dfs, struct pointer_node **stack)
|
||||
{
|
||||
unsigned serial = 0, component = 0, depth = 0, active = 0;
|
||||
for (unsigned i = 0; i < t->pointer_count; i++) {
|
||||
@@ -3853,7 +3805,7 @@ pointer_solve(struct translator *t, struct pointer_node **dfs,
|
||||
node->active = true;
|
||||
stack[active++] = node;
|
||||
}
|
||||
unsigned count = pointer_dependencies(node, reflection);
|
||||
unsigned count = pointer_dependencies(node);
|
||||
if (node->next < count) {
|
||||
LLVMValueRef llvm = pointer_dependency(t, node, node->next++);
|
||||
struct pointer_node *dep = llvm ? pointer_node(t, llvm) : NULL;
|
||||
@@ -3871,7 +3823,7 @@ pointer_solve(struct translator *t, struct pointer_node **dfs,
|
||||
do {
|
||||
stack[--active]->active = false;
|
||||
} while (stack[active] != node);
|
||||
if (!pointer_component(t, stack, active, end, component++, reflection))
|
||||
if (!pointer_component(t, stack, active, end, component++))
|
||||
return false;
|
||||
}
|
||||
depth--;
|
||||
@@ -3923,7 +3875,7 @@ pointer_provenance(struct translator *t)
|
||||
}
|
||||
}
|
||||
t->pointer_count = next; /* Allocations are roots, not nodes. */
|
||||
return pointer_solve(t, dfs, stack, false) && pointer_solve(t, dfs, stack, true);
|
||||
return pointer_solve(t, dfs, stack);
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -4000,7 +3952,7 @@ cfg_declare_phi(struct translator *t, LLVMValueRef inst)
|
||||
struct value *root = node ? find_value(t, node->root) : NULL;
|
||||
if (!root)
|
||||
return fail(t, STELA_AIR_MEMORY, "pointer PHI lacks completed provenance proof");
|
||||
pointer_authority(value, root, node->view_root);
|
||||
pointer_authority(value, root);
|
||||
}
|
||||
return _mesa_hash_table_insert(t->values, inst, value) != NULL ||
|
||||
fail(t, STELA_AIR_ALLOCATION, "AIR PHI value map allocation failed");
|
||||
@@ -4170,7 +4122,7 @@ cfg_emit(struct translator *t)
|
||||
/* Constants are materialized before the predecessor's jump. Uses
|
||||
* of loop-carried PHIs retain their original simultaneous defs. */
|
||||
t->b.cursor = nir_before_instr(nir_block_last_instr(pred->end));
|
||||
if (target->pointer_root && !same_pointer_authority(target, find_value(t, incoming)))
|
||||
if (target->pointer_root && !same_pointer_resource(target, find_value(t, incoming)))
|
||||
return fail(t, STELA_AIR_MEMORY, "pointer PHI incoming authority differs from proof");
|
||||
struct value *aggregate = target->aggregate_count ? aggregate_value(t, incoming) : NULL;
|
||||
if (target->aggregate_count &&
|
||||
|
||||
@@ -335,10 +335,8 @@ static void run(LLVMMemoryBufferRef raw,const char *vsname,const char *fsname,bo
|
||||
if(!original) {
|
||||
const struct {const char *old,*replacement;enum stela_air_error_kind error;} cases[]={
|
||||
{"i32 2,!\"air.struct_type_info\"","i32 1,!\"air.struct_type_info\"",STELA_AIR_ARGUMENT},
|
||||
{"i32 0,i32 16,i32 0,!\"float4\"","i32 4,i32 16,i32 0,!\"float4\"",STELA_AIR_TYPE},
|
||||
{"!\"air.read\",!\"air.address_space\"","!\"air.write\",!\"air.address_space\"",STELA_AIR_ARGUMENT},
|
||||
{"<float 1.0,float 0.5,float 0.25,float 0.0>","<float 1.0,float poison,float 0.25,float 0.0>",STELA_AIR_INSTRUCTION},
|
||||
{"%Input = type { <4 x float> }","%Input = type { <4 x i32> }",STELA_AIR_TYPE},
|
||||
{"e-p:64:64-i32:32", "e-p:64:64-p2:32:32-i32:32", STELA_AIR_TARGET},
|
||||
{"getelementptr %Input", "getelementptr <vscale x 4 x float>", STELA_AIR_TYPE},
|
||||
};
|
||||
@@ -405,7 +403,7 @@ link_and_option_failures(LLVMMemoryBufferRef raw, const char *vsname, const char
|
||||
}
|
||||
|
||||
static void
|
||||
primitive_layout_semantics(void)
|
||||
primitive_buffer_semantics(void)
|
||||
{
|
||||
char *a = change(fixture, "!\"air.struct_type_info\",!7,", "");
|
||||
char *vector = change(a, "!\"Input\"", "!\"float4\""); free(a);
|
||||
@@ -416,8 +414,6 @@ primitive_layout_semantics(void)
|
||||
a = change(scalar, "i32 16,!\"air.arg_type_align_size\",i32 16,!\"air.arg_type_name\",!\"float4\"",
|
||||
"i32 4,!\"air.arg_type_align_size\",i32 4,!\"air.arg_type_name\",!\"uint\""); free(scalar); scalar = a;
|
||||
const char *sources[] = {vector, scalar};
|
||||
const char *layouts[] = {"v128:128", "i32:32"};
|
||||
const char *overaligned[] = {"v128:256", "i32:64"};
|
||||
for (unsigned i = 0; i < 2; i++) {
|
||||
LLVMMemoryBufferRef raw = bitcode(sources[i]); struct snapshot vs, fs; struct stela_air_error e;
|
||||
CHECK(stela_air_inspect_stage(LLVMGetBufferStart(raw), LLVMGetBufferSize(raw),
|
||||
@@ -429,17 +425,9 @@ primitive_layout_semantics(void)
|
||||
struct stela_air_stage_options o = options(STELA_AIR_VERTEX, map, count, &callbacks);
|
||||
nir_shader *nir = translate(raw, "test_vertex", &o); ralloc_free(nir);
|
||||
LLVMDisposeMemoryBuffer(raw);
|
||||
char *bad = change(sources[i], layouts[i], overaligned[i]); raw = bitcode(bad); free(bad);
|
||||
callbacks = 0;
|
||||
CHECK(!stela_air_inspect_stage(LLVMGetBufferStart(raw), LLVMGetBufferSize(raw),
|
||||
"test_vertex", STELA_AIR_VERTEX, count_stage_callback, &callbacks, &e) && e.kind == STELA_AIR_TYPE);
|
||||
CHECK(callbacks == 0);
|
||||
CHECK(!stela_air_stage_to_nir(LLVMGetBufferStart(raw), LLVMGetBufferSize(raw),
|
||||
"test_vertex", &nir_options, &o, &e) && e.kind == STELA_AIR_TYPE && callbacks == 0);
|
||||
LLVMDisposeMemoryBuffer(raw);
|
||||
}
|
||||
free(vector); free(scalar);
|
||||
puts("Primitive float4 and unused uint reflection require exact original DataLayout before callbacks");
|
||||
puts("Primitive float4 and unused uint render buffers translate without structure reflection");
|
||||
}
|
||||
|
||||
static char *
|
||||
@@ -716,27 +704,9 @@ pointer_phi_stage_semantics(void)
|
||||
}
|
||||
LLVMDisposeMemoryBuffer(raw);
|
||||
}
|
||||
/* Source roots with equal rights and type remain independent resources. */
|
||||
char *text = vertex_body(root);
|
||||
/* A root PHI still validates the reflected struct before any first GEP. */
|
||||
char *bad = change(text,
|
||||
"getelementptr %Input, ptr addrspace(2) %p, i64 0, i32 0",
|
||||
"getelementptr <4 x float>, ptr addrspace(2) %p, i64 0");
|
||||
refusal(bad, "test_vertex", STELA_AIR_VERTEX, &o, STELA_AIR_TYPE);
|
||||
free(bad); free(text);
|
||||
text = vertex_body(derived);
|
||||
bad = change(text, "[%pa,%a],[%pb,%b]", "[%buffer,%a],[%pb,%b]");
|
||||
refusal(bad, "test_vertex", STELA_AIR_VERTEX, &o, STELA_AIR_MEMORY);
|
||||
free(bad); free(text);
|
||||
text = vertex_body(cycle);
|
||||
bad = change(text, "[%buffer,%entry],[%p,%latch]", "[%buffer,%entry],[%step,%latch]");
|
||||
free(text); text = change(bad, "latch:\n %next = add",
|
||||
"latch:\n %step = getelementptr %Input, ptr addrspace(2) %p, i64 0\n %next = add");
|
||||
free(bad);
|
||||
refusal(text, "test_vertex", STELA_AIR_VERTEX, &o, STELA_AIR_MEMORY);
|
||||
free(text);
|
||||
/* Source roots with equal rights/type remain independent constant views. */
|
||||
text = vertex_body(root);
|
||||
bad = change(text, "ptr addrspace(2) %buffer)", "ptr addrspace(2) %buffer, ptr addrspace(2) %other)");
|
||||
char *bad = change(text, "ptr addrspace(2) %buffer)", "ptr addrspace(2) %buffer, ptr addrspace(2) %other)");
|
||||
free(text); text = change(bad, "!4 = !{!5,!6}", "!4 = !{!5,!6,!26}"); free(bad);
|
||||
bad = change(text, "[%buffer,%a],[%alias,%b]", "[%buffer,%a],[%other,%b]"); free(text);
|
||||
const char *extra = "!26 = !{i32 2,!\"air.buffer\",!\"air.location_index\",i32 1,i32 1,!\"air.read\",!\"air.address_space\",i32 2,"
|
||||
@@ -745,7 +715,7 @@ pointer_phi_stage_semantics(void)
|
||||
text = malloc(bytes); CHECK(text); snprintf(text, bytes, "%s%s", bad, extra); free(bad);
|
||||
refusal(text, "test_vertex", STELA_AIR_VERTEX, &o, STELA_AIR_MEMORY);
|
||||
free(text);
|
||||
puts("AS2 pointer PHIs preserve homogeneous root/derived reflection, exact view bounds and root identity");
|
||||
puts("AS2 pointer PHIs join root and derived pointers of one resource and keep root identity");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -816,7 +786,7 @@ pointer_equality_stage_semantics(void)
|
||||
"icmp eq ptr addrspace(2) %p, null");
|
||||
refusal(bad, "test_vertex", STELA_AIR_VERTEX, &o, STELA_AIR_MEMORY);
|
||||
free(bad); free(text);
|
||||
puts("AS2 same-resource eq/ne ignore only reflection typing and retain exact loop-PHI output decisions");
|
||||
puts("AS2 same-resource eq/ne retain exact loop-PHI output decisions");
|
||||
}
|
||||
|
||||
#undef STAGE_PAIR
|
||||
@@ -1030,10 +1000,6 @@ static void unused_stage_buffer_semantics(void)
|
||||
const struct {const char *old,*replacement;enum stela_air_error_kind kind;} bad[]={
|
||||
{"i32 7,i32 1,!\"air.read\"","i32 7,i32 1,!\"air.write\"",STELA_AIR_ARGUMENT},
|
||||
{"ptr addrspace(2) %unused","ptr addrspace(1) %unused",STELA_AIR_ARGUMENT},
|
||||
{"!\"float4\",!\"air.arg_name\",!\"unused\"","!\"unknown\",!\"air.arg_name\",!\"unused\"",STELA_AIR_ARGUMENT},
|
||||
{"!\"air.arg_type_size\",i32 16,!\"air.arg_type_align_size\",i32 16,!\"air.arg_type_name\",!\"float4\",!\"air.arg_name\",!\"unused\"",
|
||||
"!\"air.arg_type_size\",i32 8,!\"air.arg_type_align_size\",i32 16,!\"air.arg_type_name\",!\"float4\",!\"air.arg_name\",!\"unused\"",STELA_AIR_ARGUMENT},
|
||||
{"v128:128","v128:256",STELA_AIR_TYPE},
|
||||
};
|
||||
for(unsigned k=0;k<sizeof(bad)/sizeof(bad[0]);k++) {
|
||||
char *invalid=change(text,bad[k].old,bad[k].replacement);bindings.count=0;
|
||||
@@ -1059,7 +1025,8 @@ static LLVMMemoryBufferRef file(const char *path)
|
||||
CHECK(n>=4 && n<=AIR_MAX_BITCODE_BYTES && !fseek(f,0,SEEK_SET));
|
||||
char *b=malloc((size_t)n);CHECK(b && fread(b,1,(size_t)n,f)==(size_t)n && !fclose(f));
|
||||
uint8_t hash[32];_mesa_blake3_compute(b,(size_t)n,hash);printf("input bytes%ld blake3",n);
|
||||
for(unsigned i=0;i<32;i++)printf("%02x",hash[i]);puts("");
|
||||
for(unsigned i=0;i<32;i++)printf("%02x",hash[i]);
|
||||
puts("");
|
||||
LLVMMemoryBufferRef result=LLVMCreateMemoryBufferWithMemoryRangeCopy(b,(size_t)n,"unchanged-stage-input");free(b);return result;
|
||||
}
|
||||
#include "air_funnel_stage_tests.h"
|
||||
@@ -1071,7 +1038,7 @@ int main(int argc,char **argv)
|
||||
link_and_option_failures(b,"test_vertex","test_fragment");LLVMDisposeMemoryBuffer(b);
|
||||
stage_binding_prelude_contract();
|
||||
unused_stage_buffer_semantics();
|
||||
primitive_layout_semantics();
|
||||
primitive_buffer_semantics();
|
||||
output_oracle_controls();
|
||||
arithmetic_and_lane_semantics();
|
||||
aggregate_phi_semantics();
|
||||
|
||||
Reference in new issue
Block a user