Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. // Load texture from DDS.
  2. {
  3. std::unique_ptr<uint8_t[]> ddsData;
  4. std::vector<D3D12_SUBRESOURCE_DATA> subresouceData;
  5. ThrowIfFailed(LoadDDSTextureFromFile(m_device.Get(),
  6. L"test.DDS",
  7. &m_texture,
  8. ddsData,
  9. subresouceData));
  10. D3D12_RESOURCE_DESC textureDesc = m_texture->GetDesc();
  11.  
  12. const UINT subresoucesize
  13. = static_cast<UINT>(subresouceData.size());
  14. const UINT64 uploadBufferSize
  15. = GetRequiredIntermediateSize(m_texture.Get(), 0, subresoucesize);
  16.  
  17. // Create the GPU upload buffer.
  18. ThrowIfFailed(m_device->CreateCommittedResource(
  19. &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
  20. D3D12_HEAP_FLAG_NONE,
  21. &CD3DX12_RESOURCE_DESC::Buffer(uploadBufferSize),
  22. D3D12_RESOURCE_STATE_GENERIC_READ,
  23. nullptr,
  24. IID_PPV_ARGS(&textureUploadHeap)));
  25.  
  26. UpdateSubresources(m_commandList.Get(),
  27. m_texture.Get(),
  28. textureUploadHeap.Get(),
  29. 0,
  30. 0,
  31. subresoucesize,
  32. &subresouceData[0]);
  33. m_commandList->ResourceBarrier(1,
  34. &CD3DX12_RESOURCE_BARRIER::Transition(m_texture.Get(),
  35. D3D12_RESOURCE_STATE_COPY_DEST,
  36. D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
  37.  
  38. // Describe and create a SRV for the texture.
  39. D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
  40. srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
  41. srvDesc.Format = textureDesc.Format;
  42. srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
  43. srvDesc.Texture2D.MipLevels = subresoucesize;
  44. m_device->CreateShaderResourceView(m_texture.Get(),
  45. &srvDesc,
  46. m_srvHeap->GetCPUDescriptorHandleForHeapStart());
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement