spirv_to_dxil: Convert out parameters to a single object
authorEnrico Galli <enrico.galli@intel.com>
Mon, 30 Aug 2021 21:45:11 +0000 (14:45 -0700)
committerMarge Bot <eric+marge@anholt.net>
Fri, 3 Sep 2021 16:21:03 +0000 (16:21 +0000)
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12707>

src/microsoft/spirv_to_dxil/spirv_to_dxil.c
src/microsoft/spirv_to_dxil/spirv_to_dxil.h

index 4e0973f..3b2570e 100644 (file)
@@ -45,7 +45,8 @@ bool
 spirv_to_dxil(const uint32_t *words, size_t word_count,
               struct dxil_spirv_specialization *specializations,
               unsigned int num_specializations, dxil_spirv_shader_stage stage,
-              const char *entry_point_name, void **buffer, size_t *size)
+              const char *entry_point_name,
+              struct dxil_spirv_object *out_dxil)
 {
    if (stage == MESA_SHADER_NONE || stage == MESA_SHADER_KERNEL)
       return false;
@@ -187,16 +188,17 @@ spirv_to_dxil(const uint32_t *words, size_t word_count,
       return false;
    }
 
-   blob_finish_get_buffer(&dxil_blob, buffer, size);
+   blob_finish_get_buffer(&dxil_blob, &out_dxil->binary.buffer,
+                          &out_dxil->binary.size);
 
    glsl_type_singleton_decref();
    return true;
 }
 
 void
-spirv_to_dxil_free(void* buffer)
+spirv_to_dxil_free(struct dxil_spirv_object *dxil)
 {
-   free(buffer);
+   free(dxil->binary.buffer);
 }
 
 uint64_t
index c0a0b4d..27a5f83 100644 (file)
@@ -69,31 +69,36 @@ struct dxil_spirv_specialization {
    bool defined_on_module;
 };
 
+struct dxil_spirv_object {
+   struct {
+      void *buffer;
+      size_t size;
+   } binary;
+};
+
 /**
  * Compile a SPIR-V module into DXIL.
  * \param  words  SPIR-V module to compile
  * \param  word_count  number of words in the SPIR-V module
  * \param  specializations  specialization constants to compile with the shader
  * \param  num_specializations  number of specialization constants
- * \param  buffer  will contain the DXIL bytes on success. Needs to be freed()
- * \param  size  length of returned buffer
+ * \param  stage  shader stage
+ * \param  entry_point_name  name of shader entrypoint
+ * \param  out_dxil  will contain the DXIL bytes on success (call spirv_to_dxil_free after use)
  * \return  true if compilation succeeded
  */
 bool
-spirv_to_dxil(const uint32_t* words,
-              size_t word_count,
-              struct dxil_spirv_specialization* specializations,
-              unsigned int num_specializations,
-              dxil_spirv_shader_stage stage,
-              const char* entry_point_name,
-              void** buffer,
-              size_t* size);
+spirv_to_dxil(const uint32_t *words, size_t word_count,
+              struct dxil_spirv_specialization *specializations,
+              unsigned int num_specializations, dxil_spirv_shader_stage stage,
+              const char *entry_point_name,
+              struct dxil_spirv_object *out_dxil);
 
 /**
  * Free the buffer allocated by spirv_to_dxil.
  */
 void
-spirv_to_dxil_free(void* buffer);
+spirv_to_dxil_free(struct dxil_spirv_object *dxil);
 
 uint64_t
 spirv_to_dxil_get_version(void);