From cea3815dffa76794b91cb5fe1a1eeffb99d71456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 13 Apr 2015 12:54:45 -0700 Subject: [PATCH] Fixed HLSL shader stripping. --- 3rdparty/ocornut-imgui/imgui.cpp | 1 + examples/common/imgui/vs_ocornut_imgui.bin.h | 70 ++++++++++-------- examples/runtime/shaders/dx11/fs_tree.bin | Bin 1164 -> 1349 bytes examples/runtime/shaders/dx11/vs_hdr_blur.bin | Bin 742 -> 1080 bytes .../runtime/shaders/dx11/vs_hdr_tonemap.bin | Bin 742 -> 1028 bytes .../shaders/dx11/vs_shadowmaps_hblur.bin | Bin 742 -> 1149 bytes .../shaders/dx11/vs_shadowmaps_vblur.bin | Bin 742 -> 1149 bytes scripts/shaderc.lua | 5 ++ tools/shaderc/shaderc_hlsl.cpp | 21 ++++-- 9 files changed, 62 insertions(+), 35 deletions(-) diff --git a/3rdparty/ocornut-imgui/imgui.cpp b/3rdparty/ocornut-imgui/imgui.cpp index bc946094..6db74348 100644 --- a/3rdparty/ocornut-imgui/imgui.cpp +++ b/3rdparty/ocornut-imgui/imgui.cpp @@ -338,6 +338,7 @@ #include // new (ptr) #ifdef _MSC_VER +#pragma warning (disable: 4100) // unreferenced formal parameter #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #endif diff --git a/examples/common/imgui/vs_ocornut_imgui.bin.h b/examples/common/imgui/vs_ocornut_imgui.bin.h index be479206..5473ca3a 100644 --- a/examples/common/imgui/vs_ocornut_imgui.bin.h +++ b/examples/common/imgui/vs_ocornut_imgui.bin.h @@ -60,35 +60,45 @@ static const uint8_t vs_ocornut_imgui_dx9[367] = 0xb4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0xe4, 0x90, 0x01, 0x00, // ................ 0x00, 0x02, 0x02, 0x00, 0x03, 0xe0, 0x02, 0x00, 0xe4, 0x90, 0xff, 0xff, 0x00, 0x00, 0x00, // ............... }; -static const uint8_t vs_ocornut_imgui_dx11[450] = +static const uint8_t vs_ocornut_imgui_dx11[612] = { - 0x56, 0x53, 0x48, 0x03, 0x01, 0x83, 0xf2, 0xe1, 0x00, 0x00, 0xac, 0x01, 0x44, 0x58, 0x42, 0x43, // VSH.........DXBC - 0x7a, 0x4e, 0x9b, 0x63, 0x05, 0x18, 0x79, 0x85, 0xb1, 0xe7, 0x0b, 0x3c, 0x75, 0x62, 0x38, 0x17, // zN.c..y............... - 0x00, 0x00, // .. + 0x56, 0x53, 0x48, 0x03, 0x01, 0x83, 0xf2, 0xe1, 0x01, 0x00, 0x0b, 0x75, 0x5f, 0x76, 0x69, 0x65, // VSH........u_vie + 0x77, 0x54, 0x65, 0x78, 0x65, 0x6c, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3c, 0x02, 0x44, 0x58, // wTexel......<.DX + 0x42, 0x43, 0x22, 0x5c, 0xcc, 0x36, 0x58, 0xb2, 0x23, 0x45, 0x8a, 0x2b, 0xbd, 0x13, 0xac, 0xf2, // BC"..6X.#E.+.... + 0xa4, 0x09, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, // ......<.......,. + 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x68, 0x00, // ..........ISGNh. + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, // ..........P..... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, // ................ + 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, // ..V............. + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x03, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, // .........._..... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x03, // ................ + 0x00, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, // ..COLOR.POSITION + 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0x4f, 0x53, 0x47, 0x4e, 0x6c, 0x00, // .TEXCOORD.OSGNl. + 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, // ..........P..... + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, // ................ + 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, // ................ + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, // ..........b..... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x0c, // ................ + 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x43, 0x4f, // ..SV_POSITION.CO + 0x4c, 0x4f, 0x52, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0xab, 0x53, 0x48, // LOR.TEXCOORD..SH + 0x44, 0x52, 0x24, 0x01, 0x00, 0x00, 0x40, 0x00, 0x01, 0x00, 0x49, 0x00, 0x00, 0x00, 0x59, 0x00, // DR$...@...I...Y. + 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x5f, 0x00, // ..F. ........._. + 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0x32, 0x10, // .........._...2. + 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x02, 0x00, // ......_...2..... + 0x00, 0x00, 0x67, 0x00, 0x00, 0x04, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, // ..g.... ........ + 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, // ..e.... ......e. + 0x00, 0x03, 0x32, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, // ..2 ......h..... + 0x00, 0x00, 0x36, 0x00, 0x00, 0x08, 0xc2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, // ..6.... .......@ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x80, 0x3f, 0x38, 0x00, 0x00, 0x08, 0x32, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, // .?8...2.......F. + 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......F. ....... + 0x00, 0x00, 0x32, 0x00, 0x00, 0x09, 0x12, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, // ..2.... ........ + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0x40, // .......@.....@.@ + 0x00, 0x00, 0x00, 0x00, 0x80, 0xbf, 0x32, 0x00, 0x00, 0x0a, 0x22, 0x20, 0x10, 0x00, 0x00, 0x00, // ......2..." .... + 0x00, 0x00, 0x1a, 0x00, 0x10, 0x80, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, // ......A........@ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x36, 0x00, // .....@.@.....?6. + 0x00, 0x05, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, 0x00, 0x00, // ... ......F..... + 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x32, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x10, // ..6...2 ......F. + 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x03, 0x05, 0x00, 0x01, 0x00, // ......>......... + 0x10, 0x00, 0x10, 0x00, // .... }; diff --git a/examples/runtime/shaders/dx11/fs_tree.bin b/examples/runtime/shaders/dx11/fs_tree.bin index c60d3fd9d2723d19b9d7e5be98ffc36b204ed7aa..e3545cabcc2b467df6e1e4acf7198a6cf417344a 100644 GIT binary patch literal 1349 zcmZ8g&ubG=5T0y)Y_eLrlt8s0EJYBCAm&g+q}kYH+kj>zNlWUbS_xQC2r<>0Y&~l5 zB6#Y-d;bG3if0A?1`kEAJ$Tjc+xI4k9hiOdzWLraGjDgJ&Sv)av(>kbcn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w`guYJHB|iId^k^yM282G~L(V^%6nFTT}#pG6b)~M?esVm~$>8ubB>czWa>fT`^;vn>;aRQOx-iw*s$VUFPB*;!O!P zz25NDSs2fVv};^>_KTVM^4($0UwQ0*nlhRu4^&)t&|1~yjKlZ@x>Mfl4LUJkc1sy9 zRZrK)5cp#8{ogqsVd|DloU?NW%-lg;&iPX>Vh5$R_TzrkH@QKOkDqzkhk0N6bY;YR z9Bq{UVpas1MR^B=0BBzT delta 240 zcmdnN@r>0bEZBqj_T%4g7#a9W<8$*8HpRqY+sRuA?uGB5yTHu@Y5S?5;P1FRz#wxW~ND2`P$(Jz!@j@3WTJ!`+tlMz`X+t*VShE;R3PoO<4E#er#H#=$g5Xdml#ll(;@11AXU4{ z1DW0)WKMFqU{72Crq4apjq`@*-sc(iig`xg$&orm$3e7v!-WK9p~RJSWR08Dy4VOUe%??6}$qyQ_bF++|b^Q9yuTLX4O|> zkRO!5X*k6Ifg=6PqcZ(Q0H`%*wbJ(9(3+tZ&!L5<38xsW=%1`p4(X^iee&MwQ|FOe xu=B{VS2^vaFTR7tP#rmbueA`zUaiw!a$2Vxy|6Cqg&gaYTj$@!iAYYG@&`fhWOo1n delta 240 zcmZqSc*bfI7VN=%`||dzf4zoScJFJu?3s zSpMGQs`id*s|WiS85n>v8~v0RC2N3e2L?ulc%V=u0|Sd&p8}A@z`!xNlQEl-aq?G2 zc}CXBwoKxTER%Ja)EU_(hcfAxume??F)*+iDF^`dGBCIaKxmNIC!iP;NK6D(j2Vj< V3l=d}Br!V%pz%zM3<3-d3;?xKE6@M{ diff --git a/examples/runtime/shaders/dx11/vs_shadowmaps_hblur.bin b/examples/runtime/shaders/dx11/vs_shadowmaps_hblur.bin index 6a61e06b403840842c75ac17d44b74779316fe53..587e1c5ea52bef6d27f7ab99ef99ae706cc9ba19 100644 GIT binary patch literal 1149 zcmZuwziU%b6h8UU{H_gwE=4e75pl>MPV$<@v;pZ0ec@53XTV2WNo+}p3OYO-TngO^ zor}0+aqdzOoE-cE1eZc-L6@#Be&4(IBpu#?ll$H8e)pX3yi0s$HAN3 z@NF-A7Y_0wl9GjSFx-0?4t&tv(cY_~R3$65ad0s7`osOf?(6Mtf7BlyBRf$6MQY2AoC~$RRbTW#r*w#lZNN zJnLlux~|vhb=(c6P$-OZLvCN64z#d!|NnkPs`e8)gp!1~!@F4LM7!&A#3Pj9Lx zW{_tpPt4$oF{eB+gZvzlde0A%Y)`!P*5(x&IBt+u_nI(eezyOs#BjSCzd<6{1xfX>f*x$O{IZ;^pmrF z(+;H$exn$1$9JFxz2~Wqxm&%{4w>XTob#i-1HaSRo0eO$wW;Hq@qIp(O%HP4>>a;2 V0bEZBqj_T%4g7#a9W<8$*8HpRqY+sRuA?uGB5yTHl`~vO4b0`4h)P8@j#(S1_lsq4 z@{FvL^_avNSth$NsWY-o&STPNWS=~bNj%1kfr0gtf&c>(P`#Uo0MHZ$2ACK#7BLnq UVysAFb__rxm>3xZ7$z_P0B=?+_5c6? diff --git a/examples/runtime/shaders/dx11/vs_shadowmaps_vblur.bin b/examples/runtime/shaders/dx11/vs_shadowmaps_vblur.bin index 6a61e06b403840842c75ac17d44b74779316fe53..0bef94602dde18dc901e1a7b1a8355203539627e 100644 GIT binary patch literal 1149 zcmZuwO-mb56utQ{9~w0Xr6sFSp>-i$WFbXFMopuE;)F~Hb~O!j@PnjEB(}Q_{(#bj z3x7aylT9hEy6oR@DU>d{62V0`o-^;=(ZyVNd1uZ$_ug~gBVBJRb9MdyUq+@z{>gsu zsS|t-`gsva$?V7<9DWG;UC^!J;XzT#l9joUe?0JdgQNcb$K6(M*c%+@r3Lvyw!X8z zu`>VV^5pF4%Wu!xuYP84?@}nWkQK>bU&IQrUW06Uo7-=J(^v&^SQ^wa^6;@{VDw9# z^)di0*K2l~?zVK^>}NP*Y%TZkG-vW`!5zrwkTX>t^i!t~dX-9& zmi^jR%b7Tva`dkp?x{Fu?+G3fYw`~0lX;U;j(w(_NbWrHSEN6yiw+Ysr5gItPtNvD zJCr*34I{)az8N*>Jxx6W`nY%6A(NcLIZtg4{Km7dEBEL=_-1^c7xo>Q``hMR0bEZBqj_T%4g7#a9W<8$*8HpRqY+sRuA?uGB5yTHl`~vO4b0`4h)P8@j#(S1_lsq4 z@{FvL^_avNSth$NsWY-o&STPNWS=~bNj%1kfr0gtf&c>(P`#Uo0MHZ$2ACK#7BLnq UVysAFb__rxm>3xZ7$z_P0B=?+_5c6? diff --git a/scripts/shaderc.lua b/scripts/shaderc.lua index 37589b09..a52f74bb 100644 --- a/scripts/shaderc.lua +++ b/scripts/shaderc.lua @@ -14,6 +14,11 @@ project "shaderc" path.join(GLSL_OPTIMIZER, "src"), } + removeflags { + -- GCC 4.9 -O2 + -fno-strict-aliasing don't work together... + "OptimizeSpeed", + } + configuration { "vs*" } includedirs { path.join(GLSL_OPTIMIZER, "src/glsl/msvc"), diff --git a/tools/shaderc/shaderc_hlsl.cpp b/tools/shaderc/shaderc_hlsl.cpp index efeb24dc..8c19a1a6 100644 --- a/tools/shaderc/shaderc_hlsl.cpp +++ b/tools/shaderc/shaderc_hlsl.cpp @@ -14,6 +14,12 @@ # define D3D_SVF_USED 2 #endif // D3D_SVF_USED +#ifndef IID_ID3D11ShaderReflection +// In case MinGW is missing IID... +static const GUID GUID_ID3D11ShaderReflection = { 0x0a233719, 0x3960, 0x4578, { 0x9d, 0x7c, 0x20, 0x3b, 0x8b, 0x1d, 0x9c, 0xc1 } }; +# define IID_ID3D11ShaderReflection GUID_ID3D11ShaderReflection +#endif // IID_ID3D11ShaderReflection + struct CTHeader { uint32_t Size; @@ -345,7 +351,7 @@ bool getReflectionDataDx11(ID3DBlob* _code, bool _vshader, UniformArray& _unifor un.regCount = BX_ALIGN_16(varDesc.Size) / 16; _uniforms.push_back(un); - BX_TRACE("\t%s, %d, size %d, flags 0x%08x, %d" + BX_TRACE("\t%s, %d, size %d, flags 0x%08x, %d (used)" , varDesc.Name , varDesc.StartOffset , varDesc.Size @@ -355,8 +361,10 @@ bool getReflectionDataDx11(ID3DBlob* _code, bool _vshader, UniformArray& _unifor } else { - if (0 == (varDesc.uFlags & D3D_SVF_USED)) + if (0 == (varDesc.uFlags & D3D_SVF_USED) ) + { unusedUniforms.push_back(varDesc.Name); + } BX_TRACE("\t%s, unknown type", varDesc.Name); } @@ -517,18 +525,21 @@ bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::stri while (!reader.isEof() ) { std::string line = reader.getLine(); - for (UniformNameList::const_iterator it = unusedUniforms.begin(); it != unusedUniforms.end(); ++it) + for (UniformNameList::const_iterator it = unusedUniforms.begin(), itEnd = unusedUniforms.end(); it != itEnd; ++it) { size_t index = line.find("uniform "); if (index == std::string::npos) + { continue; + } // matching lines like: uniform u_name; // we want to replace "uniform" with "static" so that it's no longer - // included in the uniform blob that the application must upload + // included in the uniform blob that the application must upload x // we can't just remove them, because unused functions might still reference // them and cause a compile error when they're gone - if (line.find(*it) != std::string::npos) + ; + if (!!bx::findIdentifierMatch(line.c_str(), it->c_str() ) ) { line = line.replace(index, strLength, "static"); unusedUniforms.erase(it);