@@ -315,6 +315,10 @@ static std::unique_ptr<RenderCommandQueue> g_copyQueue;
315315static std::unique_ptr<RenderCommandList> g_copyCommandList;
316316static 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+
318322static std::unique_ptr<RenderSwapChain> g_swapChain;
319323static 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+
30963127static 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