removed SPVParseData

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-03-21 18:04:26 +08:00
parent 0dae30fa06
commit fb4c8ed8c2
2 changed files with 147 additions and 268 deletions

View File

@ -3,11 +3,10 @@
#include<hgl/type/StringList.h> #include<hgl/type/StringList.h>
#include<hgl/filesystem/FileSystem.h> #include<hgl/filesystem/FileSystem.h>
using namespace hgl; namespace hgl
using namespace hgl::io;
namespace glsl_compiler
{ {
namespace graph
{
enum class ShaderLanguageType enum class ShaderLanguageType
{ {
GLSL=0, GLSL=0,
@ -27,9 +26,10 @@ namespace glsl_compiler
const char * preamble = nullptr; const char * preamble = nullptr;
}; };
UTF8StringList include_list;
CompileInfo compile_info; CompileInfo compile_info;
struct SPVParseData;
struct GLSLCompilerInterface struct GLSLCompilerInterface
{ {
bool (*Init)(); bool (*Init)();
@ -54,7 +54,7 @@ namespace glsl_compiler
typedef GLSLCompilerInterface *(*GetInterfaceFUNC)(); typedef GLSLCompilerInterface *(*GetInterfaceFUNC)();
bool Init() bool InitShaderCompiler()
{ {
compile_info.includes=nullptr; compile_info.includes=nullptr;
compile_info.includes_count=0; compile_info.includes_count=0;
@ -91,7 +91,7 @@ namespace glsl_compiler
return(false); return(false);
} }
void Close() void CloseShaderCompiler()
{ {
delete[] compile_info.includes; delete[] compile_info.includes;
compile_info.includes=nullptr; compile_info.includes=nullptr;
@ -109,54 +109,20 @@ namespace glsl_compiler
} }
} }
void AddGLSLIncludePath(const char *path) const char PreambleString[]="";//#extension GL_GOOGLE_include_directive : require\n";
{
if(include_list.Find(path)==-1)
include_list.Add(path);
}
const char PreambleString[]="#extension GL_GOOGLE_include_directive : require\n";
void RebuildGLSLIncludePath() void RebuildGLSLIncludePath()
{ {
delete[] compile_info.includes;
compile_info.includes_count=include_list.GetCount();
compile_info.includes=new const char *[compile_info.includes_count];
for(uint32_t i=0;i<compile_info.includes_count;i++)
compile_info.includes[i]=include_list[i].c_str();
if(compile_info.includes_count>0)
compile_info.preamble=PreambleString; compile_info.preamble=PreambleString;
} }
uint32_t GetType (const char *ext_name) void FreeSPVData(SPVData *spv_data)
{
if(gsi)
return gsi->GetType(ext_name);
return 0;
}
void Free (SPVData *spv_data)
{ {
if(gsi) if(gsi)
gsi->Free(spv_data); gsi->Free(spv_data);
} }
SPVParseData *ParseSPV(SPVData *spv_data) SPVData *CompileShader(const uint32_t type,const char *source)
{
return gsi?gsi->ParseSPV(spv_data):nullptr;
}
void FreeSPVParse(SPVParseData *spv)
{
if(gsi&&spv)
gsi->FreeParseSPVData(spv);
}
SPVData *Compile(const uint32_t type,const char *source)
{ {
if(!gsi) if(!gsi)
return(nullptr); return(nullptr);
@ -167,12 +133,9 @@ namespace glsl_compiler
source+=3; source+=3;
else else
if(bom!=ByteOrderMask::NONE) if(bom!=ByteOrderMask::NONE)
{
std::cerr<<"GLSLCompiler does not support BOMHeader outside of UTF8"<<std::endl;
return(nullptr); return(nullptr);
}
glsl_compiler::SPVData *spv=gsi->Compile(type,source,&compile_info); SPVData *spv=gsi->Compile(type,source,&compile_info);
if(!spv)return(nullptr); if(!spv)return(nullptr);
@ -180,19 +143,11 @@ namespace glsl_compiler
if(!result) if(!result)
{ {
std::cerr<<"glsl compile failed."<<std::endl; FreeSPVData(spv);
if(spv->log)
std::cerr<<"info: "<<spv->log<<std::endl;
if(spv->debug_log)
std::cerr<<"debug info: "<<spv->debug_log<<std::endl;
glsl_compiler::Free(spv);
return(nullptr); return(nullptr);
} }
std::cout<<"Compile successed! spv length "<<spv->spv_length<<" bytes."<<std::endl;
return spv; return spv;
} }
}//namespace glsl_compiler }//namespace graph
}//namespace hgl

View File

@ -1,102 +1,26 @@
#ifndef HGL_GLSL_COMPILER_INCLUDE #ifndef HGL_GLSL_COMPILER_INCLUDE
#define HGL_GLSL_COMPILER_INCLUDE #define HGL_GLSL_COMPILER_INCLUDE
#include<hgl/type/String.h> #include<hgl/type/DataType.h>
#include<hgl/type/Map.h>
#include<stdint.h>
#include<hgl/graph/VKShaderStage.h>
namespace hgl namespace hgl
{ {
namespace io namespace graph
{ {
class MemoryOutputStream;
class DataOutputStream;
}
}
namespace glsl_compiler
{
using namespace hgl;
using namespace hgl::graph;
enum class DescriptorType //等同VkDescriptorType
{
SAMPLER = 0,
COMBINED_IMAGE_SAMPLER,
SAMPLED_IMAGE,
STORAGE_IMAGE,
UNIFORM_TEXEL_BUFFER,
STORAGE_TEXEL_BUFFER,
UNIFORM_BUFFER,
STORAGE_BUFFER,
UNIFORM_BUFFER_DYNAMIC,
STORAGE_BUFFER_DYNAMIC,
INPUT_ATTACHMENT,
ENUM_CLASS_RANGE(SAMPLER,INPUT_ATTACHMENT)
};
struct Descriptor
{
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
uint8_t set;
uint8_t binding;
};
struct PushConstant
{
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
uint8_t offset;
uint8_t size;
};
struct SubpassInput
{
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
uint8_t input_attachment_index;
uint8_t binding;
};
template<typename T>
struct ShaderResourceData
{
uint32_t count;
T *items;
};
using ShaderDescriptorResource=ShaderResourceData<Descriptor>[size_t(DescriptorType::RANGE_SIZE)];
struct SPVData struct SPVData
{ {
bool result; bool result;
char *log; char *log;
char *debug_log; char *debug_log;
uint32_t *spv_data; uint32 *spv_data;
uint32_t spv_length; uint32 spv_length;
}; };
struct SPVParseData bool InitShaderCompiler();
{ void CloseShaderCompiler();
ShaderStageIO stage_io;
ShaderDescriptorResource resource;
ShaderResourceData<PushConstant> push_constant;
ShaderResourceData<SubpassInput> subpass_input;
};
bool Init(); SPVData * CompileShader (const uint32 type,const char *source);
void Close(); void FreeSPVData (SPVData *spv_data);
}//namespace graph
void AddGLSLIncludePath(const char *); }//namespace hgl
void RebuildGLSLIncludePath();
uint32_t GetType (const char *ext_name);
SPVData * Compile (const uint32_t type,const char *source);
void Free (SPVData *spv_data);
SPVParseData * ParseSPV(SPVData *spv_data);
void FreeSPVParse(SPVParseData *spv);
}//namespace glsl_compiler
#endif//HGL_GLSL_COMPILER_INCLUDE #endif//HGL_GLSL_COMPILER_INCLUDE