mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-13 16:18:56 +00:00
d3d12: Suballocate from big buffer for texture upload too
This commit is contained in:
parent
f1f31e22f9
commit
07e13b8613
@ -278,7 +278,7 @@ D3D12GSRender::D3D12GSRender()
|
|||||||
|
|
||||||
m_constantsData.Init(m_device.Get(), 1024 * 1024 * 64, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_FLAG_NONE);
|
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_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())
|
if (Ini.GSOverlay.GetValue())
|
||||||
InitD2DStructures();
|
InitD2DStructures();
|
||||||
@ -705,7 +705,7 @@ void D3D12GSRender::Flip()
|
|||||||
|
|
||||||
size_t w = 0, h = 0, rowPitch = 0;
|
size_t w = 0, h = 0, rowPitch = 0;
|
||||||
|
|
||||||
ID3D12Resource *stagingTexture;
|
size_t offset = 0;
|
||||||
if (m_read_buffer)
|
if (m_read_buffer)
|
||||||
{
|
{
|
||||||
CellGcmDisplayInfo* buffers = vm::get_ptr<CellGcmDisplayInfo>(m_gcm_buffers_addr);
|
CellGcmDisplayInfo* buffers = vm::get_ptr<CellGcmDisplayInfo>(m_gcm_buffers_addr);
|
||||||
@ -719,21 +719,13 @@ void D3D12GSRender::Flip()
|
|||||||
assert(m_textureUploadData.canAlloc(textureSize));
|
assert(m_textureUploadData.canAlloc(textureSize));
|
||||||
size_t heapOffset = m_textureUploadData.alloc(textureSize);
|
size_t heapOffset = m_textureUploadData.alloc(textureSize);
|
||||||
|
|
||||||
ThrowIfFailed(m_device->CreatePlacedResource(
|
void *buffer;
|
||||||
m_textureUploadData.m_heap,
|
ThrowIfFailed(m_textureUploadData.m_heap->Map(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize), &buffer));
|
||||||
heapOffset,
|
void *dstBuffer = (char*)buffer + 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));
|
|
||||||
for (unsigned row = 0; row < h; row++)
|
for (unsigned row = 0; row < h; row++)
|
||||||
memcpy((char*)dstBuffer + row * rowPitch, (char*)src_buffer + row * w * 4, w * 4);
|
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(
|
ThrowIfFailed(
|
||||||
@ -747,7 +739,7 @@ void D3D12GSRender::Flip()
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
getCurrentResourceStorage().m_commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(storage.m_RAMFramebuffer.Get(), 0), 0, 0, 0,
|
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));
|
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();
|
resourceToFlip = storage.m_RAMFramebuffer.Get();
|
||||||
|
@ -334,7 +334,7 @@ private:
|
|||||||
// Vertex storage
|
// Vertex storage
|
||||||
DataHeap<ID3D12Resource, 65536> m_vertexIndexData;
|
DataHeap<ID3D12Resource, 65536> m_vertexIndexData;
|
||||||
// Texture storage
|
// Texture storage
|
||||||
DataHeap<ID3D12Heap, 65536> m_textureUploadData;
|
DataHeap<ID3D12Resource, 65536> m_textureUploadData;
|
||||||
DataHeap<ID3D12Heap, 65536> m_UAVHeap;
|
DataHeap<ID3D12Heap, 65536> m_UAVHeap;
|
||||||
DataHeap<ID3D12Heap, 65536> m_readbackResources;
|
DataHeap<ID3D12Heap, 65536> m_readbackResources;
|
||||||
|
|
||||||
|
@ -394,8 +394,7 @@ ID3D12Resource *uploadSingleTexture(
|
|||||||
const RSXTexture &texture,
|
const RSXTexture &texture,
|
||||||
ID3D12Device *device,
|
ID3D12Device *device,
|
||||||
ID3D12GraphicsCommandList *commandList,
|
ID3D12GraphicsCommandList *commandList,
|
||||||
DataHeap<ID3D12Heap, 65536> &textureBuffersHeap,
|
DataHeap<ID3D12Resource, 65536> &textureBuffersHeap)
|
||||||
std::vector<ComPtr<ID3D12Resource> > &stagingRamTexture)
|
|
||||||
{
|
{
|
||||||
ID3D12Resource *vramTexture;
|
ID3D12Resource *vramTexture;
|
||||||
size_t w = texture.GetWidth(), h = texture.GetHeight();
|
size_t w = texture.GetWidth(), h = texture.GetHeight();
|
||||||
@ -550,24 +549,14 @@ ID3D12Resource *uploadSingleTexture(
|
|||||||
// Multiple of 256
|
// Multiple of 256
|
||||||
size_t rowPitch = align(blockSizeInByte * widthInBlocks, 256);
|
size_t rowPitch = align(blockSizeInByte * widthInBlocks, 256);
|
||||||
|
|
||||||
ComPtr<ID3D12Resource> Texture;
|
|
||||||
size_t textureSize = rowPitch * heightInBlocks * 2; // * 4 for mipmap levels
|
size_t textureSize = rowPitch * heightInBlocks * 2; // * 4 for mipmap levels
|
||||||
assert(textureBuffersHeap.canAlloc(textureSize));
|
assert(textureBuffersHeap.canAlloc(textureSize));
|
||||||
size_t heapOffset = textureBuffersHeap.alloc(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);
|
auto pixels = vm::get_ptr<const u8>(texaddr);
|
||||||
void *textureData;
|
void *buffer;
|
||||||
ThrowIfFailed(Texture->Map(0, nullptr, (void**)&textureData));
|
ThrowIfFailed(textureBuffersHeap.m_heap->Map(0, &CD3DX12_RANGE(heapOffset, heapOffset + textureSize), &buffer));
|
||||||
|
void *textureData = (char*)buffer + heapOffset;
|
||||||
std::vector<MipmapLevelInfo> mipInfos;
|
std::vector<MipmapLevelInfo> mipInfos;
|
||||||
|
|
||||||
switch (format)
|
switch (format)
|
||||||
@ -608,7 +597,7 @@ ID3D12Resource *uploadSingleTexture(
|
|||||||
break;
|
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());
|
D3D12_RESOURCE_DESC texturedesc = CD3DX12_RESOURCE_DESC::Tex2D(dxgiFormat, (UINT)w, (UINT)h, 1, texture.GetMipmap());
|
||||||
textureSize = device->GetResourceAllocationInfo(0, 1, &texturedesc).SizeInBytes;
|
textureSize = device->GetResourceAllocationInfo(0, 1, &texturedesc).SizeInBytes;
|
||||||
@ -626,7 +615,7 @@ ID3D12Resource *uploadSingleTexture(
|
|||||||
for (const MipmapLevelInfo mli : mipInfos)
|
for (const MipmapLevelInfo mli : mipInfos)
|
||||||
{
|
{
|
||||||
commandList->CopyTextureRegion(&CD3DX12_TEXTURE_COPY_LOCATION(vramTexture, (UINT)miplevel), 0, 0, 0,
|
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++;
|
miplevel++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,7 +727,7 @@ size_t D3D12GSRender::UploadTextures(ID3D12GraphicsCommandList *cmdlist)
|
|||||||
}
|
}
|
||||||
else
|
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;
|
m_texturesCache[texaddr] = vramTexture;
|
||||||
|
|
||||||
u32 s = (u32)align(getTextureSize(m_textures[i]), 4096);
|
u32 s = (u32)align(getTextureSize(m_textures[i]), 4096);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user