spirv: add interface for drivers to define support extensions.
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. Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net> Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Acked-by: Jason Ekstrand <jason@jlekstrand.net> Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
@@ -41,10 +41,16 @@ struct nir_spirv_specialization {
|
|||||||
uint32_t data;
|
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,
|
nir_function *spirv_to_nir(const uint32_t *words, size_t word_count,
|
||||||
struct nir_spirv_specialization *specializations,
|
struct nir_spirv_specialization *specializations,
|
||||||
unsigned num_specializations,
|
unsigned num_specializations,
|
||||||
gl_shader_stage stage, const char *entry_point_name,
|
gl_shader_stage stage, const char *entry_point_name,
|
||||||
|
const struct nir_spirv_supported_extensions *ext,
|
||||||
const nir_shader_compiler_options *options);
|
const nir_shader_compiler_options *options);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@@ -73,7 +73,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
nir_function *func = spirv_to_nir(map, word_count, NULL, 0,
|
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);
|
nir_print_shader(func->shader, stderr);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -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
|
static bool
|
||||||
vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
|
vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
|
||||||
const uint32_t *w, unsigned count)
|
const uint32_t *w, unsigned count)
|
||||||
@@ -2519,8 +2525,6 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, SpvOp opcode,
|
|||||||
case SpvCapabilityInt8:
|
case SpvCapabilityInt8:
|
||||||
case SpvCapabilitySparseResidency:
|
case SpvCapabilitySparseResidency:
|
||||||
case SpvCapabilityMinLod:
|
case SpvCapabilityMinLod:
|
||||||
case SpvCapabilityImageMSArray:
|
|
||||||
case SpvCapabilityStorageImageExtendedFormats:
|
|
||||||
case SpvCapabilityTransformFeedback:
|
case SpvCapabilityTransformFeedback:
|
||||||
case SpvCapabilityStorageImageReadWithoutFormat:
|
case SpvCapabilityStorageImageReadWithoutFormat:
|
||||||
case SpvCapabilityStorageImageWriteWithoutFormat:
|
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",
|
vtn_warn("Unsupported OpenCL-style SPIR-V capability: %s",
|
||||||
spirv_capability_to_string(cap));
|
spirv_capability_to_string(cap));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SpvCapabilityStorageImageExtendedFormats:
|
||||||
|
spv_check_supported(storage_image_extended_formats, cap);
|
||||||
|
break;
|
||||||
|
case SpvCapabilityImageMSArray:
|
||||||
|
spv_check_supported(image_ms_array, cap);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -3015,6 +3026,7 @@ nir_function *
|
|||||||
spirv_to_nir(const uint32_t *words, size_t word_count,
|
spirv_to_nir(const uint32_t *words, size_t word_count,
|
||||||
struct nir_spirv_specialization *spec, unsigned num_spec,
|
struct nir_spirv_specialization *spec, unsigned num_spec,
|
||||||
gl_shader_stage stage, const char *entry_point_name,
|
gl_shader_stage stage, const char *entry_point_name,
|
||||||
|
const struct nir_spirv_supported_extensions *ext,
|
||||||
const nir_shader_compiler_options *options)
|
const nir_shader_compiler_options *options)
|
||||||
{
|
{
|
||||||
const uint32_t *word_end = words + word_count;
|
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);
|
exec_list_make_empty(&b->functions);
|
||||||
b->entry_point_stage = stage;
|
b->entry_point_stage = stage;
|
||||||
b->entry_point_name = entry_point_name;
|
b->entry_point_name = entry_point_name;
|
||||||
|
b->ext = ext;
|
||||||
|
|
||||||
/* Handle all the preamble instructions */
|
/* Handle all the preamble instructions */
|
||||||
words = vtn_foreach_instruction(b, words, word_end,
|
words = vtn_foreach_instruction(b, words, word_end,
|
||||||
|
@@ -347,6 +347,7 @@ struct vtn_builder {
|
|||||||
|
|
||||||
nir_shader *shader;
|
nir_shader *shader;
|
||||||
nir_function_impl *impl;
|
nir_function_impl *impl;
|
||||||
|
const struct nir_spirv_supported_extensions *ext;
|
||||||
struct vtn_block *block;
|
struct vtn_block *block;
|
||||||
|
|
||||||
/* Current file, line, and column. Useful for debugging. Set
|
/* Current file, line, and column. Useful for debugging. Set
|
||||||
|
@@ -124,7 +124,7 @@ anv_shader_compile_to_nir(struct anv_device *device,
|
|||||||
nir_function *entry_point =
|
nir_function *entry_point =
|
||||||
spirv_to_nir(spirv, module->size / 4,
|
spirv_to_nir(spirv, module->size / 4,
|
||||||
spec_entries, num_spec_entries,
|
spec_entries, num_spec_entries,
|
||||||
stage, entrypoint_name, nir_options);
|
stage, entrypoint_name, NULL, nir_options);
|
||||||
nir_shader *nir = entry_point->shader;
|
nir_shader *nir = entry_point->shader;
|
||||||
assert(nir->stage == stage);
|
assert(nir->stage == stage);
|
||||||
nir_validate_shader(nir);
|
nir_validate_shader(nir);
|
||||||
|
Reference in New Issue
Block a user