Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viewport doesn't render at default size [512,512] #66483

Closed
robojeb opened this issue Sep 27, 2022 · 12 comments · Fixed by #68358
Closed

Viewport doesn't render at default size [512,512] #66483

robojeb opened this issue Sep 27, 2022 · 12 comments · Fixed by #68358

Comments

@robojeb
Copy link

robojeb commented Sep 27, 2022

Godot version

4.0-beta1

System information

Windows 10, NVIDIA GeForce RTX 3050 Ti Laptop GPU

Issue description

When creating a SubViewport that renders to a texture if the default viewport size of (512,512) is used the texture renders as all pink, but if the Viewport size is changed (514, 514) it will render properly.

Weirdly, when set to (512,512) it doesn't throw any errors, but when set to another size it throws a bunch of errors:

ERROR: Attempted to use the same texture in framebuffer attachment and a uniform (set: 3, binding: 1), this is not allowed.
   at: (drivers/vulkan/rendering_device_vulkan.cpp:7679)

Steps to reproduce

Create a scene with the following:

  • Node3d
    • SubViewport
      • Camera3d
    • MeshInstance [Like a cube, scooch it down the Z axis so the camera(s) can see it]
    • MeshInstance [Plane facing the Z axis and scooted off to the side so it doesn't block the cube]
    • Camera3d [Probably want to scoot it back a bit so you can tell the angle is different from the camera rendering to texture]

Add a script on the root (because of #66247 ) with the following:

extends Node3D

@onready var vp = $SubViewport
@onready var screen = $MeshInstance3d2

# Called when the node enters the scene tree for the first time.
func _ready():
	screen.get_active_material(0).albedo_texture = vp.get_texture()

Minimal reproduction project

OpenTest.zip

@Calinou Calinou added this to the 4.0 milestone Sep 27, 2022
@robojeb
Copy link
Author

robojeb commented Sep 29, 2022

A few updates, on Linux (Manjaro) running Nvidia proprietary drivers for a 1080ti I don't see any size which results in correct rendering.

I also built Godot and ran it under a debugger.
As far as I can tell the Texture is created successfully (rendering_device_vulkan.cpp:1875 returns VK_SUCCESS).
I don't have enough familiarity with the rest of the rendering pipeline to dig further tonight.

@Calinou
Copy link
Member

Calinou commented Sep 29, 2022

Is the viewport's Update mode set to Always? This is currently required for viewport textures to be generated correctly.

@robojeb
Copy link
Author

robojeb commented Sep 29, 2022

Setting the value to "Always" makes the texture render in the editor but still shows up as the pink non-Texture when running the scene.
Changing the size does work when running the scene.

Quick Edit: Setting the mode to "Always" also seems to resolve #66247 in the editor (so you get a live texture preview which is nice) but doesn't fix the issue when running the scene.

Second Edit: I re-tested on Linux and now I am also getting the pink texture at the default size, I may have made a mistake in my earlier test.

@robojeb
Copy link
Author

robojeb commented Sep 29, 2022

I ran Godot built from source in a debugger.

It looks like when the Viewport texture size is default it never goes through texture_create() in the Vulkan renderer.
But when the texture size is non-standard it does hit texture_create().

So the underlying issue may be with how Godot is trying to detect changes in texture size.

@Calinou
Copy link
Member

Calinou commented Sep 29, 2022

It looks like when the Viewport texture size is default it never goes through texture_create() in the Vulkan renderer.
But when the texture size is non-standard it does hit texture_create().

This sounds similar to what's happening with ReflectionProbes when their extents are set to the default value (which #55178 should incindentally resolve).

@robojeb
Copy link
Author

robojeb commented Sep 30, 2022

I spent some more time tracing the issue through the debugger.

The issue is that when the RendererViewport is initially created it has a size [0,0].
This means that during creation when executing TextureStorage::_update_render_target() it will early return at rendering_server_default.cpp:2157.
subviewport_create_early_return

This also happens for the main viewport but as soon as the Window receives a size update it triggers _set_size() on the Viewport which in turn calls TextureStorage::_update_render_target().

Theoretically setting the "Transparent BG" or "MSAA" options to non-defaults should trigger the TextureStorage::_update_render_target() function, but even with one of those settings nothing ever updates the RendererViewport size parameters so it still hits that early return.
subviewport_msaa_update_early_return

This same thing could theoretically happen to the main viewport if it was initialized to a window size [512,512] (and hiDPI is disabled), but in practice it seems like a Window event comes in which has a different p_stretch_transform which is enough to actually cause the size of the main window texture to get set.

The fix probably involves triggering RS::get_singleton()->viewport_set_size(viewport, size.width, size.height) manually as part of a post instantiation step for all Viewport objects, though this is a little wasteful if during scene initialization we end up reducing the size.

@conradax
Copy link

The bug is still there in Godot4.0 Beta3.
The SubViewport is always pink with the DEFAULT size of (512,512), But everything works fine after size changed.

Here's my minimal reproduction project: subviewport_bug.zip

If anyone got problem with this bug, Here're some workaround:

  • In Editor, set SubViewport Size to anything else then set it back to (512,512)
  • In Runtime, add extra line of code like Subviewport.size = Vector2i(512,512)

@alfredbaudisch
Copy link
Contributor

Currently, with Beta3, it seems that no matter the size of the SubViewport, it renders ONLY if it's inside a SubViewportContainer, otherwise it's always pink.

Should this be a new bug report @Calinou?

@Calinou
Copy link
Member

Calinou commented Oct 28, 2022

Currently, with Beta3, it seems that no matter the size of the SubViewport, it renders ONLY if it's inside a SubViewportContainer, otherwise it's always pink.

Is the viewport's update mode set to Always? See #55471.

@alfredbaudisch
Copy link
Contributor

alfredbaudisch commented Oct 28, 2022

Currently, with Beta3, it seems that no matter the size of the SubViewport, it renders ONLY if it's inside a SubViewportContainer, otherwise it's always pink.

Is the viewport's update mode set to Always? See #55471.

Only Clear Mode was Always, setting Update Mode to Always made it work again. Thanks.

image

@marcarneg
Copy link

marcarneg commented Feb 2, 2023

Tried it with Godot 4 beta 17, "Mobile" renderer preset on Win10, dedicated graphics card (not a notebook).
RenderingportBug.zip

Can't get the SubViewPort to work properly. When it works, it doesn't update Material changes, sometimes it just shows a pink texture.

Edit: I just realized, that this ticket was closed already. Sorry!!

@Chevifier
Copy link

Tried it with Godot 4 beta 17, "Mobile" renderer preset on Win10, dedicated graphics card (not a notebook). RenderingportBug.zip

Can't get the SubViewPort to work properly. When it works, it doesn't update Material changes, sometimes it just shows a pink texture.

Edit: I just realized, that this ticket was closed already. Sorry!!

Im here trying to use it too. This hasnt been fixed it looks like. Shows up fine in editor but either Pink or Blank at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants