core: refactor renderable size ownership (#4512)

This commit is contained in:
Bart Louwers
2026-09-01 17:35:29 +02:00
committed by GitHub
parent be3f03b86e
commit e5d0fce32a
35 changed files with 131 additions and 122 deletions

View File

@@ -107,7 +107,7 @@ public:
wgpu::TextureView offscreenTextureView;
wgpu::Texture depthTexture;
wgpu::TextureView depthTextureView;
Size framebufferSize;
Size offscreenTextureSize;
};
HeadlessBackend::HeadlessBackend(Size size_, SwapBehaviour swapBehaviour_, gfx::ContextMode mode)
@@ -116,8 +116,6 @@ HeadlessBackend::HeadlessBackend(Size size_, SwapBehaviour swapBehaviour_, gfx::
impl(std::make_unique<Impl>()) {
static_cast<void>(swapBehaviour_);
impl->framebufferSize = size_;
#if MLN_WEBGPU_IMPL_DAWN
// Initialize Dawn instance with TimedWaitAny feature enabled
wgpu::InstanceFeatureName timedWaitAnyFeature = wgpu::InstanceFeatureName::TimedWaitAny;
@@ -221,6 +219,9 @@ HeadlessBackend::~HeadlessBackend() {
void HeadlessBackend::createOffscreenTextures() {
if (!impl->device) return;
const auto renderableSize = getSize();
impl->offscreenTextureSize = renderableSize;
// Release old textures if they exist
impl->offscreenTextureView = nullptr;
impl->offscreenTexture = nullptr;
@@ -236,8 +237,7 @@ void HeadlessBackend::createOffscreenTextures() {
#elif MLN_WEBGPU_IMPL_WGPU
colorDesc.dimension = wgpu::TextureDimension::_2D;
#endif
colorDesc.size = {
static_cast<uint32_t>(impl->framebufferSize.width), static_cast<uint32_t>(impl->framebufferSize.height), 1};
colorDesc.size = {renderableSize.width, renderableSize.height, 1};
colorDesc.format = wgpu::TextureFormat::RGBA8Unorm;
colorDesc.mipLevelCount = 1;
colorDesc.sampleCount = 1;
@@ -282,8 +282,7 @@ void HeadlessBackend::createOffscreenTextures() {
#elif MLN_WEBGPU_IMPL_WGPU
depthDesc.dimension = wgpu::TextureDimension::_2D;
#endif
depthDesc.size = {
static_cast<uint32_t>(impl->framebufferSize.width), static_cast<uint32_t>(impl->framebufferSize.height), 1};
depthDesc.size = {renderableSize.width, renderableSize.height, 1};
depthDesc.format = wgpu::TextureFormat::Depth24PlusStencil8;
depthDesc.mipLevelCount = 1;
depthDesc.sampleCount = 1;
@@ -323,8 +322,8 @@ void HeadlessBackend::createOffscreenTextures() {
gfx::Renderable& HeadlessBackend::getDefaultRenderable() {
if (!hasResource()) {
setResource(
std::make_unique<HeadlessRenderableResource>(*this, static_cast<webgpu::Context&>(getContext()), size));
setResource(std::make_unique<HeadlessRenderableResource>(
*this, static_cast<webgpu::Context&>(getContext()), getSize()));
}
return *this;
}
@@ -350,8 +349,7 @@ RendererBackend* HeadlessBackend::getRendererBackend() {
void HeadlessBackend::activate() {
active = true;
// Ensure textures are created if size changed
if (impl && impl->framebufferSize != getSize()) {
impl->framebufferSize = getSize();
if (impl && impl->offscreenTextureSize != getSize()) {
createOffscreenTextures();
}
}
@@ -375,9 +373,6 @@ void* HeadlessBackend::getDepthStencilView() {
}
mln::Size HeadlessBackend::getFramebufferSize() const {
if (impl) {
return impl->framebufferSize;
}
return getSize();
}