{"id":2190,"date":"2020-09-05T10:42:10","date_gmt":"2020-09-05T02:42:10","guid":{"rendered":"http:\/\/www.hyzgame.com\/?p=2190"},"modified":"2020-09-05T10:45:32","modified_gmt":"2020-09-05T02:45:32","slug":"%e7%8b%ac%e7%ab%8b%e7%9a%84glsl%e7%bc%96%e8%af%91%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"http:\/\/www.hyzgame.com\/?p=2190","title":{"rendered":"\u72ec\u7acb\u7684GLSL\u7f16\u8bd1\u5de5\u5177"},"content":{"rendered":"<p>\u7531\u4e8e\u4f7f\u7528SPIRV-Cross\u4ee5\u53caglslang\u7684\u6e90\u4ee3\u7801\u7248\u672c\u6709\u592a\u591a\u7684\u7f16\u8bd1\u914d\u7f6e\u9009\u9879\uff0c\u5f88\u70e6\uff0c\u6240\u4ee5\u6211\u5236\u4f5c\u4e86\u4e00\u4e2a\u52a8\u6001\u94fe\u63a5\u5e93\u7248\u7684GLSL\u5230SPV\u7f16\u8bd1\u5668\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/hyzboy\/GLSLCompiler\">Github\u4ed3\u5e93<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/hyzboy\/GLSLCompiler\/releases\">\u4e0b\u8f7d\u94fe\u63a5<\/a><\/p>\n<p>\u4f7f\u7528\u4ee3\u7801\u5927\u81f4\u5982\u4e0b\uff1a<\/p>\n<p>namespace glsl_compiler<br \/>\n{<br \/>\nenum class DescriptorType \/\/\u7b49\u540cVkDescriptorType<br \/>\n{<br \/>\nSAMPLER = 0,<br \/>\nCOMBINED_IMAGE_SAMPLER = 1,<br \/>\nSAMPLED_IMAGE = 2,<br \/>\nSTORAGE_IMAGE = 3,<br \/>\nUNIFORM_TEXEL_BUFFER = 4,<br \/>\nSTORAGE_TEXEL_BUFFER = 5,<br \/>\nUNIFORM_BUFFER = 6,<br \/>\nSTORAGE_BUFFER = 7,<br \/>\nUNIFORM_BUFFER_DYNAMIC = 8,<br \/>\nSTORAGE_BUFFER_DYNAMIC = 9,<br \/>\nINPUT_ATTACHMENT = 10,<\/p>\n<p>BEGIN_RANGE=SAMPLER,<br \/>\nEND_RANGE=INPUT_ATTACHMENT,<br \/>\nRANGE_SIZE=(END_RANGE-BEGIN_RANGE)+1<br \/>\n};<\/p>\n<p>enum class VertexAttribBaseType<br \/>\n{<br \/>\nBool=0,<br \/>\nInt,<br \/>\nUInt,<br \/>\nFloat,<br \/>\nDouble,<br \/>\n};\/\/enum class VertexAttribBaseType<\/p>\n<p>struct ShaderStage<br \/>\n{<br \/>\nchar name[128];<br \/>\nuint8_t location;<br \/>\nuint32_t basetype; \/\/\u5bf9\u5e94enum class VertexAttribBaseType<br \/>\nuint32_t vec_size;<br \/>\n};\/\/<\/p>\n<p>struct ShaderStageData<br \/>\n{<br \/>\nuint32_t count;<br \/>\nShaderStage *items;<br \/>\n};<\/p>\n<p>struct ShaderResource<br \/>\n{<br \/>\nchar name[128];<\/p>\n<p>uint8_t set;<br \/>\nuint8_t binding;<br \/>\n};<\/p>\n<p>struct ShaderResourceData<br \/>\n{<br \/>\nuint32_t count;<br \/>\nShaderResource *items;<br \/>\n};<\/p>\n<p>struct SPVData<br \/>\n{<br \/>\nbool result;<br \/>\nchar *log;<br \/>\nchar *debug_log;<\/p>\n<p>uint32_t *spv_data;<br \/>\nuint32_t spv_length;<\/p>\n<p>ShaderStageData input,output;<br \/>\nShaderResourceData resource[size_t(DescriptorType::RANGE_SIZE)];<br \/>\n};<\/p>\n<p>struct GLSLCompilerInterface<br \/>\n{<br \/>\nbool (*Init)(); \/\/\/&lt;\u521d\u59cb\u5316<br \/>\nvoid (*Close)(); \/\/\/&lt;\u5173\u95ed<\/p>\n<p>uint32_t (*GetType)(const char *ext_name); \/\/\/&lt;\u6839\u636e\u6269\u5c55\u540d\u83b7\u53d6SHADER\u7c7b\u578b<br \/>\nSPVData * (*Compile)(const uint32_t type,const char *source); \/\/\/&lt;\u7f16\u8bd1glsl<\/p>\n<p>void (*Free)(SPVData *); \/\/\/&lt;\u91ca\u653e\u6570\u636e<br \/>\n};<br \/>\n}\/\/namespace glsl_shader<\/p>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ol>\n<li>\u52a0\u8f7d\u52a8\u6001\u94fe\u63a5\u5e93<\/li>\n<li>\u4ece\u52a8\u6001\u94fe\u63a5\u5e93\u83b7\u53d6GetInterface\u51fd\u6570<\/li>\n<li>\u7528GetInterface\u51fd\u6570\u5f97\u5230\u4e00\u4e2aGLSLCompilerInterface\u6307\u9488(\u4ee5\u4e0b\u7b80\u79f0GSI)<\/li>\n<li>\u8c03\u7528GSI::Init\u51fd\u6570<\/li>\n<li>\u81ea\u884c\u52a0\u8f7dglsl\u7684\u6587\u672c\uff0c\u5e76\u4fdd\u8bc1\u4e3aansi\u6216utf8\u5b57\u7b26\u96c6<\/li>\n<li>\u622a\u53d6glsl\u6587\u4ef6\u6269\u5c55\u540d(\u4e0d\u5305\u62ec.)\uff0c\u6216\u81ea\u884c\u4f20\u9012\u4e00\u4e2a\u5b57\u7b26\u4e32\u7ed9GSI::GetType\u51fd\u6570\uff0c\u4ee5\u83b7\u53d6shader\u7c7b\u578b\u3002<br \/>\nshader\u6587\u4ef6\u6269\u5c55\u540d\u89c4\u5219\u540cglslangValidator<\/p>\n<ul>\n<li>vert \u9876\u70b9<\/li>\n<li>tesc \u9576\u5d4c\u63a7\u5236<\/li>\n<li>tese \u9576\u5d4c\u8bc4\u4f30<\/li>\n<li>geom \u51e0\u4f55<\/li>\n<li>frag \u7247\u65ad<\/li>\n<li>comp \u8ba1\u7b97<\/li>\n<li>task \u4efb\u52a1<\/li>\n<li>mesh \u7f51\u683c<\/li>\n<\/ul>\n<\/li>\n<li>\u8c03\u7528GSI::Compile\u51fd\u6570\uff0c\u5e76\u540c\u65f6\u4f20\u9012shader\u7c7b\u578b\u4ee5\u53cashader\u6587\u672c\u5b57\u7b26\u4e32<\/li>\n<li>\u6839\u636e\u5f97\u5230\u7684SPVData::result\u6765\u5224\u65ad\u662f\u5426\u6210\u529f\n<ul>\n<li>result\u4e3afalse\u8868\u793a\u5931\u8d25\uff0c\u5728log\/debug_log\u4e2d\u5305\u542b\u8fd4\u56de\u7684\u9519\u8bef\u4fe1\u606f<\/li>\n<li>result\u4e3atrue\u8868\u793a\u6210\u529f\uff0c\u5728spv_data,spv_length\u4e2d\u5305\u542b\u7f16\u8bd1\u597d\u7684spv\u6570\u636e<\/li>\n<\/ul>\n<\/li>\n<li>\u81ea\u884c\u5904\u7406spv\u6570\u636e<\/li>\n<li>\u8c03\u7528GSI::Free\u91ca\u653eSPVData\u6307\u9488<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u4e8e\u4f7f\u7528SPIRV-Cross\u4ee5\u53caglslang\u7684\u6e90\u4ee3\u7801\u7248\u672c\u6709\u592a\u591a\u7684\u7f16\u8bd1\u914d\u7f6e\u9009\u9879\uff0c\u5f88\u70e6\uff0c\u6240\u4ee5\u6211\u5236\u4f5c\u4e86\u4e00\u4e2a\u52a8\u6001\u94fe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2190","post","type-post","status-publish","format-standard","hentry","category-1"],"_links":{"self":[{"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/posts\/2190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2190"}],"version-history":[{"count":3,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/posts\/2190\/revisions"}],"predecessor-version":[{"id":2193,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=\/wp\/v2\/posts\/2190\/revisions\/2193"}],"wp:attachment":[{"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2190"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.hyzgame.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}