@@ -887,6 +887,7 @@ struct RenderCommand
887887 GuestDevice* device;
888888 uint32_t flags;
889889 GuestTexture* texture;
890+ uint32_t destSliceOrFace;
890891 } stretchRect;
891892
892893 struct
@@ -3196,6 +3197,7 @@ static GuestTexture* CreateTexture(uint32_t width, uint32_t height, uint32_t dep
31963197 texture->height = height;
31973198 texture->depth = depth;
31983199 texture->format = desc.format ;
3200+ texture->mipLevels = viewDesc.mipLevels ;
31993201 texture->viewDimension = viewDesc.dimension ;
32003202 texture->descriptorIndex = g_textureDescriptorAllocator.allocate ();
32013203
@@ -3332,13 +3334,14 @@ static void FlushViewport()
33323334 }
33333335}
33343336
3335- static void StretchRect (GuestDevice* device, uint32_t flags, uint32_t , GuestTexture* texture)
3337+ static void StretchRect (GuestDevice* device, uint32_t flags, uint32_t , GuestTexture* texture, uint32_t , uint32_t , uint32_t destSliceOrFace )
33363338{
33373339 // printf("StretchRect %x\n", texture);
33383340 RenderCommand cmd;
33393341 cmd.type = RenderCommandType::StretchRect;
33403342 cmd.stretchRect .flags = flags;
33413343 cmd.stretchRect .texture = texture;
3344+ cmd.stretchRect .destSliceOrFace = destSliceOrFace;
33423345 g_renderQueue.enqueue (cmd);
33433346}
33443347
@@ -3358,7 +3361,7 @@ static void ProcStretchRect(const RenderCommand& cmd)
33583361
33593362 args.texture ->sourceSurface = surface;
33603363 // printf("ProcStretchRect: surface - %x %x ? (%x : %x)\n", surface, isDepthStencil, g_depthStencil, g_renderTarget);
3361- surface->destinationTextures .emplace (args.texture );
3364+ surface->destinationTextures .emplace (args.texture , args. destSliceOrFace );
33623365
33633366 // If the texture is assigned to any slots, set it again. This'll also push the barrier.
33643367 for (uint32_t i = 0 ; i < std::size (g_textures); i++)
@@ -3484,7 +3487,7 @@ static bool PopulateBarriersForStretchRect(GuestSurface* renderTarget, GuestSurf
34843487
34853488 AddBarrier (surface, srcLayout);
34863489
3487- for (const auto texture : surface->destinationTextures )
3490+ for (const auto [ texture, _] : surface->destinationTextures )
34883491 AddBarrier (texture, dstLayout);
34893492
34903493 addedAny = true ;
@@ -3505,7 +3508,7 @@ static void ExecutePendingStretchRectCommands(GuestSurface* renderTarget, GuestS
35053508 const bool multiSampling = surface->sampleCount != RenderSampleCount::COUNT_1 ;
35063509 const bool isDepthStencil = RenderFormatIsDepth (surface->format );
35073510
3508- for (const auto texture : surface->destinationTextures )
3511+ for (const auto [ texture, slice] : surface->destinationTextures )
35093512 {
35103513 bool shaderResolve = true ;
35113514
@@ -3595,27 +3598,36 @@ static void ExecutePendingStretchRectCommands(GuestSurface* renderTarget, GuestS
35953598 }
35963599 }
35973600
3598- if (texture->framebuffer == nullptr )
3601+ auto & framebuffer = texture->framebuffers [slice];
3602+ if (framebuffer == nullptr )
35993603 {
36003604 if (isDepthStencil)
36013605 {
3606+ RenderTextureViewDesc viewDesc;
3607+ viewDesc.format = texture->format ;
3608+ viewDesc.dimension = texture->viewDimension ;
3609+ viewDesc.mipLevels = texture->mipLevels ;
3610+ viewDesc.arrayIndex = slice;
3611+ viewDesc.arraySize = 1 ;
3612+ auto & view = texture->framebufferViews .emplace_back (texture->texture ->createTextureView (viewDesc));
3613+
36023614 RenderFramebufferDesc desc;
3603- desc.depthAttachment = texture-> texture ;
3604- texture-> framebuffer = g_device->createFramebuffer (desc);
3615+ desc.depthAttachmentView = view. get () ;
3616+ framebuffer = g_device->createFramebuffer (desc);
36053617 }
36063618 else
36073619 {
36083620 RenderFramebufferDesc desc;
36093621 desc.colorAttachments = const_cast <const RenderTexture**>(&texture->texture );
36103622 desc.colorAttachmentsCount = 1 ;
3611- texture-> framebuffer = g_device->createFramebuffer (desc);
3623+ framebuffer = g_device->createFramebuffer (desc);
36123624 }
36133625 }
36143626
3615- if (g_framebuffer != texture-> framebuffer .get ())
3627+ if (g_framebuffer != framebuffer.get ())
36163628 {
3617- commandList->setFramebuffer (texture-> framebuffer .get ());
3618- g_framebuffer = texture-> framebuffer .get ();
3629+ commandList->setFramebuffer (framebuffer.get ());
3630+ g_framebuffer = framebuffer.get ();
36193631 }
36203632
36213633 commandList->setPipeline (pipeline);
@@ -3671,7 +3683,7 @@ static void ProcExecutePendingStretchRectCommands(const RenderCommand& cmd)
36713683 if (!RenderFormatIsDepth (surface->format ))
36723684 ExecutePendingStretchRectCommands (surface, nullptr );
36733685
3674- for (const auto texture : surface->destinationTextures )
3686+ for (const auto [ texture, _] : surface->destinationTextures )
36753687 texture->sourceSurface = nullptr ;
36763688
36773689 surface->destinationTextures .clear ();
@@ -5911,6 +5923,7 @@ static bool LoadTexture(GuestTexture& texture, const uint8_t* data, size_t dataS
59115923
59125924 texture.width = ddsDesc.width ;
59135925 texture.height = ddsDesc.height ;
5926+ texture.mipLevels = viewDesc.mipLevels ;
59145927 texture.viewDimension = viewDesc.dimension ;
59155928
59165929 struct Slice
@@ -8236,7 +8249,7 @@ int D3DDevice_EndTiling(GuestDevice* device, uint32_t flags, Rect* pResolveRects
82368249 // printf("pResolveParams: %x %x %x\n", resolveParams->format.get(), resolveParams->unk.get(), resolveParams->format2.get());
82378250 // }
82388251 if (pDestTexture) {
8239- StretchRect (device, flags, 0 , pDestTexture);
8252+ StretchRect (device, flags, 0 , pDestTexture, 0 , 0 , 0 );
82408253 }
82418254 return 0 ;
82428255}
0 commit comments