Module: Mesa Branch: main Commit: 62c3492d0b7649beb0e23ff1f8fb015a5968b0a4 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=62c3492d0b7649beb0e23ff1f8fb015a5968b0a4
Author: Michael Tang <[email protected]> Date: Mon Aug 23 19:08:08 2021 -0700 microsoft/compiler: Add support for SV_SampleIndex intrinsic Reviewed-by: Jesse Natalie <[email protected]> Reviewed-by: Erik Faye-Lund <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12513> --- src/microsoft/compiler/dxil_function.c | 1 + src/microsoft/compiler/dxil_signature.c | 3 +++ src/microsoft/compiler/nir_to_dxil.c | 30 +++++++++++++++++++----------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/microsoft/compiler/dxil_function.c b/src/microsoft/compiler/dxil_function.c index 88af18e84c6..804b62ffd83 100644 --- a/src/microsoft/compiler/dxil_function.c +++ b/src/microsoft/compiler/dxil_function.c @@ -60,6 +60,7 @@ static struct predefined_func_descr predefined_funcs[] = { {"dx.op.sampleCmpLevelZero", "R", "i@@ffffiiif", DXIL_ATTR_KIND_READ_ONLY}, {"dx.op.textureLoad", "R", "i@iiiiiii", DXIL_ATTR_KIND_READ_ONLY}, {"dx.op.discard", "v", "ib", DXIL_ATTR_KIND_READ_NONE}, +{"dx.op.sampleIndex", "i", "i", DXIL_ATTR_KIND_READ_NONE}, {"dx.op.emitStream", "v", "ic", DXIL_ATTR_KIND_NONE}, {"dx.op.cutStream", "v", "ic", DXIL_ATTR_KIND_NONE}, {"dx.op.getDimensions", "D", "i@i", DXIL_ATTR_KIND_READ_ONLY}, diff --git a/src/microsoft/compiler/dxil_signature.c b/src/microsoft/compiler/dxil_signature.c index 71c9643f9a9..2b2928fff65 100644 --- a/src/microsoft/compiler/dxil_signature.c +++ b/src/microsoft/compiler/dxil_signature.c @@ -185,6 +185,9 @@ get_semantic_sv_name(nir_variable *var, struct semantic_info *info, bool _vulkan case SYSTEM_VALUE_PRIMITIVE_ID: info->kind = DXIL_SEM_PRIMITIVE_ID; break; + case SYSTEM_VALUE_SAMPLE_ID: + info->kind = DXIL_SEM_SAMPLE_INDEX; + break; default: unreachable("unsupported system value"); } diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index 55f3cbd66c5..972000171ef 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -246,6 +246,8 @@ enum dxil_intr { DXIL_INTR_DDX_FINE = 85, DXIL_INTR_DDY_FINE = 86, + DXIL_INTR_SAMPLE_INDEX = 90, + DXIL_INTR_THREAD_ID = 93, DXIL_INTR_GROUP_ID = 94, DXIL_INTR_THREAD_ID_IN_GROUP = 95, @@ -2345,24 +2347,25 @@ emit_load_local_workgroup_id(struct ntd_context *ctx, } static bool -emit_load_primitiveid(struct ntd_context *ctx, - nir_intrinsic_instr *intr) +emit_load_unary_external_function(struct ntd_context *ctx, + nir_intrinsic_instr *intr, const char *name, + int32_t dxil_intr) { - const struct dxil_func *func = dxil_get_function(&ctx->mod, "dx.op.primitiveID", DXIL_I32); + const struct dxil_func *func = + dxil_get_function(&ctx->mod, name, DXIL_I32); if (!func) return false; - const struct dxil_value *opcode = dxil_module_get_int32_const(&ctx->mod, - DXIL_INTR_PRIMITIVE_ID); + const struct dxil_value *opcode = + dxil_module_get_int32_const(&ctx->mod, dxil_intr); if (!opcode) return false; - const struct dxil_value *args[] = { - opcode - }; + const struct dxil_value *args[] = {opcode}; - const struct dxil_value *primid = dxil_emit_call(&ctx->mod, func, args, ARRAY_SIZE(args)); - store_dest_value(ctx, &intr->dest, 0, primid); + const struct dxil_value *value = + dxil_emit_call(&ctx->mod, func, args, ARRAY_SIZE(args)); + store_dest_value(ctx, &intr->dest, 0, value); return true; } @@ -3552,7 +3555,11 @@ emit_intrinsic(struct ntd_context *ctx, nir_intrinsic_instr *intr) return emit_load_input_interpolated(ctx, intr, ctx->system_value[SYSTEM_VALUE_INSTANCE_ID]); case nir_intrinsic_load_primitive_id: - return emit_load_primitiveid(ctx, intr); + return emit_load_unary_external_function(ctx, intr, "dx.op.primitiveID", + DXIL_INTR_PRIMITIVE_ID); + case nir_intrinsic_load_sample_id: + return emit_load_unary_external_function(ctx, intr, "dx.op.sampleIndex", + DXIL_INTR_SAMPLE_INDEX); case nir_intrinsic_load_shared_dxil: return emit_load_shared(ctx, intr); case nir_intrinsic_load_scratch_dxil: @@ -4773,6 +4780,7 @@ struct sysvalue_name { {SYSTEM_VALUE_INSTANCE_ID, -1, "SV_InstanceID"}, {SYSTEM_VALUE_FRONT_FACE, VARYING_SLOT_FACE, "SV_IsFrontFace"}, {SYSTEM_VALUE_PRIMITIVE_ID, VARYING_SLOT_PRIMITIVE_ID, "SV_PrimitiveID"}, + {SYSTEM_VALUE_SAMPLE_ID, -1, "SV_SampleIndex"}, }; static bool
