shaderc_hlsl.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include "shaderc.h"
  6. #if SHADERC_CONFIG_HLSL
  7. #define INITGUID
  8. #include <d3dcompiler.h>
  9. #include <d3d11shader.h>
  10. #ifndef D3D_SVF_USED
  11. # define D3D_SVF_USED 2
  12. #endif // D3D_SVF_USED
  13. struct CTHeader
  14. {
  15. uint32_t Size;
  16. uint32_t Creator;
  17. uint32_t Version;
  18. uint32_t Constants;
  19. uint32_t ConstantInfo;
  20. uint32_t Flags;
  21. uint32_t Target;
  22. };
  23. struct CTInfo
  24. {
  25. uint32_t Name;
  26. uint16_t RegisterSet;
  27. uint16_t RegisterIndex;
  28. uint16_t RegisterCount;
  29. uint16_t Reserved;
  30. uint32_t TypeInfo;
  31. uint32_t DefaultValue;
  32. };
  33. struct CTType
  34. {
  35. uint16_t Class;
  36. uint16_t Type;
  37. uint16_t Rows;
  38. uint16_t Columns;
  39. uint16_t Elements;
  40. uint16_t StructMembers;
  41. uint32_t StructMemberInfo;
  42. };
  43. struct RemapInputSemantic
  44. {
  45. bgfx::Attrib::Enum m_attr;
  46. const char* m_name;
  47. uint8_t m_index;
  48. };
  49. static const RemapInputSemantic s_remapInputSemantic[bgfx::Attrib::Count+1] =
  50. {
  51. { bgfx::Attrib::Position, "POSITION", 0 },
  52. { bgfx::Attrib::Normal, "NORMAL", 0 },
  53. { bgfx::Attrib::Tangent, "TANGENT", 0 },
  54. { bgfx::Attrib::Bitangent, "BITANGENT", 0 },
  55. { bgfx::Attrib::Color0, "COLOR", 0 },
  56. { bgfx::Attrib::Color1, "COLOR", 1 },
  57. { bgfx::Attrib::Indices, "BLENDINDICES", 0 },
  58. { bgfx::Attrib::Weight, "BLENDWEIGHT", 0 },
  59. { bgfx::Attrib::TexCoord0, "TEXCOORD", 0 },
  60. { bgfx::Attrib::TexCoord1, "TEXCOORD", 1 },
  61. { bgfx::Attrib::TexCoord2, "TEXCOORD", 2 },
  62. { bgfx::Attrib::TexCoord3, "TEXCOORD", 3 },
  63. { bgfx::Attrib::TexCoord4, "TEXCOORD", 4 },
  64. { bgfx::Attrib::TexCoord5, "TEXCOORD", 5 },
  65. { bgfx::Attrib::TexCoord6, "TEXCOORD", 6 },
  66. { bgfx::Attrib::TexCoord7, "TEXCOORD", 7 },
  67. { bgfx::Attrib::Count, "", 0 },
  68. };
  69. const RemapInputSemantic& findInputSemantic(const char* _name, uint8_t _index)
  70. {
  71. for (uint32_t ii = 0; ii < bgfx::Attrib::Count; ++ii)
  72. {
  73. const RemapInputSemantic& ris = s_remapInputSemantic[ii];
  74. if (0 == strcmp(ris.m_name, _name)
  75. && ris.m_index == _index)
  76. {
  77. return ris;
  78. }
  79. }
  80. return s_remapInputSemantic[bgfx::Attrib::Count];
  81. }
  82. struct UniformRemap
  83. {
  84. UniformType::Enum id;
  85. D3D_SHADER_VARIABLE_CLASS paramClass;
  86. D3D_SHADER_VARIABLE_TYPE paramType;
  87. uint8_t columns;
  88. uint8_t rows;
  89. };
  90. static const UniformRemap s_uniformRemap[7] =
  91. {
  92. { UniformType::Int1, D3D_SVC_SCALAR, D3D_SVT_INT, 0, 0 },
  93. { UniformType::Vec4, D3D_SVC_VECTOR, D3D_SVT_FLOAT, 0, 0 },
  94. { UniformType::Mat3, D3D_SVC_MATRIX_COLUMNS, D3D_SVT_FLOAT, 3, 3 },
  95. { UniformType::Mat4, D3D_SVC_MATRIX_COLUMNS, D3D_SVT_FLOAT, 4, 4 },
  96. };
  97. UniformType::Enum findUniformType(const D3D11_SHADER_TYPE_DESC& constDesc)
  98. {
  99. for (uint32_t ii = 0; ii < BX_COUNTOF(s_uniformRemap); ++ii)
  100. {
  101. const UniformRemap& remap = s_uniformRemap[ii];
  102. if (remap.paramClass == constDesc.Class
  103. && remap.paramType == constDesc.Type)
  104. {
  105. if (D3D_SVC_MATRIX_COLUMNS != constDesc.Class)
  106. {
  107. return remap.id;
  108. }
  109. if (remap.columns == constDesc.Columns
  110. && remap.rows == constDesc.Rows)
  111. {
  112. return remap.id;
  113. }
  114. }
  115. }
  116. return UniformType::Count;
  117. }
  118. static uint32_t s_optimizationLevelDx11[4] =
  119. {
  120. D3DCOMPILE_OPTIMIZATION_LEVEL0,
  121. D3DCOMPILE_OPTIMIZATION_LEVEL1,
  122. D3DCOMPILE_OPTIMIZATION_LEVEL2,
  123. D3DCOMPILE_OPTIMIZATION_LEVEL3,
  124. };
  125. typedef std::vector<std::string> UniformNameList;
  126. bool getReflectionDataDx9(ID3DBlob* _code, UniformArray& _uniforms)
  127. {
  128. // see reference for magic values: https://msdn.microsoft.com/en-us/library/ff552891(VS.85).aspx
  129. const uint32_t D3DSIO_COMMENT = 0x0000FFFE;
  130. const uint32_t D3DSIO_END = 0x0000FFFF;
  131. const uint32_t D3DSI_OPCODE_MASK = 0x0000FFFF;
  132. const uint32_t D3DSI_COMMENTSIZE_MASK = 0x7FFF0000;
  133. const uint32_t CTAB_CONSTANT = MAKEFOURCC('C','T','A','B');
  134. // parse the shader blob for the constant table
  135. const size_t codeSize = _code->GetBufferSize();
  136. const uint32_t* ptr = (const uint32_t*)_code->GetBufferPointer();
  137. const uint32_t* end = (const uint32_t*)( (const uint8_t*)ptr + codeSize);
  138. const CTHeader* header = NULL;
  139. ptr++; // first byte is shader type / version; skip it since we already know
  140. while (ptr < end && *ptr != D3DSIO_END)
  141. {
  142. uint32_t cur = *ptr++;
  143. if ( (cur & D3DSI_OPCODE_MASK) != D3DSIO_COMMENT)
  144. {
  145. continue;
  146. }
  147. // try to find CTAB comment block
  148. uint32_t commentSize = (cur & D3DSI_COMMENTSIZE_MASK) >> 16;
  149. uint32_t fourcc = *ptr;
  150. if (fourcc == CTAB_CONSTANT)
  151. {
  152. // found the constant table data
  153. header = (const CTHeader*)(ptr + 1);
  154. uint32_t tableSize = (commentSize - 1) * 4;
  155. if (tableSize < sizeof(CTHeader) || header->Size != sizeof(CTHeader) )
  156. {
  157. fprintf(stderr, "Error: Invalid constant table data\n");
  158. return false;
  159. }
  160. break;
  161. }
  162. // this is a different kind of comment section, so skip over it
  163. ptr += commentSize - 1;
  164. }
  165. if (!header)
  166. {
  167. fprintf(stderr, "Error: Could not find constant table data\n");
  168. return false;
  169. }
  170. const uint8_t* headerBytePtr = (const uint8_t*)header;
  171. const char* creator = (const char*)(headerBytePtr + header->Creator);
  172. BX_TRACE("Creator: %s 0x%08x", creator, header->Version);
  173. BX_TRACE("Num constants: %d", header->Constants);
  174. BX_TRACE("# cl ty RxC S By Name");
  175. const CTInfo* ctInfoArray = (const CTInfo*)(headerBytePtr + header->ConstantInfo);
  176. for (uint32_t ii = 0; ii < header->Constants; ++ii)
  177. {
  178. const CTInfo& ctInfo = ctInfoArray[ii];
  179. const CTType& ctType = *(const CTType*)(headerBytePtr + ctInfo.TypeInfo);
  180. const char* name = (const char*)(headerBytePtr + ctInfo.Name);
  181. BX_TRACE("%3d %2d %2d [%dx%d] %d %s[%d] c%d (%d)"
  182. , ii
  183. , ctType.Class
  184. , ctType.Type
  185. , ctType.Rows
  186. , ctType.Columns
  187. , ctType.StructMembers
  188. , name
  189. , ctType.Elements
  190. , ctInfo.RegisterIndex
  191. , ctInfo.RegisterCount
  192. );
  193. D3D11_SHADER_TYPE_DESC desc;
  194. desc.Class = (D3D_SHADER_VARIABLE_CLASS)ctType.Class;
  195. desc.Type = (D3D_SHADER_VARIABLE_TYPE)ctType.Type;
  196. desc.Rows = ctType.Rows;
  197. desc.Columns = ctType.Columns;
  198. UniformType::Enum type = findUniformType(desc);
  199. if (UniformType::Count != type)
  200. {
  201. Uniform un;
  202. un.name = '$' == name[0] ? name + 1 : name;
  203. un.type = type;
  204. un.num = (uint8_t)ctType.Elements;
  205. un.regIndex = ctInfo.RegisterIndex;
  206. un.regCount = ctInfo.RegisterCount;
  207. _uniforms.push_back(un);
  208. }
  209. }
  210. return true;
  211. }
  212. bool getReflectionDataDx11(ID3DBlob* _code, bool _vshader, UniformArray& _uniforms, uint8_t& _numAttrs, uint16_t* _attrs, uint16_t& _size, UniformNameList& unusedUniforms)
  213. {
  214. ID3D11ShaderReflection* reflect = NULL;
  215. HRESULT hr = D3DReflect(_code->GetBufferPointer()
  216. , _code->GetBufferSize()
  217. , IID_ID3D11ShaderReflection
  218. , (void**)&reflect
  219. );
  220. if (FAILED(hr) )
  221. {
  222. fprintf(stderr, "Error: 0x%08x\n", (uint32_t)hr);
  223. return false;
  224. }
  225. D3D11_SHADER_DESC desc;
  226. hr = reflect->GetDesc(&desc);
  227. if (FAILED(hr) )
  228. {
  229. fprintf(stderr, BX_FILE_LINE_LITERAL "Error: 0x%08x\n", (uint32_t)hr);
  230. return false;
  231. }
  232. BX_TRACE("Creator: %s 0x%08x", desc.Creator, desc.Version);
  233. BX_TRACE("Num constant buffers: %d", desc.ConstantBuffers);
  234. BX_TRACE("Input:");
  235. if (_vshader) // Only care about input semantic on vertex shaders
  236. {
  237. for (uint32_t ii = 0; ii < desc.InputParameters; ++ii)
  238. {
  239. D3D11_SIGNATURE_PARAMETER_DESC spd;
  240. reflect->GetInputParameterDesc(ii, &spd);
  241. BX_TRACE("\t%2d: %s%d, vt %d, ct %d, mask %x, reg %d"
  242. , ii
  243. , spd.SemanticName
  244. , spd.SemanticIndex
  245. , spd.SystemValueType
  246. , spd.ComponentType
  247. , spd.Mask
  248. , spd.Register
  249. );
  250. const RemapInputSemantic& ris = findInputSemantic(spd.SemanticName, spd.SemanticIndex);
  251. if (ris.m_attr != bgfx::Attrib::Count)
  252. {
  253. _attrs[_numAttrs] = bgfx::attribToId(ris.m_attr);
  254. ++_numAttrs;
  255. }
  256. }
  257. }
  258. BX_TRACE("Output:");
  259. for (uint32_t ii = 0; ii < desc.OutputParameters; ++ii)
  260. {
  261. D3D11_SIGNATURE_PARAMETER_DESC spd;
  262. reflect->GetOutputParameterDesc(ii, &spd);
  263. BX_TRACE("\t%2d: %s%d, %d, %d", ii, spd.SemanticName, spd.SemanticIndex, spd.SystemValueType, spd.ComponentType);
  264. }
  265. for (uint32_t ii = 0, num = bx::uint32_min(1, desc.ConstantBuffers); ii < num; ++ii)
  266. {
  267. ID3D11ShaderReflectionConstantBuffer* cbuffer = reflect->GetConstantBufferByIndex(ii);
  268. D3D11_SHADER_BUFFER_DESC bufferDesc;
  269. hr = cbuffer->GetDesc(&bufferDesc);
  270. _size = (uint16_t)bufferDesc.Size;
  271. if (SUCCEEDED(hr) )
  272. {
  273. BX_TRACE("%s, %d, vars %d, size %d"
  274. , bufferDesc.Name
  275. , bufferDesc.Type
  276. , bufferDesc.Variables
  277. , bufferDesc.Size
  278. );
  279. for (uint32_t jj = 0; jj < bufferDesc.Variables; ++jj)
  280. {
  281. ID3D11ShaderReflectionVariable* var = cbuffer->GetVariableByIndex(jj);
  282. ID3D11ShaderReflectionType* type = var->GetType();
  283. D3D11_SHADER_VARIABLE_DESC varDesc;
  284. hr = var->GetDesc(&varDesc);
  285. if (SUCCEEDED(hr) )
  286. {
  287. D3D11_SHADER_TYPE_DESC constDesc;
  288. hr = type->GetDesc(&constDesc);
  289. if (SUCCEEDED(hr) )
  290. {
  291. UniformType::Enum uniformType = findUniformType(constDesc);
  292. if (UniformType::Count != uniformType
  293. && 0 != (varDesc.uFlags & D3D_SVF_USED) )
  294. {
  295. Uniform un;
  296. un.name = varDesc.Name;
  297. un.type = uniformType;
  298. un.num = constDesc.Elements;
  299. un.regIndex = varDesc.StartOffset;
  300. un.regCount = BX_ALIGN_16(varDesc.Size) / 16;
  301. _uniforms.push_back(un);
  302. BX_TRACE("\t%s, %d, size %d, flags 0x%08x, %d (used)"
  303. , varDesc.Name
  304. , varDesc.StartOffset
  305. , varDesc.Size
  306. , varDesc.uFlags
  307. , uniformType
  308. );
  309. }
  310. else
  311. {
  312. if (0 == (varDesc.uFlags & D3D_SVF_USED) )
  313. {
  314. unusedUniforms.push_back(varDesc.Name);
  315. }
  316. BX_TRACE("\t%s, unknown type", varDesc.Name);
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. BX_TRACE("Bound:");
  324. for (uint32_t ii = 0; ii < desc.BoundResources; ++ii)
  325. {
  326. D3D11_SHADER_INPUT_BIND_DESC bindDesc;
  327. hr = reflect->GetResourceBindingDesc(ii, &bindDesc);
  328. if (SUCCEEDED(hr) )
  329. {
  330. // if (bindDesc.Type == D3D_SIT_SAMPLER)
  331. {
  332. BX_TRACE("\t%s, %d, %d, %d"
  333. , bindDesc.Name
  334. , bindDesc.Type
  335. , bindDesc.BindPoint
  336. , bindDesc.BindCount
  337. );
  338. }
  339. }
  340. }
  341. if (NULL != reflect)
  342. {
  343. reflect->Release();
  344. }
  345. return true;
  346. }
  347. bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::string& _code, bx::WriterI* _writer, bool _firstPass)
  348. {
  349. BX_TRACE("DX11");
  350. const char* profile = _cmdLine.findOption('p', "profile");
  351. if (NULL == profile)
  352. {
  353. fprintf(stderr, "Shader profile must be specified.\n");
  354. return false;
  355. }
  356. bool debug = _cmdLine.hasArg('\0', "debug");
  357. uint32_t flags = D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY;
  358. flags |= debug ? D3DCOMPILE_DEBUG : 0;
  359. flags |= _cmdLine.hasArg('\0', "avoid-flow-control") ? D3DCOMPILE_AVOID_FLOW_CONTROL : 0;
  360. flags |= _cmdLine.hasArg('\0', "no-preshader") ? D3DCOMPILE_NO_PRESHADER : 0;
  361. flags |= _cmdLine.hasArg('\0', "partial-precision") ? D3DCOMPILE_PARTIAL_PRECISION : 0;
  362. flags |= _cmdLine.hasArg('\0', "prefer-flow-control") ? D3DCOMPILE_PREFER_FLOW_CONTROL : 0;
  363. flags |= _cmdLine.hasArg('\0', "backwards-compatibility") ? D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY : 0;
  364. bool werror = _cmdLine.hasArg('\0', "Werror");
  365. if (werror)
  366. {
  367. flags |= D3DCOMPILE_WARNINGS_ARE_ERRORS;
  368. }
  369. uint32_t optimization = 3;
  370. if (_cmdLine.hasArg(optimization, 'O') )
  371. {
  372. optimization = bx::uint32_min(optimization, BX_COUNTOF(s_optimizationLevelDx11)-1);
  373. flags |= s_optimizationLevelDx11[optimization];
  374. }
  375. else
  376. {
  377. flags |= D3DCOMPILE_SKIP_OPTIMIZATION;
  378. }
  379. BX_TRACE("Profile: %s", profile);
  380. BX_TRACE("Flags: 0x%08x", flags);
  381. ID3DBlob* code;
  382. ID3DBlob* errorMsg;
  383. // Output preprocessed shader so that HLSL can be debugged via GPA
  384. // or PIX. Compiling through memory won't embed preprocessed shader
  385. // file path.
  386. std::string hlslfp;
  387. if (debug)
  388. {
  389. hlslfp = _cmdLine.findOption('o');
  390. hlslfp += ".hlsl";
  391. writeFile(hlslfp.c_str(), _code.c_str(), (int32_t)_code.size() );
  392. }
  393. HRESULT hr = D3DCompile(_code.c_str()
  394. , _code.size()
  395. , hlslfp.c_str()
  396. , NULL
  397. , NULL
  398. , "main"
  399. , profile
  400. , flags
  401. , 0
  402. , &code
  403. , &errorMsg
  404. );
  405. if (FAILED(hr)
  406. || (werror && NULL != errorMsg) )
  407. {
  408. const char* log = (char*)errorMsg->GetBufferPointer();
  409. int32_t line = 0;
  410. int32_t column = 0;
  411. int32_t start = 0;
  412. int32_t end = INT32_MAX;
  413. if (2 == sscanf(log, "(%u,%u):", &line, &column)
  414. && 0 != line)
  415. {
  416. start = bx::uint32_imax(1, line-10);
  417. end = start + 20;
  418. }
  419. printCode(_code.c_str(), line, start, end);
  420. fprintf(stderr, "Error: 0x%08x %s\n", (uint32_t)hr, log);
  421. errorMsg->Release();
  422. return false;
  423. }
  424. UniformArray uniforms;
  425. uint8_t numAttrs = 0;
  426. uint16_t attrs[bgfx::Attrib::Count];
  427. uint16_t size = 0;
  428. if (_d3d == 9)
  429. {
  430. if (!getReflectionDataDx9(code, uniforms) )
  431. {
  432. return false;
  433. }
  434. }
  435. else
  436. {
  437. UniformNameList unusedUniforms;
  438. if (!getReflectionDataDx11(code, profile[0] == 'v', uniforms, numAttrs, attrs, size, unusedUniforms) )
  439. {
  440. return false;
  441. }
  442. if (_firstPass
  443. && unusedUniforms.size() > 0)
  444. {
  445. const size_t strLength = strlen("uniform");
  446. // first time through, we just find unused uniforms and get rid of them
  447. std::string output;
  448. LineReader reader(_code.c_str() );
  449. while (!reader.isEof() )
  450. {
  451. std::string line = reader.getLine();
  452. for (UniformNameList::iterator it = unusedUniforms.begin(), itEnd = unusedUniforms.end(); it != itEnd; ++it)
  453. {
  454. size_t index = line.find("uniform ");
  455. if (index == std::string::npos)
  456. {
  457. continue;
  458. }
  459. // matching lines like: uniform u_name;
  460. // we want to replace "uniform" with "static" so that it's no longer
  461. // included in the uniform blob that the application must upload
  462. // we can't just remove them, because unused functions might still reference
  463. // them and cause a compile error when they're gone
  464. if (!!bx::findIdentifierMatch(line.c_str(), it->c_str() ) )
  465. {
  466. line = line.replace(index, strLength, "static");
  467. unusedUniforms.erase(it);
  468. break;
  469. }
  470. }
  471. output += line;
  472. }
  473. // recompile with the unused uniforms converted to statics
  474. return compileHLSLShader(_cmdLine, _d3d, output.c_str(), _writer, false);
  475. }
  476. }
  477. uint16_t count = (uint16_t)uniforms.size();
  478. bx::write(_writer, count);
  479. uint32_t fragmentBit = profile[0] == 'p' ? BGFX_UNIFORM_FRAGMENTBIT : 0;
  480. for (UniformArray::const_iterator it = uniforms.begin(); it != uniforms.end(); ++it)
  481. {
  482. const Uniform& un = *it;
  483. uint8_t nameSize = (uint8_t)un.name.size();
  484. bx::write(_writer, nameSize);
  485. bx::write(_writer, un.name.c_str(), nameSize);
  486. uint8_t type = un.type|fragmentBit;
  487. bx::write(_writer, type);
  488. bx::write(_writer, un.num);
  489. bx::write(_writer, un.regIndex);
  490. bx::write(_writer, un.regCount);
  491. BX_TRACE("%s, %s, %d, %d, %d"
  492. , un.name.c_str()
  493. , getUniformTypeName(un.type)
  494. , un.num
  495. , un.regIndex
  496. , un.regCount
  497. );
  498. }
  499. {
  500. ID3DBlob* stripped;
  501. hr = D3DStripShader(code->GetBufferPointer()
  502. , code->GetBufferSize()
  503. , D3DCOMPILER_STRIP_REFLECTION_DATA
  504. | D3DCOMPILER_STRIP_TEST_BLOBS
  505. , &stripped
  506. );
  507. if (SUCCEEDED(hr) )
  508. {
  509. code->Release();
  510. code = stripped;
  511. }
  512. }
  513. uint16_t shaderSize = (uint16_t)code->GetBufferSize();
  514. bx::write(_writer, shaderSize);
  515. bx::write(_writer, code->GetBufferPointer(), shaderSize);
  516. uint8_t nul = 0;
  517. bx::write(_writer, nul);
  518. if (_d3d > 9)
  519. {
  520. bx::write(_writer, numAttrs);
  521. bx::write(_writer, attrs, numAttrs*sizeof(uint16_t) );
  522. bx::write(_writer, size);
  523. }
  524. if (_cmdLine.hasArg('\0', "disasm") )
  525. {
  526. ID3DBlob* disasm;
  527. D3DDisassemble(code->GetBufferPointer()
  528. , code->GetBufferSize()
  529. , 0
  530. , NULL
  531. , &disasm
  532. );
  533. if (NULL != disasm)
  534. {
  535. std::string disasmfp = _cmdLine.findOption('o');
  536. disasmfp += ".disasm";
  537. writeFile(disasmfp.c_str(), disasm->GetBufferPointer(), (uint32_t)disasm->GetBufferSize() );
  538. disasm->Release();
  539. }
  540. }
  541. if (NULL != errorMsg)
  542. {
  543. errorMsg->Release();
  544. }
  545. code->Release();
  546. return true;
  547. }
  548. #else
  549. bool compileHLSLShader(bx::CommandLine& _cmdLine, uint32_t _d3d, const std::string& _code, bx::WriterI* _writer, bool _firstPass)
  550. {
  551. BX_UNUSED(_cmdLine, _d3d, _code, _writer, _firstPass);
  552. fprintf(stderr, "HLSL compiler is not supported on this platform.\n");
  553. return false;
  554. }
  555. #endif // SHADERC_CONFIG_HLSL