microsoft/compiler: Split handle annotation into two parts
authorJesse Natalie <jenatali@microsoft.com>
Mon, 27 Feb 2023 18:33:32 +0000 (10:33 -0800)
committerMarge Bot <emma+marge@anholt.net>
Thu, 23 Mar 2023 21:48:43 +0000 (21:48 +0000)
The first part gets the resource props struct, and the second
actually emits the annotate instruction. Later changes will
get the resource props struct from different sources.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21913>

src/microsoft/compiler/nir_to_dxil.c

index 4d5a809..32480c1 100644 (file)
@@ -956,14 +956,35 @@ emit_createhandle_call_pre_6_6(struct ntd_context *ctx,
 
 static const struct dxil_value *
 emit_annotate_handle(struct ntd_context *ctx,
-                     enum dxil_resource_class resource_class,
-                     unsigned resource_range_id,
-                     const struct dxil_value *unannotated_handle)
+                     const struct dxil_value *unannotated_handle,
+                     const struct dxil_value *res_props)
 {
    const struct dxil_value *opcode = dxil_module_get_int32_const(&ctx->mod, DXIL_INTR_ANNOTATE_HANDLE);
    if (!opcode)
       return NULL;
 
+   const struct dxil_value *args[] = {
+      opcode,
+      unannotated_handle,
+      res_props
+   };
+
+   const struct dxil_func *func =
+      dxil_get_function(&ctx->mod, "dx.op.annotateHandle", DXIL_NONE);
+
+   if (!func)
+      return NULL;
+
+   return dxil_emit_call(&ctx->mod, func, args, ARRAY_SIZE(args));
+}
+
+static const struct dxil_value *
+emit_annotate_handle_from_metadata(struct ntd_context *ctx,
+                                   enum dxil_resource_class resource_class,
+                                   unsigned resource_range_id,
+                                   const struct dxil_value *unannotated_handle)
+{
+
    const struct util_dynarray *mdnodes;
    switch (resource_class) {
    case DXIL_RESOURCE_CLASS_SRV:
@@ -987,19 +1008,7 @@ emit_annotate_handle(struct ntd_context *ctx,
    if (!res_props)
       return NULL;
 
-   const struct dxil_value *args[] = {
-      opcode,
-      unannotated_handle,
-      res_props
-   };
-
-   const struct dxil_func *func =
-      dxil_get_function(&ctx->mod, "dx.op.annotateHandle", DXIL_NONE);
-
-   if (!func)
-      return NULL;
-
-   return dxil_emit_call(&ctx->mod, func, args, ARRAY_SIZE(args));
+   return emit_annotate_handle(ctx, unannotated_handle, res_props);
 }
 
 static const struct dxil_value *
@@ -1035,7 +1044,7 @@ emit_createhandle_and_annotate(struct ntd_context *ctx,
    if (!unannotated_handle)
       return NULL;
 
-   return emit_annotate_handle(ctx, resource_class, resource_range_id, unannotated_handle);
+   return emit_annotate_handle_from_metadata(ctx, resource_class, resource_range_id, unannotated_handle);
 }
 
 static const struct dxil_value *