D3D12 Texture Readback

Started by
-1 comments, last by Funkymunky 8 years, 7 months ago

Anyone had any success reading back texture data? I'm getting all black.

...


	ThrowIfFailed(device->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_READBACK), D3D12_HEAP_FLAG_NONE, &CD3DX12_RESOURCE_DESC::Buffer(readbackBufferSize), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&textureReadback)));

	D3D12_TEXTURE_COPY_LOCATION source;
	source.pResource = texture.Get();
	source.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
	source.SubresourceIndex = 0;

	D3D12_TEXTURE_COPY_LOCATION dest;
	dest.pResource = textureReadback.Get();
	dest.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
	dest.PlacedFootprint.Offset = 0;
	dest.PlacedFootprint.Footprint.Format = GetPixelFormat(descriptor);
	dest.PlacedFootprint.Footprint.Width = descriptor.width;
	dest.PlacedFootprint.Footprint.Height = descriptor.height;
	dest.PlacedFootprint.Footprint.Depth = 1;
	dest.PlacedFootprint.Footprint.RowPitch = descriptor.width * BytesPerPixel;

	list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(texture.Get(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_COPY_SOURCE));
	list->CopyTextureRegion(&dest, 0, 0, 0, &source, nullptr);
	list->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(texture.Get(), D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));

...

After this I use a fence and wait for it to complete, then I call Map on the textureReadback and memcpy the data to the buffer I want it in. And it's all zeros.

This topic is closed to new replies.

Advertisement