Skip to content

Commit 0092935

Browse files
Merge branch 'main' into mem-alloc-check
2 parents 839bff7 + acf260a commit 0092935

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1056
-250
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,13 @@ FodyWeavers.xsd
397397

398398
# JetBrains Rider
399399
*.sln.iml
400+
401+
# IntelliJ IDEs
402+
.idea/
403+
404+
# macOS metadata
405+
*.DS_Store
406+
407+
# CMake Files
408+
**/cmake-build-debug
409+
**/CMakeCache.txt

UnleashedRecomp/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ set(UNLEASHED_RECOMP_USER_CXX_SOURCES
183183
"user/config.cpp"
184184
"user/registry.cpp"
185185
"user/paths.cpp"
186+
"user/persistent_data.cpp"
187+
"user/persistent_storage_manager.cpp"
186188
)
187189

188190
set(UNLEASHED_RECOMP_MOD_CXX_SOURCES
@@ -229,7 +231,8 @@ set(UNLEASHED_RECOMP_CXX_SOURCES
229231
"app.cpp"
230232
"exports.cpp"
231233
"main.cpp"
232-
"misc_impl.cpp"
234+
"misc_impl.cpp"
235+
"preload_executable.cpp"
233236
"sdl_listener.cpp"
234237
"stdafx.cpp"
235238
"version.cpp"
@@ -310,7 +313,11 @@ endif()
310313
if (UNLEASHED_RECOMP_D3D12)
311314
find_package(directx-headers CONFIG REQUIRED)
312315
find_package(directx12-agility CONFIG REQUIRED)
313-
target_compile_definitions(UnleashedRecomp PRIVATE UNLEASHED_RECOMP_D3D12)
316+
target_compile_definitions(UnleashedRecomp PRIVATE
317+
UNLEASHED_RECOMP_D3D12
318+
D3D12MA_USING_DIRECTX_HEADERS
319+
D3D12MA_OPTIONS16_SUPPORTED
320+
)
314321
endif()
315322

316323
if (CMAKE_SYSTEM_NAME MATCHES "Linux")

UnleashedRecomp/api/SWA/System/ApplicationDocument.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ namespace SWA
8080
boost::shared_ptr<Hedgehog::Mirage::CRenderScene> m_spRenderScene;
8181
SWA_INSERT_PADDING(0x04);
8282
boost::shared_ptr<CGameParameter> m_spGameParameter;
83-
SWA_INSERT_PADDING(0x78);
83+
SWA_INSERT_PADDING(0x0C);
84+
boost::anonymous_shared_ptr m_spItemParamManager;
85+
SWA_INSERT_PADDING(0x64);
8486
boost::shared_ptr<Hedgehog::Base::CCriticalSection> m_spCriticalSection;
85-
SWA_INSERT_PADDING(0x20);
87+
SWA_INSERT_PADDING(0x14);
88+
bool m_ShowDLCInfo;
89+
SWA_INSERT_PADDING(0x08);
8690
};
8791

8892
// TODO: Hedgehog::Base::TSynchronizedPtr<CApplicationDocument>
@@ -111,7 +115,9 @@ namespace SWA
111115
SWA_ASSERT_OFFSETOF(CApplicationDocument::CMember, m_Field10C, 0x10C);
112116
SWA_ASSERT_OFFSETOF(CApplicationDocument::CMember, m_spRenderScene, 0x12C);
113117
SWA_ASSERT_OFFSETOF(CApplicationDocument::CMember, m_spGameParameter, 0x138);
118+
SWA_ASSERT_OFFSETOF(CApplicationDocument::CMember, m_spItemParamManager, 0x14C);
114119
SWA_ASSERT_OFFSETOF(CApplicationDocument::CMember, m_spCriticalSection, 0x1B8);
120+
SWA_ASSERT_OFFSETOF(CApplicationDocument::CMember, m_ShowDLCInfo, 0x1D4);
115121
SWA_ASSERT_SIZEOF(CApplicationDocument::CMember, 0x1E0);
116122

117123
SWA_ASSERT_OFFSETOF(CApplicationDocument, m_pMember, 0x04);

UnleashedRecomp/api/SWA/System/GameParameter.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ namespace SWA
77
class CGameParameter // : public Hedgehog::Universe::CMessageActor
88
{
99
public:
10-
struct SSaveData;
10+
struct SSaveData
11+
{
12+
SWA_INSERT_PADDING(0x8600);
13+
be<uint32_t> DLCFlags[8];
14+
SWA_INSERT_PADDING(0x15C);
15+
};
16+
1117
struct SStageParameter;
1218

1319
SWA_INSERT_PADDING(0x94);
1420
xpointer<SSaveData> m_pSaveData;
1521
xpointer<SStageParameter> m_pStageParameter;
1622
};
23+
24+
SWA_ASSERT_OFFSETOF(CGameParameter::SSaveData, DLCFlags, 0x8600);
1725
}

UnleashedRecomp/apu/audio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
void XAudioInitializeSystem();
1111
void XAudioRegisterClient(PPCFunc* callback, uint32_t param);
1212
void XAudioSubmitFrame(void* samples);
13-
void XAudioConfigValueChangedCallback(class IConfigDef* configDef);
1413

1514
uint32_t XAudioRegisterRenderDriverClient(be<uint32_t>* callback, be<uint32_t>* driver);
1615
uint32_t XAudioUnregisterRenderDriverClient(uint32_t driver);

UnleashedRecomp/apu/driver/sdl2_driver.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,3 @@ void XAudioSubmitFrame(void* samples)
150150
SDL_QueueAudio(g_audioDevice, &audioFrames, sizeof(audioFrames));
151151
}
152152
}
153-
154-
void XAudioConfigValueChangedCallback(IConfigDef* configDef)
155-
{
156-
if (configDef == &Config::ChannelConfiguration)
157-
{
158-
if (g_audioThread->joinable())
159-
{
160-
g_audioThreadShouldExit = true;
161-
g_audioThread->join();
162-
}
163-
164-
CreateAudioDevice();
165-
CreateAudioThread();
166-
}
167-
}

UnleashedRecomp/gpu/rhi/plume_d3d12.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ namespace plume {
442442
return D3D12_HEAP_TYPE_UPLOAD;
443443
case RenderHeapType::READBACK:
444444
return D3D12_HEAP_TYPE_READBACK;
445+
case RenderHeapType::GPU_UPLOAD:
446+
return D3D12_HEAP_TYPE_GPU_UPLOAD;
445447
default:
446448
assert(false && "Unknown heap type.");
447449
return D3D12_HEAP_TYPE_DEFAULT;
@@ -2385,7 +2387,7 @@ namespace plume {
23852387
range.End = readRange->end;
23862388
}
23872389

2388-
void *outputData;
2390+
void *outputData = nullptr;
23892391
d3d->Map(subresource, (readRange != nullptr) ? &range : nullptr, &outputData);
23902392
return outputData;
23912393
}
@@ -2629,14 +2631,22 @@ namespace plume {
26292631

26302632
// D3D12Pool
26312633

2632-
D3D12Pool::D3D12Pool(D3D12Device *device, const RenderPoolDesc &desc) {
2634+
D3D12Pool::D3D12Pool(D3D12Device *device, const RenderPoolDesc &desc, bool gpuUploadHeapFallback) {
26332635
assert(device != nullptr);
26342636

26352637
this->device = device;
26362638
this->desc = desc;
26372639

26382640
D3D12MA::POOL_DESC poolDesc = {};
2639-
poolDesc.HeapProperties.Type = toD3D12(desc.heapType);
2641+
2642+
// When using an UMA architecture without explicit support for GPU Upload heaps, we instead just make a custom heap with the same properties as Upload heaps.
2643+
if ((desc.heapType == RenderHeapType::GPU_UPLOAD) && gpuUploadHeapFallback) {
2644+
poolDesc.HeapProperties = device->d3d->GetCustomHeapProperties(0, D3D12_HEAP_TYPE_UPLOAD);
2645+
}
2646+
else {
2647+
poolDesc.HeapProperties.Type = toD3D12(desc.heapType);
2648+
}
2649+
26402650
poolDesc.MinBlockCount = desc.minBlockCount;
26412651
poolDesc.MaxBlockCount = desc.maxBlockCount;
26422652
poolDesc.Flags |= desc.useLinearAlgorithm ? D3D12MA::POOL_FLAG_ALGORITHM_LINEAR : D3D12MA::POOL_FLAG_NONE;
@@ -3390,13 +3400,15 @@ namespace plume {
33903400
if (SUCCEEDED(res)) {
33913401
triangleFanSupportOption = d3d12Options15.TriangleFanSupported;
33923402
}
3393-
3394-
// Check if dynamic depth bias is supported.
3403+
3404+
// Check if dynamic depth bias and GPU upload heap are supported.
33953405
bool dynamicDepthBiasOption = false;
3406+
bool gpuUploadHeapOption = false;
33963407
D3D12_FEATURE_DATA_D3D12_OPTIONS16 d3d12Options16 = {};
33973408
res = deviceOption->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &d3d12Options16, sizeof(d3d12Options16));
33983409
if (SUCCEEDED(res)) {
33993410
dynamicDepthBiasOption = d3d12Options16.DynamicDepthBiasSupported;
3411+
gpuUploadHeapOption = d3d12Options16.GPUUploadHeapSupported;
34003412
}
34013413

34023414
// Check if the architecture has UMA.
@@ -3431,6 +3443,11 @@ namespace plume {
34313443
capabilities.triangleFan = triangleFanSupportOption;
34323444
capabilities.dynamicDepthBias = dynamicDepthBiasOption;
34333445
capabilities.uma = uma;
3446+
3447+
// Pretend GPU Upload heaps are supported if UMA is supported, as the backend has a workaround using a custom pool for it.
3448+
capabilities.gpuUploadHeap = uma || gpuUploadHeapOption;
3449+
gpuUploadHeapFallback = uma && !gpuUploadHeapOption;
3450+
34343451
description.name = deviceName;
34353452
description.dedicatedVideoMemory = adapterDesc.DedicatedVideoMemory;
34363453
description.vendor = RenderDeviceVendor(adapterDesc.VendorId);
@@ -3528,6 +3545,13 @@ namespace plume {
35283545
colorTargetHeapAllocator = std::make_unique<D3D12DescriptorHeapAllocator>(this, TargetDescriptorHeapSize, D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
35293546
depthTargetHeapAllocator = std::make_unique<D3D12DescriptorHeapAllocator>(this, TargetDescriptorHeapSize, D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
35303547

3548+
// Create the custom upload pool that will be used as the fallback when using an UMA architecture without explicit support for GPU Upload heaps.
3549+
if (gpuUploadHeapFallback) {
3550+
RenderPoolDesc poolDesc;
3551+
poolDesc.heapType = RenderHeapType::GPU_UPLOAD;
3552+
customUploadPool = std::make_unique<D3D12Pool>(this, poolDesc, true);
3553+
}
3554+
35313555
// Create a command queue only for retrieving the timestamp frequency. Delete it immediately afterwards.
35323556
std::unique_ptr<D3D12CommandQueue> timestampCommandQueue = std::make_unique<D3D12CommandQueue>(this, RenderCommandListType::DIRECT);
35333557
res = timestampCommandQueue->d3d->GetTimestampFrequency(&timestampFrequency);
@@ -3577,7 +3601,12 @@ namespace plume {
35773601
}
35783602

35793603
std::unique_ptr<RenderBuffer> D3D12Device::createBuffer(const RenderBufferDesc &desc) {
3580-
return std::make_unique<D3D12Buffer>(this, nullptr, desc);
3604+
if ((desc.heapType == RenderHeapType::GPU_UPLOAD) && gpuUploadHeapFallback) {
3605+
return std::make_unique<D3D12Buffer>(this, customUploadPool.get(), desc);
3606+
}
3607+
else {
3608+
return std::make_unique<D3D12Buffer>(this, nullptr, desc);
3609+
}
35813610
}
35823611

35833612
std::unique_ptr<RenderTexture> D3D12Device::createTexture(const RenderTextureDesc &desc) {
@@ -3589,7 +3618,7 @@ namespace plume {
35893618
}
35903619

35913620
std::unique_ptr<RenderPool> D3D12Device::createPool(const RenderPoolDesc &desc) {
3592-
return std::make_unique<D3D12Pool>(this, desc);
3621+
return std::make_unique<D3D12Pool>(this, desc, gpuUploadHeapFallback);
35933622
}
35943623

35953624
std::unique_ptr<RenderPipelineLayout> D3D12Device::createPipelineLayout(const RenderPipelineLayoutDesc &desc) {

UnleashedRecomp/gpu/rhi/plume_d3d12.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ namespace plume {
329329
D3D12Device *device = nullptr;
330330
RenderPoolDesc desc;
331331

332-
D3D12Pool(D3D12Device *device, const RenderPoolDesc &desc);
332+
D3D12Pool(D3D12Device *device, const RenderPoolDesc &desc, bool gpuUploadHeapFallback);
333333
~D3D12Pool() override;
334334
std::unique_ptr<RenderBuffer> createBuffer(const RenderBufferDesc &desc) override;
335335
std::unique_ptr<RenderTexture> createTexture(const RenderTextureDesc &desc) override;
@@ -430,9 +430,11 @@ namespace plume {
430430
std::unique_ptr<D3D12DescriptorHeapAllocator> samplerHeapAllocator;
431431
std::unique_ptr<D3D12DescriptorHeapAllocator> colorTargetHeapAllocator;
432432
std::unique_ptr<D3D12DescriptorHeapAllocator> depthTargetHeapAllocator;
433+
std::unique_ptr<D3D12Pool> customUploadPool;
433434
RenderDeviceCapabilities capabilities;
434435
RenderDeviceDescription description;
435436
uint64_t timestampFrequency = 1;
437+
bool gpuUploadHeapFallback = false;
436438

437439
D3D12Device(D3D12Interface *renderInterface, const std::string &preferredDeviceName);
438440
~D3D12Device() override;

UnleashedRecomp/gpu/rhi/plume_render_interface_types.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ namespace plume {
351351
UNKNOWN,
352352
DEFAULT,
353353
UPLOAD,
354-
READBACK
354+
READBACK,
355+
GPU_UPLOAD
355356
};
356357

357358
enum class RenderTextureArrangement {
@@ -1807,6 +1808,9 @@ namespace plume {
18071808

18081809
// UMA.
18091810
bool uma = false;
1811+
1812+
// GPU Upload heap.
1813+
bool gpuUploadHeap = false;
18101814
};
18111815

18121816
struct RenderInterfaceCapabilities {

UnleashedRecomp/gpu/rhi/plume_vulkan.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,12 @@ namespace plume {
808808
bufferInfo.usage |= VK_BUFFER_USAGE_TRANSFER_DST_BIT;
809809
createInfo.flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
810810
break;
811+
case RenderHeapType::GPU_UPLOAD:
812+
bufferInfo.usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
813+
bufferInfo.usage |= VK_BUFFER_USAGE_TRANSFER_DST_BIT;
814+
createInfo.flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
815+
createInfo.requiredFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
816+
break;
811817
default:
812818
assert(false && "Unknown heap type.");
813819
break;
@@ -833,7 +839,7 @@ namespace plume {
833839
}
834840

835841
if (res != VK_SUCCESS) {
836-
fprintf(stderr, "vkCreateBuffer failed with error code 0x%X.\n", res);
842+
fprintf(stderr, "vmaCreateBuffer failed with error code 0x%X.\n", res);
837843
return;
838844
}
839845
}
@@ -3887,6 +3893,15 @@ namespace plume {
38873893
VkDeviceSize memoryHeapSize = 0;
38883894
const VkPhysicalDeviceMemoryProperties *memoryProps = nullptr;
38893895
vmaGetMemoryProperties(allocator, &memoryProps);
3896+
3897+
constexpr VkMemoryPropertyFlags uploadHeapPropertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
3898+
bool hasHostVisibleDeviceLocalMemory = false;
3899+
for (uint32_t i = 0; i < memoryProps->memoryTypeCount; i++) {
3900+
if ((memoryProps->memoryTypes[i].propertyFlags & uploadHeapPropertyFlags) == uploadHeapPropertyFlags) {
3901+
hasHostVisibleDeviceLocalMemory = true;
3902+
}
3903+
}
3904+
38903905
for (uint32_t i = 0; i < memoryProps->memoryHeapCount; i++) {
38913906
if (memoryProps->memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) {
38923907
memoryHeapSize = std::max(memoryProps->memoryHeaps[i].size, memoryHeapSize);
@@ -3907,6 +3922,8 @@ namespace plume {
39073922
capabilities.preferHDR = memoryHeapSize > (512 * 1024 * 1024);
39083923
capabilities.triangleFan = true;
39093924
capabilities.dynamicDepthBias = true;
3925+
capabilities.uma = (description.type == RenderDeviceType::INTEGRATED) && hasHostVisibleDeviceLocalMemory;
3926+
capabilities.gpuUploadHeap = capabilities.uma;
39103927

39113928
// Fill Vulkan-only capabilities.
39123929
loadStoreOpNoneSupported = supportedOptionalExtensions.find(VK_EXT_LOAD_STORE_OP_NONE_EXTENSION_NAME) != supportedOptionalExtensions.end();

UnleashedRecomp/gpu/shader/csd_no_tex_vs.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void main(
4343
out float4 oColor0 : COLOR0,
4444
out float4 oColor1 : COLOR1)
4545
{
46-
oPos.xy = (iPosition0.xy - 0.5) * g_ViewportSize.zw * float2(2.0, -2.0) + float2(-1.0, 1.0);
46+
oPos.xy = iPosition0.xy * g_ViewportSize.zw * float2(2.0, -2.0) + float2(-1.0, 1.0);
4747
oPos.z = g_Z.x;
4848
oPos.w = 1.0;
4949
oTexCoord0 = iColor0.wxyz;

UnleashedRecomp/gpu/shader/csd_vs.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void main(
4444
out float4 oColor0 : COLOR0,
4545
out float4 oColor1 : COLOR1)
4646
{
47-
oPos.xy = (iPosition0.xy - 0.5) * g_ViewportSize.zw * float2(2.0, -2.0) + float2(-1.0, 1.0);
47+
oPos.xy = iPosition0.xy * g_ViewportSize.zw * float2(2.0, -2.0) + float2(-1.0, 1.0);
4848
oPos.z = g_Z.x;
4949
oPos.w = 1.0;
5050
oTexCoord0 = iColor0.wxyz;

UnleashedRecomp/gpu/shader/movie_vs.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Interpolators main(in VertexShaderInput In)
44
{
55
Interpolators Out;
66
Out.ProjPos = In.ObjPos;
7+
Out.ProjPos.xy += g_HalfPixelOffset * Out.ProjPos.w;
78
Out.UV = In.UV;
89
return Out;
910
}

0 commit comments

Comments
 (0)