diff --git a/crates/stela-driver-gpu/src/compiler/air_to_nir.c b/crates/stela-driver-gpu/src/compiler/air_to_nir.c index 62286d67e4..0cf4a72860 100644 --- a/crates/stela-driver-gpu/src/compiler/air_to_nir.c +++ b/crates/stela-driver-gpu/src/compiler/air_to_nir.c @@ -2437,6 +2437,21 @@ interpolant_call(struct translator *t, LLVMValueRef inst, const char *name, size return put_value(t, inst, stage_narrow(&t->b, def, io->primitive), 0); } +/* "air.is_uniform.", which states what make_uniform guarantees. */ +static bool +uniform_call(struct translator *t, LLVMValueRef inst, const char *name, size_t name_length, + bool *lowered) +{ + static const char uniform[] = "air.is_uniform."; + *lowered = name_length > strlen(uniform) && !memcmp(name, uniform, strlen(uniform)); + if (!*lowered) + return true; + if (LLVMGetNumArgOperands(inst) != 1 || + LLVMTypeOf(inst) != LLVMInt1TypeInContext(LLVMGetTypeContext(LLVMTypeOf(inst)))) + return fail(t, STELA_AIR_TYPE, "is_uniform answers a bool of one value"); + return put_value(t, inst, nir_imm_true(&t->b), 0); +} + /* "air.get_num_samples.i32" and "air.get_sample_position.v2f32", whose last * operand is 0, from the pass's samples; an index past them reads one of the * 16 positions the pass holds. */ @@ -4071,6 +4086,10 @@ instruction(struct translator *t, LLVMValueRef inst) return false; if (lowered) return true; + /* An assumption only permits optimization, so honoring none is exact. */ + unsigned assume = LLVMLookupIntrinsicID("llvm.assume", strlen("llvm.assume")); + if (assume && LLVMGetIntrinsicID(callee) == assume) + return true; } if (LLVMIsAFunction(callee)) { unsigned intrinsic = LLVMGetIntrinsicID(callee); @@ -4151,6 +4170,10 @@ instruction(struct translator *t, LLVMValueRef inst) return false; if (lowered) return true; + if (!uniform_call(t, inst, name, name_length, &lowered)) + return false; + if (lowered) + return true; if (!texture_call(t, inst, name, name_length, &lowered)) return false; if (lowered) diff --git a/crates/stela-driver-gpu/src/compiler/tests/air_render_io.c b/crates/stela-driver-gpu/src/compiler/tests/air_render_io.c index 4f0f4d7653..14f5c97c4b 100644 --- a/crates/stela-driver-gpu/src/compiler/tests/air_render_io.c +++ b/crates/stela-driver-gpu/src/compiler/tests/air_render_io.c @@ -657,6 +657,25 @@ fragment_functions_read_their_pass_samples(void) free(other); } +/* A value declared uniform is, and the assumption that says so adds nothing. */ +static void +uniform_values_are_assumed(void) +{ + char *assumed = change(sampled, "%f = uitofp", "%u = call i1 @air.is_uniform.i32(i32 %n)\n" + "call void @llvm.assume(i1 %u)\n%f = uitofp"); + char *declared = change(assumed, "declare i32 @air.get_num_samples.i32(i32)\n", + "declare i32 @air.get_num_samples.i32(i32)\n" + "declare i1 @air.is_uniform.i32(i32)\ndeclare void @llvm.assume(i1)\n"); + struct stela_air_error error = {0}; + nir_shader *shader = translate(declared, STELA_AIR_FRAGMENT, false, &error); + if (!shader) + fprintf(stderr, "assumed: %u %s\n", error.kind, error.detail); + assert(shader && error.kind == STELA_AIR_OK); + ralloc_free(shader); + free(assumed); + free(declared); +} + static void refuses_unrepresentable_render_io(void) { @@ -741,6 +760,7 @@ main(void) fragment_functions_interpolate_their_interpolants(); void_functions_write_nothing(); fragment_functions_read_their_pass_samples(); + uniform_values_are_assumed(); refuses_unrepresentable_render_io(); glsl_type_singleton_decref(); puts("air render io: ok");