forked from Misaki/GhostEngine
Refactor and enhance graphics and audio systems
Updated target frameworks to .NET 10.0 across multiple projects for compatibility with the latest features. Refactored namespaces and introduced new classes for shader descriptors, FMOD integration, and DirectX 12 utilities using TerraFX. Replaced `Win32` bindings with TerraFX equivalents for DirectX 12. Added a C# wrapper for FMOD Studio API, including DSP and error handling. Enhanced entity queries, component storage, and query filters for better performance and type safety. Introduced new test projects and updated the solution structure. Added `meshoptimizer` bindings and integrated `meshoptimizer_native.dll`. Improved code readability, maintainability, and performance.
This commit is contained in:
@@ -9,21 +9,16 @@ namespace Ghost.Graphics.Data;
|
||||
|
||||
public struct Material : IHandleType
|
||||
{
|
||||
internal UnsafeArray<CBufferCache> _cBufferCaches;
|
||||
internal CBufferCache _materialPropertiesCache;
|
||||
|
||||
public Identifier<Shader> Shader
|
||||
{
|
||||
get; internal set;
|
||||
}
|
||||
|
||||
internal void Dispose()
|
||||
internal readonly void Dispose()
|
||||
{
|
||||
foreach (var cache in _cBufferCaches)
|
||||
{
|
||||
cache.Dispose();
|
||||
}
|
||||
|
||||
_cBufferCaches.Dispose();
|
||||
_materialPropertiesCache.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +51,7 @@ public ref struct MaterialAccessor
|
||||
throw new ArgumentException($"Property '{propertyId}' has a size mismatch. Expected {propInfo.Size} bytes, but got {sizeof(T)} bytes.");
|
||||
}
|
||||
|
||||
var cache = _materialData._cBufferCaches[propInfo.CBufferIndex];
|
||||
var cache = _materialData._materialPropertiesCache[propInfo.CBufferIndex];
|
||||
|
||||
Unsafe.WriteUnaligned(ref cache.CpuData[(int)propInfo.ByteOffset], value);
|
||||
}
|
||||
@@ -155,9 +150,15 @@ public ref struct MaterialAccessor
|
||||
/// <param name="propertyName">The name of the shader property (e.g., "_TextureIndex1")</param>
|
||||
/// <param name="texture">The bindless texture to reference</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void SetTextureIndex(string propertyName, Handle<Texture> texture)
|
||||
public readonly void SetTextureBindless(string propertyName, Handle<Texture> texture)
|
||||
{
|
||||
SetUInt(propertyName, texture.BindlessDescriptor.Index);
|
||||
var bindlessIndex = _resourceDatabase.GetBindlessIndex(texture.AsResource());
|
||||
if (bindlessIndex == -1)
|
||||
{
|
||||
throw new ArgumentException("The provided texture does not have a valid bindless index. Ensure the texture is created with bindless support.");
|
||||
}
|
||||
|
||||
SetUInt(propertyName, (uint)bindlessIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -167,10 +168,15 @@ public ref struct MaterialAccessor
|
||||
/// <param name="vertexBufferIndexProperty">The name of the vertex buffer index property</param>
|
||||
/// <param name="indexBufferIndexProperty">The name of the index buffer index property</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void SetMeshBufferIndex(ref readonly Mesh mesh, string vertexBufferIndexProperty = "_VertexBufferIndex", string indexBufferIndexProperty = "_IndexBufferIndex")
|
||||
public readonly void SetBufferBindless(string propertyName, Handle<GraphicsBuffer> buffer)
|
||||
{
|
||||
SetUInt(vertexBufferIndexProperty, mesh.vertexBuffer.BindlessDescriptor.Index);
|
||||
SetUInt(indexBufferIndexProperty, mesh.indexBuffer.BindlessDescriptor.Index);
|
||||
var bindlessIndex = _resourceDatabase.GetBindlessIndex(buffer.AsResource());
|
||||
if (bindlessIndex == -1)
|
||||
{
|
||||
throw new ArgumentException("The provided buffer does not have a valid bindless index. Ensure the buffer is created with bindless support.");
|
||||
}
|
||||
|
||||
SetUInt(propertyName, (uint)bindlessIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -180,7 +186,7 @@ public ref struct MaterialAccessor
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void UploadMaterialData(ICommandBuffer cmb)
|
||||
{
|
||||
foreach (var cache in _materialData._cBufferCaches)
|
||||
foreach (var cache in _materialData._materialPropertiesCache)
|
||||
{
|
||||
cmb.Upload(cache.GpuResource, cache.CpuData.AsSpan());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user