[Mesa-dev] [PATCH 04/12] nir/spirv: improve parsing of the memory model
Jason Ekstrand
jason at jlekstrand.net
Mon Jan 7 17:02:55 UTC 2019
On Tue, Dec 4, 2018 at 12:27 PM Karol Herbst <kherbst at redhat.com> wrote:
> 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 | 26 ++++++++++++++++++++++----
> src/compiler/spirv/vtn_private.h | 3 +++
> 5 files changed, 36 insertions(+), 4 deletions(-)
>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index db935c8496b..a111e87ed71 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -2249,6 +2249,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;
>
I think this is worth stashing but it seems to me like it belongs in the cs
portion of shader_info along with the local workgroup size rather than
nir_shader.
> } 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 e41a7e960ce..1a7d5b3a9bd 100644
> --- a/src/compiler/spirv/spirv_to_nir.c
> +++ b/src/compiler/spirv/spirv_to_nir.c
> @@ -3581,9 +3581,27 @@ vtn_handle_preamble_instruction(struct vtn_builder
> *b, SpvOp opcode,
> break;
>
> case SpvOpMemoryModel:
> - vtn_assert(w[1] == SpvAddressingModelLogical);
> + switch (w[1]) {
> + case SpvAddressingModelPhysical32:
> + b->shader->ptr_size = 32;
> + b->physical_ptrs = true;
> + break;
> + case SpvAddressingModelPhysical64:
> + b->shader->ptr_size = 64;
> + b->physical_ptrs = true;
> + break;
> + case SpvAddressingModelLogical:
> + b->shader->ptr_size = 0;
> + b->physical_ptrs = false;
> + break;
> + default:
> + vtn_fail("Unknown addressing model");
> + break;
>
With my patches for giving pointers explicit types, we'll likely want to
add a type for global and function and set global/function/shared to the
explicitly defined size here.
> + }
> +
> vtn_assert(w[2] == SpvMemoryModelSimple ||
> - w[2] == SpvMemoryModelGLSL450);
> + w[2] == SpvMemoryModelGLSL450 ||
> + w[2] == SpvMemoryModelOpenCL);
> break;
>
> case SpvOpEntryPoint:
> @@ -4258,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);
> @@ -4268,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;
>
> diff --git a/src/compiler/spirv/vtn_private.h
> b/src/compiler/spirv/vtn_private.h
> index da7a04ce59f..47f26dac642 100644
> --- a/src/compiler/spirv/vtn_private.h
> +++ b/src/compiler/spirv/vtn_private.h
> @@ -605,6 +605,9 @@ struct vtn_builder {
> unsigned func_param_idx;
>
> bool has_loop_continue;
> +
> + /* when a physical memory model is choosen */
> + bool physical_ptrs;
> };
>
> nir_ssa_def *
> --
> 2.19.2
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20190107/49d4d15c/attachment.html>
More information about the mesa-dev
mailing list