diff --git a/VKShaderParse.h b/VKShaderParse.h new file mode 100644 index 0000000..f2fa7ce --- /dev/null +++ b/VKShaderParse.h @@ -0,0 +1,70 @@ +#pragma once +#include +#include + +using namespace hgl; + +using SPVResVector=spirv_cross::SmallVector; + +class ShaderParse +{ + spirv_cross::Compiler *compiler; + spirv_cross::ShaderResources resource; + +public: + + ShaderParse(const void *spv_data,const uint32_t spv_size) + { + compiler=new spirv_cross::Compiler((const uint32_t *)spv_data,spv_size/sizeof(uint32_t)); + + resource=compiler->get_shader_resources(); + } + + ~ShaderParse() + { + delete compiler; + } + +#define SHADER_PARSE_GET_RESOURCE(name,buf_name) const SPVResVector &Get##name()const{return resource.buf_name;} + + SHADER_PARSE_GET_RESOURCE(UBO, uniform_buffers) + SHADER_PARSE_GET_RESOURCE(SSBO, storage_buffers) + SHADER_PARSE_GET_RESOURCE(StageInputs, stage_inputs) + SHADER_PARSE_GET_RESOURCE(StageOutputs, stage_outputs) + SHADER_PARSE_GET_RESOURCE(Sampler, sampled_images) + SHADER_PARSE_GET_RESOURCE(Subpass, subpass_inputs) + + //SmallVector storage_images; + //SmallVector atomic_counters; + //SmallVector acceleration_structures; + //SmallVector push_constant_buffers; + //SmallVector separate_images; + //SmallVector separate_samplers; + +#undef SHADER_PARSE_GET_RESOURCE + +public: + + const AnsiString GetName(const spirv_cross::Resource &res)const + { + return AnsiString(compiler->get_name(res.id).c_str()); + } + + const uint32_t GetBinding(const spirv_cross::Resource &res)const + { + return compiler->get_decoration(res.id,spv::DecorationBinding); + } + + const uint32_t GetLocation(const spirv_cross::Resource &res)const + { + return compiler->get_decoration(res.id,spv::DecorationLocation); + } + + void GetFormat(const spirv_cross::Resource &res,spirv_cross::SPIRType::BaseType *base_type,uint8 *vecsize) + { + const spirv_cross::SPIRType &type=compiler->get_type(res.type_id); + + *base_type =type.basetype; + *vecsize =type.vecsize; + } +};//class ShaderParse