Skip to content

Commit

Permalink
added bindless support on imgui_renderer (JeanPhilippeKernel#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanPhilippeKernel authored Jan 24, 2025
1 parent adb990c commit fc9cdf7
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 184 deletions.
16 changes: 13 additions & 3 deletions Resources/Shaders/imgui.frag
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#version 460 core
#extension GL_EXT_nonuniform_qualifier : require
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : enable

layout(location = 0) out vec4 fColor;
layout(set = 0, binding = 0) uniform sampler2D sTexture;
layout(set = 0, binding = 0) uniform sampler2D TextureArray[];

layout(location = 0) in struct
{
vec4 Color;
vec2 UV;
vec4 TexData;
} In;

void main()
{
fColor = In.Color * texture(sTexture, In.UV.st);
uint texId = uint(In.TexData.z);
if (texId < 0xFFFFFFFFu)
{
vec4 texVal = texture(TextureArray[nonuniformEXT(texId)], In.TexData.xy);
fColor = In.Color * texVal;
}
}
10 changes: 4 additions & 6 deletions Resources/Shaders/imgui.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
layout(location = 0) in vec2 aPos;
layout(location = 1) in vec2 aUV;
layout(location = 2) in vec4 aColor;

layout(push_constant) uniform uPushConstant
{
vec2 uScale;
vec2 uTranslate;
uint index;
}
pc;

out gl_PerVertex
{
vec4 gl_Position;
};
layout(location = 0) out struct
{
vec4 Color;
vec2 UV;
vec4 TexData;
} Out;

void main()
{
Out.Color = aColor;
Out.UV = aUV;
Out.TexData = vec4(aUV, pc.index, 0.0);
gl_Position = vec4(aPos * pc.uScale + pc.uTranslate, 0, 1);
}
10 changes: 7 additions & 3 deletions Tetragrama/Components/ProjectViewUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ namespace Tetragrama::Components
{
if (!m_textures_loaded)
{
m_directory_icon = renderer->AsyncLoader->LoadTextureFileSync("Settings/Icons/DirectoryIcon.png");
m_file_icon = renderer->AsyncLoader->LoadTextureFileSync("Settings/Icons/FileIcon.png");
m_directory_icon = renderer->AsyncLoader->LoadTextureFileSync("Settings/Icons/DirectoryIcon.png");
m_file_icon = renderer->AsyncLoader->LoadTextureFileSync("Settings/Icons/FileIcon.png");

renderer->Device->TextureHandleToUpdates.Enqueue(m_directory_icon);
renderer->Device->TextureHandleToUpdates.Enqueue(m_file_icon);

m_textures_loaded = true;
}

Expand Down Expand Up @@ -99,7 +103,7 @@ namespace Tetragrama::Components

ImGui::PushID(name.c_str());

ImTextureID icon = entry.is_directory() ? static_cast<ImTextureID>(renderer->ImguiRenderer->UpdateDirIconOutput(m_directory_icon)) : static_cast<ImTextureID>(renderer->ImguiRenderer->UpdateFileIconOutput(m_file_icon));
ImTextureID icon = entry.is_directory() ? (ImTextureID) m_directory_icon.Index : (ImTextureID) m_file_icon.Index;

const float margin = 5.0f;
ImVec2 cursorPos = ImGui::GetCursorPos();
Expand Down
4 changes: 2 additions & 2 deletions Tetragrama/Components/SceneViewportUIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ namespace Tetragrama::Components
// Scene texture representation
if (!m_scene_texture || m_refresh_texture_handle)
{
m_scene_texture = renderer->GetImguiFrameOutput();
m_scene_texture = renderer->GetFrameOutput();
m_refresh_texture_handle = false;
}

ImGui::Image(m_scene_texture, m_viewport_size, ImVec2(0, 1), ImVec2(1, 0));
ImGui::Image((ImTextureID) m_scene_texture.Index, m_viewport_size, ImVec2(0, 1), ImVec2(1, 0));
// ViewPort bound computation
ImVec2 viewport_windows_size = ImGui::GetWindowSize();
ImVec2 minimum_bound = ImGui::GetWindowPos();
Expand Down
24 changes: 12 additions & 12 deletions Tetragrama/Components/SceneViewportUIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ namespace Tetragrama::Components
// std::future<void> SceneViewportUnfocusedMessageHandlerAsync(Messengers::GenericMessage<bool>&);

private:
bool m_is_window_focused{false};
bool m_is_window_hovered{false};
bool m_is_window_clicked{false};
bool m_refresh_texture_handle{false};
bool m_request_renderer_resize{false};
bool m_is_resizing{false};
int m_idle_frame_count = 0;
int m_idle_frame_threshold = 9; // SwapchainImageCount * 3
ImVec2 m_viewport_size{0.f, 0.f};
ImVec2 m_content_region_available_size{0.f, 0.f};
std::array<ImVec2, 2> m_viewport_bounds;
VkDescriptorSet m_scene_texture{VK_NULL_HANDLE};
bool m_is_window_focused{false};
bool m_is_window_hovered{false};
bool m_is_window_clicked{false};
bool m_refresh_texture_handle{false};
bool m_request_renderer_resize{false};
bool m_is_resizing{false};
int m_idle_frame_count = 0;
int m_idle_frame_threshold = 9; // SwapchainImageCount * 3
ImVec2 m_viewport_size{0.f, 0.f};
ImVec2 m_content_region_available_size{0.f, 0.f};
std::array<ImVec2, 2> m_viewport_bounds;
ZEngine::Rendering::Textures::TextureHandle m_scene_texture{};
};
} // namespace Tetragrama::Components
7 changes: 4 additions & 3 deletions ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace ZEngine::Rendering::Renderers

FrameColorRenderTarget = Device->GlobalTextures->Add(CreateTexture({.PerformTransition = false, .Width = 1280, .Height = 780, .Format = ImageFormat::R8G8B8A8_UNORM}));
FrameDepthRenderTarget = Device->GlobalTextures->Add(CreateTexture({.PerformTransition = false, .Width = 1280, .Height = 780, .Format = ImageFormat::DEPTH_STENCIL_FROM_DEVICE}));

Device->TextureHandleToUpdates.Enqueue(FrameColorRenderTarget);
/*
* Subsystems initialization
*/
Expand Down Expand Up @@ -114,10 +116,9 @@ namespace ZEngine::Rendering::Renderers
RenderGraph->Execute(frame_index, command_buffer, scene);
}

VkDescriptorSet GraphicRenderer::GetImguiFrameOutput()
Textures::TextureHandle GraphicRenderer::GetFrameOutput()
{
auto rt_handle = RenderGraph->GetRenderTarget(FrameColorRenderTargetName);
return ImguiRenderer->UpdateFrameOutput(rt_handle);
return RenderGraph->GetRenderTarget(FrameColorRenderTargetName);
}

Helpers::Ref<RenderPasses::RenderPass> GraphicRenderer::CreateRenderPass(const Specifications::RenderPassSpecification& spec)
Expand Down
2 changes: 1 addition & 1 deletion ZEngine/ZEngine/Rendering/Renderers/GraphicRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace ZEngine::Rendering::Renderers
void Deinitialize();
void Update();
void DrawScene(Hardwares::CommandBuffer* const command_buffer, Cameras::Camera* const camera, Scenes::SceneRawData* const scene);
VkDescriptorSet GetImguiFrameOutput();
Textures::TextureHandle GetFrameOutput();

Helpers::Ref<RenderPasses::RenderPass> CreateRenderPass(const Specifications::RenderPassSpecification& spec);
Helpers::Ref<Textures::Texture> CreateTexture(const Specifications::TextureSpecification& spec);
Expand Down
Loading

0 comments on commit fc9cdf7

Please sign in to comment.