d3d12: Suballocate from big buffer for texture upload too

This commit is contained in:
Vincent Lejeune 2015-09-27 19:04:33 +02:00
parent f1f31e22f9
commit 07e13b8613
3 changed files with 16 additions and 35 deletions

View File

@ -278,7 +278,7 @@ D3D12GSRender::D3D12GSRender()
m_constantsData.Init(m_device.Get(), 1024 * 1024 * 64, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
m_vertexIndexData.Init(m_device.Get(), 1024 * 1024 * 384, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
m_textureUploadData.Init(m_device.Get(), 1024 * 1024 * 256, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS);
m_textureUploadData.Init(m_device.Get(), 1024 * 1024 * 256, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
if (Ini.GSOverlay.GetValue())
InitD2DStructures();
@ -705,7 +705,7 @@ void D3D12GSRender::Flip()
size_t w = 0, h = 0, rowPitch = 0;
ID3D12Resource *stagingTexture;
size_t offset = 0;
if (m_read_buffer)
{
CellGcmDisplayInfo* buffers = vm::get_ptr<CellGcmDisplayInfo>(m_gcm_buffers_addr);
@ -719,21 +719,13 @@ void D3D12GSRender::Flip()
assert(m_textureUploadData.canAlloc(textureSize));
size_t heapOffset = m_textureUploadData.alloc(textureSize);
ThrowIfFailed(m_device->CreatePlacedResource(
m_textureUploadData.m_heap,
heapOffset,
&CD3DX12_RESOURCE_DESC::Buffer(textureSize),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(&stagingTexture)
));
getCurrentResourceStorage().m_singleFrameLifetimeResources.push_back(stagingTexture);
void *dstBuffer;
ThrowIfFailed(stagingTexture->Map(0, nullptr, &dstBuffer));
void *buffer;
ThrowIfFailed(m_textureUploadData.m_heap->Map(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize), &buffer));
void *dstBuffer = (char*)buffer + heapOffset;
for (unsigned row = 0; row < h; row++)
memcpy((char*)dstBuffer + row * rowPitch, (char*)src_buffer + row * w * 4, w * 4);
stagingTexture->Unmap(0, nullptr);
m_textureUploadData.m_heap->Unmap(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize));
offset = heapOffset;
}
ThrowIfFailed(
@ -747,7 +739,7 @@ void D3D12GSRender::Flip()
)
);
getCurrentResourceStorage().m_commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(storage.m_RAMFramebuffer.Get(), 0), 0, 0, 0,
&CD3DX12_TEXTURE_COPY_LOCATION(stagingTexture, { 0, { DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)w, (UINT)h, 1, (UINT)rowPitch} }), nullptr);
&CD3DX12_TEXTURE_COPY_LOCATION(m_textureUploadData.m_heap, { offset, { DXGI_FORMAT_R8G8B8A8_UNORM, (UINT)w, (UINT)h, 1, (UINT)rowPitch} }), nullptr);
getCurrentResourceStorage().m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(storage.m_RAMFramebuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ));
resourceToFlip = storage.m_RAMFramebuffer.Get();

View File

@ -334,7 +334,7 @@ private:
// Vertex storage
DataHeap<ID3D12Resource, 65536> m_vertexIndexData;
// Texture storage
DataHeap<ID3D12Heap, 65536> m_textureUploadData;
DataHeap<ID3D12Resource, 65536> m_textureUploadData;
DataHeap<ID3D12Heap, 65536> m_UAVHeap;
DataHeap<ID3D12Heap, 65536> m_readbackResources;

View File

@ -394,8 +394,7 @@ ID3D12Resource *uploadSingleTexture(
const RSXTexture &texture,
ID3D12Device *device,
ID3D12GraphicsCommandList *commandList,
DataHeap<ID3D12Heap, 65536> &textureBuffersHeap,
std::vector<ComPtr<ID3D12Resource> > &stagingRamTexture)
DataHeap<ID3D12Resource, 65536> &textureBuffersHeap)
{
ID3D12Resource *vramTexture;
size_t w = texture.GetWidth(), h = texture.GetHeight();
@ -550,24 +549,14 @@ ID3D12Resource *uploadSingleTexture(
// Multiple of 256
size_t rowPitch = align(blockSizeInByte * widthInBlocks, 256);
ComPtr<ID3D12Resource> Texture;
size_t textureSize = rowPitch * heightInBlocks * 2; // * 4 for mipmap levels
assert(textureBuffersHeap.canAlloc(textureSize));
size_t heapOffset = textureBuffersHeap.alloc(textureSize);
ThrowIfFailed(device->CreatePlacedResource(
textureBuffersHeap.m_heap,
heapOffset,
&CD3DX12_RESOURCE_DESC::Buffer(textureSize),
D3D12_RESOURCE_STATE_GENERIC_READ,
nullptr,
IID_PPV_ARGS(Texture.GetAddressOf())
));
stagingRamTexture.push_back(Texture);
auto pixels = vm::get_ptr<const u8>(texaddr);
void *textureData;
ThrowIfFailed(Texture->Map(0, nullptr, (void**)&textureData));
void *buffer;
ThrowIfFailed(textureBuffersHeap.m_heap->Map(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize), &buffer));
void *textureData = (char*)buffer + heapOffset;
std::vector<MipmapLevelInfo> mipInfos;
switch (format)
@ -608,7 +597,7 @@ ID3D12Resource *uploadSingleTexture(
break;
}
}
Texture->Unmap(0, nullptr);
textureBuffersHeap.m_heap->Unmap(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize));
D3D12_RESOURCE_DESC texturedesc = CD3DX12_RESOURCE_DESC::Tex2D(dxgiFormat, (UINT)w, (UINT)h, 1, texture.GetMipmap());
textureSize = device->GetResourceAllocationInfo(0, 1, &texturedesc).SizeInBytes;
@ -626,7 +615,7 @@ ID3D12Resource *uploadSingleTexture(
for (const MipmapLevelInfo mli : mipInfos)
{
commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(vramTexture, (UINT)miplevel), 0, 0, 0,
&CD3DX12_TEXTURE_COPY_LOCATION(Texture.Get(), { mli.offset, { dxgiFormat, (UINT)mli.width, (UINT)mli.height, 1, (UINT)mli.rowPitch } }), nullptr);
&CD3DX12_TEXTURE_COPY_LOCATION(textureBuffersHeap.m_heap, { heapOffset + mli.offset, { dxgiFormat, (UINT)mli.width, (UINT)mli.height, 1, (UINT)mli.rowPitch } }), nullptr);
miplevel++;
}
@ -738,7 +727,7 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist)
}
else
{
vramTexture = uploadSingleTexture(m_textures[i], m_device.Get(), cmdlist, m_textureUploadData, getCurrentResourceStorage().m_singleFrameLifetimeResources);
vramTexture = uploadSingleTexture(m_textures[i], m_device.Get(), cmdlist, m_textureUploadData);
m_texturesCache[texaddr] = vramTexture;
u32 s = (u32)align(getTextureSize(m_textures[i]), 4096);