<p>The problem was that I didn't call &quot;ExecuteCommandLists&quot; at the very end of function declaring and creating resources. I did execute command lists every frame but first I clear it and then record per frame commands.</p>
<p>Not sure why other stuff worked so far i.e. CBVs, device creation.</p>

CC BY-SA 4.0
2024-03-02T10:27:14.493Z
2024-03-02T10:27:14.493Z
DirectX_Programmer
<p>I'm having a problem with loading texture in DX12 with DirectXTK. It seems to be loading all the metadata, since in PIX, I can see bound resource with correct width/height and format. But it's entirely black as if data wasn't actually copied to the resource:</p>
<p><a href="https://i.sstatic.net/JNcff.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JNcff.png" alt="PIX" /></a></p>
<p>Code:</p>
<pre><code>// Resources
D3D12_DESCRIPTOR_HEAP_DESC srvHeapDesc = {};
srvHeapDesc.NumDescriptors = 1;
srvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
srvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
ThrowIfFailed(m_device-&gt;CreateDescriptorHeap(&amp;srvHeapDesc, IID_PPV_ARGS(&amp;m_srvHeap)));

ComPtr&lt;ID3D12Resource&gt; texture;
ComPtr&lt;ID3D12Resource&gt; uploadHeap;
const wchar_t* path = L&quot;C:\some_path\example_image.png&quot;; // Full file path

// Load file data and save to resource
std::unique_ptr&lt;uint8_t[]&gt; decodedData;
std::vector&lt;D3D12_SUBRESOURCE_DATA&gt; textureData;
D3D12_SUBRESOURCE_DATA textureDataSingle;
const CD3DX12_HEAP_PROPERTIES heapUpload = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);

HRESULT hr = LoadWICTextureFromFileEx(device, path, 0, flags, WIC_LOADER_DEFAULT, texture.ReleaseAndGetAddressOf(), decodedData, textureDataSingle);
ThrowIfFailed(hr);

const UINT64 uploadBufferSize = GetRequiredIntermediateSize(texture.Get(), 0, 1);
const CD3DX12_RESOURCE_DESC resourceDesc = CD3DX12_RESOURCE_DESC::Buffer(uploadBufferSize);

ThrowIfFailed(device-&gt;CreateCommittedResource(
    &amp;heapUpload,
    D3D12_HEAP_FLAG_NONE,
    &amp;resourceDesc,
    D3D12_RESOURCE_STATE_GENERIC_READ,
    nullptr,
    IID_PPV_ARGS(&amp;uploadHeap)
));

UpdateSubresources(commandList.Get(), texture.Get(), uploadHeap.Get(), 0, 0, 1, &amp;textureDataSingle);
const CD3DX12_RESOURCE_BARRIER barrier = CD3DX12_RESOURCE_BARRIER::Transition(texture.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
commandList-&gt;ResourceBarrier(1, &amp;barrier);

// Create SRV
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = { texture-&gt;GetDesc().Format, D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING };
srvDesc.Texture2D.MipLevels = 1;
CD3DX12_CPU_DESCRIPTOR_HANDLE srvHandle(srvHeap-&gt;GetCPUDescriptorHandleForHeapStart(), srvIndex, device-&gt;GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));
device-&gt;CreateShaderResourceView(texture.Get(), &amp;srvDesc, srvHandle);

// Binding
ID3D12DescriptorHeap* ppHeaps[] = { m_srvHeap.Get() };
m_commandList-&gt;SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);
CD3DX12_GPU_DESCRIPTOR_HANDLE srvHandle0(m_srvHeap-&gt;GetGPUDescriptorHandleForHeapStart(), 0, m_device-&gt;GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));
m_commandList-&gt;SetGraphicsRootDescriptorTable(3, srvHandle0);
</code></pre>

<texture><directx12>
Empty texture passed down to GPU in DirectX12
DirectX_Programmer
# Empty texture passed down to GPU in DirectX12

(Asked by: username_0 on 2024-03-01)

I'm having a problem with loading texture in DX12 with DirectXTK. It seems to be loading all the metadata, since in PIX, I can see bound resource with correct width/height and format. But it's entirely black as if data wasn't actually copied to the resource:

[![PIX](https://i.sstatic.net/JNcff.png)](https://i.sstatic.net/JNcff.png)

Code:

```
// Resources
D3D12_DESCRIPTOR_HEAP_DESC srvHeapDesc = {};
srvHeapDesc.NumDescriptors = 1;
srvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
srvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
ThrowIfFailed(m_device->CreateDescriptorHeap(&srvHeapDesc, IID_PPV_ARGS(&m_srvHeap)));

ComPtr<ID3D12Resource> texture;
ComPtr<ID3D12Resource> uploadHeap;
const wchar_t* path = L"C:\some_path\example_image.png"; // Full file path

// Load file data and save to resource
std::unique_ptr<uint8_t[]> decodedData;
std::vector<D3D12_SUBRESOURCE_DATA> textureData;
D3D12_SUBRESOURCE_DATA textureDataSingle;
const CD3DX12_HEAP_PROPERTIES heapUpload = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);

HRESULT hr = LoadWICTextureFromFileEx(device, path, 0, flags, WIC_LOADER_DEFAULT, texture.ReleaseAndGetAddressOf(), decodedData, textureDataSingle);
ThrowIfFailed(hr);

const UINT64 uploadBufferSize = GetRequiredIntermediateSize(texture.Get(), 0, 1);
const CD3DX12_RESOURCE_DESC resourceDesc = CD3DX12_RESOURCE_DESC::Buffer(uploadBufferSize);

ThrowIfFailed(device->CreateCommittedResource(
    &heapUpload,
    D3D12_HEAP_FLAG_NONE,
    &resourceDesc,
    D3D12_RESOURCE_STATE_GENERIC_READ,
    nullptr,
    IID_PPV_ARGS(&uploadHeap)
));

UpdateSubresources(commandList.Get(), texture.Get(), uploadHeap.Get(), 0, 0, 1, &textureDataSingle);
const CD3DX12_RESOURCE_BARRIER barrier = CD3DX12_RESOURCE_BARRIER::Transition(texture.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
commandList->ResourceBarrier(1, &barrier);

// Create SRV
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = { texture->GetDesc().Format, D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING };
srvDesc.Texture2D.MipLevels = 1;
CD3DX12_CPU_DESCRIPTOR_HANDLE srvHandle(srvHeap->GetCPUDescriptorHandleForHeapStart(), srvIndex, device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));
device->CreateShaderResourceView(texture.Get(), &srvDesc, srvHandle);

// Binding
ID3D12DescriptorHeap* ppHeaps[] = { m_srvHeap.Get() };
m_commandList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps);
CD3DX12_GPU_DESCRIPTOR_HANDLE srvHandle0(m_srvHeap->GetGPUDescriptorHandleForHeapStart(), 0, m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV));
m_commandList->SetGraphicsRootDescriptorTable(3, srvHandle0);

```

**Tags:** texture, directx12


---

## 1 answers

### Answer by username_0 on 2024-03-02. Score: 0 | Accepted answer

The problem was that I didn't call "ExecuteCommandLists" at the very end of function declaring and creating resources. I did execute command lists every frame but first I clear it and then record per frame commands.

Not sure why other stuff worked so far i.e. CBVs, device creation.


---

