Skip to content

Commit 5652f9a

Browse files
committed
[Chore] (MG_Backend/DirectVulkan): implements BlitFramebuffer using backend manager APIs
1 parent f3b0b24 commit 5652f9a

4 files changed

Lines changed: 180 additions & 189 deletions

File tree

MobileGL/MG_Backend/DirectVulkan/Renderer/UniformDescriptorBinder.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,28 @@ namespace MobileGL::MG_Backend::DirectVulkan {
538538
return outImageInfo.sampler != VK_NULL_HANDLE;
539539
}
540540

541+
Bool UniformDescriptorBinder::ResolveSamplerDescriptorOverride(
542+
const SamplerBindingOverride& samplerBindingOverride,
543+
VkDescriptorImageInfo& outImageInfo) const {
544+
MOBILEGL_ASSERT(m_textureManager != nullptr, "ResolveSamplerDescriptorOverride: texture manager is null");
545+
MOBILEGL_ASSERT(m_samplerManager != nullptr, "ResolveSamplerDescriptorOverride: sampler manager is null");
546+
if (samplerBindingOverride.texture == nullptr || samplerBindingOverride.sampler == nullptr) {
547+
return false;
548+
}
549+
550+
auto* resource = m_textureManager->SyncTextureAndGetDescriptor(*samplerBindingOverride.texture);
551+
if (resource == nullptr || !IsValidSampledImageLayout(resource->layout)) {
552+
return false;
553+
}
554+
555+
outImageInfo = {
556+
.sampler = m_samplerManager->GetOrCreateSampler(*samplerBindingOverride.sampler),
557+
.imageView = resource->view,
558+
.imageLayout = resource->layout,
559+
};
560+
return outImageInfo.sampler != VK_NULL_HANDLE;
561+
}
562+
541563
Bool UniformDescriptorBinder::ResolveSamplerTexture(const MG_State::GLState::ProgramObject& program,
542564
const ProgramLayout& layout, Uint32 binding,
543565
SharedPtr<MG_State::GLState::ITextureObject>& outTexture) const {
@@ -786,7 +808,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
786808
Bool UniformDescriptorBinder::BindProgramUniformBuffers(VkCommandBuffer commandBuffer,
787809
const MG_State::GLState::ProgramObject& program,
788810
Uint32 frameIndex) {
811+
return BindProgramUniformBuffers(commandBuffer, program, frameIndex, nullptr);
812+
}
813+
814+
Bool UniformDescriptorBinder::BindProgramUniformBuffers(VkCommandBuffer commandBuffer,
815+
const MG_State::GLState::ProgramObject& program,
816+
Uint32 frameIndex,
817+
const SamplerBindingOverride* samplerBindingOverride) {
789818
ProgramLayout* layout = GetOrCreateProgramLayout(program);
819+
MOBILEGL_ASSERT(layout != nullptr,
820+
"UniformDescriptorBinder::BindProgramUniformBuffers: program layout is null");
790821

791822
auto& frame = m_frames[frameIndex];
792823
if (frame.descriptorPools.empty()) {
@@ -903,7 +934,15 @@ namespace MobileGL::MG_Backend::DirectVulkan {
903934
dynamicOffsets.push_back(static_cast<Uint32>(payloadOffset));
904935
} else {
905936
VkDescriptorImageInfo imageInfo{};
906-
Bool hasImage = ResolveSamplerDescriptor(commandBuffer, program, *layout, binding, imageInfo);
937+
Bool hasImage = false;
938+
if (samplerBindingOverride != nullptr &&
939+
samplerBindingOverride->binding == binding &&
940+
samplerBindingOverride->texture != nullptr &&
941+
samplerBindingOverride->sampler != nullptr) {
942+
hasImage = ResolveSamplerDescriptorOverride(*samplerBindingOverride, imageInfo);
943+
} else {
944+
hasImage = ResolveSamplerDescriptor(commandBuffer, program, *layout, binding, imageInfo);
945+
}
907946
if (!hasImage) {
908947
MGLOG_E("UniformDescriptorBinder::BindProgramUniformBuffers failed: sampler binding %u has no valid texture descriptor",
909948
binding);

MobileGL/MG_Backend/DirectVulkan/Renderer/UniformDescriptorBinder.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#include <vk_mem_alloc.h>
1717

1818
namespace MobileGL::MG_State::GLState {
19+
class ITextureObject;
1920
class ProgramObject;
21+
class SamplerObject;
2022
}
2123

2224
namespace MobileGL::MG_Backend::DirectVulkan {
@@ -28,6 +30,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
2830
CombinedImageSampler
2931
};
3032

33+
struct SamplerBindingOverride {
34+
Uint32 binding = 0;
35+
MG_State::GLState::ITextureObject* texture = nullptr;
36+
const MG_State::GLState::SamplerObject* sampler = nullptr;
37+
};
38+
3139
Bool Initialize(VkDevice device, VmaAllocator allocator, VkDeviceSize minUniformBufferOffsetAlignment,
3240
Uint32 frameCount, Uint32 maxBindings = 16, Uint32 setsPerFrame = 64,
3341
VkDeviceSize perFrameUploadBytes = 4 * 1024 * 1024,
@@ -40,6 +48,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
4048
Vector<MG_State::GLState::ITextureObject*>& outTextures);
4149
Bool BindProgramUniformBuffers(VkCommandBuffer commandBuffer,
4250
const MG_State::GLState::ProgramObject& program, Uint32 frameIndex);
51+
Bool BindProgramUniformBuffers(VkCommandBuffer commandBuffer,
52+
const MG_State::GLState::ProgramObject& program, Uint32 frameIndex,
53+
const SamplerBindingOverride* samplerBindingOverride);
4354

4455
private:
4556
struct DescriptorPoolBucket {
@@ -79,6 +90,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
7990
Bool ResolveSamplerDescriptor(VkCommandBuffer commandBuffer, const MG_State::GLState::ProgramObject& program,
8091
const ProgramLayout& layout, Uint32 binding,
8192
VkDescriptorImageInfo& outImageInfo) const;
93+
Bool ResolveSamplerDescriptorOverride(const SamplerBindingOverride& samplerBindingOverride,
94+
VkDescriptorImageInfo& outImageInfo) const;
8295
Bool ReflectBindingKinds(const MG_State::GLState::ProgramObject& program, Vector<BindingKind>& outKinds) const;
8396
ProgramLayout* GetOrCreateProgramLayout(const MG_State::GLState::ProgramObject& program);
8497
Bool AllocateUploadRegion(FrameResources& frame, VkDeviceSize size, VkDeviceSize& outOffset);

0 commit comments

Comments
 (0)