From 9ed7a53b4cb45f82478a8c1b3b8cd0d160c5fe6e Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Thu, 24 Jul 2025 20:14:52 +0300 Subject: [PATCH] Fix validation errors in Agility SDK 1.616.1. --- UnleashedRecomp/gpu/rhi/plume_d3d12.cpp | 8 ++++- UnleashedRecomp/gpu/video.cpp | 40 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/UnleashedRecomp/gpu/rhi/plume_d3d12.cpp b/UnleashedRecomp/gpu/rhi/plume_d3d12.cpp index 073ea68..5a6c846 100644 --- a/UnleashedRecomp/gpu/rhi/plume_d3d12.cpp +++ b/UnleashedRecomp/gpu/rhi/plume_d3d12.cpp @@ -1566,6 +1566,10 @@ namespace plume { auto makeBarrier = [&](ID3D12Resource *resource, D3D12_RESOURCE_STATES stateBefore, D3D12_RESOURCE_STATES stateAfter, bool supportsUAV, D3D12_RESOURCE_BARRIER &resourceBarrier) { resourceBarrier = {}; + if (type == RenderCommandListType::COPY) { + return false; + } + if (stateBefore != stateAfter) { resourceBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; resourceBarrier.Transition.StateBefore = stateBefore; @@ -2228,11 +2232,13 @@ namespace plume { this->device = device; - HRESULT res = device->d3d->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d)); + HRESULT res = device->d3d->CreateFence(1, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d)); if (FAILED(res)) { fprintf(stderr, "CreateFence failed with error code 0x%lX.\n", res); return; } + + semaphoreValue = 1; } D3D12CommandSemaphore::~D3D12CommandSemaphore() { diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 2333dfb..ad5b3e5 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -315,6 +315,10 @@ static std::unique_ptr g_copyQueue; static std::unique_ptr g_copyCommandList; static std::unique_ptr g_copyCommandFence; +static Mutex g_discardMutex; +static std::unique_ptr g_discardCommandList; +static std::unique_ptr g_discardCommandFence; + static std::unique_ptr g_swapChain; static bool g_swapChainValid; @@ -1849,6 +1853,12 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver, bool graphicsApiRetry) g_copyCommandList = g_device->createCommandList(RenderCommandListType::COPY); g_copyCommandFence = g_device->createCommandFence(); + if (!g_vulkan) + { + g_discardCommandList = g_device->createCommandList(RenderCommandListType::DIRECT); + g_discardCommandFence = g_device->createCommandFence(); + } + uint32_t bufferCount = 2; switch (Config::TripleBuffering) @@ -3093,6 +3103,27 @@ static RenderFormat ConvertFormat(uint32_t format) } } +static void DiscardTexture(GuestBaseTexture* texture, RenderTextureLayout layout) +{ + if (!g_vulkan) + { + std::lock_guard lock(g_discardMutex); + + g_discardCommandList->begin(); + if (texture->layout != layout) + { + g_discardCommandList->barriers(RenderBarrierStage::GRAPHICS, RenderTextureBarrier(texture->texture, layout)); + texture->layout = layout; + } + + g_discardCommandList->discardTexture(texture->texture); + g_discardCommandList->end(); + + g_queue->executeCommandLists(g_discardCommandList.get(), g_discardCommandFence.get()); + g_queue->waitForCommandFence(g_discardCommandFence.get()); + } +} + 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) { const auto texture = g_userHeap.AllocPhysical(type == 17 ? ResourceType::VolumeTexture : ResourceType::Texture); @@ -3150,6 +3181,12 @@ static GuestTexture* CreateTexture(uint32_t width, uint32_t height, uint32_t dep texture->texture->setName(fmt::format("Texture {:X}", g_memory.MapVirtual(texture))); #endif + if (desc.flags != RenderTextureFlag::NONE) + { + DiscardTexture(texture, desc.flags == RenderTextureFlag::RENDER_TARGET ? + RenderTextureLayout::COLOR_WRITE : RenderTextureLayout::DEPTH_WRITE); + } + return texture; } @@ -3218,6 +3255,9 @@ static GuestSurface* CreateSurface(uint32_t width, uint32_t height, uint32_t for surface->texture->setName(fmt::format("{} {:X}", desc.flags & RenderTextureFlag::RENDER_TARGET ? "Render Target" : "Depth Stencil", g_memory.MapVirtual(surface))); #endif + DiscardTexture(surface, desc.flags == RenderTextureFlag::RENDER_TARGET ? + RenderTextureLayout::COLOR_WRITE : RenderTextureLayout::DEPTH_WRITE); + return surface; }