This video documents a significant refactor of the Hazel Engine's renderer, transitioning its resource management system from a Vulkan-specific implementation to a more abstract, NVRHI-based approach. The creator outlines the crucial concept of "resource frequency" (per-object, per-render-pass, static) to optimize descriptor set organization and binding. The core of the work involves rewriting the descriptor set manager and integrating a robust shader reflection system that treats shaders as the "source of truth" for resource declarations, ensuring input validation. Initial functional tests confirm progress in uniform buffer validation and binding set creation. However, the session culminates in complex debugging challenges, particularly with the shader reflection system incorrectly identifying texture dimensions (e.g., 1D instead of 2D or Cube), and a fundamental incompatibility arising from HLSL's separate texture and sampler model clashing with Vulkan's combined image sampler requirements, leading to unresolved resource binding errors.
Exploring Hazel Engine's Renderer Rewrite: From Vulkan to NVRHI
0:00 Renderer Refactor Context: The video begins by setting the stage for a major rewrite of Hazel Engine's renderer, focusing on getting 2D rendering operational as a stepping stone to 3D. The primary task identified is redesigning the resource/descriptor management system for better abstraction and multi-API support.
6:00 Resource Management Philosophy: The creator delves into the core problem of bridging shader resources (textures, buffers) with render passes. A key concept introduced is "resource frequency," categorizing how often resources change:
Set 0 (Per-Object): Most frequent, e.g., material textures.
Set 1 (Per-Render-Pass): Medium frequency, e.g., camera uniform buffers.
Set 2 (Per-Renderer-Frame): Less frequent, data applying to an entire renderer frame.
Set 3 (Static): Least frequent, e.g., BRDF lookup tables that never change.
This strategy aims to optimize GPU driver performance by defining the lifetime of resources.
19:05 Shader as Source of Truth: Shaders are established as the "source of truth" for defining resource inputs and outputs. This allows for automated validation, ensuring all required inputs are set and preventing accidental mismatches between shader expectations and engine-provided resources.
30:00 Descriptor Set Manager Rewrite (to NVRHI Binding Sets): The main refactoring effort involves converting Vulkan-specific VkDescriptorSet usage to NVRHI's more abstract binding set descriptions. This includes changes to data structures (e.g., using static arrays instead of vectors for better memory layout) and direct binding set creation, moving away from descriptor pools.
30:00 Dynamic Resource Handling: The system incorporates a mechanism (invalidate and update) for resources that can implicitly change (e.g., a framebuffer resized by the user). This uses a polling approach to check if underlying resource handles have changed, updating bindings as needed, a trade-off for reduced dependency complexity.
1:50:00 Architecture Simplification: The class hierarchy is streamlined by removing Vulkan-specific subclasses (e.g., VulkanRenderPass, VulkanComputePass), abstracting towards a single set of render and compute pass classes that can work with any graphics backend via NVRHI.
Initial tests confirm successful validation of camera uniform buffers and creation of NVRHI binding sets based on render pass specifications.
Texture Dimension Mismatch: A significant issue arises where the shader reflection system incorrectly identifies the dimensions of various textures (e.g., ImGUI font texture, shadow map textures, cube maps) as 1D, preventing correct binding.
Sampler Separation Conflict: A core problem is encountered with NVRHI's handling of samplers. The HLSL shader model allows separate textures and samplers, but Vulkan's VkDescriptorImageInfo expects a combined image sampler, leading to null sampler errors when updating descriptor sets. This highlights a fundamental challenge in multi-API abstraction.
3:03:35 Conclusion: The descriptor set manager rewrite is largely complete, but critical issues remain concerning texture dimension detection in shader reflection and the handling of separated textures and samplers, which will be addressed in future development streams.