[Mesa-dev] [PATCH 13/22] nir/spirv: parse memory model
Karol Herbst
kherbst at redhat.com
Tue Nov 13 15:48:17 UTC 2018
Signed-off-by: Karol Herbst <kherbst at redhat.com>
---
src/compiler/nir/nir.h | 8 ++++++++
src/compiler/nir/nir_clone.c | 1 +
src/compiler/nir/nir_serialize.c | 2 ++
src/compiler/spirv/spirv_to_nir.c | 15 +++++++++++++--
4 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 11e3d18320a..be4f64464f9 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2204,6 +2204,14 @@ typedef struct nir_shader {
*/
void *constant_data;
unsigned constant_data_size;
+
+ /**
+ * pointer size is:
+ * AddressingModelLogical: 0 (default)
+ * AddressingModelPhysical32: 32
+ * AddressingModelPhysical64: 64
+ */
+ unsigned ptr_size;
} nir_shader;
static inline nir_function_impl *
diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c
index 989c5051a54..d47d3e8cb72 100644
--- a/src/compiler/nir/nir_clone.c
+++ b/src/compiler/nir/nir_clone.c
@@ -733,6 +733,7 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s)
ns->num_uniforms = s->num_uniforms;
ns->num_outputs = s->num_outputs;
ns->num_shared = s->num_shared;
+ ns->ptr_size = s->ptr_size;
ns->constant_data_size = s->constant_data_size;
if (s->constant_data_size > 0) {
diff --git a/src/compiler/nir/nir_serialize.c b/src/compiler/nir/nir_serialize.c
index 43016310048..5ec6972b02a 100644
--- a/src/compiler/nir/nir_serialize.c
+++ b/src/compiler/nir/nir_serialize.c
@@ -1106,6 +1106,7 @@ nir_serialize(struct blob *blob, const nir_shader *nir)
blob_write_uint32(blob, nir->num_uniforms);
blob_write_uint32(blob, nir->num_outputs);
blob_write_uint32(blob, nir->num_shared);
+ blob_write_uint32(blob, nir->ptr_size);
blob_write_uint32(blob, exec_list_length(&nir->functions));
nir_foreach_function(fxn, nir) {
@@ -1165,6 +1166,7 @@ nir_deserialize(void *mem_ctx,
ctx.nir->num_uniforms = blob_read_uint32(blob);
ctx.nir->num_outputs = blob_read_uint32(blob);
ctx.nir->num_shared = blob_read_uint32(blob);
+ ctx.nir->ptr_size = blob_read_uint32(blob);
unsigned num_functions = blob_read_uint32(blob);
for (unsigned i = 0; i < num_functions; i++)
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index db2ee51340c..e597b2462cb 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -3588,9 +3588,20 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
break;
case SpvOpMemoryModel:
+ if (w[2] == SpvMemoryModelOpenCL) {
+ if (w[1] == SpvAddressingModelPhysical32)
+ b->shader->ptr_size = 32;
+ else if (w[1] == SpvAddressingModelPhysical64)
+ b->shader->ptr_size = 64;
+ else
+ vtn_fail("Couldn't parse OpenCL Memory Model");
+ break;
+ }
+
vtn_assert(w[1] == SpvAddressingModelLogical);
vtn_assert(w[2] == SpvMemoryModelSimple ||
w[2] == SpvMemoryModelGLSL450);
+ b->shader->ptr_size = 0;
break;
case SpvOpEntryPoint:
@@ -4265,6 +4276,8 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
/* Skip the SPIR-V header, handled at vtn_create_builder */
words+= 5;
+ b->shader = nir_shader_create(b, stage, nir_options, NULL);
+
/* Handle all the preamble instructions */
words = vtn_foreach_instruction(b, words, word_end,
vtn_handle_preamble_instruction);
@@ -4275,8 +4288,6 @@ spirv_to_nir(const uint32_t *words, size_t word_count,
return NULL;
}
- b->shader = nir_shader_create(b, stage, nir_options, NULL);
-
/* Set shader info defaults */
b->shader->info.gs.invocations = 1;
--
2.19.1
More information about the mesa-dev
mailing list