Add Encoding.GetBytes polyfill to simplify D3DCompiler

このコミットが含まれているのは:
Sergio Pedri committed 2023-12-17 12:48:27 +01:00
1 親 963ec0ecb4
コミット ef821be2b2
2ファイル変更
+28 -13

検索条件に一致するファイルはありません

+5 -13
ファイルの表示
@@ -47,19 +47,11 @@ internal static unsafe partial class D3DCompiler
D2D1CompileOptions options)
#endif
{
// Transcode the input HLSL source from Unicode to ASCII encoding
int maxLength = Encoding.ASCII.GetMaxByteCount(source.Length);
byte[] buffer = ArrayPool<byte>.Shared.Rent(maxLength);
int writtenBytes;
#if SOURCE_GENERATOR
fixed (char* pSource = source)
fixed (byte* pBuffer = buffer)
{
writtenBytes = Encoding.ASCII.GetBytes(pSource, source.Length, pBuffer, buffer.Length);
}
#else
writtenBytes = Encoding.ASCII.GetBytes(source, buffer);
#endif
int writtenBytes = Encoding.ASCII.GetBytes(source, buffer);
ReadOnlySpan<byte> sourceAscii = new(buffer, 0, writtenBytes);
bool enableLinking = (options & D2D1CompileOptions.EnableLinking) == D2D1CompileOptions.EnableLinking;
bool stripReflectionData = (options & D2D1CompileOptions.StripReflectionData) == D2D1CompileOptions.StripReflectionData;
@@ -75,7 +67,7 @@ internal static unsafe partial class D3DCompiler
// Compile the standalone D2D1 full shader
using ComPtr<ID3DBlob> d3DBlobFullShader = Compile(
source: buffer.AsSpan(0, writtenBytes),
source: sourceAscii,
macro: ASCII.D2D_FULL_SHADER,
d2DEntry: ASCII.Execute,
entryPoint: ASCII.Execute,
@@ -94,7 +86,7 @@ internal static unsafe partial class D3DCompiler
// Compile the export function
using ComPtr<ID3DBlob> d3DBlobFunction = Compile(
source: buffer.AsSpan(0, writtenBytes),
source: sourceAscii,
macro: ASCII.D2D_FUNCTION,
d2DEntry: ASCII.Execute,
entryPoint: default,