Skip to content

Commit 9ed7a53

Browse files
Fix validation errors in Agility SDK 1.616.1.
1 parent ada0db6 commit 9ed7a53

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

UnleashedRecomp/gpu/rhi/plume_d3d12.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,10 @@ namespace plume {
15661566
auto makeBarrier = [&](ID3D12Resource *resource, D3D12_RESOURCE_STATES stateBefore, D3D12_RESOURCE_STATES stateAfter, bool supportsUAV, D3D12_RESOURCE_BARRIER &resourceBarrier) {
15671567
resourceBarrier = {};
15681568

1569+
if (type == RenderCommandListType::COPY) {
1570+
return false;
1571+
}
1572+
15691573
if (stateBefore != stateAfter) {
15701574
resourceBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
15711575
resourceBarrier.Transition.StateBefore = stateBefore;
@@ -2228,11 +2232,13 @@ namespace plume {
22282232

22292233
this->device = device;
22302234

2231-
HRESULT res = device->d3d->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d));
2235+
HRESULT res = device->d3d->CreateFence(1, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&d3d));
22322236
if (FAILED(res)) {
22332237
fprintf(stderr, "CreateFence failed with error code 0x%lX.\n", res);
22342238
return;
22352239
}
2240+
2241+
semaphoreValue = 1;
22362242
}
22372243

22382244
D3D12CommandSemaphore::~D3D12CommandSemaphore() {

UnleashedRecomp/gpu/video.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ static std::unique_ptr<RenderCommandQueue> g_copyQueue;
315315
static std::unique_ptr<RenderCommandList> g_copyCommandList;
316316
static std::unique_ptr<RenderCommandFence> g_copyCommandFence;
317317

318+
static Mutex g_discardMutex;
319+
static std::unique_ptr<RenderCommandList> g_discardCommandList;
320+
static std::unique_ptr<RenderCommandFence> g_discardCommandFence;
321+
318322
static std::unique_ptr<RenderSwapChain> g_swapChain;
319323
static bool g_swapChainValid;
320324

@@ -1849,6 +1853,12 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver, bool graphicsApiRetry)
18491853
g_copyCommandList = g_device->createCommandList(RenderCommandListType::COPY);
18501854
g_copyCommandFence = g_device->createCommandFence();
18511855

1856+
if (!g_vulkan)
1857+
{
1858+
g_discardCommandList = g_device->createCommandList(RenderCommandListType::DIRECT);
1859+
g_discardCommandFence = g_device->createCommandFence();
1860+
}
1861+
18521862
uint32_t bufferCount = 2;
18531863

18541864
switch (Config::TripleBuffering)
@@ -3093,6 +3103,27 @@ static RenderFormat ConvertFormat(uint32_t format)
30933103
}
30943104
}
30953105

3106+
static void DiscardTexture(GuestBaseTexture* texture, RenderTextureLayout layout)
3107+
{
3108+
if (!g_vulkan)
3109+
{
3110+
std::lock_guard lock(g_discardMutex);
3111+
3112+
g_discardCommandList->begin();
3113+
if (texture->layout != layout)
3114+
{
3115+
g_discardCommandList->barriers(RenderBarrierStage::GRAPHICS, RenderTextureBarrier(texture->texture, layout));
3116+
texture->layout = layout;
3117+
}
3118+
3119+
g_discardCommandList->discardTexture(texture->texture);
3120+
g_discardCommandList->end();
3121+
3122+
g_queue->executeCommandLists(g_discardCommandList.get(), g_discardCommandFence.get());
3123+
g_queue->waitForCommandFence(g_discardCommandFence.get());
3124+
}
3125+
}
3126+
30963127
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)
30973128
{
30983129
const auto texture = g_userHeap.AllocPhysical<GuestTexture>(type == 17 ? ResourceType::VolumeTexture : ResourceType::Texture);
@@ -3150,6 +3181,12 @@ static GuestTexture* CreateTexture(uint32_t width, uint32_t height, uint32_t dep
31503181
texture->texture->setName(fmt::format("Texture {:X}", g_memory.MapVirtual(texture)));
31513182
#endif
31523183

3184+
if (desc.flags != RenderTextureFlag::NONE)
3185+
{
3186+
DiscardTexture(texture, desc.flags == RenderTextureFlag::RENDER_TARGET ?
3187+
RenderTextureLayout::COLOR_WRITE : RenderTextureLayout::DEPTH_WRITE);
3188+
}
3189+
31533190
return texture;
31543191
}
31553192

@@ -3218,6 +3255,9 @@ static GuestSurface* CreateSurface(uint32_t width, uint32_t height, uint32_t for
32183255
surface->texture->setName(fmt::format("{} {:X}", desc.flags & RenderTextureFlag::RENDER_TARGET ? "Render Target" : "Depth Stencil", g_memory.MapVirtual(surface)));
32193256
#endif
32203257

3258+
DiscardTexture(surface, desc.flags == RenderTextureFlag::RENDER_TARGET ?
3259+
RenderTextureLayout::COLOR_WRITE : RenderTextureLayout::DEPTH_WRITE);
3260+
32213261
return surface;
32223262
}
32233263

0 commit comments

Comments
 (0)