CmD3D11Texture.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. #include "CmD3D11Texture.h"
  2. #include "CmD3D11Mappings.h"
  3. #include "CmD3D11Device.h"
  4. #include "CmD3D11RenderSystem.h"
  5. #include "CmException.h"
  6. #include "CmAsyncOp.h"
  7. #if CM_DEBUG_MODE
  8. #define THROW_IF_NOT_RENDER_THREAD throwIfNotRenderThread();
  9. #else
  10. #define THROW_IF_NOT_RENDER_THREAD
  11. #endif
  12. namespace CamelotEngine
  13. {
  14. D3D11Texture::D3D11Texture()
  15. : m1DTex(nullptr)
  16. , m2DTex(nullptr)
  17. , m3DTex(nullptr)
  18. , mTex(nullptr)
  19. , mShaderResourceView(nullptr)
  20. , mStagingBuffer(nullptr)
  21. , mLockedSubresourceIdx(-1)
  22. , mLockedForReading(false)
  23. , mStaticBuffer(nullptr)
  24. {
  25. }
  26. D3D11Texture::~D3D11Texture()
  27. {
  28. THROW_IF_NOT_RENDER_THREAD;
  29. freeInternalResources();
  30. }
  31. void D3D11Texture::copyImpl(TexturePtr& target)
  32. {
  33. D3D11Texture* other = static_cast<D3D11Texture*>(target.get());
  34. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  35. D3D11Device& device = rs->getPrimaryDevice();
  36. device.getImmediateContext()->CopyResource(other->getDX11Resource(), mTex);
  37. if (device.hasError())
  38. {
  39. String errorDescription = device.getErrorDescription();
  40. CM_EXCEPT(RenderingAPIException, "D3D11 device cannot copy resource\nError Description:" + errorDescription);
  41. }
  42. }
  43. PixelData D3D11Texture::lockImpl(GpuLockOptions options, UINT32 mipLevel, UINT32 face)
  44. {
  45. UINT32 mipWidth = mipLevel >> mWidth;
  46. UINT32 mipHeight = mipLevel >> mHeight;
  47. UINT32 mipDepth = mipLevel >> mDepth;
  48. PixelData lockedArea(mipWidth, mipHeight, mipDepth, mFormat);
  49. D3D11_MAP flags = D3D11Mappings::_getLockOptions(options);
  50. switch(options)
  51. {
  52. case GBL_WRITE_ONLY_NO_OVERWRITE:
  53. flags = D3D11_MAP_WRITE_NO_OVERWRITE;
  54. break;
  55. case GBL_READ_WRITE:
  56. flags = D3D11_MAP_READ_WRITE;
  57. break;
  58. case GBL_WRITE_ONLY_DISCARD:
  59. flags = D3D11_MAP_WRITE_DISCARD;
  60. break;
  61. case GBL_READ_ONLY:
  62. flags = D3D11_MAP_READ;
  63. break;
  64. case GBL_WRITE_ONLY:
  65. flags = D3D11_MAP_WRITE;
  66. break;
  67. default:
  68. break;
  69. };
  70. if(flags == D3D11_MAP_READ || flags == D3D11_MAP_READ_WRITE)
  71. {
  72. lockedArea.data = _mapstagingbuffer(flags, face, mipLevel);
  73. mLockedForReading = true;
  74. }
  75. else
  76. {
  77. if(mUsage == TU_DYNAMIC)
  78. lockedArea.data = _map(mTex, flags, face, mipLevel);
  79. else
  80. lockedArea.data = _mapstaticbuffer(lockedArea, mipLevel, face);
  81. mLockedForReading = false;
  82. }
  83. return lockedArea;
  84. }
  85. void D3D11Texture::unlockImpl()
  86. {
  87. if(mLockedForReading)
  88. _unmapstagingbuffer();
  89. else
  90. {
  91. if(mUsage == TU_DYNAMIC)
  92. _unmap(mTex);
  93. else
  94. _unmapstaticbuffer();
  95. }
  96. }
  97. void D3D11Texture::initialize_internal()
  98. {
  99. THROW_IF_NOT_RENDER_THREAD
  100. createInternalResources();
  101. Resource::initialize_internal();
  102. }
  103. void D3D11Texture::createInternalResourcesImpl()
  104. {
  105. // load based on tex.type
  106. switch (getTextureType())
  107. {
  108. case TEX_TYPE_1D:
  109. _create1DTex();
  110. break;
  111. case TEX_TYPE_2D:
  112. case TEX_TYPE_CUBE_MAP:
  113. _create2DTex();
  114. break;
  115. case TEX_TYPE_3D:
  116. _create3DTex();
  117. break;
  118. default:
  119. freeInternalResources();
  120. CM_EXCEPT(RenderingAPIException, "Unknown texture type");
  121. }
  122. }
  123. void D3D11Texture::freeInternalResourcesImpl()
  124. {
  125. SAFE_RELEASE(mTex);
  126. SAFE_RELEASE(mShaderResourceView);
  127. SAFE_RELEASE(m1DTex);
  128. SAFE_RELEASE(m2DTex);
  129. SAFE_RELEASE(m3DTex);
  130. SAFE_RELEASE(mStagingBuffer);
  131. }
  132. void D3D11Texture::_create1DTex()
  133. {
  134. // We must have those defined here
  135. assert(mWidth > 0);
  136. // Determine which D3D11 pixel format we'll use
  137. HRESULT hr;
  138. DXGI_FORMAT d3dPF = D3D11Mappings::_getPF(D3D11Mappings::_getClosestSupportedPF(mFormat));
  139. D3D11_TEXTURE1D_DESC desc;
  140. desc.Width = static_cast<UINT32>(mWidth);
  141. desc.ArraySize = 1;
  142. desc.Format = d3dPF;
  143. desc.MiscFlags = 0;
  144. if((mUsage & TU_RENDERTARGET) != 0)
  145. {
  146. desc.Usage = D3D11_USAGE_DEFAULT;
  147. desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
  148. desc.CPUAccessFlags = (mUsage & TU_RENDERTARGET) != 0 ? 0 : D3D11Mappings::_getAccessFlags(mUsage);
  149. desc.MipLevels = 1;
  150. }
  151. else
  152. {
  153. desc.Usage = D3D11Mappings::_getUsage(mUsage);
  154. desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
  155. desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage);
  156. // Determine total number of mipmaps including main one (d3d11 convention)
  157. UINT32 numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > mWidth) ? 0 : mNumMipmaps + 1;
  158. desc.MipLevels = numMips;
  159. }
  160. // Create the texture
  161. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  162. D3D11Device& device = rs->getPrimaryDevice();
  163. hr = device.getD3D11Device()->CreateTexture1D(&desc, nullptr, &m1DTex);
  164. // Check result and except if failed
  165. if (FAILED(hr) || device.hasError())
  166. {
  167. freeInternalResources();
  168. String errorDescription = device.getErrorDescription();
  169. CM_EXCEPT(RenderingAPIException, "Error creating texture\nError Description:" + errorDescription);
  170. }
  171. hr = m1DTex->QueryInterface(__uuidof(ID3D11Resource), (void **)mTex);
  172. if(FAILED(hr) || device.hasError())
  173. {
  174. freeInternalResources();
  175. String errorDescription = device.getErrorDescription();
  176. CM_EXCEPT(RenderingAPIException, "Can't get base texture\nError Description:" + errorDescription);
  177. }
  178. m1DTex->GetDesc(&desc);
  179. mNumMipmaps = desc.MipLevels - 1;
  180. // Create texture view
  181. ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
  182. mSRVDesc.Format = desc.Format;
  183. mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
  184. mSRVDesc.Texture1D.MipLevels = desc.MipLevels;
  185. hr = device.getD3D11Device()->CreateShaderResourceView(m1DTex, &mSRVDesc, &mShaderResourceView);
  186. if (FAILED(hr) || device.hasError())
  187. {
  188. String errorDescription = device.getErrorDescription();
  189. CM_EXCEPT(RenderingAPIException, "D3D11 device can't create shader resource view.\nError Description:" + errorDescription);
  190. }
  191. }
  192. void D3D11Texture::_create2DTex()
  193. {
  194. // We must have those defined here
  195. assert(mWidth > 0 || mHeight > 0);
  196. // Determine which D3D11 pixel format we'll use
  197. HRESULT hr;
  198. DXGI_FORMAT d3dPF = D3D11Mappings::_getPF(D3D11Mappings::_getClosestSupportedPF(mFormat));
  199. D3D11_TEXTURE2D_DESC desc;
  200. desc.Width = static_cast<UINT32>(mWidth);
  201. desc.Height = static_cast<UINT32>(mHeight);
  202. desc.ArraySize = 1;
  203. desc.Format = d3dPF;
  204. desc.MiscFlags = 0;
  205. if((mUsage & TU_RENDERTARGET) != 0)
  206. {
  207. desc.Usage = D3D11_USAGE_DEFAULT;
  208. desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
  209. desc.CPUAccessFlags = (mUsage & TU_RENDERTARGET) != 0 ? 0 : D3D11Mappings::_getAccessFlags(mUsage);
  210. desc.MipLevels = 1;
  211. DXGI_SAMPLE_DESC sampleDesc;
  212. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  213. rs->determineFSAASettings(mFSAA, mFSAAHint, d3dPF, &sampleDesc);
  214. desc.SampleDesc = sampleDesc;
  215. if(getTextureType() == TEX_TYPE_CUBE_MAP)
  216. {
  217. CM_EXCEPT(NotImplementedException, "Cube map not yet supported as a render target."); // TODO: Will be once I add proper texture array support
  218. }
  219. }
  220. else
  221. {
  222. desc.Usage = D3D11Mappings::_getUsage(mUsage);
  223. desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
  224. desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage);
  225. // Determine total number of mipmaps including main one (d3d11 convention)
  226. UINT32 numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > mWidth) ? 0 : mNumMipmaps + 1;
  227. desc.MipLevels = numMips;
  228. DXGI_SAMPLE_DESC sampleDesc;
  229. sampleDesc.Count = 1;
  230. sampleDesc.Quality = 0;
  231. desc.SampleDesc = sampleDesc;
  232. }
  233. if (getTextureType() == TEX_TYPE_CUBE_MAP)
  234. {
  235. desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
  236. desc.ArraySize = 6;
  237. }
  238. // Create the texture
  239. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  240. D3D11Device& device = rs->getPrimaryDevice();
  241. hr = device.getD3D11Device()->CreateTexture2D(&desc, nullptr, &m2DTex);
  242. // Check result and except if failed
  243. if (FAILED(hr) || device.hasError())
  244. {
  245. freeInternalResources();
  246. String errorDescription = device.getErrorDescription();
  247. CM_EXCEPT(RenderingAPIException, "Error creating texture\nError Description:" + errorDescription);
  248. }
  249. hr = m2DTex->QueryInterface(__uuidof(ID3D11Resource), (void **)mTex);
  250. if(FAILED(hr) || device.hasError())
  251. {
  252. freeInternalResources();
  253. String errorDescription = device.getErrorDescription();
  254. CM_EXCEPT(RenderingAPIException, "Can't get base texture\nError Description:" + errorDescription);
  255. }
  256. m2DTex->GetDesc(&desc);
  257. mNumMipmaps = desc.MipLevels - 1;
  258. // Create shader texture view
  259. ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
  260. mSRVDesc.Format = desc.Format;
  261. if((mUsage & TU_RENDERTARGET) != 0)
  262. {
  263. if(mFSAA > 0)
  264. {
  265. mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
  266. mSRVDesc.Texture2D.MostDetailedMip = 0;
  267. mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
  268. }
  269. else
  270. {
  271. mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
  272. mSRVDesc.Texture2D.MostDetailedMip = 0;
  273. mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
  274. }
  275. }
  276. else
  277. {
  278. switch(getTextureType())
  279. {
  280. case TEX_TYPE_CUBE_MAP:
  281. mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
  282. mSRVDesc.TextureCube.MipLevels = desc.MipLevels;
  283. mSRVDesc.TextureCube.MostDetailedMip = 0;
  284. break;
  285. case TEX_TYPE_2D:
  286. mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
  287. mSRVDesc.Texture2D.MostDetailedMip = 0;
  288. mSRVDesc.Texture2D.MipLevels = desc.MipLevels;
  289. break;
  290. }
  291. }
  292. hr = device.getD3D11Device()->CreateShaderResourceView(m2DTex, &mSRVDesc, &mShaderResourceView);
  293. if (FAILED(hr) || device.hasError())
  294. {
  295. String errorDescription = device.getErrorDescription();
  296. CM_EXCEPT(RenderingAPIException, "D3D11 device can't create shader resource view.\nError Description:" + errorDescription);
  297. }
  298. }
  299. void D3D11Texture::_create3DTex()
  300. {
  301. // We must have those defined here
  302. assert(mWidth > 0 && mHeight > 0 && mDepth > 0);
  303. // Determine which D3D11 pixel format we'll use
  304. HRESULT hr;
  305. DXGI_FORMAT d3dPF = D3D11Mappings::_getPF(D3D11Mappings::_getClosestSupportedPF(mFormat));
  306. D3D11_TEXTURE3D_DESC desc;
  307. desc.Width = static_cast<UINT32>(mWidth);
  308. desc.Height = static_cast<UINT32>(mHeight);
  309. desc.Depth = static_cast<UINT32>(mDepth);
  310. desc.Format = d3dPF;
  311. desc.MiscFlags = 0;
  312. if((mUsage & TU_RENDERTARGET) != 0)
  313. {
  314. desc.Usage = D3D11_USAGE_DEFAULT;
  315. desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
  316. desc.CPUAccessFlags = (mUsage & TU_RENDERTARGET) != 0 ? 0 : D3D11Mappings::_getAccessFlags(mUsage);
  317. desc.MipLevels = 1;
  318. }
  319. else
  320. {
  321. desc.Usage = D3D11Mappings::_getUsage(mUsage);
  322. desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
  323. desc.CPUAccessFlags = D3D11Mappings::_getAccessFlags(mUsage);
  324. // Determine total number of mipmaps including main one (d3d11 convention)
  325. UINT numMips = (mNumMipmaps == MIP_UNLIMITED || (1U << mNumMipmaps) > std::max(std::max(mWidth, mHeight), mDepth)) ? 0 : mNumMipmaps + 1;
  326. desc.MipLevels = numMips;
  327. }
  328. // Create the texture
  329. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  330. D3D11Device& device = rs->getPrimaryDevice();
  331. hr = device.getD3D11Device()->CreateTexture3D(&desc, nullptr, &m3DTex);
  332. // Check result and except if failed
  333. if (FAILED(hr) || device.hasError())
  334. {
  335. freeInternalResources();
  336. String errorDescription = device.getErrorDescription();
  337. CM_EXCEPT(RenderingAPIException, "Error creating texture\nError Description:" + errorDescription);
  338. }
  339. hr = m3DTex->QueryInterface(__uuidof(ID3D11Resource), (void **)mTex);
  340. if(FAILED(hr) || device.hasError())
  341. {
  342. freeInternalResources();
  343. String errorDescription = device.getErrorDescription();
  344. CM_EXCEPT(RenderingAPIException, "Can't get base texture\nError Description:" + errorDescription);
  345. }
  346. // Create texture view
  347. m3DTex->GetDesc(&desc);
  348. mNumMipmaps = desc.MipLevels - 1;
  349. ZeroMemory(&mSRVDesc, sizeof(mSRVDesc));
  350. mSRVDesc.Format = desc.Format;
  351. mSRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
  352. mSRVDesc.Texture3D.MostDetailedMip = 0;
  353. mSRVDesc.Texture3D.MipLevels = desc.MipLevels;
  354. hr = device.getD3D11Device()->CreateShaderResourceView(m2DTex, &mSRVDesc, &mShaderResourceView);
  355. if (FAILED(hr) || device.hasError())
  356. {
  357. String errorDescription = device.getErrorDescription();
  358. CM_EXCEPT(RenderingAPIException, "D3D11 device can't create shader resource view.\nError Description:" + errorDescription);
  359. }
  360. }
  361. void* D3D11Texture::_map(ID3D11Resource* res, D3D11_MAP flags, UINT32 mipLevel, UINT32 face)
  362. {
  363. D3D11_MAPPED_SUBRESOURCE pMappedResource;
  364. pMappedResource.pData = nullptr;
  365. mipLevel = Math::Clamp(mipLevel, (UINT32)mipLevel, getNumMipmaps());
  366. face = Math::Clamp(face, (UINT32)0, mDepth - 1);
  367. if(getTextureType() == TEX_TYPE_3D)
  368. face = 0;
  369. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  370. D3D11Device& device = rs->getPrimaryDevice();
  371. mLockedSubresourceIdx = D3D11CalcSubresource(mipLevel, face, getNumMipmaps()+1);
  372. device.getImmediateContext()->Map(res, mLockedSubresourceIdx, flags, 0, &pMappedResource);
  373. if (device.hasError())
  374. {
  375. String errorDescription = device.getErrorDescription();
  376. CM_EXCEPT(RenderingAPIException, "D3D11 device cannot map texture\nError Description:" + errorDescription);
  377. }
  378. return pMappedResource.pData;
  379. }
  380. void D3D11Texture::_unmap(ID3D11Resource* res)
  381. {
  382. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  383. D3D11Device& device = rs->getPrimaryDevice();
  384. device.getImmediateContext()->Unmap(res, mLockedSubresourceIdx);
  385. if (device.hasError())
  386. {
  387. String errorDescription = device.getErrorDescription();
  388. CM_EXCEPT(RenderingAPIException, "D3D11 device unmap resource\nError Description:" + errorDescription);
  389. }
  390. }
  391. void* D3D11Texture::_mapstagingbuffer(D3D11_MAP flags, UINT32 mipLevel, UINT32 face)
  392. {
  393. if(!mStagingBuffer)
  394. _createStagingBuffer();
  395. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  396. D3D11Device& device = rs->getPrimaryDevice();
  397. device.getImmediateContext()->CopyResource(mStagingBuffer, mTex);
  398. return _map(mStagingBuffer, flags, face, mipLevel);
  399. }
  400. void D3D11Texture::_unmapstagingbuffer()
  401. {
  402. _unmap(mStagingBuffer);
  403. }
  404. void* D3D11Texture::_mapstaticbuffer(PixelData lock, UINT32 mipLevel, UINT32 face)
  405. {
  406. UINT32 sizeOfImage = lock.getConsecutiveSize();
  407. mLockedSubresourceIdx = D3D11CalcSubresource(mipLevel, face, getNumMipmaps()+1);
  408. UINT8* bufferData = new UINT8[sizeOfImage];
  409. mStaticBuffer = new PixelData(lock.getWidth(), lock.getHeight(), lock.getDepth(), lock.getFormat(), bufferData, true);
  410. return bufferData;
  411. }
  412. void D3D11Texture::_unmapstaticbuffer()
  413. {
  414. UINT32 rowWidth = D3D11Mappings::_getSizeInBytes(mStaticBuffer->getFormat(), mStaticBuffer->getWidth());
  415. UINT32 sliceWidth = D3D11Mappings::_getSizeInBytes(mStaticBuffer->getFormat(), mStaticBuffer->getWidth(), mStaticBuffer->getHeight());
  416. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  417. D3D11Device& device = rs->getPrimaryDevice();
  418. device.getImmediateContext()->UpdateSubresource(mTex, mLockedSubresourceIdx, nullptr, mStaticBuffer->data, rowWidth, sliceWidth);
  419. if (device.hasError())
  420. {
  421. String errorDescription = device.getErrorDescription();
  422. CM_EXCEPT(RenderingAPIException, "D3D11 device cannot map texture\nError Description:" + errorDescription);
  423. }
  424. SAFE_DELETE(mStaticBuffer);
  425. }
  426. void D3D11Texture::_createStagingBuffer()
  427. {
  428. D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
  429. D3D11Device& device = rs->getPrimaryDevice();
  430. switch (getTextureType())
  431. {
  432. case TEX_TYPE_1D:
  433. {
  434. D3D11_TEXTURE1D_DESC desc;
  435. m1DTex->GetDesc(&desc);
  436. desc.BindFlags = 0;
  437. desc.MiscFlags = 0;
  438. desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
  439. desc.Usage = D3D11_USAGE_STAGING;
  440. device.getD3D11Device()->CreateTexture1D(&desc, NULL, (ID3D11Texture1D**)(&mStagingBuffer));
  441. }
  442. break;
  443. case TEX_TYPE_2D:
  444. case TEX_TYPE_CUBE_MAP:
  445. case TEX_TYPE_2D_ARRAY:
  446. {
  447. D3D11_TEXTURE2D_DESC desc;
  448. m2DTex->GetDesc(&desc);
  449. desc.BindFlags = 0;
  450. desc.MiscFlags = 0;
  451. desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
  452. desc.Usage = D3D11_USAGE_STAGING;
  453. device.getD3D11Device()->CreateTexture2D(&desc, NULL, (ID3D11Texture2D**)(&mStagingBuffer));
  454. }
  455. break;
  456. case TEX_TYPE_3D:
  457. {
  458. D3D11_TEXTURE3D_DESC desc;
  459. m3DTex->GetDesc(&desc);
  460. desc.BindFlags = 0;
  461. desc.MiscFlags = 0;
  462. desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
  463. desc.Usage = D3D11_USAGE_STAGING;
  464. device.getD3D11Device()->CreateTexture3D(&desc, NULL, (ID3D11Texture3D**)(&mStagingBuffer));
  465. }
  466. break;
  467. }
  468. }
  469. }
  470. #undef THROW_IF_NOT_RENDER_THREAD