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

Add support for user images to ImGui integration of SampleBase #9

Open
Marlax0 opened this issue Feb 12, 2025 · 4 comments
Open

Add support for user images to ImGui integration of SampleBase #9

Marlax0 opened this issue Feb 12, 2025 · 4 comments

Comments

@Marlax0
Copy link

Marlax0 commented Feb 12, 2025

I see SampleBase has ImGui integrated, but it doesn't have support for user images or custom font textures.
A working example of this for NRI would be really useful, and I guess this would be the most convenient place to do it.

Ideally the Descriptor* would be used as the ImTextureID, but I'm not sure how to make that work with NRI's design.

I'm currently very inexperienced with NRI, but integration is clearly not as simple as:

nri::Descriptor* image = (nri::Descriptor*)drawCmd.GetTexID();

if (image)
{
    nri::DescriptorRangeUpdateDesc descriptorRangeUpdateDesc[] = {
        {&image, 1},
        {&m_Sampler, 1}};

    NRI.UpdateDescriptorRanges(*m_DescriptorSet, 0, helper::GetCountOf(descriptorRangeUpdateDesc), descriptorRangeUpdateDesc);
}

NRI.CmdSetScissors(commandBuffer, &rect, 1);
NRI.CmdDrawIndexed(commandBuffer, {drawCmd.ElemCount, 1, indexOffset, vertexOffset, 0});

(As UpdateDescriptorRanges() is immediate but CmdDrawIndexed() buffered.)

Since the descriptor set part of NRI sort of resembles Vulkan, perhaps this issue is relevant: ocornut/imgui#914

@dzhdanNV
Copy link
Collaborator

Hi! As it was discussed here NVIDIA-RTX/NRI#111, it does make sense to develop an NRI-based ImGui backend and (ideally) just get it published in "ImGui" repo. But as a start, why not do it in NRIFramework? I will add support to user images soon...

@dzhdanNV
Copy link
Collaborator

I think, the productization should be done in this order:

  • fully functional ImGui renderer in NRI framework
  • wrap this into a standalone NRI extension
  • reorganize into an ImGui backend

@Marlax0
Copy link
Author

Marlax0 commented Feb 16, 2025

I think that plan sounds great.

To learn NRI, I wanted to create a simple 2D sprite batcher utility, which generates triangles and draw lists in a similar way to ImGui.
So from my perspective a fully featured ImGui backend would be another excellent example to learn from.

I ended up just grabbing a DescriptorSet* from a frame-buffered pool, whenever the current batch texture changes.

I'm sure there is a better way, so I'm looking forward to seeing what someone with more NRI experience can come up with for ImGui.
I picked up NRI after exclusively learning D3D12, so the whole DescriptorSet concept is new to me.

@dzhdanNV
Copy link
Collaborator

I ended up just grabbing a DescriptorSet from a frame-buffered pool, whenever the current batch texture changes.

Sounds right. IMO, to minimize copy operations 2 sets are needed: one for all static stuff, another one (with several instances) for a texture (which can change). The another one should be allocated from a ring buffer, big enough to maintain desired number of user textures per frame multiplied by number of frames in flight.

so I'm looking forward to seeing what someone with more NRI experience can come up with for ImGui.

We will see what I will be able to reach :) What I use now does vertex data packing to minimize CPU-GPU traffic and offers minimal HDR support.

I picked up NRI after exclusively learning D3D12, so the whole DescriptorSet concept is new to me.

NRI tries to not introduce new concepts. DescriptorSet is from Vulkan. It's there because... Vulkan is the common denominator (i.e. D3D12 and even D3D11 can be made looking like VK, while VK can not be made looking like D3D12). DescriptorSet in D3D12 backend is just a continuous range of descriptors in a DescriptorPool (descriptor heap in D3D12).

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