Exemple #1
0
        public unsafe IDxcBlob CompileLibrary(string filename, DxcShaderModel targetString)
        {
            // Open and read the file
            string pTextBlob = File.ReadAllText(filename);

            // Compile
            var pResult = DxcCompiler.Compile(DxcShaderStage.Library, pTextBlob, string.Empty, string.Empty, new DxcCompilerOptions()
            {
                ShaderModel = targetString
            });

            // Verify the result
            int resultCode;

            resultCode = pResult.GetStatus();
            if (resultCode != 0)
            {
                var    error   = pResult.GetErrors();
                string message = Marshal.PtrToStringAnsi((IntPtr)error.GetBufferPointer(), (int)error.GetBufferSize());
                Debug.WriteLine(message);
            }

            IDxcBlob pBlob;

            pBlob = pResult.GetResult();
            return(pBlob);
        }
Exemple #2
0
        public IDxcBlob CompileLibrary(string filename, DxcShaderModel targetString)
        {
            // Open and read the file
            string pTextBlob = File.ReadAllText(filename);

            // Compile
            var pResult = DxcCompiler.Compile(DxcShaderStage.Library, pTextBlob, string.Empty, string.Empty, new DxcCompilerOptions()
            {
                ShaderModel = targetString
            });

            // Verify the result
            int resultCode;

            resultCode = pResult.GetStatus();
            if (resultCode != 0)
            {
                Debug.WriteLine(pResult.GetStatus());
            }

            IDxcBlob pBlob;

            pBlob = pResult.GetResult();
            return(pBlob);
        }
Exemple #3
0
        private static string GetShaderProfile(ShaderStage shaderStage, DxcShaderModel shaderModel)
        {
            string shaderProfile = shaderStage switch
            {
                ShaderStage.VertexShader => "vs",
                ShaderStage.PixelShader => "ps",
                ShaderStage.GeometryShader => "gs",
                ShaderStage.HullShader => "hs",
                ShaderStage.DomainShader => "ds",
                ShaderStage.ComputeShader => "cs",
                ShaderStage.Library => "lib",
                _ => ""
            };

            shaderProfile += $"_{shaderModel.Major}_{shaderModel.Minor}";

            return(shaderProfile);
        }
    }
Exemple #4
0
    public static string GetShaderProfile(DxcShaderStage shaderStage, DxcShaderModel shaderModel)
    {
        string shaderProfile;

        switch (shaderStage)
        {
        case DxcShaderStage.Vertex:
            shaderProfile = "vs";
            break;

        case DxcShaderStage.Pixel:
            shaderProfile = "ps";
            break;

        case DxcShaderStage.Geometry:
            shaderProfile = "gs";
            break;

        case DxcShaderStage.Hull:
            shaderProfile = "hs";
            break;

        case DxcShaderStage.Domain:
            shaderProfile = "ds";
            break;

        case DxcShaderStage.Compute:
            shaderProfile = "cs";
            break;

        case DxcShaderStage.Library:
            shaderProfile = "lib";
            break;

        default:
            return(string.Empty);
        }

        shaderProfile += $"_{shaderModel.Major}_{shaderModel.Minor}";
        return(shaderProfile);
    }
Exemple #5
0
 public static byte[] Compile(DxcShaderStage shaderStage, string source, string entryPoint, string sourceName, DxcShaderModel shaderModel)
 {
     return(Compile(shaderStage, source, entryPoint, sourceName, new DxcCompilerOptions {
         ShaderModel = shaderModel, PackMatrixInRowMajor = true
     }));
 }