mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
69 lines
1.8 KiB
Beef
69 lines
1.8 KiB
Beef
#if GE_GRAPHICS_DX11
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using DirectX.Common;
|
|
using DirectX.D3D11;
|
|
using GlitchyEngine.Platform.DX11;
|
|
using System.Collections;
|
|
|
|
using internal GlitchyEngine.Renderer;
|
|
using internal GlitchyEngine.Platform.DX11;
|
|
|
|
namespace GlitchyEngine.Renderer
|
|
{
|
|
public extension VertexLayout
|
|
{
|
|
private Dictionary<ID3DBlob*, ID3D11InputLayout*> _validatedShaders = new .() ~
|
|
{
|
|
if (_ != null)
|
|
{
|
|
for (let entry in _)
|
|
{
|
|
entry.key.Release();
|
|
entry.value.Release();
|
|
}
|
|
|
|
delete _;
|
|
}
|
|
};
|
|
|
|
private void ToNativeLayout(VertexElement[] input, InputElementDescription[] output)
|
|
{
|
|
Debug.Assert(input.Count == output.Count);
|
|
|
|
for(int i < input.Count)
|
|
output[i] = .(input[i].SemanticName, input[i].SemanticIndex, (.)input[i].Format, input[i].InputSlot, input[i].AlignedByteOffset, (.)input[i].InputSlotClass, input[i].InstanceDataStepRate);
|
|
}
|
|
|
|
/// This should happen during shader compilation!
|
|
/// Validates or gets the validated input layout for the given vertexshader.
|
|
internal ID3D11InputLayout* GetNativeVertexLayout(ID3DBlob* vertexShaderCode)
|
|
{
|
|
Debug.Profiler.ProfileResourceFunction!();
|
|
|
|
ID3D11InputLayout* layout = null;
|
|
|
|
if (!_validatedShaders.TryGetValue(vertexShaderCode, out layout))
|
|
{
|
|
var nativeElements = scope InputElementDescription[_elements.Count];
|
|
|
|
ToNativeLayout(_elements, nativeElements);
|
|
|
|
var result = NativeDevice.CreateInputLayout(nativeElements.CArray(), (.)nativeElements.Count, vertexShaderCode.GetBufferPointer(), vertexShaderCode.GetBufferSize(), &layout);
|
|
if(result.Failed)
|
|
{
|
|
Log.EngineLogger.Error($"Failed to create D3D11 input layout: Message({(int)result}): {result}");
|
|
Debug.FatalError();
|
|
}
|
|
|
|
_validatedShaders[vertexShaderCode..AddRef()] = layout;
|
|
}
|
|
|
|
return layout;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|