[RFC,5/7] spirv: Add support for the Vulkan memory model

Submitted by Jason Ekstrand on Sept. 10, 2018, 6:04 p.m.

Details

Message ID 20180910180437.25000-6-jason.ekstrand@intel.com
State New
Headers show
Series "anv: Support VK_KHR_vulkan_memory_model" ( rev: 1 ) in Mesa

Commit Message

Jason Ekstrand Sept. 10, 2018, 6:04 p.m.
---
 src/compiler/shader_info.h        |  1 +
 src/compiler/spirv/spirv_to_nir.c | 20 ++++++++++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
index 65bc0588d67..a19840666ac 100644
--- a/src/compiler/shader_info.h
+++ b/src/compiler/shader_info.h
@@ -62,6 +62,7 @@  struct spirv_supported_capabilities {
    bool post_depth_coverage;
    bool transform_feedback;
    bool geometry_streams;
+   bool vk_memory_model;
 };
 
 typedef struct shader_info {
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 3378641513c..dcce05ce83b 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -3600,6 +3600,10 @@  vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
          spv_check_supported(post_depth_coverage, cap);
          break;
 
+      case SpvCapabilityVulkanMemoryModelKHR:
+         spv_check_supported(vk_memory_model, cap);
+         break;
+
       default:
          vtn_fail("Unhandled capability");
       }
@@ -3612,8 +3616,20 @@  vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
 
    case SpvOpMemoryModel:
       vtn_assert(w[1] == SpvAddressingModelLogical);
-      vtn_assert(w[2] == SpvMemoryModelSimple ||
-                 w[2] == SpvMemoryModelGLSL450);
+      switch (w[2]) {
+      case SpvMemoryModelSimple:
+      case SpvMemoryModelGLSL450:
+         break;
+
+      case SpvMemoryModelVulkanKHR:
+         vtn_fail_if(!b->options->caps.vk_memory_model,
+                     "Vulkan memory model is unsupported by this driver");
+         break;
+
+      default:
+         vtn_fail("Unsupported memory model: %s",
+                  spirv_memorymodel_to_string(w[2]));
+      }
       break;
 
    case SpvOpEntryPoint:

Comments

This patch looks like what I would expect.  Contingent on the previous
patch, this patch is

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>

On 09/10/2018 11:04 AM, Jason Ekstrand wrote:
> ---
>  src/compiler/shader_info.h        |  1 +
>  src/compiler/spirv/spirv_to_nir.c | 20 ++++++++++++++++++--
>  2 files changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
> index 65bc0588d67..a19840666ac 100644
> --- a/src/compiler/shader_info.h
> +++ b/src/compiler/shader_info.h
> @@ -62,6 +62,7 @@ struct spirv_supported_capabilities {
>     bool post_depth_coverage;
>     bool transform_feedback;
>     bool geometry_streams;
> +   bool vk_memory_model;
>  };
>  
>  typedef struct shader_info {
> diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
> index 3378641513c..dcce05ce83b 100644
> --- a/src/compiler/spirv/spirv_to_nir.c
> +++ b/src/compiler/spirv/spirv_to_nir.c
> @@ -3600,6 +3600,10 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
>           spv_check_supported(post_depth_coverage, cap);
>           break;
>  
> +      case SpvCapabilityVulkanMemoryModelKHR:
> +         spv_check_supported(vk_memory_model, cap);
> +         break;
> +
>        default:
>           vtn_fail("Unhandled capability");
>        }
> @@ -3612,8 +3616,20 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
>  
>     case SpvOpMemoryModel:
>        vtn_assert(w[1] == SpvAddressingModelLogical);
> -      vtn_assert(w[2] == SpvMemoryModelSimple ||
> -                 w[2] == SpvMemoryModelGLSL450);
> +      switch (w[2]) {
> +      case SpvMemoryModelSimple:
> +      case SpvMemoryModelGLSL450:
> +         break;
> +
> +      case SpvMemoryModelVulkanKHR:
> +         vtn_fail_if(!b->options->caps.vk_memory_model,
> +                     "Vulkan memory model is unsupported by this driver");
> +         break;
> +
> +      default:
> +         vtn_fail("Unsupported memory model: %s",
> +                  spirv_memorymodel_to_string(w[2]));
> +      }
>        break;
>  
>     case SpvOpEntryPoint:
>