Skip to content

Redesign the Zenith.NET rendering hardware interface - #28

Merged
qian-o merged 467 commits into
masterfrom
refactor/rhi-redesign
Jul 29, 2026
Merged

qian-o merged 467 commits into
masterfrom
refactor/rhi-redesign

Conversation

@qian-o

@qian-o qian-o commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Redesign the Zenith.NET RHI around a unified resource, pipeline, command, synchronization, and presentation model.
  • Align the DirectX 12, Metal, and Vulkan backends with the redesigned public API, including bindless resources, ray tracing, mesh shading, queries, and timestamp conversion.
  • Update extensions, views, experiments, package metadata, guides, tutorials, and generated API documentation for the new model.

Validation

  • dotnet build Zenith.NET.slnx -c Release --nologo --disable-build-servers
  • dotnet format Zenith.NET.slnx --verify-no-changes --no-restore
  • docfx documents/docfx.json --warningsAsErrors
  • Platform detection smoke test on macOS/Metal
  • Markdown relative-link and code-fence validation across 28 files

qian-o added 30 commits June 14, 2026 19:57
Renamed RenderState fields: RasterizerState → Rasterizer, DepthStencilState → DepthStencil, and BlendState → Blend. Updated all usages across the codebase to match the new names for improved consistency and readability.
Refactored variable name colorAttachmentBlendStates to states in DXGraphicsPipeline and DXMeshShadingPipeline for improved naming consistency. No functional changes were made.
The Metal backend in ZenithCompiler no longer passes the
"-Xmetal" and "-std=metal4.0" arguments. Only "metallib"
and "-capability metallib_latest" are now included for
Metal compilation.
Introduced the ThreadGroupSize struct with X, Y, and Z fields in the Zenith.NET namespace. Updated ShaderDesc to include a ThreadGroupSize field for specifying thread group dimensions.
Refactored CompileFromFile and CompileFromSource to return ShaderDesc instead of byte array, using SlangCompiler.CompileWithReflection to include reflection data. Renamed entry to name, added ThreadGroupSize extraction, and simplified argument construction by replacing SlangCompilerArguments with Arguments.
Refactored shader creation calls to pass compiled shader code
directly to CreateShader, eliminating the use of anonymous
objects with Name and CodeBytes properties. This reduces
verbosity and streamlines shader instantiation in
PathTracingRenderer, RasterizationRenderer, and ImGuiRenderer.
Added MTLComputePipeline class for Metal compute pipeline integration, updated MTLGraphicsContext to instantiate it, introduced extension methods for casting, and replaced unsafe ResourceHandle casting with bit manipulation.
Added MTLMeshShadingPipeline for Metal backend, including pipeline and depth-stencil state creation, blend/attachment format handling, and resource cleanup. Introduced Metal() extension methods for MeshShadingPipeline and Heap. Updated MTLGraphicsContext to instantiate MTLMeshShadingPipeline.
Added MTLQueryHeap class for Metal backend, managing Metal counter heaps and result buffers. Updated MTLGraphicsContext to instantiate MTLQueryHeap. Introduced extension for casting QueryHeap to MTLQueryHeap. Improved resource cleanup and added methods for result handling and resource naming.
Added MTLSwapChain to manage Metal-specific swap chain operations, including initialization, resizing, presentation, and cleanup. Replaced NotImplementedException in CreateSwapChainImpl. Introduced extension method for casting SwapChain to MTLSwapChain.
Ensure MetalDrawable is disposed immediately after presenting in PresentImpl(), releasing resources before acquiring the next drawable from MetalLayer.
Changed SubresourceIndex to use arrayLayer-major order,
calculating index as (arrayLayer * mipLevels) + mipLevel
instead of (mipLevel * arrayLayers) + arrayLayer. This
aligns subresource indexing with expected conventions.
Changed linear index calculation for subresources in DXTexture and Texture classes from (MipLevel * ArrayLayers) + ArrayLayer to MipLevel + (ArrayLayer * MipLevels), ensuring consistent addressing of subresources in memory.
Deleted the TextureSubresourceLayers struct and its associated fields (MipLevel, BaseArrayLayer, LayerCount) from TextureSubresourceLayers.cs, including the namespace declaration.
Introduced ImportTextureType enum and ImportTextureDesc struct to enable importing external textures (D3D11, D3D12, Metal, etc.). Extended GraphicsContext with ImportTexture method and abstract implementation. Updated SurfaceType enum formatting and removed D3D11Interop surface creation in favor of the new import mechanism.
Replaced OpaqueWin32 with VulkanWin32 and OpaqueFd with VulkanLinux in the ImportTextureType enum. Added a new VulkanAndroid value to extend platform support.
Renamed the main rendering texture from Target to Drawable across the codebase for clarity. Updated related property and parameter names in Surface, RenderEventArgs, and ZenithView. Renamed ZenithViewHelper.Format to DrawableFormat and updated all references to ensure consistent and correct usage for texture creation and swap chain setup.
Replaces platform-specific D3DTexture classes with unified Surface abstractions for WinUI, MAUI, and WPF. Updates all usages to leverage Surface, centralizing Direct3D interop, keyed mutex, and shared handle logic. Switches to ZenithViewHelper.DrawableFormat for texture/swapchain formats. Adds ImportTextureImpl to GraphicsContext for D3D11 texture import. Refactors DXSwapChain for consistent backbuffer management. Improves maintainability and cross-platform rendering consistency.
Replaces ColorFormat with DrawableFormat in Surface and related code. DrawableFormat now returns a default value for unsupported pixel formats instead of throwing exceptions, improving robustness when handling unknown formats. Affects bitmap creation, swap chain, and texture descriptors.
Expanded texture usages for swapchain textures to include Sampled, Storage, CopySrc, and CopyDst in both DX and Metal backends. Simplified Metal swapchain drawable update logic and implemented shared texture import in MTLGraphicsContext.
Removed Sampled, Storage, and CopySrc usages from texture creation, retaining only ColorAttachment and CopyDst. Also removed redundant context.Register call in MTLHeap for cleaner heap initialization.
Refactor DXSwapChain to use GraphicsCommandQueue for swap chain creation. In MTLSwapChain, signal the drawable before presenting to improve synchronization.
Replaces ImportTexture/ImportTextureDesc with an overloaded
CreateTexture method that accepts TextureDesc, NativeTextureType,
and a native handle. Removes ImportTextureType and ImportTextureDesc.
Updates all platform-specific and abstract implementations to use
the new API. Introduces NativeTextureType enum for clarity.
Allow CommandSubmission.Queue to be nullable and update all usages to check for null before waiting. Refactor App.cs to track and wait for the last submission for proper synchronization. Improve ImGui UI code clarity. Update DXCommandQueue and MTLCommandQueue to skip null queues in WaitImpl, preventing potential null reference errors.
Removed the call to Context.GraphicsCommandQueue.SignalDrawable(MetalDrawable) in the PresentImpl() method of MTLSwapChain. Now, only MetalDrawable.Present() is invoked before disposing and acquiring the next drawable. This simplifies the present logic and may address unnecessary signaling.
Refactor NativeTextureType to use explicit, platform-specific names and add new types for cross-platform support. Update texture creation logic in Surface, ZenithView.WinUI, and MTLGraphicsContext to use the new enum values and improve platform handling. Enhances clarity and maintainability.
Changed DXCommandBuffer constructor to accept DXCommandQueue instead of the base CommandQueue type, and updated the base constructor call to match. This ensures type consistency and may enable DX-specific functionality.
Introduced MTLCommandBuffer with method stubs and partial timestamp support. Refactored MTLBuffer to remove GpuAddress field, updating MTLBufferView to access GPU address via Buffer property. Updated MTLCommandQueue to create MTLCommandBuffer and expose Context.
Replaced primary constructor with explicit one. Removed ResourceHandle field and introduced auto-properties for ConstantHandle, StorageReadOnlyHandle, and StorageReadWriteHandle, initializing them in the constructor. Updated property overrides accordingly.
Add implementations for buffer/texture copy, debug markers, render pass, and barrier methods in MTLCommandBuffer. Manage Metal command encoders and defer scissor/viewport state as needed. Refactor DXCommandBuffer to use local variables for scissor/viewport assignment. Add stub for BarrierStages conversion in MTLFormats and improve resource cleanup.
qian-o added 22 commits July 27, 2026 23:08
The Microsoft YaHei font file (msyh.ttf) was completely replaced with a new binary version. This update may affect font rendering in the application. No source code changes were made in this commit.
Swapped the display order of "Particles" and "FPS" in ImGui.Text.
Now, "FPS" is shown before "Particles". No other logic changed.
The MemoryPlayground project and all related files (MemoryPlayground.csproj, Program.cs, launchSettings.json) were deleted. The solution file (Zenith.NET.slnx) was updated to remove references to MemoryPlayground.
Added launchSettings.json defining two profiles: "FluidTank" for standard execution and "FluidTank (WSL)" for running the project using WSL2. This enables flexible project launch configurations.
Upgraded the NuGet package version in NuGet.Packaging.props from 0.0.8 to 1.0.0-rc to incorporate the latest release candidate features and fixes.
Refactored EndRenderEncoding and EndComputeEncoding to use explicit null checks for Render and Compute objects. This prevents potential null reference exceptions by ensuring methods return early if dependencies are missing, replacing the previous use of the null-conditional operator.
Added a UTF-8 Byte Order Mark (BOM) to the beginning of queries.md and shaders.md to ensure proper encoding recognition. No other content was changed.
The BOM (Byte Order Mark) was added to both the `Zenith.NET.slnx` and `FluidTank.csproj` files. No other content changes were made.
Refactored mathematical expressions for clarity and consistency:
- Added parentheses in CameraHandler.cs to clarify NDC calculations.
- Made multiplication order explicit in FluidTankGeometry.cs for improved readability. No logic changes were made.
Copilot AI review requested due to automatic review settings July 29, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

qian-o added 4 commits July 29, 2026 17:27
Introduce ImGuiHelper with Overlay and Settings methods to streamline ImGui window rendering. Update App class to use these helpers for displaying device info and Cornell Box settings, replacing previous UI logic.
Removed IDisposableObject and INativeObject interfaces. DisposableObject now implements IDisposable directly. GraphicsContext and GraphicsResource no longer implement INativeObject.
@qian-o
qian-o merged commit c635d9e into master Jul 29, 2026
2 checks passed
@qian-o
qian-o deleted the refactor/rhi-redesign branch July 29, 2026 10:44
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

Successfully merging this pull request may close these issues.

2 participants