Module: Mesa
Branch: master
Commit: 9a4099858bc9ab802ac77f7fbfb85c7646203cd0
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9a4099858bc9ab802ac77f7fbfb85c7646203cd0

Author: Alejandro PiƱeiro <[email protected]>
Date:   Tue Mar 16 00:19:01 2021 +0100

v3dv/pipeline: don't create a variant if compilation failed

Also return the proper Vulkan result for this case, that is somewhat
tricky. Technically Create[Graphics/Compute]Pipeline only allow OOM
errors. So for this case, there is only the alternative of the generic
VK_ERROR_UNKNOWN, even if we known the cause of the error. From spec:

 "VK_ERROR_UNKNOWN will be returned by an implementation when an
  unexpected error occurs that cannot be attributed to valid behavior
  of the application and implementation. Under these conditions, it
  may be returned from any command returning a VkResult"

Reviewed-by: Iago Toral Quiroga <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9403>

---

 src/broadcom/vulkan/v3dv_pipeline.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/broadcom/vulkan/v3dv_pipeline.c 
b/src/broadcom/vulkan/v3dv_pipeline.c
index 190e8026e68..0f5852b29b8 100644
--- a/src/broadcom/vulkan/v3dv_pipeline.c
+++ b/src/broadcom/vulkan/v3dv_pipeline.c
@@ -1421,13 +1421,19 @@ v3dv_shader_variant_create(struct v3dv_device *device,
    return variant;
 }
 
-/* For a given key, it returns the compiled version of the shader.
+/* For a given key, it returns the compiled version of the shader.  Returns a
+ * new reference to the shader_variant to the caller, or NULL.
  *
- * If the method returns NULL it means that it was not able to allocate the
- * resources for the variant. out_vk_result would return the corresponding OOM
- * error.
- *
- * Returns a new reference to the shader_variant to the caller.
+ * If the method returns NULL it means that something wrong happened:
+ *   * Not enough memory: this is one of the possible outcomes defined by
+ *     vkCreateXXXPipelines. out_vk_result will return the proper oom error.
+ *   * Compilation error: hypothetically this shouldn't happen, as the spec
+ *     states that vkShaderModule needs to be created with a valid SPIR-V, so
+ *     any compilation failure is a driver bug. In the practice, something as
+ *     common as failing to register allocate can lead to a compilation
+ *     failure. In that case the only option (for any driver) is
+ *     VK_ERROR_UNKNOWN, even if we know that the problem was a compiler
+ *     error.
  */
 static struct v3dv_shader_variant*
 pipeline_compile_shader_variant(struct v3dv_pipeline_stage *p_stage,
@@ -1463,19 +1469,21 @@ pipeline_compile_shader_variant(struct 
v3dv_pipeline_stage *p_stage,
                            p_stage->program_id, 0,
                            &qpu_insts_size);
 
+   struct v3dv_shader_variant *variant = NULL;
+
    if (!qpu_insts) {
       fprintf(stderr, "Failed to compile %s prog %d NIR to VIR\n",
               gl_shader_stage_name(p_stage->stage),
               p_stage->program_id);
+      *out_vk_result = VK_ERROR_UNKNOWN;
+   } else {
+      variant =
+         v3dv_shader_variant_create(pipeline->device, p_stage->stage,
+                                    prog_data, prog_data_size,
+                                    0, /* assembly_offset, no final value yet 
*/
+                                    qpu_insts, qpu_insts_size,
+                                    out_vk_result);
    }
-
-   struct v3dv_shader_variant *variant =
-      v3dv_shader_variant_create(pipeline->device, p_stage->stage,
-                                 prog_data, prog_data_size,
-                                 0, /* assembly_offset, no final value yet */
-                                 qpu_insts, qpu_insts_size,
-                                 out_vk_result);
-
    /* At this point we don't need anymore the nir shader, but we are freeing
     * all the temporary p_stage structs used during the pipeline creation when
     * we finish it, so let's not worry about freeing the nir here.

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to