@@ -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++)
@@ -3486,7 +3489,7 @@ static bool PopulateBarriersForStretchRect(GuestSurface* renderTarget, GuestSurf
34863489
34873490 AddBarrier (surface, srcLayout);
34883491
3489- for (const auto texture : surface->destinationTextures )
3492+ for (const auto [ texture, _] : surface->destinationTextures )
34903493 AddBarrier (texture, dstLayout);
34913494
34923495 addedAny = true ;
@@ -3507,7 +3510,7 @@ static void ExecutePendingStretchRectCommands(GuestSurface* renderTarget, GuestS
35073510 const bool multiSampling = surface->sampleCount != RenderSampleCount::COUNT_1 ;
35083511 const bool isDepthStencil = RenderFormatIsDepth (surface->format );
35093512
3510- for (const auto texture : surface->destinationTextures )
3513+ for (const auto [ texture, slice] : surface->destinationTextures )
35113514 {
35123515 bool shaderResolve = true ;
35133516
@@ -3597,27 +3600,36 @@ static void ExecutePendingStretchRectCommands(GuestSurface* renderTarget, GuestS
35973600 }
35983601 }
35993602
3600- if (texture->framebuffer == nullptr )
3603+ auto & framebuffer = texture->framebuffers [slice];
3604+ if (framebuffer == nullptr )
36013605 {
36023606 if (isDepthStencil)
36033607 {
3608+ RenderTextureViewDesc viewDesc;
3609+ viewDesc.format = texture->format ;
3610+ viewDesc.dimension = texture->viewDimension ;
3611+ viewDesc.mipLevels = texture->mipLevels ;
3612+ viewDesc.arrayIndex = slice;
3613+ viewDesc.arraySize = 1 ;
3614+ auto & view = texture->framebufferViews .emplace_back (texture->texture ->createTextureView (viewDesc));
3615+
36043616 RenderFramebufferDesc desc;
3605- desc.depthAttachment = texture-> texture ;
3606- texture-> framebuffer = g_device->createFramebuffer (desc);
3617+ desc.depthAttachmentView = view. get () ;
3618+ framebuffer = g_device->createFramebuffer (desc);
36073619 }
36083620 else
36093621 {
36103622 RenderFramebufferDesc desc;
36113623 desc.colorAttachments = const_cast <const RenderTexture**>(&texture->texture );
36123624 desc.colorAttachmentsCount = 1 ;
3613- texture-> framebuffer = g_device->createFramebuffer (desc);
3625+ framebuffer = g_device->createFramebuffer (desc);
36143626 }
36153627 }
36163628
3617- if (g_framebuffer != texture-> framebuffer .get ())
3629+ if (g_framebuffer != framebuffer.get ())
36183630 {
3619- commandList->setFramebuffer (texture-> framebuffer .get ());
3620- g_framebuffer = texture-> framebuffer .get ();
3631+ commandList->setFramebuffer (framebuffer.get ());
3632+ g_framebuffer = framebuffer.get ();
36213633 }
36223634
36233635 commandList->setPipeline (pipeline);
@@ -3673,7 +3685,7 @@ static void ProcExecutePendingStretchRectCommands(const RenderCommand& cmd)
36733685 if (!RenderFormatIsDepth (surface->format ))
36743686 ExecutePendingStretchRectCommands (surface, nullptr );
36753687
3676- for (const auto texture : surface->destinationTextures )
3688+ for (const auto [ texture, _] : surface->destinationTextures )
36773689 texture->sourceSurface = nullptr ;
36783690
36793691 surface->destinationTextures .clear ();
@@ -5915,6 +5927,7 @@ static bool LoadTexture(GuestTexture& texture, const uint8_t* data, size_t dataS
59155927
59165928 texture.width = ddsDesc.width ;
59175929 texture.height = ddsDesc.height ;
5930+ texture.mipLevels = viewDesc.mipLevels ;
59185931 texture.viewDimension = viewDesc.dimension ;
59195932
59205933 struct Slice
@@ -8240,7 +8253,7 @@ int D3DDevice_EndTiling(GuestDevice* device, uint32_t flags, Rect* pResolveRects
82408253 // printf("pResolveParams: %x %x %x\n", resolveParams->format.get(), resolveParams->unk.get(), resolveParams->format2.get());
82418254 // }
82428255 if (pDestTexture) {
8243- StretchRect (device, flags, 0 , pDestTexture);
8256+ StretchRect (device, flags, 0 , pDestTexture, 0 , 0 , 0 );
82448257 }
82458258 return 0 ;
82468259}
0 commit comments