Refactor shader pipeline and improve modularity

- Added `generatedCodePath` to `FullPassDescriptor` for better shader code organization.
- Removed redundant `IID_PPV_ARGS` method and unused `Misaki.HighPerformance.Unsafe` reference.
- Refactored `Material` and `MaterialAccessor` to use `CBuffer` and updated buffer size handling.
- Renamed command buffer variables in `RenderingContext` for consistency.
- Updated `D3D12PipelineLibrary` to cache compiled shader results and added `ShaderPassKey`.
- Refactored `D3D12GraphicsEngine` to integrate `_copyCommandBuffer` lifecycle.
- Enhanced `D3D12ResourceAllocator` with shader pass creation using constant buffer info.
- Simplified `D3D12ShaderCompiler` with `GENERATED_CODE_PATH` support and improved reflection handling.
- Introduced `CBufferPropertyInfo` and `CBufferInfo` structs for better encapsulation.
- Updated HLSL shaders to use `g_PerMaterialData` and dynamic includes.
- Improved error handling in `SDLCompiler` with try-catch blocks and better messages.
- Refactored `test.gshader` to use dynamically generated includes.
- Fixed typos, improved code readability, and removed unused code.
This commit is contained in:
2025-11-14 19:41:36 +09:00
parent 708b8cd065
commit d91d6f6e57
20 changed files with 325 additions and 321 deletions

View File

@@ -7,66 +7,23 @@ using System.Runtime.InteropServices;
namespace Ghost.Graphics.Core;
public readonly struct TextureInfo
{
public uint RegisterSlot
{
get; init;
}
public uint RootParameterIndex
{
get; init;
}
}
public readonly struct PropertyInfo
{
public uint CBufferIndex
{
get; init;
}
public uint ByteOffset
{
get; init;
}
public uint Size
{
get; init;
}
}
public readonly struct CBufferInfo
{
public uint Size
{
get; init;
}
public uint RegisterSlot
{
get; init;
}
}
public unsafe class ShaderPass : IResourceReleasable
public class ShaderPass : IResourceReleasable
{
private CBufferInfo _cbufferInfo;
// NOTE: This is for per pass cbuffer only. Global, per view, and per mesh cbuffers are fixed.
private readonly Dictionary<string, int> _propertyLookup;
private readonly UnsafeList<PropertyInfo> _properties;
internal CBufferInfo PassPropertyInfo
{
get;
}
public CBufferInfo CBuffer => _cbufferInfo;
public ShaderPass(CBufferInfo info, UnsafeList<PropertyInfo> properties, Dictionary<string, int> propertyNameToIdMap)
public ShaderPass(CBufferInfo info)
{
PassPropertyInfo = info;
_properties = properties;
_propertyLookup = propertyNameToIdMap;
_cbufferInfo = info;
_propertyLookup = new Dictionary<string, int>(info.Properties.Count);
for (var i = 0; i < info.Properties.Count; i++)
{
_propertyLookup[info.Properties[i].Name] = i;
}
}
public int GetPropertyId(string propertyName)
@@ -74,19 +31,18 @@ public unsafe class ShaderPass : IResourceReleasable
return _propertyLookup.TryGetValue(propertyName, out var id) ? id : -1;
}
public PropertyInfo GetPropertyInfo(int id)
public CBufferPropertyInfo GetPropertyInfo(int id)
{
return _properties[id];
return _cbufferInfo.Properties[id];
}
public PropertyInfo GetPropertyInfo(string propertyName)
public CBufferPropertyInfo GetPropertyInfo(string propertyName)
{
return _properties[GetPropertyId(propertyName)];
return _cbufferInfo.Properties[GetPropertyId(propertyName)];
}
void IResourceReleasable.ReleaseResource(IResourceDatabase database)
{
_properties.Dispose();
}
}