[Mesa-dev] [PATCH 1/2] spirv: add interface for drivers to define support extensions.
Dave Airlie
airlied at gmail.com
Tue Dec 27 23:30:54 UTC 2016
From: Dave Airlie <airlied at redhat.com>
I expect over time the struct contents will change as all
drivers support stuff etc, but for now this should be a good
starting point.
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
src/compiler/spirv/nir_spirv.h | 6 ++++++
src/compiler/spirv/spirv2nir.c | 2 +-
src/compiler/spirv/spirv_to_nir.c | 17 +++++++++++++++--
src/compiler/spirv/vtn_private.h | 1 +
src/intel/vulkan/anv_pipeline.c | 2 +-
5 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/src/compiler/spirv/nir_spirv.h b/src/compiler/spirv/nir_spirv.h
index 500f2cb..d959f3f 100644
--- a/src/compiler/spirv/nir_spirv.h
+++ b/src/compiler/spirv/nir_spirv.h
@@ -41,10 +41,16 @@ struct nir_spirv_specialization {
uint32_t data;
};
+struct nir_spirv_supported_extensions {
+ bool storage_image_extended_formats;
+ bool image_ms_array;
+};
+
nir_function *spirv_to_nir(const uint32_t *words, size_t word_count,
struct nir_spirv_specialization *specializations,
unsigned num_specializations,
gl_shader_stage stage, const char *entry_point_name,
+ const struct nir_spirv_supported_extensions *ext,
const nir_shader_compiler_options *options);
#ifdef __cplusplus
diff --git a/src/compiler/spirv/spirv2nir.c b/src/compiler/spirv/spirv2nir.c
index 3dc0735..0ae14fb 100644
--- a/src/compiler/spirv/spirv2nir.c
+++ b/src/compiler/spirv/spirv2nir.c
@@ -73,7 +73,7 @@ int main(int argc, char **argv)
}
nir_function *func = spirv_to_nir(map, word_count, NULL, 0,
- MESA_SHADER_FRAGMENT, "main", NULL);
+ MESA_SHADER_FRAGMENT, "main", NULL, NULL);
nir_print_shader(func->shader, stderr);
return 0;
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 57d0886..b8acc1e 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -2461,6 +2461,12 @@ stage_for_execution_model(SpvExecutionModel model)
}
}
+#define spv_check_supported(name, cap) do { \
+ if (!(b->ext && b->ext->name)) \
+ vtn_warn("Unsupported SPIR-V capability: %s", \
+ spirv_capability_to_string(cap)); \
+ } while(0)
+
static bool
vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
const uint32_t *w, unsigned count)
@@ -2519,8 +2525,6 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
case SpvCapabilityInt8:
case SpvCapabilitySparseResidency:
case SpvCapabilityMinLod:
- case SpvCapabilityImageMSArray:
- case SpvCapabilityStorageImageExtendedFormats:
case SpvCapabilityTransformFeedback:
case SpvCapabilityStorageImageReadWithoutFormat:
case SpvCapabilityStorageImageWriteWithoutFormat:
@@ -2541,6 +2545,13 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
vtn_warn("Unsupported OpenCL-style SPIR-V capability: %s",
spirv_capability_to_string(cap));
break;
+
+ case SpvCapabilityStorageImageExtendedFormats:
+ spv_check_supported(storage_image_extended_formats, cap);
+ break;
+ case SpvCapabilityImageMSArray:
+ spv_check_supported(image_ms_array, cap);
+ break;
}
break;
}
@@ -3015,6 +3026,7 @@ nir_function *
spirv_to_nir(const uint32_t *words, size_t word_count,
struct nir_spirv_specialization *spec, unsigned num_spec,
gl_shader_stage stage, const char *entry_point_name,
+ const struct nir_spirv_supported_extensions *ext,
const nir_shader_compiler_options *options)
{
const uint32_t *word_end = words + word_count;
@@ -3037,6 +3049,7 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
exec_list_make_empty(&b->functions);
b->entry_point_stage = stage;
b->entry_point_name = entry_point_name;
+ b->ext = ext;
/* Handle all the preamble instructions */
words = vtn_foreach_instruction(b, words, word_end,
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index 47579fe..9302611 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -347,6 +347,7 @@ struct vtn_builder {
nir_shader *shader;
nir_function_impl *impl;
+ const struct nir_spirv_supported_extensions *ext;
struct vtn_block *block;
/* Current file, line, and column. Useful for debugging. Set
diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index e2fbcab..db35d70 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -124,7 +124,7 @@ anv_shader_compile_to_nir(struct anv_device *device,
nir_function *entry_point =
spirv_to_nir(spirv, module->size / 4,
spec_entries, num_spec_entries,
- stage, entrypoint_name, nir_options);
+ stage, entrypoint_name, NULL, nir_options);
nir_shader *nir = entry_point->shader;
assert(nir->stage == stage);
nir_validate_shader(nir);
--
2.7.4
More information about the mesa-dev
mailing list