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

WebGPU ImGui::Image not accepts different texture formats #7592

Closed
PhantomCloak opened this issue May 15, 2024 · 3 comments
Closed

WebGPU ImGui::Image not accepts different texture formats #7592

PhantomCloak opened this issue May 15, 2024 · 3 comments

Comments

@PhantomCloak
Copy link

PhantomCloak commented May 15, 2024

Version/Branch of Dear ImGui:

Version 1.90.6, Branch: master

Back-ends:

imgui_impl_wgpu.cpp + imgui_impl_glfw.cpp

Compiler, OS:

macOS + Clang 17.0.6

Full config/build information:

No response

Details:

My Issue/Question:

I stumbled upon issue which when I directly attempt to display depth texture of the render pass through ImGui::Image program stops with below error, presumably due to sampler mismatch when Image tries to bind Depth texture as an WGPUTextureSampleType_Float format instead of WGPUTextureSampleType_Depth and I wonder if it's an design decision or missing feature? since being not able to set or specify the texture format for Image leads to introduce some manual labor on the users side such as converting different texture formats to WGPUTextureSampleType_Float through an additional pass.

Error:

WGPU error: None of the supported sample types (UnfilterableFloat|Depth) of [Texture (unlabeled 3840x2160 px, TextureFormat::Depth32Float)] match the expected sample
 types (Float).
 - While validating entries[0] as a Sampled Texture.
Expected entry layout: {sampleType: TextureSampleType::Float, viewDimension: 2, multisampled: 0}
 - While validating [BindGroupDescriptor] against [BindGroupLayout (unlabeled)]
 - While calling [Device "My Device"].CreateBindGroup([BindGroupDescriptor]).

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

  
  WGPUTextureDescriptor depthTextureDesc = {};
  depthTextureDesc.dimension = WGPUTextureDimension_2D;
  depthTextureDesc.format = WGPUTextureFormat_Depth32Float;
  depthTextureDesc.mipLevelCount = 1;
  depthTextureDesc.sampleCount = 1;
  depthTextureDesc.size.width = width;
  depthTextureDesc.size.height = height;
  depthTextureDesc.size.depthOrArrayLayers = 1;
  
  // Create shadowDepth texture ...
  // Create shadowDepthview ...
  
  ImGui::Image((ImTextureID)shadowDepthView, ImVec2(size.x, size.y));
@ocornut
Copy link
Owner

ocornut commented May 15, 2024

This is a topic that applies to every backends.

Generally the suggested solution (e.g. #3590) is to use a AddCallback() drawcmd to manually make the render change sampler or other render state. Note how e.g. #7511 or #6908 would lead to same direction.

Now, whether this is easy or even possible might depends on the backend and how to alter that render state.
For some backends user code may lack access to backend internal data and we may need a solution for that.
I think you should dig in WGPU backend and see if you can find a way to implement this via draw callbacks.

Generally I think we ought to find solution to make some common case easier (e.g. switch from linear to point filtering).
#2697 essentially proposed making user able to rewire texture binding code while using standard backends which is probably a desirable eventually but would drag a bunch of other things, as user code may need more standardized access to some backend internal data.

@PhantomCloak
Copy link
Author

Thanks for the clarification. I agree this not might be easy since problem is tricky to solve in a backend agnostic way which is case for WebGPU too due to lack of api to determine texture state after creation but I will look draw callbacks and what can I do. I close this issue due to there is already plenty of discussions about similar points.

@ocornut
Copy link
Owner

ocornut commented May 16, 2024

The general idea is:

  • try to solve it with callbacks
  • if something is in your way to be able to solve it with callbacks, please discuss specifics and we can discuss modifying backend accordingly.

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

No branches or pull requests

2 participants