forked from Misaki/GhostEngine
Add high-performance material/shader system (Ghost.Shader.Concept)
Introduces a new Ghost.Shader.Concept project implementing a modern, data-oriented material and shader system with: - Global/local keyword bitsets (fast O(1) ops, 64 bytes) - Multi-pass shader program and per-pass render state overrides - Thread-safe, 16-byte aligned material property blocks - Material pooling to reduce GC pressure - Batch renderer for efficient PSO grouping and async variant warmup - Full demo (Program.cs) and extensive documentation (ARCHITECTURE.md, README.md, PROJECT_SUMMARY.md) - Minor integration: new enums, doc updates, and keyword handling in existing code No breaking changes to the existing engine; all new code is isolated. This serves as a reference implementation for high-performance, extensible material/shader architectures.
This commit is contained in:
@@ -58,7 +58,7 @@ public readonly struct ShaderPassKey : IEquatable<ShaderPassKey>
|
||||
|
||||
public readonly struct GraphicsPipelineKey
|
||||
{
|
||||
public const int KEY_STRING_LENGTH = 17; // 16 chars + null terminator
|
||||
public const int KEY_STRING_LENGTH = 33; // 32 chars + null terminator
|
||||
|
||||
public readonly UInt128 value;
|
||||
|
||||
@@ -98,12 +98,13 @@ public readonly struct GraphicsPipelineKey
|
||||
|
||||
public Result GetString(Span<char> destination)
|
||||
{
|
||||
if (!value.TryFormat(destination, out _, "X16"))
|
||||
if (!value.TryFormat(destination, out var num, "X16"))
|
||||
{
|
||||
return Result.Failure("Failed to format GraphicsPipelineKey to string.");
|
||||
}
|
||||
|
||||
destination[16] = '\0';
|
||||
// Just in case.
|
||||
destination[num] = '\0';
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
@@ -733,7 +734,7 @@ public struct BufferDesc
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Memory type for the buffer
|
||||
/// Memory space for the buffer
|
||||
/// </summary>
|
||||
public ResourceMemoryType MemoryType
|
||||
{
|
||||
@@ -814,7 +815,7 @@ public struct SwapChainDesc
|
||||
public struct SwapChainTarget
|
||||
{
|
||||
/// <summary>
|
||||
/// Target type
|
||||
/// Target space
|
||||
/// </summary>
|
||||
public SwapChainTargetType Type
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Ghost.Graphics.RHI;
|
||||
public interface ICommandBuffer : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the type of the command buffer.
|
||||
/// Gets the space of the command buffer.
|
||||
/// </summary>
|
||||
CommandBufferType Type
|
||||
{
|
||||
@@ -125,7 +125,7 @@ public interface ICommandBuffer : IDisposable
|
||||
/// Binds an index buffer for indexed drawing.
|
||||
/// </summary>
|
||||
/// <param name="buffer">The handle to the graphics buffer containing index data.</param>
|
||||
/// <param name="type">The type of indices (e.g., 16-bit or 32-bit).</param>
|
||||
/// <param name="type">The space of indices (e.g., 16-bit or 32-bit).</param>
|
||||
/// <param name="offset">The offset in bytes from the start of the buffer.</param>
|
||||
void SetIndexBuffer(Handle<GraphicsBuffer> buffer, IndexType type, ulong offset = 0);
|
||||
|
||||
@@ -179,9 +179,9 @@ public interface ICommandBuffer : IDisposable
|
||||
/// <summary>
|
||||
/// Uploads the specified data to the buffer represented by the given handle.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The unmanaged Value type of the elements to upload to the buffer.</typeparam>
|
||||
/// <typeparam name="T">The unmanaged Value space of the elements to upload to the buffer.</typeparam>
|
||||
/// <param name="buffer">A handle to the buffer that will receive the uploaded data.</param>
|
||||
/// <param name="data">A read-only span containing the data to upload to the buffer. The span must contain elements of type
|
||||
/// <param name="data">A read-only span containing the data to upload to the buffer. The span must contain elements of space
|
||||
/// <typeparamref name="T"/>.</param>
|
||||
void UploadBuffer<T>(Handle<GraphicsBuffer> buffer, ReadOnlySpan<T> data)
|
||||
where T : unmanaged;
|
||||
|
||||
@@ -50,10 +50,10 @@ public interface IGraphicsEngine : IDisposable
|
||||
void ClearRenderers();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new command allocator for the specified command buffer type.
|
||||
/// Creates a new command allocator for the specified command buffer space.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of command buffer for which to create the allocator. The default is CommandBufferType.Graphics.</param>
|
||||
/// <returns>An <see cref="ICommandAllocator"/> instance configured for the specified command buffer type.</returns>
|
||||
/// <param name="type">The space of command buffer for which to create the allocator. The default is CommandBufferType.Graphics.</param>
|
||||
/// <returns>An <see cref="ICommandAllocator"/> instance configured for the specified command buffer space.</returns>
|
||||
ICommandAllocator CreateCommandAllocator(CommandBufferType type = CommandBufferType.Graphics);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Ghost.Graphics.RHI;
|
||||
public interface IShaderPipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// Pipeline type
|
||||
/// Pipeline space
|
||||
/// </summary>
|
||||
PipelineType Type
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ public interface IResourceDatabase : IDisposable
|
||||
/// <summary>
|
||||
/// Imports an external unmanaged resource and returns a handle for use within the resource management system.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the unmanaged resource pointer to import.</typeparam>
|
||||
/// <typeparam name="T">The space of the unmanaged resource pointer to import.</typeparam>
|
||||
/// <param name="resourcePtr">A pointer to the external unmanaged resource to be imported. Must remain valid for the duration of the resource's usage.</param>
|
||||
/// <param name="initialState">The initial state to assign to the imported resource.</param>
|
||||
/// <returns>A handle representing the imported resource, which can be used for subsequent operations.</returns>
|
||||
|
||||
Reference in New Issue
Block a user