ShaderCompiler.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Context.h"
  24. #include "File.h"
  25. #include "FileSystem.h"
  26. #include "List.h"
  27. #include "Mutex.h"
  28. #include "ProcessUtils.h"
  29. #include "StringUtils.h"
  30. #include "Thread.h"
  31. #include "XMLFile.h"
  32. #include <cstdio>
  33. #include <cstring>
  34. #include <Windows.h>
  35. #include <d3d9.h>
  36. #include <D3DX9Shader.h>
  37. #include "DebugNew.h"
  38. enum ShaderType
  39. {
  40. VS = 0,
  41. PS,
  42. Both
  43. };
  44. struct Parameter
  45. {
  46. Parameter()
  47. {
  48. }
  49. Parameter(const String& name, unsigned index) :
  50. name_(name),
  51. index_(index)
  52. {
  53. }
  54. bool operator < (const Parameter& rhs) const
  55. {
  56. if (index_ != rhs.index_)
  57. return index_ < rhs.index_;
  58. else
  59. return name_ < rhs.name_;
  60. }
  61. bool operator > (const Parameter& rhs) const
  62. {
  63. if (index_ != rhs.index_)
  64. return index_ > rhs.index_;
  65. else
  66. return name_ > rhs.name_;
  67. }
  68. bool operator == (const Parameter& rhs) const
  69. {
  70. return (index_ == rhs.index_) && (name_ == rhs.name_);
  71. }
  72. bool operator != (const Parameter& rhs) const
  73. {
  74. return (index_ != rhs.index_) || (name_ != rhs.name_);
  75. }
  76. String name_;
  77. unsigned index_;
  78. };
  79. struct Variation
  80. {
  81. Variation()
  82. {
  83. }
  84. Variation(const String& name, bool isOption) :
  85. name_(name),
  86. option_(isOption)
  87. {
  88. }
  89. String name_;
  90. Vector<String> defines_;
  91. Vector<String> excludes_;
  92. Vector<String> includes_;
  93. Vector<String> requires_;
  94. bool option_;
  95. };
  96. struct CompiledVariation
  97. {
  98. ShaderType type_;
  99. String name_;
  100. Vector<String> defines_;
  101. PODVector<unsigned char> byteCode_;
  102. unsigned byteCodeOffset_;
  103. Set<Parameter> constants_;
  104. Set<Parameter> textureUnits_;
  105. String errorMsg_;
  106. };
  107. struct Shader
  108. {
  109. Shader(const String& name, ShaderType type) :
  110. name_(name),
  111. type_(type)
  112. {
  113. }
  114. String name_;
  115. ShaderType type_;
  116. Vector<Variation> variations_;
  117. };
  118. SharedPtr<Context> context_(new Context());
  119. SharedPtr<FileSystem> fileSystem_(new FileSystem(context_));
  120. String inDir_;
  121. String inFile_;
  122. String outDir_;
  123. Set<Parameter> constants_;
  124. Set<Parameter> textureUnits_;
  125. Vector<String> defines_;
  126. bool useSM3_ = false;
  127. volatile bool compileFailed_ = false;
  128. List<CompiledVariation*> workList_;
  129. Mutex workMutex_;
  130. Mutex globalParamMutex_;
  131. String hlslCode_;
  132. int main(int argc, char** argv);
  133. void Run(const Vector<String>& arguments);
  134. void CompileVariations(const Shader& baseShader, XMLElement& shaders);
  135. void Compile(CompiledVariation* variation);
  136. class WorkerThread : public RefCounted, public Thread
  137. {
  138. public:
  139. void ThreadFunction()
  140. {
  141. for (;;)
  142. {
  143. CompiledVariation* workItem = 0;
  144. {
  145. MutexLock lock(workMutex_);
  146. if (!workList_.Empty())
  147. {
  148. workItem = workList_.Front();
  149. workList_.Erase(workList_.Begin());
  150. if (!workItem->name_.Empty())
  151. PrintLine("Compiling shader variation " + workItem->name_);
  152. else
  153. PrintLine("Compiling base shader variation");
  154. }
  155. }
  156. if (!workItem)
  157. return;
  158. // If compile(s) failed, just empty the list, but do not compile more
  159. if (!compileFailed_)
  160. Compile(workItem);
  161. }
  162. }
  163. };
  164. class IncludeHandler : public ID3DXInclude
  165. {
  166. public:
  167. STDMETHOD(Open)(D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes)
  168. {
  169. String fileName = inDir_ + String((const char*)pFileName);
  170. File file(context_, fileName);
  171. if (!file.IsOpen())
  172. return E_FAIL;
  173. unsigned fileSize = file.GetSize();
  174. void* fileData = new unsigned char[fileSize];
  175. *pBytes = fileSize;
  176. *ppData = fileData;
  177. file.Read(fileData, fileSize);
  178. return S_OK;
  179. }
  180. STDMETHOD(Close)(LPCVOID pData)
  181. {
  182. delete[] (unsigned char*)pData;
  183. return S_OK;
  184. }
  185. };
  186. int main(int argc, char** argv)
  187. {
  188. Vector<String> arguments;
  189. for (int i = 1; i < argc; ++i)
  190. {
  191. String argument(argv[i]);
  192. arguments.Push(GetInternalPath(argument));
  193. }
  194. Run(arguments);
  195. return 0;
  196. }
  197. void Run(const Vector<String>& arguments)
  198. {
  199. if (arguments.Size() < 2)
  200. {
  201. ErrorExit(
  202. "Usage: ShaderCompiler <definitionfile> <outputpath> [SM3] [define1] [define2]\n\n"
  203. "HLSL files will be loaded from definition file directory, and binary files will\n"
  204. "be output to the output path, preserving the subdirectory structure.\n"
  205. );
  206. }
  207. unsigned pos = arguments[0].FindLast('/');
  208. if (pos != String::NPOS)
  209. {
  210. inDir_ = arguments[0].Substring(0, pos);
  211. inFile_ = arguments[0].Substring(pos + 1);
  212. }
  213. else
  214. {
  215. inFile_ = arguments[0];
  216. }
  217. outDir_ = arguments[1];
  218. inDir_ = AddTrailingSlash(inDir_);
  219. outDir_ = AddTrailingSlash(outDir_);
  220. for (unsigned i = 2; i < arguments.Size(); ++i)
  221. {
  222. String arg = arguments[i].ToUpper();
  223. if (arg == "SM3")
  224. useSM3_ = true;
  225. else if (arg == "SM2")
  226. useSM3_ = false;
  227. defines_.Push(arg);
  228. }
  229. XMLFile doc(context_);
  230. File source(context_);
  231. source.Open(arguments[0]);
  232. if (!doc.Load(source))
  233. ErrorExit("Could not open input file " + arguments[0]);
  234. XMLElement shaders = doc.GetRootElement("shaders");
  235. if (!shaders)
  236. ErrorExit("No shaders element in " + source.GetName());
  237. XMLFile outDoc(context_);
  238. XMLElement outShaders = outDoc.CreateRootElement("shaders");
  239. XMLElement shader = shaders.GetChildElement("shader");
  240. while (shader)
  241. {
  242. constants_.Clear();
  243. textureUnits_.Clear();
  244. String source = shader.GetString("name");
  245. ShaderType compileType = Both;
  246. String type = shader.GetString("type");
  247. if ((type == "VS") || (type == "vs"))
  248. compileType = VS;
  249. if ((type == "PS") || (type == "ps"))
  250. compileType = PS;
  251. Shader baseShader(source, compileType);
  252. XMLElement variation = shader.GetChildElement("");
  253. while (variation)
  254. {
  255. String value = variation.GetName();
  256. if ((value == "variation") || (value == "option"))
  257. {
  258. String name = variation.GetString("name");
  259. Variation newVar(name, value == "option");
  260. String simpleDefine = variation.GetString("define");
  261. if (!simpleDefine.Empty())
  262. newVar.defines_.Push(simpleDefine);
  263. String simpleExclude = variation.GetString("exclude");
  264. if (!simpleExclude.Empty())
  265. newVar.excludes_.Push(simpleExclude);
  266. String simpleInclude = variation.GetString("include");
  267. if (!simpleInclude.Empty())
  268. newVar.includes_.Push(simpleInclude);
  269. String simpleRequire = variation.GetString("require");
  270. if (!simpleRequire.Empty())
  271. newVar.requires_.Push(simpleRequire);
  272. XMLElement define = variation.GetChildElement("define");
  273. while (define)
  274. {
  275. newVar.defines_.Push(define.GetString("name"));
  276. define = define.GetNextElement("define");
  277. }
  278. XMLElement exclude = variation.GetChildElement("exclude");
  279. while (exclude)
  280. {
  281. newVar.excludes_.Push(exclude.GetString("name"));
  282. exclude = exclude.GetNextElement("exclude");
  283. }
  284. XMLElement include = variation.GetChildElement("include");
  285. while (include)
  286. {
  287. newVar.includes_.Push(include.GetString("name"));
  288. include = include.GetNextElement("include");
  289. }
  290. XMLElement require = variation.GetChildElement("require");
  291. while (require)
  292. {
  293. newVar.requires_.Push(require.GetString("name"));
  294. require = require.GetNextElement("require");
  295. }
  296. baseShader.variations_.Push(newVar);
  297. }
  298. variation = variation.GetNextElement();
  299. }
  300. if (baseShader.type_ != Both)
  301. CompileVariations(baseShader, outShaders);
  302. else
  303. {
  304. baseShader.type_ = VS;
  305. CompileVariations(baseShader, outShaders);
  306. baseShader.type_ = PS;
  307. CompileVariations(baseShader, outShaders);
  308. }
  309. shader = shader.GetNextElement("shader");
  310. }
  311. }
  312. void CompileVariations(const Shader& baseShader, XMLElement& shaders)
  313. {
  314. unsigned combinations = 1;
  315. PODVector<unsigned> usedCombinations;
  316. Map<String, unsigned> nameToIndex;
  317. Vector<CompiledVariation> compiledVariations;
  318. bool hasVariations = false;
  319. const Vector<Variation>& variations = baseShader.variations_;
  320. if (variations.Size() > 32)
  321. ErrorExit("Maximum amount of variations exceeded");
  322. // Load the shader source code
  323. {
  324. String inputFileName = inDir_ + baseShader.name_ + ".hlsl";
  325. File hlslFile(context_, inputFileName);
  326. if (!hlslFile.IsOpen())
  327. ErrorExit("Could not open input file " + inputFileName);
  328. hlslCode_.Clear();
  329. while (!hlslFile.IsEof())
  330. hlslCode_ += hlslFile.ReadLine() + "\n";
  331. }
  332. for (unsigned i = 0; i < variations.Size(); ++i)
  333. {
  334. combinations *= 2;
  335. nameToIndex[variations[i].name_] = i;
  336. if (!variations[i].option_)
  337. hasVariations = true;
  338. }
  339. for (unsigned i = 0; i < combinations; ++i)
  340. {
  341. unsigned active = i; // Variations/options active on this particular combination
  342. bool variationActive = false;
  343. bool skipThis = false;
  344. // Check for excludes/includes/requires
  345. for (unsigned j = 0; j < variations.Size(); ++j)
  346. {
  347. if ((active >> j) & 1)
  348. {
  349. for (unsigned k = 0; k < variations[j].includes_.Size(); ++k)
  350. {
  351. if (nameToIndex.Find(variations[j].includes_[k]) != nameToIndex.End())
  352. active |= (1 << nameToIndex[variations[j].includes_[k]]);
  353. }
  354. for (unsigned k = 0; k < variations[j].excludes_.Size(); ++k)
  355. {
  356. if (nameToIndex.Find(variations[j].excludes_[k]) != nameToIndex.End())
  357. active &= ~(1 << nameToIndex[variations[j].excludes_[k]]);
  358. }
  359. // If it's a variation, exclude all other variations
  360. if (!variations[j].option_)
  361. {
  362. for (unsigned k = 0; k < variations.Size(); ++k)
  363. {
  364. if ((k != j) && (!variations[k].option_))
  365. active &= ~(1 << k);
  366. }
  367. variationActive = true;
  368. }
  369. for (unsigned k = 0; k < variations[j].requires_.Size(); ++k)
  370. {
  371. bool requireFound = false;
  372. for (unsigned l = 0; l < defines_.Size(); ++l)
  373. {
  374. if (defines_[l] == variations[j].requires_[k])
  375. {
  376. requireFound = true;
  377. break;
  378. }
  379. }
  380. for (unsigned l = 0; l < variations.Size(); ++l)
  381. {
  382. if (((active >> l) & 1) && (l != j))
  383. {
  384. if (variations[l].name_ == variations[j].requires_[k])
  385. {
  386. requireFound = true;
  387. break;
  388. }
  389. for (unsigned m = 0; m < variations[l].defines_.Size(); ++m)
  390. {
  391. if (variations[l].defines_[m] == variations[j].requires_[k])
  392. {
  393. requireFound = true;
  394. break;
  395. }
  396. }
  397. }
  398. if (requireFound)
  399. break;
  400. }
  401. if (!requireFound)
  402. skipThis = true;
  403. }
  404. }
  405. }
  406. // If variations are included, check that one of them is active
  407. if ((hasVariations) && (!variationActive))
  408. continue;
  409. if (skipThis)
  410. continue;
  411. // Check that this combination is unique
  412. bool unique = true;
  413. for (unsigned j = 0; j < usedCombinations.Size(); ++j)
  414. {
  415. if (usedCombinations[j] == active)
  416. {
  417. unique = false;
  418. break;
  419. }
  420. }
  421. if (unique)
  422. {
  423. // Build shader variation name & defines active variations
  424. String outName;
  425. Vector<String> defines;
  426. for (unsigned j = 0; j < variations.Size(); ++j)
  427. {
  428. if (active & (1 << j))
  429. {
  430. if (variations[j].name_.Length())
  431. outName += variations[j].name_;
  432. for (unsigned k = 0; k < variations[j].defines_.Size(); ++k)
  433. defines.Push(variations[j].defines_[k]);
  434. }
  435. }
  436. CompiledVariation compile;
  437. compile.type_ = baseShader.type_;
  438. compile.name_ = outName;
  439. compile.defines_ = defines;
  440. compiledVariations.Push(compile);
  441. usedCombinations.Push(active);
  442. }
  443. }
  444. // Prepare the work list
  445. // (all variations must be created first, so that vector resize does not change pointers)
  446. for (unsigned i = 0; i < compiledVariations.Size(); ++i)
  447. workList_.Push(&compiledVariations[i]);
  448. // Create and start worker threads. Use all cores except one to not lock up the computer completely
  449. unsigned numWorkerThreads = GetNumCPUCores() - 1;
  450. if (!numWorkerThreads)
  451. numWorkerThreads = 1;
  452. Vector<SharedPtr<WorkerThread> > workerThreads;
  453. workerThreads.Resize(numWorkerThreads);
  454. for (unsigned i = 0; i < workerThreads.Size(); ++i)
  455. {
  456. workerThreads[i] = new WorkerThread();
  457. workerThreads[i]->Start();
  458. }
  459. // This will wait until the thread functions have stopped
  460. for (unsigned i = 0; i < workerThreads.Size(); ++i)
  461. workerThreads[i]->Stop();
  462. // Check that all shaders compiled
  463. for (unsigned i = 0; i < compiledVariations.Size(); ++i)
  464. {
  465. if (!compiledVariations[i].errorMsg_.Empty())
  466. ErrorExit("Failed to compile shader " + baseShader.name_ + "_" + compiledVariations[i].name_ + ": " + compiledVariations[i].errorMsg_);
  467. }
  468. // Build the output file
  469. String outFileName = outDir_ + inDir_ + baseShader.name_;
  470. outFileName += (baseShader.type_ == VS) ? ".vs" : ".ps";
  471. outFileName += (useSM3_) ? "3" : "2";
  472. File outFile(context_, outFileName, FILE_WRITE);
  473. if (!outFile.IsOpen())
  474. ErrorExit("Could not open output file " + outFileName);
  475. // Convert the global parameters to vectors for index based search
  476. Vector<Parameter> constants;
  477. Vector<Parameter> textureUnits;
  478. for (Set<Parameter>::ConstIterator i = constants_.Begin(); i != constants_.End(); ++i)
  479. constants.Push(*i);
  480. for (Set<Parameter>::ConstIterator i = textureUnits_.Begin(); i != textureUnits_.End(); ++i)
  481. textureUnits.Push(*i);
  482. outFile.WriteID("USHD");
  483. outFile.WriteShort(baseShader.type_);
  484. outFile.WriteShort(useSM3_ ? 3 : 2);
  485. outFile.WriteUInt(constants.Size());
  486. for (unsigned i = 0; i < constants.Size(); ++i)
  487. {
  488. outFile.WriteString(constants[i].name_);
  489. outFile.WriteUByte(constants[i].index_);
  490. }
  491. outFile.WriteUInt(textureUnits.Size());
  492. for (unsigned i = 0; i < textureUnits.Size(); ++i)
  493. {
  494. outFile.WriteString(textureUnits[i].name_);
  495. outFile.WriteUByte(textureUnits[i].index_);
  496. }
  497. outFile.WriteUInt(compiledVariations.Size());
  498. for (unsigned i = 0; i < compiledVariations.Size(); ++i)
  499. {
  500. CompiledVariation& variation = compiledVariations[i];
  501. outFile.WriteString(variation.name_);
  502. for (unsigned j = 0; j < constants.Size(); ++j)
  503. outFile.WriteBool(variation.constants_.Find(constants[j]) != variation.constants_.End());
  504. for (unsigned j = 0; j < textureUnits.Size(); ++j)
  505. outFile.WriteBool(variation.textureUnits_.Find(textureUnits[j]) != variation.textureUnits_.End());
  506. unsigned dataSize = variation.byteCode_.Size();
  507. outFile.WriteUInt(dataSize);
  508. if (dataSize)
  509. outFile.Write(&variation.byteCode_[0], dataSize);
  510. }
  511. }
  512. void Compile(CompiledVariation* variation)
  513. {
  514. IncludeHandler includeHandler;
  515. PODVector<D3DXMACRO> macros;
  516. // Insert variation-specific and global defines
  517. for (unsigned i = 0; i < variation->defines_.Size(); ++i)
  518. {
  519. D3DXMACRO macro;
  520. macro.Name = variation->defines_[i].CString();
  521. macro.Definition = "1";
  522. macros.Push(macro);
  523. }
  524. for (unsigned i = 0; i < defines_.Size(); ++i)
  525. {
  526. D3DXMACRO macro;
  527. macro.Name = defines_[i].CString();
  528. macro.Definition = "1";
  529. macros.Push(macro);
  530. }
  531. D3DXMACRO endMacro;
  532. endMacro.Name = 0;
  533. endMacro.Definition = 0;
  534. macros.Push(endMacro);
  535. LPD3DXBUFFER shaderCode = 0;
  536. LPD3DXBUFFER errorMsgs = 0;
  537. LPD3DXCONSTANTTABLE constantTable = 0;
  538. // Set the profile, entrypoint and flags according to the shader being compiled
  539. String profile;
  540. String entryPoint;
  541. unsigned flags = 0;
  542. if (variation->type_ == VS)
  543. {
  544. entryPoint = "VS";
  545. if (!useSM3_)
  546. profile = "vs_2_0";
  547. else
  548. profile = "vs_3_0";
  549. }
  550. else
  551. {
  552. entryPoint = "PS";
  553. if (!useSM3_)
  554. profile = "ps_2_0";
  555. else
  556. {
  557. profile = "ps_3_0";
  558. flags |= D3DXSHADER_PREFER_FLOW_CONTROL;
  559. }
  560. }
  561. // Compile using D3DX
  562. HRESULT hr = D3DXCompileShader(hlslCode_.CString(), hlslCode_.Length(), &macros.Front(), &includeHandler,
  563. entryPoint.CString(), profile.CString(), flags, &shaderCode, &errorMsgs, &constantTable);
  564. if (FAILED(hr))
  565. {
  566. variation->errorMsg_ = String((const char*)errorMsgs->GetBufferPointer(), errorMsgs->GetBufferSize());
  567. compileFailed_ = true;
  568. }
  569. else
  570. {
  571. unsigned dataSize = shaderCode->GetBufferSize();
  572. if (dataSize)
  573. {
  574. variation->byteCode_.Resize(dataSize);
  575. memcpy(&variation->byteCode_[0], shaderCode->GetBufferPointer(), dataSize);
  576. }
  577. }
  578. // Parse the constant table for constants and texture units
  579. D3DXCONSTANTTABLE_DESC desc;
  580. constantTable->GetDesc(&desc);
  581. for (unsigned i = 0; i < desc.Constants; ++i)
  582. {
  583. D3DXHANDLE handle = constantTable->GetConstant(NULL, i);
  584. D3DXCONSTANT_DESC constantDesc;
  585. unsigned numElements = 1;
  586. constantTable->GetConstantDesc(handle, &constantDesc, &numElements);
  587. String name(constantDesc.Name);
  588. unsigned index = constantDesc.RegisterIndex;
  589. // Check if the parameter is a constant or a texture sampler
  590. bool isSampler = (name[0] == 's');
  591. name = name.Substring(1);
  592. MutexLock lock(globalParamMutex_);
  593. if (isSampler)
  594. {
  595. // Skip if it's a G-buffer sampler
  596. if (name.Find("Buffer") == String::NPOS)
  597. {
  598. Parameter newTextureUnit(name, index);
  599. variation->textureUnits_.Insert(newTextureUnit);
  600. textureUnits_.Insert(newTextureUnit);
  601. }
  602. }
  603. else
  604. {
  605. Parameter newParam(name, index);
  606. variation->constants_.Insert(newParam);
  607. constants_.Insert(newParam);
  608. }
  609. }
  610. if (shaderCode)
  611. shaderCode->Release();
  612. if (constantTable)
  613. constantTable->Release();
  614. if (errorMsgs)
  615. errorMsgs->Release();
  616. }