CommandBufferCompiler.cpp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. #include "..\..\..\common_h\render.h"
  2. #ifndef COMPILE_PROPS_INCLUDED
  3. #error CompileProps.h must be included
  4. #endif
  5. #if defined (_XBOX) && defined(_PRECOMPILED_COMMAND_BUFFER_BAKER)
  6. #include "CommandBufferCompiler.h"
  7. #include "..\..\..\common_h\FileService.h"
  8. #include "..\DefaultStates\DefaultStates.h"
  9. #include "..\Render.h"
  10. #include "..\batch\PrecompiledBatch.h"
  11. CommandBufferCompiler::CommandBufferCompiler()
  12. {
  13. dwUsedSpaceInCmdBuffer = 0;
  14. commandBuffer = NULL;
  15. pFS = (IFileService *)api->GetService("FileService");
  16. dwHeaderSize = 0;
  17. dwPhysicalSize = 0;
  18. dwInitializationSize = 0;
  19. }
  20. CommandBufferCompiler::~CommandBufferCompiler()
  21. {
  22. if (commandBuffer)
  23. {
  24. commandBuffer->Release();
  25. commandBuffer = NULL;
  26. }
  27. if (shaderStates.pBoundedVS)
  28. {
  29. shaderStates.pBoundedVS->Release();
  30. }
  31. shaderStates.pBoundedVS = NULL;
  32. if (shaderStates.pBoundedPS)
  33. {
  34. shaderStates.pBoundedPS->Release();
  35. }
  36. shaderStates.pBoundedPS = NULL;
  37. }
  38. void DebugOut (const char * str, ...)
  39. {
  40. static char tempBuffer[16384];
  41. va_list args;
  42. va_start(args, str);
  43. vsnprintf_s(tempBuffer, 16384 - 4, 16384-4, str, args);
  44. va_end(args);
  45. OutputDebugString(tempBuffer);
  46. }
  47. void CommandBufferCompiler::SetName (const char* szTechName)
  48. {
  49. techName = szTechName;
  50. }
  51. void CommandBufferCompiler::ExtractRenderState (D3DRENDERSTATETYPE state, DWORD dwVal, bool bLog)
  52. {
  53. if (bLog)
  54. {
  55. DebugOut("ExtractRenderState(%d, %d)\n", state, dwVal);
  56. }
  57. renderState & item = shaderStates.r_states[shaderStates.r_states.Add()];
  58. item.state = state;
  59. item.val = dwVal;
  60. }
  61. void CommandBufferCompiler::ExtractSamplerState (DWORD sampler, D3DSAMPLERSTATETYPE type, DWORD dwVal)
  62. {
  63. if ((type != D3DSAMP_ADDRESSU) &&
  64. (type != D3DSAMP_ADDRESSV) &&
  65. (type != D3DSAMP_MAGFILTER) &&
  66. (type != D3DSAMP_MINFILTER ) &&
  67. (type != D3DSAMP_MIPFILTER ))
  68. {
  69. return;
  70. }
  71. dword dwIdx = INVALID_ARRAY_INDEX;
  72. for (dword i = 0; i < shaderStates.textures.Size(); i++)
  73. {
  74. if (shaderStates.textures[i].dwStage == sampler)
  75. {
  76. dwIdx = i;
  77. break;
  78. }
  79. }
  80. if (dwIdx == INVALID_ARRAY_INDEX)
  81. {
  82. dwIdx = shaderStates.textures.Add();
  83. }
  84. texture & tex = shaderStates.textures[dwIdx];
  85. tex.dwStage = sampler;
  86. switch (type)
  87. {
  88. case D3DSAMP_ADDRESSU:
  89. tex.clampU = (D3DTEXTUREADDRESS )dwVal;
  90. break;
  91. case D3DSAMP_ADDRESSV:
  92. tex.clampV = (D3DTEXTUREADDRESS )dwVal;
  93. break;
  94. case D3DSAMP_MAGFILTER:
  95. tex.magFilter = (D3DTEXTUREFILTERTYPE)dwVal;
  96. break;
  97. case D3DSAMP_MINFILTER:
  98. tex.minFilter = (D3DTEXTUREFILTERTYPE)dwVal;
  99. break;
  100. case D3DSAMP_MIPFILTER:
  101. tex.mipFilter = (D3DTEXTUREFILTERTYPE)dwVal;
  102. break;
  103. }
  104. }
  105. void CommandBufferCompiler::PatchShadersAndDumpMicrocode(IDirect3DVertexDeclaration9 * pVDecl, array<DWORD> & vertexDeclStrides)
  106. {
  107. Assert(shaderStates.pBoundedVS);
  108. shaderStates.pBoundedVS->Bind(0, pVDecl, &vertexDeclStrides[0], shaderStates.pBoundedPS);
  109. bool bBoundedVS = shaderStates.pBoundedVS->IsBound();
  110. Assert(bBoundedVS);
  111. if (shaderStates.pVertexShaderFunc)
  112. {
  113. ID3DXBuffer* microcodeTextVS = NULL;
  114. D3DXDisassembleShader(shaderStates.pVertexShaderFunc, FALSE, NULL, &microcodeTextVS);
  115. if (microcodeTextVS)
  116. {
  117. const char * szStr = (const char*)microcodeTextVS->GetBufferPointer();
  118. ParsePredefinedConstants (szStr, shaderStates.vs_consts, false);
  119. microcodeTextVS->Release();
  120. microcodeTextVS = NULL;
  121. }
  122. }
  123. if (shaderStates.pPixelShaderFunc)
  124. {
  125. ID3DXBuffer* microcodeTextPS = NULL;
  126. D3DXDisassembleShader(shaderStates.pPixelShaderFunc, FALSE, NULL, &microcodeTextPS);
  127. if (microcodeTextPS)
  128. {
  129. const char * szStr = (const char*)microcodeTextPS->GetBufferPointer();
  130. ParsePredefinedConstants (szStr, shaderStates.ps_consts, true);
  131. microcodeTextPS->Release();
  132. microcodeTextPS = NULL;
  133. }
  134. }
  135. ExtractMicrocode(shaderStates.pPixelShaderFunc, CommandBufferCompiler::MT_PIXEL_SHADER);
  136. ExtractMicrocode(shaderStates.pVertexShaderFunc, CommandBufferCompiler::MT_VERTEX_SHADER);
  137. }
  138. void CommandBufferCompiler::ExtractPixelShader(CONST DWORD *pShaderFunction)
  139. {
  140. Assert(shaderStates.pBoundedPS == NULL);
  141. if (pShaderFunction == NULL)
  142. {
  143. return;
  144. }
  145. NGRender::pRS->D3D()->CreatePixelShader(pShaderFunction, &shaderStates.pBoundedPS);
  146. shaderStates.pPixelShaderFunc = pShaderFunction;
  147. }
  148. void CommandBufferCompiler::ExtractVertexShader(CONST DWORD *pShaderFunction)
  149. {
  150. Assert(shaderStates.pBoundedVS == NULL);
  151. if (pShaderFunction == NULL)
  152. {
  153. return;
  154. }
  155. NGRender::pRS->D3D()->CreateVertexShader(pShaderFunction, &shaderStates.pBoundedVS);
  156. shaderStates.pVertexShaderFunc = pShaderFunction;
  157. }
  158. bool CommandBufferCompiler::ExtractConstants (CONST DWORD *pShaderFunction, MicrocodeType type)
  159. {
  160. UINT constSize;
  161. D3DXCONSTANTTABLE_DESC constTableDesc;
  162. ID3DXConstantTable* pAttributes = NULL;
  163. D3DXGetShaderConstantTable(pShaderFunction, &pAttributes);
  164. if (pAttributes == NULL)
  165. {
  166. printf ("ERROR!!! - not constant table found\n");
  167. return false;
  168. }
  169. // pass & p = shaderStates;
  170. array<shaderConstant> * consts = &shaderStates.vs_consts;
  171. if (type == CommandBufferCompiler::MT_PIXEL_SHADER)
  172. {
  173. consts = &shaderStates.ps_consts;
  174. }
  175. bool bNeedWarning = true;
  176. pAttributes->GetDesc(&constTableDesc);
  177. for (UINT idx = 0; idx < constTableDesc.Constants; idx++)
  178. {
  179. bNeedWarning = true;
  180. D3DXCONSTANT_DESC constDesc;;
  181. D3DXHANDLE v_cont = pAttributes->GetConstant(NULL, idx);
  182. pAttributes->GetConstantDesc(v_cont, &constDesc, &constSize);
  183. if (constDesc.RegisterSet == D3DXRS_FLOAT4)
  184. {
  185. if (constDesc.Class == D3DXPC_MATRIX_COLUMNS && constDesc.Type == D3DXPT_FLOAT && constDesc.Rows == 4 && constDesc.Columns == 4)
  186. {
  187. bNeedWarning = false;
  188. consts->Add(shaderConstant(constDesc.Name, CT_MATRIX4x4, constDesc.RegisterIndex, constDesc.RegisterCount, constDesc.Elements));
  189. }
  190. if (constDesc.Class == D3DXPC_VECTOR && constDesc.Type == D3DXPT_FLOAT && constDesc.Rows == 1 && constDesc.Columns == 4)
  191. {
  192. bNeedWarning = false;
  193. consts->Add(shaderConstant(constDesc.Name, CT_FLOAT4, constDesc.RegisterIndex, constDesc.RegisterCount, constDesc.Elements));
  194. }
  195. if (constDesc.Class == D3DXPC_VECTOR && constDesc.Type == D3DXPT_FLOAT && constDesc.Rows == 1 && constDesc.Columns == 3)
  196. {
  197. bNeedWarning = false;
  198. consts->Add(shaderConstant(constDesc.Name, CT_FLOAT3, constDesc.RegisterIndex, constDesc.RegisterCount, constDesc.Elements));
  199. }
  200. if (constDesc.Class == D3DXPC_SCALAR && constDesc.Type == D3DXPT_FLOAT && constDesc.Rows == 1 && constDesc.Columns == 1)
  201. {
  202. bNeedWarning = false;
  203. consts->Add(shaderConstant(constDesc.Name, CT_FLOAT, constDesc.RegisterIndex, constDesc.RegisterCount, constDesc.Elements));
  204. }
  205. }
  206. if (constDesc.RegisterSet == D3DXRS_BOOL)
  207. {
  208. if (constDesc.Class == D3DXPC_SCALAR && constDesc.Type == D3DXPT_BOOL && constDesc.Rows == 1 && constDesc.Columns == 1)
  209. {
  210. /*
  211. if (constDesc.RegisterCount != 32)
  212. {
  213. //bool ставятся не пачками по 32 - ошибка!!!
  214. api->Trace("ERROR : '%s' Bool registers must sets by chunks of 32 elements!!!", constDesc.Name);
  215. Assert(false);
  216. }
  217. */
  218. if ((constDesc.RegisterIndex % 32) != 0)
  219. {
  220. //регистры bool начинаются не кратно 32 - ошибка!!!
  221. api->Trace("ERROR : '%s' Bool registers address must be 32 bools aligned!!!", constDesc.Name);
  222. Assert(false);
  223. }
  224. bNeedWarning = false;
  225. consts->Add(shaderConstant(constDesc.Name, CT_BOOL, constDesc.RegisterIndex, constDesc.RegisterCount, constDesc.Elements));
  226. }
  227. }
  228. if (constDesc.RegisterSet == D3DXRS_SAMPLER)
  229. {
  230. //just skip, we already grab sampler description...
  231. bNeedWarning = false;
  232. }
  233. if (bNeedWarning)
  234. {
  235. printf ("WARNING! : skip constant with name : '%s' - unsupported type for backend!\n", constDesc.Name);
  236. }
  237. } //constTableDesc.Constants
  238. return true;
  239. }
  240. void CommandBufferCompiler::ExtractMicrocode(CONST DWORD *pShaderFunction, MicrocodeType type)
  241. {
  242. if (pShaderFunction == NULL)
  243. {
  244. return;
  245. }
  246. /*
  247. ID3DXBuffer* microcodeText = NULL;
  248. D3DXDisassembleShaderEx(passDesc.pPixelShaderFunction,
  249. D3DXDISASSEMBLER_SHOW_TIMING_ESTIMATE |
  250. D3DXDISASSEMBLER_SHOW_RUNTIME_DATA |
  251. D3DXDISASSEMBLER_SHOW_MICROCODE_DEFAULTS |
  252. D3DXDISASSEMBLER_SHOW_CONSTANT_TABLE_DEFAULTS,
  253. NULL,
  254. &microcodeText);
  255. if (microcodeText)
  256. {
  257. IFileService * fs = (IFileService *)api->GetService("FileService");
  258. static char tmp[MAX_PATH];
  259. crt_snprintf(tmp, MAX_PATH, "devkit:\\ps_%s_pass_%d.mc", tDesc.Name, n);
  260. IFile* file = fs->OpenFile(tmp, file_create_always, _FL_);
  261. if (file)
  262. {
  263. file->Write(microcodeText->GetBufferPointer(), microcodeText->GetBufferSize());
  264. file->Release();
  265. file = NULL;
  266. microcodeText->Release();
  267. microcodeText = NULL;
  268. }
  269. }
  270. */
  271. //------------------------------------------------------------------
  272. ExtractConstants(pShaderFunction, type);
  273. switch (type)
  274. {
  275. case CommandBufferCompiler::MT_PIXEL_SHADER:
  276. {
  277. microcode & mc = shaderStates.microcodePS;
  278. XGGetMicrocodeShaderParts( pShaderFunction, &mc.parts );
  279. IDirect3DPixelShader9* shaderBody = (IDirect3DPixelShader9*)mc.Allocate(mc.parts.cbCachedPartSize);
  280. XGSetPixelShaderHeader( shaderBody, mc.parts.cbCachedPartSize, &mc.parts );
  281. break;
  282. }
  283. case CommandBufferCompiler::MT_VERTEX_SHADER:
  284. {
  285. microcode & mc = shaderStates.microcodeVS;
  286. XGGetMicrocodeShaderParts( pShaderFunction, &mc.parts );
  287. IDirect3DVertexShader9* shaderBody = (IDirect3DVertexShader9*)mc.Allocate(mc.parts.cbCachedPartSize);
  288. XGSetVertexShaderHeader( shaderBody, mc.parts.cbCachedPartSize, &mc.parts );
  289. break;
  290. }
  291. default:
  292. Assert(false && "Unknown microcode type!");
  293. }
  294. /*
  295. IFile* file = pFS->OpenFile(fileName, file_create_always, _FL_);
  296. if (file)
  297. {
  298. //Надо еще хидер тут...
  299. file->Write(pShaderBody, parts.cbCachedPartSize);
  300. file->Write(parts.pPhysicalPart, parts.cbPhysicalPartSize);
  301. file->Release();
  302. file = NULL;
  303. }
  304. */
  305. }
  306. void CommandBufferCompiler::ResetToDefaultStates(D3DDevice* pCommandBufferDevice)
  307. {
  308. /////////////////////////////////////////////////////////////////////////////
  309. DWORD dwValue = 0;
  310. for (dword n = 0; n < RENDER_STATES_ARRAY_SIZE; n++)
  311. {
  312. if (DefaultRenderStates::GetDefaultValue((D3DRENDERSTATETYPE)n, dwValue))
  313. {
  314. pCommandBufferDevice->SetRenderState((D3DRENDERSTATETYPE)n, dwValue);
  315. }
  316. }
  317. pCommandBufferDevice->SetVertexShader(NULL);
  318. pCommandBufferDevice->SetPixelShader(NULL);
  319. pCommandBufferDevice->SetVertexDeclaration(NULL);
  320. pCommandBufferDevice->SetStreamSource(0, NULL, 0, 0);
  321. pCommandBufferDevice->SetStreamSource(1, NULL, 0, 0);
  322. pCommandBufferDevice->SetStreamSource(2, NULL, 0, 0);
  323. //pCommandBufferDevice->SetStreamSource(3, NULL, 0, 0);
  324. pCommandBufferDevice->SetIndices(NULL);
  325. /////////////////////////////////////////////////////////////////////////////
  326. }
  327. void CommandBufferCompiler::ParsePredefinedConstants (const char* szShaderBody, array<shaderConstant> & shaderConsts, bool bPixelShader)
  328. {
  329. static char digit[32];
  330. int stringLen = (int)strlen (szShaderBody);
  331. for (int i = 0; i < (stringLen-6); i++)
  332. {
  333. if (szShaderBody[i+0] == 'd' && szShaderBody[i+1] == 'e' && szShaderBody[i+2] == 'f' && szShaderBody[i+3] == ' ' && szShaderBody[i+4] == 'c')
  334. {
  335. int remainChars = (stringLen - i);
  336. if (remainChars > 3)
  337. {
  338. remainChars = 3;
  339. }
  340. //сканим и как только не число все...
  341. for (DWORD counter = 0; counter < remainChars; counter++)
  342. {
  343. char mustBeDigit = szShaderBody[i + 5 + counter];
  344. if (!(mustBeDigit >= '0' && mustBeDigit <= '9'))
  345. {
  346. break;
  347. }
  348. digit[counter] = mustBeDigit;
  349. }
  350. digit[counter] = 0;
  351. int predefinedRegIndex = atoi(digit);
  352. assert (predefinedRegIndex <= 255);
  353. shaderConstant & shConst = shaderConsts[shaderConsts.Add()];
  354. shConst.dwRegisterIndex = predefinedRegIndex;
  355. shConst.dwElements = 1;
  356. shConst.dwRegisterCounts = 1;
  357. shConst.type = CT_FLOAT4;
  358. shConst.szName.Format("c_defined_%d", predefinedRegIndex);
  359. shConst.bPredefinedInShaderBody = true;
  360. //дальше ставим смещение...
  361. i = i + 5 + counter;
  362. }
  363. if (szShaderBody[i+0] == 'd' && szShaderBody[i+1] == 'e' && szShaderBody[i+2] == 'f' && szShaderBody[i+3] == 'i' && szShaderBody[i+4] == ' ' && szShaderBody[i+5] == 'i')
  364. {
  365. int remainChars = (stringLen - i);
  366. if (remainChars > 2)
  367. {
  368. remainChars = 2;
  369. }
  370. //сканим и как только не число все...
  371. for (int counter = 0; counter < remainChars; counter++)
  372. {
  373. char mustBeDigit = szShaderBody[i + 6 + counter];
  374. if (!(mustBeDigit >= '0' && mustBeDigit <= '9'))
  375. {
  376. break;
  377. }
  378. digit[counter] = mustBeDigit;
  379. }
  380. digit[counter] = 0;
  381. int predefinedRegIndex = atoi(digit);
  382. /*
  383. Type HLSL Constant Range Microcode Constant Range
  384. Vertex Shader Floating-Point c0–c255 c0–c255
  385. Pixel Shader Floating-Point c0–c255 c0–c255
  386. Vertex Shader Boolean b0–b127 b0–b127
  387. Pixel Shader Boolean b0–b127 b128–b255
  388. Vertex Shader Integer i0–i15 i0–i15
  389. Pixel Shader Integer i0–i15 i16–i31
  390. Vertex Shader Fetch/Sampler s0–s3 tf16–tf19
  391. Pixel Shader Fetch/Sampler s0–s15 tf0–tf15
  392. */
  393. if (bPixelShader)
  394. {
  395. predefinedRegIndex -= 16;
  396. }
  397. assert (predefinedRegIndex <= 15);
  398. shaderConstant & shConst = shaderConsts[shaderConsts.Add()];
  399. shConst.dwRegisterIndex = predefinedRegIndex;
  400. shConst.dwElements = 1;
  401. shConst.dwRegisterCounts = 1;
  402. shConst.type = CT_INT4;
  403. shConst.szName.Format("i_defined_%d", predefinedRegIndex);
  404. shConst.bPredefinedInShaderBody = true;
  405. //дальше ставим смещение...
  406. i = i + 6 + counter;
  407. }
  408. }
  409. }
  410. void CommandBufferCompiler::Finalize(D3DDevice* pCommandBufferDevice, precompiledBatch * pBatch)
  411. {
  412. ResetToDefaultStates(pCommandBufferDevice);
  413. IBaseTexture* fakeTextureStorm = NGRender::pRS->getWhiteTexture();
  414. IDirect3DBaseTexture9 * fakeTexture = (IDirect3DBaseTexture9 *)fakeTextureStorm->GetBaseTexture();
  415. D3DVertexBuffer * fakeVb = NULL;
  416. pCommandBufferDevice->CreateVertexBuffer(sizeof(Vector) * 4, 0, 0, 0, &fakeVb, NULL);
  417. D3DIndexBuffer * fakeIb = NULL;
  418. pCommandBufferDevice->CreateIndexBuffer(sizeof(WORD) * 6, 0, D3DFMT_INDEX16, 0, &fakeIb, 0);
  419. //JOKER TODO:
  420. //надо тут подготовить кусочек 'command buffer' и шейдерки отдельно все (кластеризовать шейдеры ???? ускорит закрузку)
  421. //JOKER TODO:
  422. //все сохдранять в формате, что бы можно было inplace поднять
  423. //JOKER TODO:
  424. //Декларации больше не нужны - т.к. шейдеры Binded уже...
  425. /*
  426. Zenable 1
  427. CullMode 6
  428. AlphaBlendEnable 0
  429. AlphaTestEnable 0
  430. AlphaRef 0
  431. StencilMask = 0xffffffff
  432. StencilWriteMask = 0xffffffff
  433. MultiSampleMask = 0xffffffff
  434. */
  435. //-----------------------------------------------------------------------------------------------------------------------------------------
  436. //
  437. // создаем precompiled command buffer
  438. //
  439. //-----------------------------------------------------------------------------------------------------------------------------------------
  440. if (commandBuffer != NULL)
  441. {
  442. //Уже запекали данный буффер - второй раз может придти, т.к. сначала systemShaders, потом обычные...
  443. return;
  444. }
  445. Assert(commandBuffer == NULL && "twice call !?");
  446. /*
  447. D3DDevice* pCommandBufferDevice = NULL;
  448. Direct3D_CreateDevice( 0, D3DDEVTYPE_COMMAND_BUFFER, NULL, 0, NULL, &pCommandBufferDevice );
  449. pCommandBufferDevice->Release();
  450. pCommandBufferDevice = NULL;
  451. */
  452. pCommandBufferDevice->CreateCommandBuffer( 256 * 1024, 0, &commandBuffer );
  453. /*
  454. OutputDebugString(techName.c_str());
  455. OutputDebugString("\n");
  456. */
  457. bool bLog = false;
  458. /*
  459. if (techName == "Particles" != NULL)
  460. {
  461. DebugOut("shader : '%s' -------------------------------------------------\n", techName.c_str());
  462. bLog = true;
  463. }
  464. */
  465. /*
  466. if (techName == "Create_fBm")
  467. {
  468. int a = 0;
  469. }
  470. */
  471. //for (dword passIdx = 0; passIdx < passes.Size(); passIdx++)
  472. //{
  473. //pass & p = shaderStates;
  474. //ResetToDefaultStates(pCommandBufferDevice);
  475. D3DTAGCOLLECTION InheritTags;
  476. //Отмечаем, что нам ничего не нужно...
  477. D3DTagCollection_SetAll(&InheritTags);
  478. //Нужны vertex/pixel shaderы
  479. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_VERTEXSHADER), D3DTag_Mask(D3DTAG_VERTEXSHADER));
  480. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_PIXELSHADER), D3DTag_Mask(D3DTAG_PIXELSHADER));
  481. //Шейдеры эти пакеты генерируют
  482. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_HIZENABLE), D3DTag_Mask(D3DTAG_HIZENABLE));
  483. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_HICONTROL), D3DTag_Mask(D3DTAG_HICONTROL));
  484. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_INTERPOLATORCONTROL), D3DTag_Mask(D3DTAG_INTERPOLATORCONTROL));
  485. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_PROGRAMCONTROL), D3DTag_Mask(D3DTAG_PROGRAMCONTROL));
  486. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_CONTEXTMISC), D3DTag_Mask(D3DTAG_CONTEXTMISC));
  487. //D3DRS_CULLMODE
  488. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_MODECONTROL), D3DTag_Mask(D3DTAG_MODECONTROL));
  489. //ZBuffer
  490. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_DEPTHCONTROL), D3DTag_Mask(D3DTAG_DEPTHCONTROL));
  491. //alpha blend
  492. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_BLENDCONTROL0), D3DTag_Mask(D3DTAG_BLENDCONTROL0));
  493. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_BLENDCONTROL1), D3DTag_Mask(D3DTAG_BLENDCONTROL1));
  494. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_BLENDCONTROL2), D3DTag_Mask(D3DTAG_BLENDCONTROL2));
  495. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_BLENDCONTROL3), D3DTag_Mask(D3DTAG_BLENDCONTROL3));
  496. //ColorWriteEnable
  497. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_COLORMASK), D3DTag_Mask(D3DTAG_COLORMASK));
  498. //alpha test
  499. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_COLORCONTROL), D3DTag_Mask(D3DTAG_COLORCONTROL));
  500. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_ZPASSEDRAMMODE), D3DTag_Mask(D3DTAG_ZPASSEDRAMMODE));
  501. //alpha ref
  502. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_ALPHAREF), D3DTag_Mask(D3DTAG_ALPHAREF));
  503. //double speed depth render или normal render
  504. //в тенях используется
  505. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_EDRAMMODECONTROL), D3DTag_Mask(D3DTAG_EDRAMMODECONTROL));
  506. for (dword texIdx = 0; texIdx < shaderStates.textures.Size(); texIdx++)
  507. {
  508. texture & tex = shaderStates.textures[texIdx];
  509. //sampler #tex.dwStage
  510. DWORD gpuFetchConstantTex = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(tex.dwStage);
  511. UINT64 textureConstantMask = D3DTAG_MASKENCODE(D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantTex, D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantTex);
  512. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_FETCHCONSTANTS), textureConstantMask);
  513. }
  514. //vertex stream #0 (1 и 2-й тоже автоматом будут)
  515. DWORD vertexFetchConstant = GPU_CONVERT_D3D_TO_HARDWARE_VERTEXFETCHCONSTANT(0);
  516. DWORD gpuFetchConstantVrx = (vertexFetchConstant * (65536/3 + 1)) >> 16;
  517. UINT64 vertexConstantMask = D3DTAG_MASKENCODE(D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantVrx, D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantVrx);
  518. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_FETCHCONSTANTS), vertexConstantMask);
  519. /*
  520. //vertex stream #1
  521. vertexFetchConstant = GPU_CONVERT_D3D_TO_HARDWARE_VERTEXFETCHCONSTANT(1);
  522. gpuFetchConstantVrx = (vertexFetchConstant * (65536/3 + 1)) >> 16;
  523. vertexConstantMask = D3DTAG_MASKENCODE(D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantVrx, D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantVrx);
  524. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_FETCHCONSTANTS), vertexConstantMask);
  525. //vertex stream #2
  526. vertexFetchConstant = GPU_CONVERT_D3D_TO_HARDWARE_VERTEXFETCHCONSTANT(2);
  527. gpuFetchConstantVrx = (vertexFetchConstant * (65536/3 + 1)) >> 16;
  528. vertexConstantMask = D3DTAG_MASKENCODE(D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantVrx, D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantVrx);
  529. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_FETCHCONSTANTS), vertexConstantMask);
  530. //vertex stream #3
  531. vertexFetchConstant = GPU_CONVERT_D3D_TO_HARDWARE_VERTEXFETCHCONSTANT(3);
  532. gpuFetchConstantVrx = (vertexFetchConstant * (65536/3 + 1)) >> 16;
  533. vertexConstantMask = D3DTAG_MASKENCODE(D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantVrx, D3DTAG_START(D3DTAG_FETCHCONSTANTS) + gpuFetchConstantVrx);
  534. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_FETCHCONSTANTS), vertexConstantMask);
  535. */
  536. //vertex constants
  537. for (dword vconstIdx = 0; vconstIdx < shaderStates.vs_consts.Size(); vconstIdx++)
  538. {
  539. shaderConstant & vconst = shaderStates.vs_consts[vconstIdx];
  540. assert ((vconst.dwRegisterIndex + vconst.dwRegisterCounts-1) <= 255);
  541. if (vconst.bPredefinedInShaderBody)
  542. {
  543. precompiledBatch::Trace("vertex shader const #%d predefined in shader body\n", vconst.dwRegisterIndex);
  544. }
  545. if (vconst.type == CommandBufferCompiler::CT_BOOL || vconst.type == CommandBufferCompiler::CT_INT4)
  546. {
  547. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_FLOWCONSTANTS), D3DTag_Mask(D3DTAG_FLOWCONSTANTS));
  548. //D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_FLOWCONSTANTS), D3DTag_ShaderConstantMask(vconst.dwRegisterIndex, vconst.dwRegisterCounts));
  549. } else
  550. {
  551. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_VERTEXSHADERCONSTANTS), D3DTag_ShaderConstantMask(vconst.dwRegisterIndex, vconst.dwRegisterCounts));
  552. }
  553. }
  554. //pixel constants
  555. for (dword pconstIdx = 0; pconstIdx < shaderStates.ps_consts.Size(); pconstIdx++)
  556. {
  557. shaderConstant & pconst = shaderStates.ps_consts[pconstIdx];
  558. assert ((pconst.dwRegisterIndex + pconst.dwRegisterCounts-1) <= 255);
  559. if (pconst.bPredefinedInShaderBody)
  560. {
  561. precompiledBatch::Trace("pixel shader const #%d predefined in shader body\n", pconst.dwRegisterIndex);
  562. }
  563. if (pconst.type == CommandBufferCompiler::CT_BOOL || pconst.type == CommandBufferCompiler::CT_INT4)
  564. {
  565. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_FLOWCONSTANTS), D3DTag_Mask(D3DTAG_FLOWCONSTANTS));
  566. //D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_FLOWCONSTANTS), D3DTag_ShaderConstantMask(pconst.dwRegisterIndex, pconst.dwRegisterCounts));
  567. } else
  568. {
  569. D3DTagCollection_Clear(&InheritTags, D3DTag_Index(D3DTAG_PIXELSHADERCONSTANTS), D3DTag_ShaderConstantMask(pconst.dwRegisterIndex, pconst.dwRegisterCounts));
  570. }
  571. }
  572. //
  573. pCommandBufferDevice->BeginCommandBuffer( commandBuffer, /*D3DBEGINCB_OVERWRITE_INHERITED_STATE | */D3DBEGINCB_RECORD_ALL_SET_STATE, &InheritTags, NULL, NULL, 0 );
  574. pBatch->DynamicDraw_SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALL);
  575. pBatch->DynamicDraw_SetRenderState(D3DRS_ZENABLE, TRUE);
  576. pBatch->DynamicDraw_SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
  577. pBatch->DynamicDraw_SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
  578. pBatch->DynamicDraw_SetRenderState(D3DRS_STENCILENABLE, FALSE);
  579. pBatch->DynamicDraw_SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
  580. pBatch->DynamicDraw_SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
  581. pBatch->DynamicDraw_SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
  582. pBatch->DynamicDraw_SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
  583. pBatch->DynamicDraw_SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
  584. pBatch->DynamicDraw_SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
  585. pBatch->DynamicDraw_SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
  586. pBatch->DynamicDraw_SetRenderState(D3DRS_CLIPPLANEENABLE, 0);
  587. for (dword t = 0; t < 4; t++)
  588. {
  589. pBatch->DynamicDraw_SetSamplerState(t, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
  590. pBatch->DynamicDraw_SetSamplerState(t, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
  591. pBatch->DynamicDraw_SetSamplerState(t, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
  592. pBatch->DynamicDraw_SetSamplerState(t, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
  593. pBatch->DynamicDraw_SetSamplerState(t, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
  594. }
  595. for (dword texIdx = 0; texIdx < shaderStates.textures.Size(); texIdx++)
  596. {
  597. texture & tx = shaderStates.textures[texIdx];
  598. pCommandBufferDevice->SetTexture(tx.dwStage, fakeTexture);
  599. }
  600. for (dword tIdx = 0; tIdx < shaderStates.textures.Size(); tIdx++)
  601. {
  602. texture & t = shaderStates.textures[tIdx];
  603. pBatch->DynamicDraw_SetSamplerState(t.dwStage, D3DSAMP_ADDRESSU, t.clampU);
  604. pBatch->DynamicDraw_SetSamplerState(t.dwStage, D3DSAMP_ADDRESSV, t.clampV);
  605. pBatch->DynamicDraw_SetSamplerState(t.dwStage, D3DSAMP_MINFILTER, t.minFilter);
  606. pBatch->DynamicDraw_SetSamplerState(t.dwStage, D3DSAMP_MAGFILTER, t.magFilter);
  607. pBatch->DynamicDraw_SetSamplerState(t.dwStage, D3DSAMP_MIPFILTER, t.mipFilter);
  608. }
  609. for (dword vconstIdx = 0; vconstIdx < shaderStates.vs_consts.Size(); vconstIdx++)
  610. {
  611. shaderConstant & vconst = shaderStates.vs_consts[vconstIdx];
  612. if (vconst.bPredefinedInShaderBody)
  613. {
  614. continue;
  615. }
  616. //api->Trace("v: %s\n", vconst.szName.c_str());
  617. float tmp[4];
  618. tmp[0] = 1.0f;
  619. tmp[1] = 2.0f;
  620. tmp[2] = 3.0f;
  621. tmp[3] = 4.0f;
  622. BOOL myB;
  623. myB = false;
  624. int myI[4];
  625. myI[0] = 13;
  626. myI[1] = 14;
  627. myI[2] = 15;
  628. myI[3] = 16;
  629. switch (vconst.type)
  630. {
  631. case CommandBufferCompiler::CT_BOOL:
  632. pCommandBufferDevice->SetVertexShaderConstantB(vconst.dwRegisterIndex, &myB, 1);
  633. break;
  634. case CommandBufferCompiler::CT_INT4:
  635. pCommandBufferDevice->SetVertexShaderConstantI(vconst.dwRegisterIndex, &myI[0], 1);
  636. break;
  637. default:
  638. pCommandBufferDevice->SetVertexShaderConstantF(vconst.dwRegisterIndex, tmp, 1);
  639. }
  640. }
  641. for (dword pconstIdx = 0; pconstIdx < shaderStates.ps_consts.Size(); pconstIdx++)
  642. {
  643. shaderConstant & pconst = shaderStates.ps_consts[pconstIdx];
  644. if (pconst.bPredefinedInShaderBody)
  645. {
  646. continue;
  647. }
  648. //api->Trace("p: %s\n", pconst.szName.c_str());
  649. float tmp[4];
  650. tmp[0] = 1.0f;
  651. tmp[1] = 2.0f;
  652. tmp[2] = 3.0f;
  653. tmp[3] = 4.0f;
  654. BOOL myB;
  655. myB = false;
  656. int myI[4];
  657. myI[0] = 13;
  658. myI[1] = 14;
  659. myI[2] = 15;
  660. myI[3] = 16;
  661. switch (pconst.type)
  662. {
  663. case CommandBufferCompiler::CT_BOOL:
  664. pCommandBufferDevice->SetPixelShaderConstantB(pconst.dwRegisterIndex, &myB, 1);
  665. break;
  666. case CommandBufferCompiler::CT_INT4:
  667. pCommandBufferDevice->SetPixelShaderConstantI(pconst.dwRegisterIndex, &myI[0], 1);
  668. break;
  669. default:
  670. pCommandBufferDevice->SetPixelShaderConstantF(pconst.dwRegisterIndex, tmp, 1);
  671. }
  672. }
  673. pCommandBufferDevice->SetVertexShader(shaderStates.pBoundedVS);
  674. pCommandBufferDevice->SetPixelShader(shaderStates.pBoundedPS);
  675. pBatch->DynamicDraw_SetVertexShader(shaderStates.pBoundedVS);
  676. pBatch->DynamicDraw_SetPixelShader(shaderStates.pBoundedPS);
  677. //because we have bound vertex shader...
  678. pCommandBufferDevice->SetVertexDeclaration(NULL);
  679. pCommandBufferDevice->SetIndices(fakeIb);
  680. pCommandBufferDevice->SetStreamSource(0, fakeVb, 0, 0);
  681. pCommandBufferDevice->SetStreamSource(1, fakeVb, 0, 0);
  682. pCommandBufferDevice->SetStreamSource(2, fakeVb, 0, 0);
  683. //pCommandBufferDevice->SetStreamSource(3, fakeVb, 0, 0);
  684. DWORD dwColorMask = D3DCOLORWRITEENABLE_ALL;
  685. DWORD dwDestBlend = D3DBLEND_INVSRCALPHA;
  686. DWORD dwSrcBlend = D3DBLEND_SRCALPHA;
  687. DWORD dwZWriteEnable = TRUE;
  688. DWORD dwAlphaTest = FALSE;
  689. DWORD dwAlphaBlend = FALSE;
  690. DWORD dwDepthFunc = D3DCMP_LESSEQUAL;
  691. BOOL dwZEnable = TRUE;
  692. pCommandBufferDevice->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALL);
  693. pCommandBufferDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
  694. pCommandBufferDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
  695. pCommandBufferDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
  696. pCommandBufferDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
  697. pCommandBufferDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
  698. pCommandBufferDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
  699. pCommandBufferDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
  700. for (dword stateIdx = 0; stateIdx < shaderStates.r_states.Size(); stateIdx++)
  701. {
  702. renderState & rs = shaderStates.r_states[stateIdx];
  703. pCommandBufferDevice->SetRenderState(rs.state, rs.val);
  704. pBatch->DynamicDraw_SetRenderState(rs.state, rs.val);
  705. if (rs.state == D3DRS_ALPHATESTENABLE)
  706. {
  707. dwAlphaTest = rs.val;
  708. }
  709. if (rs.state == D3DRS_ZWRITEENABLE)
  710. {
  711. dwZWriteEnable = rs.val;
  712. }
  713. if (rs.state == D3DRS_ALPHABLENDENABLE)
  714. {
  715. dwAlphaBlend = rs.val;
  716. }
  717. if (rs.state == D3DRS_DESTBLEND)
  718. {
  719. dwDestBlend = rs.val;
  720. }
  721. if (rs.state == D3DRS_SRCBLEND)
  722. {
  723. dwSrcBlend = rs.val;
  724. }
  725. if (rs.state == D3DRS_ZFUNC)
  726. {
  727. dwDepthFunc = rs.val;
  728. }
  729. if (rs.state == D3DRS_ZENABLE)
  730. {
  731. dwZEnable = rs.val;
  732. }
  733. if (rs.state == D3DRS_COLORWRITEENABLE)
  734. {
  735. dwColorMask = rs.val;
  736. }
  737. if (bLog)
  738. {
  739. DebugOut("SetRenderState (%d, %d)\n", rs.state, rs.val);
  740. }
  741. }
  742. pCommandBufferDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 0, 0, 2);
  743. pCommandBufferDevice->EndCommandBuffer();
  744. pBatch->offlineCreate(commandBuffer, shaderStates.pBoundedVS, shaderStates.pBoundedPS, bLog);
  745. if (bLog)
  746. {
  747. int a = 0;
  748. }
  749. pBatch->SetColorMask (dwColorMask);
  750. pBatch->SetZEnable(dwZEnable, dwZWriteEnable);
  751. if (dwDepthFunc == D3DCMP_LESSEQUAL)
  752. {
  753. pBatch->SetHyperZEnable(dwZEnable, dwZWriteEnable);
  754. }
  755. else if (dwDepthFunc == D3DCMP_ALWAYS)
  756. {
  757. pBatch->SetHyperZEnable(false, dwZWriteEnable);
  758. } else
  759. {
  760. pBatch->SetHyperZEnable(false, false);
  761. }
  762. if (dwAlphaBlend == FALSE)
  763. {
  764. dwSrcBlend = D3DBLEND_ONE;
  765. dwDestBlend = D3DBLEND_ZERO;
  766. }
  767. pBatch->SetBlendOp((GPUBLEND)dwSrcBlend, (GPUBLEND)dwDestBlend);
  768. pBatch->SetVertexShaderPtr(shaderStates.pBoundedVS);
  769. pBatch->SetPixelShaderPtr(shaderStates.pBoundedPS);
  770. pBatch->Freeze();
  771. pBatch->debugOutCommandBuffer(pBatch->getPhysicalBytes(), bLog);
  772. dwHeaderSize = 0;
  773. dwPhysicalSize = 0;
  774. dwInitializationSize = 0;
  775. //}
  776. //for (dword passIdx = 0; passIdx < passes.Size(); passIdx++)
  777. //{
  778. //;
  779. for (DWORD tmp = 0; tmp < shaderStates.vs_consts.Size(); tmp++)
  780. {
  781. shaderConstant & sc = shaderStates.vs_consts[tmp];
  782. if (sc.bPredefinedInShaderBody)
  783. {
  784. continue;
  785. }
  786. switch (sc.type)
  787. {
  788. case CommandBufferCompiler::CT_BOOL:
  789. pBatch->AddVertexShaderConstBool(sc.szName, sc.dwRegisterIndex, sc.dwRegisterCounts);
  790. break;
  791. case CommandBufferCompiler::CT_INT4:
  792. Assert(false);
  793. break;
  794. default:
  795. pBatch->AddVertexShaderConstVector(sc.szName, sc.dwRegisterIndex, sc.dwRegisterCounts);
  796. }
  797. }
  798. for (DWORD tmp = 0; tmp < shaderStates.ps_consts.Size(); tmp++)
  799. {
  800. shaderConstant & sc = shaderStates.ps_consts[tmp];
  801. if (sc.bPredefinedInShaderBody)
  802. {
  803. continue;
  804. }
  805. switch (sc.type)
  806. {
  807. case CommandBufferCompiler::CT_BOOL:
  808. pBatch->AddPixelShaderConstBool(sc.szName, sc.dwRegisterIndex, sc.dwRegisterCounts);
  809. break;
  810. case CommandBufferCompiler::CT_INT4:
  811. Assert(false);
  812. break;
  813. default:
  814. pBatch->AddPixelShaderConstVector(sc.szName, sc.dwRegisterIndex, sc.dwRegisterCounts);
  815. }
  816. }
  817. for (DWORD tmp = 0; tmp < shaderStates.textures.Size(); tmp++)
  818. {
  819. texture & tx = shaderStates.textures[tmp];
  820. pBatch->AddTextureSampler(tx.variableName, tx.dwStage, tx.minFilter, tx.magFilter, tx.mipFilter, tx.clampU, tx.clampV);
  821. }
  822. //}
  823. pBatch->InsertPrefetchFiller();
  824. commandBuffer->Release();
  825. commandBuffer = NULL;
  826. fakeIb->Release();
  827. fakeIb = NULL;
  828. fakeVb->Release();
  829. fakeVb = NULL;
  830. }
  831. void CommandBufferCompiler::ExtractTexture (DWORD dwIndex, const char* texvariableName)
  832. {
  833. dword dwIdx = INVALID_ARRAY_INDEX;
  834. for (dword i = 0; i < shaderStates.textures.Size(); i++)
  835. {
  836. if (shaderStates.textures[i].dwStage == dwIndex)
  837. {
  838. dwIdx = i;
  839. break;
  840. }
  841. }
  842. if (dwIdx == INVALID_ARRAY_INDEX)
  843. {
  844. dwIdx = shaderStates.textures.Add();
  845. }
  846. texture & tex = shaderStates.textures[dwIdx];
  847. tex.dwStage = dwIndex;
  848. tex.variableName = texvariableName;
  849. }
  850. #endif