Skip to content

Commit e7e3983

Browse files
committed
Bind correct depth attachment slice.
1 parent 39ee629 commit e7e3983

2 files changed

Lines changed: 30 additions & 15 deletions

File tree

MarathonRecomp/gpu/video.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

MarathonRecomp/gpu/video.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@ struct GuestBaseTexture : GuestResource
170170
struct GuestTexture : GuestBaseTexture
171171
{
172172
uint32_t depth = 0;
173+
uint32_t mipLevels = 1;
173174
RenderTextureViewDimension viewDimension = RenderTextureViewDimension::UNKNOWN;
174175
void* mappedMemory = nullptr;
175-
std::unique_ptr<RenderFramebuffer> framebuffer;
176+
ankerl::unordered_dense::map<uint32_t, std::unique_ptr<RenderFramebuffer>> framebuffers;
177+
std::vector<std::unique_ptr<RenderTextureView>> framebufferViews;
176178
std::unique_ptr<GuestTexture> patchedTexture;
177179
struct GuestSurface* sourceSurface = nullptr;
178180
};
@@ -229,7 +231,7 @@ struct GuestSurface : GuestBaseTexture
229231
uint32_t guestFormat = 0;
230232
ankerl::unordered_dense::map<const RenderTexture*, std::unique_ptr<RenderFramebuffer>> framebuffers;
231233
RenderSampleCounts sampleCount = RenderSampleCount::COUNT_1;
232-
ankerl::unordered_dense::set<GuestTexture*> destinationTextures;
234+
ankerl::unordered_dense::map<GuestTexture*, uint32_t> destinationTextures;
233235
bool wasCached = false;
234236
};
235237

0 commit comments

Comments
 (0)