Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Load texture from DDS.
- {
- std::unique_ptr<uint8_t[]> ddsData;
- std::vector<D3D12_SUBRESOURCE_DATA> subresouceData;
- ThrowIfFailed(LoadDDSTextureFromFile(m_device.Get(),
- L"test.DDS",
- &m_texture,
- ddsData,
- subresouceData));
- D3D12_RESOURCE_DESC textureDesc = m_texture->GetDesc();
- const UINT subresoucesize
- = static_cast<UINT>(subresouceData.size());
- const UINT64 uploadBufferSize
- = GetRequiredIntermediateSize(m_texture.Get(), 0, subresoucesize);
- // Create the GPU upload buffer.
- ThrowIfFailed(m_device->CreateCommittedResource(
- &CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),
- D3D12_HEAP_FLAG_NONE,
- &CD3DX12_RESOURCE_DESC::Buffer(uploadBufferSize),
- D3D12_RESOURCE_STATE_GENERIC_READ,
- nullptr,
- IID_PPV_ARGS(&textureUploadHeap)));
- UpdateSubresources(m_commandList.Get(),
- m_texture.Get(),
- textureUploadHeap.Get(),
- 0,
- 0,
- subresoucesize,
- &subresouceData[0]);
- m_commandList->ResourceBarrier(1,
- &CD3DX12_RESOURCE_BARRIER::Transition(m_texture.Get(),
- D3D12_RESOURCE_STATE_COPY_DEST,
- D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
- // Describe and create a SRV for the texture.
- D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
- srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
- srvDesc.Format = textureDesc.Format;
- srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
- srvDesc.Texture2D.MipLevels = subresoucesize;
- m_device->CreateShaderResourceView(m_texture.Get(),
- &srvDesc,
- m_srvHeap->GetCPUDescriptorHandleForHeapStart());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement