コード例 #1
0
 internal static CompiledShader CompileShader(
     string shaderText,
     ReadOnlySpan <char> name,
     ReadOnlySpan <char> entrypoint,
     ShaderCompilationOptions options
     )
 {
     return(CompileShader(ToAscii(shaderText), name, entrypoint, options));
 }
コード例 #2
0
        //private static ComPtr<IDxcCompiler2> Compiler;

        //unsafe static ShaderManager()
        //{
        //    ComPtr<IDxcCompiler2> compiler = default;
        //    Guid clsid = Windows.CLSID_DxcCompiler;
        //    Guard.ThrowIfFailed(Windows.DxcCreateInstance(&clsid, compiler.Guid, ComPtr.GetVoidAddressOf(&compiler)));
        //    Compiler = compiler.Move();
        //}

        internal unsafe static CompiledShader CompileShader(
            ReadOnlySpan <byte> shaderTextAscii,
            ReadOnlySpan <char> name,
            ReadOnlySpan <char> entrypoint,
            ShaderCompilationOptions options
            )
        {
            fixed(byte *pData = shaderTextAscii)
            fixed(byte *pName                 = ToAscii(name))
            fixed(byte *pEntrypoint           = ToAscii(entrypoint))
            fixed(byte *pTarget               = AsTargetString(options.Target))
            fixed(D3D_SHADER_MACRO * pDefines = ToAsciiDefines(options.Defines.Span))
            fixed(byte *pSecondaryData        = options.SecondaryData.Span)
            {
                ID3DBlob *data  = default;
                ID3DBlob *error = default;
                int       hr    = Windows.D3DCompile2(
                    pData,
                    (nuint)shaderTextAscii.Length,
                    (sbyte *)pName,
                    pDefines,
                    (ID3DInclude *)Windows.D3D_COMPILE_STANDARD_FILE_INCLUDE,
                    (sbyte *)pEntrypoint,
                    (sbyte *)pTarget,
                    D3DCompileFlagsExtensions.GetCompileFlags(options.Flags),
                    0,
                    D3DCompileFlagsExtensions.GetSecDataFlags(options.Flags),
                    pSecondaryData,
                    (nuint)options.SecondaryData.Length,
                    &data,
                    &error
                    );

                return(ConstructShaderFromDataAndError(hr, data, error));
            }
        }