Skip to content

Commit 6b91977

Browse files
Fix validation errors in Agility SDK 1.616.1. (#207)
Co-authored-by: Skyth (Asilkan) <19259897+blueskythlikesclouds@users.noreply.github.com>
1 parent e1abe68 commit 6b91977

1 file changed

Lines changed: 46 additions & 17 deletions

File tree

MarathonRecomp/gpu/video.cpp

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ static std::unique_ptr<RenderCommandQueue> g_copyQueue;
362362
static std::unique_ptr<RenderCommandList> g_copyCommandList;
363363
static std::unique_ptr<RenderCommandFence> g_copyCommandFence;
364364

365+
static Mutex g_discardMutex;
366+
static std::unique_ptr<RenderCommandList> g_discardCommandList;
367+
static std::unique_ptr<RenderCommandFence> g_discardCommandFence;
368+
365369
static std::unique_ptr<RenderSwapChain> g_swapChain;
366370
static bool g_swapChainValid;
367371

@@ -1913,22 +1917,9 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver, bool graphicsApiRetry)
19131917
{
19141918
bool redirectToVulkan = false;
19151919

1916-
if (deviceDescription.vendor == RenderDeviceVendor::AMD)
1917-
{
1918-
// AMD Drivers before this version have a known issue where MSAA resolve targets will fail to work correctly.
1919-
// If no specific graphics API was selected, we silently destroy this one and move to the next option as it'll
1920-
// just work incorrectly otherwise and result in visual glitches and 3D rendering not working in general.
1921-
constexpr uint64_t MinimumAMDDriverVersion = 0x1F00005DC2005CULL; // 31.0.24002.92
1922-
if ((Config::GraphicsAPI == EGraphicsAPI::Auto) && (deviceDescription.driverVersion < MinimumAMDDriverVersion))
1923-
redirectToVulkan = true;
1924-
}
1925-
else if (deviceDescription.vendor == RenderDeviceVendor::INTEL)
1926-
{
1927-
// Intel drivers on D3D12 are extremely buggy, introducing various graphical glitches.
1928-
// We will redirect users to Vulkan until a workaround can be found.
1929-
if (Config::GraphicsAPI == EGraphicsAPI::Auto)
1930-
redirectToVulkan = true;
1931-
}
1920+
// ...
1921+
// There used to be driver redirections here, but they are all free from Vulkan purgatory for now...
1922+
// ...
19321923

19331924
if (redirectToVulkan)
19341925
{
@@ -2036,6 +2027,12 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver, bool graphicsApiRetry)
20362027
g_copyCommandList = g_copyQueue->createCommandList();
20372028
g_copyCommandFence = g_device->createCommandFence();
20382029

2030+
if (g_backend == Backend::D3D12)
2031+
{
2032+
g_discardCommandList = g_queue->createCommandList();
2033+
g_discardCommandFence = g_device->createCommandFence();
2034+
}
2035+
20392036
uint32_t bufferCount = 2;
20402037

20412038
switch (Config::TripleBuffering)
@@ -3400,6 +3397,27 @@ static RenderFormat ConvertFormat(uint32_t format)
34003397
}
34013398
}
34023399

3400+
static void DiscardTexture(GuestBaseTexture* texture, RenderTextureLayout layout)
3401+
{
3402+
if (g_backend == Backend::D3D12)
3403+
{
3404+
std::lock_guard lock(g_discardMutex);
3405+
3406+
g_discardCommandList->begin();
3407+
if (texture->layout != layout)
3408+
{
3409+
g_discardCommandList->barriers(RenderBarrierStage::GRAPHICS, RenderTextureBarrier(texture->texture, layout));
3410+
texture->layout = layout;
3411+
}
3412+
3413+
g_discardCommandList->discardTexture(texture->texture);
3414+
g_discardCommandList->end();
3415+
3416+
g_queue->executeCommandLists(g_discardCommandList.get(), g_discardCommandFence.get());
3417+
g_queue->waitForCommandFence(g_discardCommandFence.get());
3418+
}
3419+
}
3420+
34033421
static GuestTexture* CreateTexture(uint32_t width, uint32_t height, uint32_t depth, uint32_t levels, uint32_t usage, uint32_t format, uint32_t pool, uint32_t type)
34043422
{
34053423
ResourceType resourceType;
@@ -3474,10 +3492,17 @@ static GuestTexture* CreateTexture(uint32_t width, uint32_t height, uint32_t dep
34743492
texture->descriptorIndex = g_textureDescriptorAllocator.allocate();
34753493

34763494
g_textureDescriptorSet->setTexture(texture->descriptorIndex, texture->texture, RenderTextureLayout::SHADER_READ, texture->textureView.get());
3477-
3495+
34783496
#ifdef _DEBUG
34793497
texture->texture->setName(fmt::format("Texture {:X}", g_memory.MapVirtual(texture)));
34803498
#endif
3499+
3500+
if (desc.flags != RenderTextureFlag::NONE)
3501+
{
3502+
DiscardTexture(texture, desc.flags == RenderTextureFlag::RENDER_TARGET ?
3503+
RenderTextureLayout::COLOR_WRITE : RenderTextureLayout::DEPTH_WRITE);
3504+
}
3505+
34813506
// printf("CreateTexture: w: %d, h: %d, depth: %d, levels: %d, usage: %d, format: %d, pool: %d, type: %d - %x\n", width, height, depth, levels, usage, format, pool, type, texture);
34823507
return texture;
34833508
}
@@ -3573,6 +3598,10 @@ static GuestSurface* CreateSurface(uint32_t width, uint32_t height, uint32_t for
35733598
#ifdef _DEBUG
35743599
surface->texture->setName(fmt::format("{} {:X}", desc.flags & RenderTextureFlag::RENDER_TARGET ? "Render Target" : "Depth Stencil", g_memory.MapVirtual(surface)));
35753600
#endif
3601+
3602+
DiscardTexture(surface, desc.flags == RenderTextureFlag::RENDER_TARGET ?
3603+
RenderTextureLayout::COLOR_WRITE : RenderTextureLayout::DEPTH_WRITE);
3604+
35763605
if (params) {
35773606
surface->wasCached = true;
35783607
g_surfaceCache.emplace_back(surface, baseValue);

0 commit comments

Comments
 (0)