Skip to content

Commit c372d9c

Browse files
committed
Resolve to correct depth slice.
1 parent 4b3e180 commit c372d9c

5 files changed

Lines changed: 46 additions & 15 deletions

File tree

MarathonRecomp/gpu/rhi/plume_render_interface_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ namespace plume {
16431643
const RenderTexture **colorAttachments = nullptr;
16441644
uint32_t colorAttachmentsCount = 0;
16451645
const RenderTexture *depthAttachment = nullptr;
1646+
uint32_t depthAttachmentSlice = 0;
16461647
bool depthAttachmentReadOnly = false;
16471648

16481649
RenderFramebufferDesc() = default;

MarathonRecomp/gpu/rhi/plume_vulkan.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2465,7 +2465,28 @@ namespace plume {
24652465
if (desc.depthAttachment != nullptr) {
24662466
depthAttachment = static_cast<const VulkanTexture *>(desc.depthAttachment);
24672467
assert((depthAttachment->desc.flags & RenderTextureFlag::DEPTH_TARGET) && "Depth attachment must be a depth target.");
2468-
imageViews.emplace_back(depthAttachment->imageView);
2468+
if (desc.depthAttachmentSlice != 0) {
2469+
VkImageViewCreateInfo viewInfo = {};
2470+
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2471+
viewInfo.image = depthAttachment->vk;
2472+
viewInfo.viewType = toImageViewType(RenderTextureViewDimension::TEXTURE_2D, depthAttachment->desc.arraySize);
2473+
viewInfo.format = toVk(depthAttachment->desc.format);
2474+
viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
2475+
viewInfo.subresourceRange.baseMipLevel = 0;
2476+
viewInfo.subresourceRange.levelCount = 1;
2477+
viewInfo.subresourceRange.baseArrayLayer = desc.depthAttachmentSlice;
2478+
viewInfo.subresourceRange.layerCount = 1;
2479+
2480+
res = vkCreateImageView(device->vk, &viewInfo, nullptr, &depthAttachmentView);
2481+
if (res != VK_SUCCESS) {
2482+
fprintf(stderr, "vkCreateImageView failed with error code 0x%X.\n", res);
2483+
return;
2484+
}
2485+
2486+
imageViews.emplace_back(depthAttachmentView);
2487+
} else {
2488+
imageViews.emplace_back(depthAttachment->imageView);
2489+
}
24692490

24702491
if (desc.colorAttachmentsCount == 0) {
24712492
width = uint32_t(depthAttachment->desc.width);
@@ -2536,6 +2557,10 @@ namespace plume {
25362557
if (renderPass != VK_NULL_HANDLE) {
25372558
vkDestroyRenderPass(device->vk, renderPass, nullptr);
25382559
}
2560+
2561+
if (depthAttachmentView != VK_NULL_HANDLE) {
2562+
vkDestroyImageView(device->vk, depthAttachmentView, nullptr);
2563+
}
25392564
}
25402565

25412566
uint32_t VulkanFramebuffer::getWidth() const {

MarathonRecomp/gpu/rhi/plume_vulkan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ namespace plume {
266266
VkRenderPass renderPass = VK_NULL_HANDLE;
267267
std::vector<const VulkanTexture *> colorAttachments;
268268
const VulkanTexture *depthAttachment = nullptr;
269+
VkImageView depthAttachmentView = VK_NULL_HANDLE;
269270
bool depthAttachmentReadOnly = false;
270271
uint32_t width = 0;
271272
uint32_t height = 0;

MarathonRecomp/gpu/video.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ struct RenderCommand
872872
GuestDevice* device;
873873
uint32_t flags;
874874
GuestTexture* texture;
875+
uint32_t destSliceOrFace;
875876
} stretchRect;
876877

877878
struct
@@ -3221,13 +3222,14 @@ static void FlushViewport()
32213222
}
32223223
}
32233224

3224-
static void StretchRect(GuestDevice* device, uint32_t flags, uint32_t, GuestTexture* texture)
3225+
static void StretchRect(GuestDevice* device, uint32_t flags, uint32_t, GuestTexture* texture, uint32_t, uint32_t, uint32_t destSliceOrFace)
32253226
{
32263227
// printf("StretchRect %x\n", texture);
32273228
RenderCommand cmd;
32283229
cmd.type = RenderCommandType::StretchRect;
32293230
cmd.stretchRect.flags = flags;
32303231
cmd.stretchRect.texture = texture;
3232+
cmd.stretchRect.destSliceOrFace = destSliceOrFace;
32313233
g_renderQueue.enqueue(cmd);
32323234
}
32333235

@@ -3247,7 +3249,7 @@ static void ProcStretchRect(const RenderCommand& cmd)
32473249

32483250
args.texture->sourceSurface = surface;
32493251
// printf("ProcStretchRect: surface - %x %x ? (%x : %x)\n", surface, isDepthStencil, g_depthStencil, g_renderTarget);
3250-
surface->destinationTextures.emplace(args.texture);
3252+
surface->destinationTextures.emplace(args.texture, args.destSliceOrFace);
32513253

32523254
// If the texture is assigned to any slots, set it again. This'll also push the barrier.
32533255
for (uint32_t i = 0; i < std::size(g_textures); i++)
@@ -3373,7 +3375,7 @@ static bool PopulateBarriersForStretchRect(GuestSurface* renderTarget, GuestSurf
33733375

33743376
AddBarrier(surface, srcLayout);
33753377

3376-
for (const auto texture : surface->destinationTextures)
3378+
for (const auto [texture, _] : surface->destinationTextures)
33773379
AddBarrier(texture, dstLayout);
33783380

33793381
addedAny = true;
@@ -3393,7 +3395,7 @@ static void ExecutePendingStretchRectCommands(GuestSurface* renderTarget, GuestS
33933395
{
33943396
const bool multiSampling = surface->sampleCount != RenderSampleCount::COUNT_1;
33953397

3396-
for (const auto texture : surface->destinationTextures)
3398+
for (const auto [texture, slice] : surface->destinationTextures)
33973399
{
33983400
bool shaderResolve = true;
33993401

@@ -3483,27 +3485,29 @@ static void ExecutePendingStretchRectCommands(GuestSurface* renderTarget, GuestS
34833485
}
34843486
}
34853487

3486-
if (texture->framebuffer == nullptr)
3488+
auto& framebuffer = texture->framebuffers[slice];
3489+
if (framebuffer == nullptr)
34873490
{
34883491
if (texture->format == RenderFormat::D32_FLOAT)
34893492
{
34903493
RenderFramebufferDesc desc;
34913494
desc.depthAttachment = texture->texture;
3492-
texture->framebuffer = g_device->createFramebuffer(desc);
3495+
desc.depthAttachmentSlice = slice;
3496+
framebuffer = g_device->createFramebuffer(desc);
34933497
}
34943498
else
34953499
{
34963500
RenderFramebufferDesc desc;
34973501
desc.colorAttachments = const_cast<const RenderTexture**>(&texture->texture);
34983502
desc.colorAttachmentsCount = 1;
3499-
texture->framebuffer = g_device->createFramebuffer(desc);
3503+
framebuffer = g_device->createFramebuffer(desc);
35003504
}
35013505
}
35023506

3503-
if (g_framebuffer != texture->framebuffer.get())
3507+
if (g_framebuffer != framebuffer.get())
35043508
{
3505-
commandList->setFramebuffer(texture->framebuffer.get());
3506-
g_framebuffer = texture->framebuffer.get();
3509+
commandList->setFramebuffer(framebuffer.get());
3510+
g_framebuffer = framebuffer.get();
35073511
}
35083512

35093513
commandList->setPipeline(pipeline);
@@ -3559,7 +3563,7 @@ static void ProcExecutePendingStretchRectCommands(const RenderCommand& cmd)
35593563
if (surface->format != RenderFormat::D32_FLOAT)
35603564
ExecutePendingStretchRectCommands(surface, nullptr);
35613565

3562-
for (const auto texture : surface->destinationTextures)
3566+
for (const auto [texture, _] : surface->destinationTextures)
35633567
texture->sourceSurface = nullptr;
35643568

35653569
surface->destinationTextures.clear();
@@ -8068,7 +8072,7 @@ int D3DDevice_EndTiling(GuestDevice* device, uint32_t flags, Rect* pResolveRects
80688072
// printf("pResolveParams: %x %x %x\n", resolveParams->format.get(), resolveParams->unk.get(), resolveParams->format2.get());
80698073
// }
80708074
if (pDestTexture) {
8071-
StretchRect(device, flags, 0, pDestTexture);
8075+
StretchRect(device, flags, 0, pDestTexture, 0, 0, 0);
80728076
}
80738077
return 0;
80748078
}

MarathonRecomp/gpu/video.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct GuestTexture : GuestBaseTexture
171171
uint32_t depth = 0;
172172
RenderTextureViewDimension viewDimension = RenderTextureViewDimension::UNKNOWN;
173173
void* mappedMemory = nullptr;
174-
std::unique_ptr<RenderFramebuffer> framebuffer;
174+
ankerl::unordered_dense::map<uint32_t, std::unique_ptr<RenderFramebuffer>> framebuffers;
175175
std::unique_ptr<GuestTexture> patchedTexture;
176176
struct GuestSurface* sourceSurface = nullptr;
177177
};
@@ -228,7 +228,7 @@ struct GuestSurface : GuestBaseTexture
228228
uint32_t guestFormat = 0;
229229
ankerl::unordered_dense::map<const RenderTexture*, std::unique_ptr<RenderFramebuffer>> framebuffers;
230230
RenderSampleCounts sampleCount = RenderSampleCount::COUNT_1;
231-
ankerl::unordered_dense::set<GuestTexture*> destinationTextures;
231+
ankerl::unordered_dense::map<GuestTexture*, uint32_t> destinationTextures;
232232
bool wasCached = false;
233233
};
234234

0 commit comments

Comments
 (0)