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

DiligentImplImGui add multi-viewport functionality #156

Open
hamyyy opened this issue Feb 10, 2022 · 6 comments
Open

DiligentImplImGui add multi-viewport functionality #156

hamyyy opened this issue Feb 10, 2022 · 6 comments

Comments

@hamyyy
Copy link
Contributor

hamyyy commented Feb 10, 2022

This is more of a feature request,

I'd love to use the ImGui "docking" branch using the Diligent engine.
By simply checking out the docking branch in the imgui submodule (DiligentTools/ThirdParty/imgui) I was able to use the new docking feature.

But I can't enable the new viewports feature, presumably because the Diligent imgui implementation has no way of processing new window creation. Not even sure where I would start to look.

Might be easier in my case since I'm using GLFW for window creation.

@TheMostDiligent
Copy link
Contributor

Imgui renderer is implemented here

@hamyyy
Copy link
Contributor Author

hamyyy commented Feb 12, 2022

After a lot of thinking and tinkering, I've finally figured out a streamlined way of integrating the docking branch into DiligentEngine. I've tested it and it works! (Docking and multi-viewports). There is one small hiccup though, fixing it will allow me to create a class that you can even add to the DiligentTools repo if you like, I created a new issue discussing it here #157

@hamyyy
Copy link
Contributor Author

hamyyy commented Feb 13, 2022

Update:

Most things seem to be in order. But I have a couple of issues.


Issue 1:

I get errors when creating a new window which crashes the application only sometimes.

Using Vulkan I get this error repeatedly while a new window had been created.

Diligent Engine: ERROR in Diligent::SwapChainVkImpl::CreateVulkanSwapChain() (SwapChainVkImpl.cpp, 248): Failed to query physical device surface capabilities

Using Direct X 11/12 I get these errors

D3D12 ERROR: ID3D12CommandQueue::Present: Resource state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE) (promoted from COMMON state) of resource (0x00000190372699E0:'Main back buffer') (subresource: 0) must be in COMMON state when transitioning to use in a different Command List type, because resource state on previous Command List type : D3D12_COMMAND_LIST_TYPE_COPY, is actually incompatible and different from that on the next Command List type : D3D12_COMMAND_LIST_TYPE_DIRECT. [ RESOURCE_MANIPULATION ERROR #990: RESOURCE_BARRIER_MISMATCHING_COMMAND_LIST_TYPE]
Diligent Engine: ERROR: Timeout elapsed while waiting for the frame waitable object. This is a strong indication of a synchronization error.
D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: Draw cannot be invoked while a bound Resource is currently mapped. The Vertex Shader Constant Buffer at slot (0) is still mapped. [ EXECUTION ERROR #364: DEVICE_DRAW_BOUND_RESOURCE_MAPPED]

Not sure what's causing these errors yet, possibly incorrect use of the Diligent API on my part (I'm fairly new to rendering APIs in general). But I'm using the Diligent::ImGuiImplDiligent which is unchanged and handles all the draw calls. Maybe it's a problem with the way I initialize the DiligentEngine for each window? (creating swapchains from existing device and context)

The errors repeatedly show only when rendering a new window and disappear otherwise. The application crashes sometimes, I can't recreate the crashing consistently.


Issue 2:

The ImGui viewports feature doesn't work with OpenGL since we cant create multiple swapchains. I'm assuming this is a known issue since it's mentioned in the multi-window tutorial. There might be a hacky way around it but it would require changing the way DiligentImguiRenderer handles binding contexts. (I'm assuming this will only work since I'm using GLFW)


Update cont.

Currently, my implementation (and any application that uses it) will heavily rely on GLFW and the respective backend files from ImGui. Implementing a backend for Diligent will require more work than is needed for my project, but if it helps others I'm willing to spend a bit more time and try and figure it out. It doesn't look particularly simple though. It needs to handle window create/delete then handle input/window events send them to ImGUI. There's a more detailed description in the ImGui Repo

@TheMostDiligent
Copy link
Contributor

For the errors: make sure that you call GetCurrentBackBufferRTV from each swap chain every frame. Follow the multiwindow tutorial.

OpenGL backend does not support multiple windows and multiple swap chains. We are not planning to add this feature and in general strongly discourage anyone to use OpenGL unless there is a very good reason to use it.

Implementing a backend for Diligent will require more work than is needed for my projec
What backend do you mean? Imgui backend?

@hamyyy
Copy link
Contributor Author

hamyyy commented Feb 13, 2022

Thanks for the quick reply!

I double checked and I am calling GetCurrentBackBufferRTV() every frame for every swap chain. The problem still persists.

I agree with you, OpenGL is a last resort, I just wanted to make sure an application won't break if someone decides to use it. The ImGui docking features are still enabled, However, the viewport features are not.

What backend do you mean? Imgui backend?

yes my bad, I meant ImGui backend (eg. imgui/backends/imgui_impl_glfw.h). Ideally, there would be one for Diligent since Diligent handles its own native window creation. glfw works for now though.

@TheMostDiligent
Copy link
Contributor

I don't know the reasons for the errors, but incorrect API usage is the most likely cause. Check Multiple Windows tutorial and ImGUI demo - they all run without errors.

I meant ImGui backend. Ideally, there would be one for Diligent since Diligent handles its own native window creation. glfw works for now though.

There already exists Diligent implementation for imgui.

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

No branches or pull requests

2 participants