2018-04-08 21:17:35 +02:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
using Ryujinx.Graphics.Gal.Shader;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Concurrent;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.OpenGL
|
|
|
|
{
|
|
|
|
class OGLShader
|
|
|
|
{
|
2018-06-20 18:30:18 +02:00
|
|
|
private enum ShadingLanguage
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-06-20 18:30:18 +02:00
|
|
|
Unknown,
|
|
|
|
GLSL,
|
|
|
|
SPIRV
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
private abstract class ShaderStage : IDisposable
|
|
|
|
{
|
|
|
|
public int Handle { get; protected set; }
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
public GalShaderType Type { get; private set; }
|
|
|
|
|
|
|
|
public IEnumerable<ShaderDeclInfo> TextureUsage { get; private set; }
|
|
|
|
public IEnumerable<ShaderDeclInfo> UniformUsage { get; private set; }
|
|
|
|
|
|
|
|
public ShaderStage(
|
|
|
|
GalShaderType Type,
|
|
|
|
IEnumerable<ShaderDeclInfo> TextureUsage,
|
|
|
|
IEnumerable<ShaderDeclInfo> UniformUsage)
|
|
|
|
{
|
2018-06-20 18:30:18 +02:00
|
|
|
this.Type = Type;
|
2018-04-08 21:17:35 +02:00
|
|
|
this.TextureUsage = TextureUsage;
|
|
|
|
this.UniformUsage = UniformUsage;
|
|
|
|
}
|
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
public abstract void Compile();
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool Disposing)
|
|
|
|
{
|
|
|
|
if (Disposing && Handle != 0)
|
|
|
|
{
|
|
|
|
GL.DeleteShader(Handle);
|
|
|
|
|
|
|
|
Handle = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class GlslStage : ShaderStage
|
|
|
|
{
|
|
|
|
public string Code { get; private set; }
|
|
|
|
|
|
|
|
public GlslStage(
|
|
|
|
GalShaderType Type,
|
|
|
|
string Code,
|
|
|
|
IEnumerable<ShaderDeclInfo> TextureUsage,
|
|
|
|
IEnumerable<ShaderDeclInfo> UniformUsage)
|
|
|
|
: base(Type, TextureUsage, UniformUsage)
|
|
|
|
{
|
|
|
|
this.Code = Code;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Compile()
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
if (Handle == 0)
|
|
|
|
{
|
|
|
|
Handle = GL.CreateShader(OGLEnumConverter.GetShaderType(Type));
|
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
GL.ShaderSource(Handle, Code);
|
|
|
|
GL.CompileShader(Handle);
|
|
|
|
|
|
|
|
CheckCompilation(Handle);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-20 18:30:18 +02:00
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
private class SpirvStage : ShaderStage
|
|
|
|
{
|
|
|
|
public byte[] Bytecode { get; private set; }
|
|
|
|
|
|
|
|
public IDictionary<string, int> Locations { get; private set; }
|
|
|
|
|
|
|
|
public SpirvStage(
|
|
|
|
GalShaderType Type,
|
|
|
|
byte[] Bytecode,
|
|
|
|
IEnumerable<ShaderDeclInfo> TextureUsage,
|
|
|
|
IEnumerable<ShaderDeclInfo> UniformUsage,
|
|
|
|
IDictionary<string, int> Locations)
|
|
|
|
: base(Type, TextureUsage, UniformUsage)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-06-20 18:30:18 +02:00
|
|
|
this.Bytecode = Bytecode;
|
|
|
|
this.Locations = Locations;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
public override void Compile()
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-06-20 18:30:18 +02:00
|
|
|
if (Handle == 0)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-06-20 18:30:18 +02:00
|
|
|
Handle = GL.CreateShader(OGLEnumConverter.GetShaderType(Type));
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
BinaryFormat SpirvFormat = (BinaryFormat)0x9551;
|
|
|
|
|
|
|
|
GL.ShaderBinary(1, new int[]{Handle}, SpirvFormat, Bytecode, Bytecode.Length);
|
|
|
|
|
|
|
|
GL.SpecializeShader(Handle, "main", 0, new int[]{}, new int[]{});
|
|
|
|
|
|
|
|
CheckCompilation(Handle);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private struct ShaderProgram
|
|
|
|
{
|
|
|
|
public ShaderStage Vertex;
|
|
|
|
public ShaderStage TessControl;
|
|
|
|
public ShaderStage TessEvaluation;
|
|
|
|
public ShaderStage Geometry;
|
|
|
|
public ShaderStage Fragment;
|
|
|
|
}
|
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
private const int BuffersPerStage = Shader.UniformBinding.BuffersPerStage;
|
|
|
|
|
|
|
|
private const int BufferSize = 16 * 1024; //ARB_uniform_buffer, 16 KiB
|
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
private ShaderProgram Current;
|
|
|
|
|
|
|
|
private ConcurrentDictionary<long, ShaderStage> Stages;
|
|
|
|
|
|
|
|
private Dictionary<ShaderProgram, int> Programs;
|
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
private ShadingLanguage Language = ShadingLanguage.Unknown;
|
|
|
|
|
|
|
|
private OGLStreamBuffer[][] Buffers;
|
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
public int CurrentProgramHandle { get; private set; }
|
|
|
|
|
|
|
|
public OGLShader()
|
|
|
|
{
|
|
|
|
Stages = new ConcurrentDictionary<long, ShaderStage>();
|
|
|
|
|
|
|
|
Programs = new Dictionary<ShaderProgram, int>();
|
2018-06-20 18:30:18 +02:00
|
|
|
|
|
|
|
Buffers = new OGLStreamBuffer[5][]; //one per stage
|
|
|
|
|
|
|
|
for (int Stage = 0; Stage < 5; Stage++)
|
|
|
|
{
|
|
|
|
Buffers[Stage] = new OGLStreamBuffer[BuffersPerStage];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Prepare(bool TrySPIRV)
|
|
|
|
{
|
|
|
|
for (int Stage = 0; Stage < 5; Stage++)
|
|
|
|
{
|
|
|
|
for (int Cbuf = 0; Cbuf < BuffersPerStage; Cbuf++)
|
|
|
|
{
|
|
|
|
OGLStreamBuffer Buffer = OGLStreamBuffer.Create(BufferTarget.UniformBuffer, BufferSize);
|
|
|
|
|
|
|
|
Buffer.Allocate();
|
|
|
|
|
|
|
|
Buffers[Stage][Cbuf] = Buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TrySPIRV)
|
|
|
|
{
|
|
|
|
if (HasSPIRV())
|
|
|
|
{
|
|
|
|
Console.WriteLine("SPIR-V Shading Language");
|
|
|
|
Language = ShadingLanguage.SPIRV;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Console.WriteLine("GLSL fallback (SPIR-V not available)");
|
|
|
|
Language = ShadingLanguage.GLSL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Language = ShadingLanguage.GLSL;
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 03:43:31 +02:00
|
|
|
public void Create(IGalMemory Memory, long Tag, GalShaderType Type)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-05-23 03:43:31 +02:00
|
|
|
Stages.GetOrAdd(Tag, (Key) => ShaderStageFactory(Memory, Tag, Type));
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 03:43:31 +02:00
|
|
|
private ShaderStage ShaderStageFactory(IGalMemory Memory, long Position, GalShaderType Type)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-06-20 18:30:18 +02:00
|
|
|
switch (Language)
|
|
|
|
{
|
|
|
|
case ShadingLanguage.SPIRV:
|
|
|
|
{
|
|
|
|
SpirvProgram Program = GetSpirvProgram(Memory, Position, Type);
|
|
|
|
|
|
|
|
return new SpirvStage(
|
|
|
|
Type,
|
|
|
|
Program.Bytecode,
|
|
|
|
Program.Textures,
|
|
|
|
Program.Uniforms,
|
|
|
|
Program.Locations);
|
|
|
|
}
|
|
|
|
|
|
|
|
case ShadingLanguage.GLSL:
|
|
|
|
{
|
|
|
|
GlslProgram Program = GetGlslProgram(Memory, Position, Type);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
return new GlslStage(
|
|
|
|
Type,
|
|
|
|
Program.Code,
|
|
|
|
Program.Textures,
|
|
|
|
Program.Uniforms);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 03:43:31 +02:00
|
|
|
private GlslProgram GetGlslProgram(IGalMemory Memory, long Position, GalShaderType Type)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
GlslDecompiler Decompiler = new GlslDecompiler();
|
|
|
|
|
2018-05-23 03:43:31 +02:00
|
|
|
return Decompiler.Decompile(Memory, Position + 0x50, Type);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
private SpirvProgram GetSpirvProgram(IGalMemory Memory, long Position, GalShaderType Type)
|
|
|
|
{
|
|
|
|
SpirvDecompiler Decompiler = new SpirvDecompiler();
|
|
|
|
|
|
|
|
return Decompiler.Decompile(Memory, Position + 0x50, Type);
|
|
|
|
}
|
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
public IEnumerable<ShaderDeclInfo> GetTextureUsage(long Tag)
|
|
|
|
{
|
|
|
|
if (Stages.TryGetValue(Tag, out ShaderStage Stage))
|
|
|
|
{
|
|
|
|
return Stage.TextureUsage;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Enumerable.Empty<ShaderDeclInfo>();
|
|
|
|
}
|
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
private int GetUniformLocation(string Name, ShaderStage Stage)
|
|
|
|
{
|
|
|
|
switch (Language)
|
|
|
|
{
|
|
|
|
case ShadingLanguage.SPIRV:
|
|
|
|
{
|
|
|
|
SpirvStage Spirv = (SpirvStage)Stage;
|
|
|
|
|
|
|
|
if (Spirv.Locations.TryGetValue(Name, out int Location))
|
|
|
|
{
|
|
|
|
return Location;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ShadingLanguage.GLSL:
|
|
|
|
{
|
|
|
|
return GL.GetUniformLocation(CurrentProgramHandle, Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool TrySpirvStageLocation(string Name, ShaderStage Stage, out int Location)
|
|
|
|
{
|
|
|
|
if (Stage == null)
|
|
|
|
{
|
|
|
|
Location = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SpirvStage Spirv = (SpirvStage)Stage;
|
|
|
|
|
|
|
|
return Spirv.Locations.TryGetValue(Name, out Location);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int GetSpirvLocation(string Name)
|
|
|
|
{
|
|
|
|
int Location;
|
|
|
|
|
|
|
|
if (TrySpirvStageLocation(Name, Current.Vertex, out Location)
|
|
|
|
|| TrySpirvStageLocation(Name, Current.TessControl, out Location)
|
|
|
|
|| TrySpirvStageLocation(Name, Current.TessEvaluation, out Location)
|
|
|
|
|| TrySpirvStageLocation(Name, Current.Geometry, out Location)
|
|
|
|
|| TrySpirvStageLocation(Name, Current.Fragment, out Location))
|
|
|
|
{
|
|
|
|
return Location;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
private int GetUniformLocation(string Name)
|
|
|
|
{
|
|
|
|
switch (Language)
|
|
|
|
{
|
|
|
|
case ShadingLanguage.SPIRV:
|
|
|
|
return GetSpirvLocation(Name);
|
|
|
|
|
|
|
|
case ShadingLanguage.GLSL:
|
|
|
|
return GL.GetUniformLocation(CurrentProgramHandle, Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
public void SetConstBuffer(long Tag, int Cbuf, byte[] Data)
|
|
|
|
{
|
|
|
|
BindProgram();
|
|
|
|
|
|
|
|
if (Stages.TryGetValue(Tag, out ShaderStage Stage))
|
|
|
|
{
|
|
|
|
foreach (ShaderDeclInfo DeclInfo in Stage.UniformUsage.Where(x => x.Cbuf == Cbuf))
|
|
|
|
{
|
2018-06-20 18:30:18 +02:00
|
|
|
if (Cbuf >= BuffersPerStage)
|
|
|
|
{
|
|
|
|
string Message = $"Game tried to write constant buffer #{Cbuf} but only 0-#{BuffersPerStage-1} are supported";
|
|
|
|
throw new NotSupportedException(Message);
|
|
|
|
}
|
|
|
|
|
|
|
|
OGLStreamBuffer Buffer = Buffers[(int)Stage.Type][Cbuf];
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
int Size = Math.Min(Data.Length, BufferSize);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
byte[] Destiny = Buffer.Map(Size);
|
2018-05-17 20:25:42 +02:00
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
Array.Copy(Data, Destiny, Size);
|
|
|
|
|
|
|
|
Buffer.Unmap(Size);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetUniform1(string UniformName, int Value)
|
|
|
|
{
|
|
|
|
BindProgram();
|
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
int Location = GetUniformLocation(UniformName);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
GL.Uniform1(Location, Value);
|
|
|
|
}
|
|
|
|
|
2018-04-14 05:39:24 +02:00
|
|
|
public void SetUniform2F(string UniformName, float X, float Y)
|
|
|
|
{
|
|
|
|
BindProgram();
|
|
|
|
|
2018-06-20 18:30:18 +02:00
|
|
|
int Location = GetUniformLocation(UniformName);
|
2018-04-14 05:39:24 +02:00
|
|
|
|
|
|
|
GL.Uniform2(Location, X, Y);
|
|
|
|
}
|
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
public void Bind(long Tag)
|
|
|
|
{
|
|
|
|
if (Stages.TryGetValue(Tag, out ShaderStage Stage))
|
|
|
|
{
|
|
|
|
Bind(Stage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Bind(ShaderStage Stage)
|
|
|
|
{
|
|
|
|
switch (Stage.Type)
|
|
|
|
{
|
|
|
|
case GalShaderType.Vertex: Current.Vertex = Stage; break;
|
|
|
|
case GalShaderType.TessControl: Current.TessControl = Stage; break;
|
|
|
|
case GalShaderType.TessEvaluation: Current.TessEvaluation = Stage; break;
|
|
|
|
case GalShaderType.Geometry: Current.Geometry = Stage; break;
|
|
|
|
case GalShaderType.Fragment: Current.Fragment = Stage; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void BindProgram()
|
|
|
|
{
|
|
|
|
if (Current.Vertex == null ||
|
|
|
|
Current.Fragment == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Programs.TryGetValue(Current, out int Handle))
|
|
|
|
{
|
|
|
|
Handle = GL.CreateProgram();
|
|
|
|
|
|
|
|
AttachIfNotNull(Handle, Current.Vertex);
|
|
|
|
AttachIfNotNull(Handle, Current.TessControl);
|
|
|
|
AttachIfNotNull(Handle, Current.TessEvaluation);
|
|
|
|
AttachIfNotNull(Handle, Current.Geometry);
|
|
|
|
AttachIfNotNull(Handle, Current.Fragment);
|
|
|
|
|
|
|
|
GL.LinkProgram(Handle);
|
|
|
|
|
|
|
|
CheckProgramLink(Handle);
|
|
|
|
|
2018-06-23 20:05:22 +02:00
|
|
|
switch (Language)
|
2018-06-20 18:30:18 +02:00
|
|
|
{
|
2018-06-23 20:05:22 +02:00
|
|
|
case ShadingLanguage.GLSL:
|
|
|
|
{
|
|
|
|
int FreeBinding = 0;
|
|
|
|
|
|
|
|
FreeBinding = BindUniformBlocksIfNotNull(Handle, FreeBinding, Current.Vertex);
|
|
|
|
FreeBinding = BindUniformBlocksIfNotNull(Handle, FreeBinding, Current.TessControl);
|
|
|
|
FreeBinding = BindUniformBlocksIfNotNull(Handle, FreeBinding, Current.TessEvaluation);
|
|
|
|
FreeBinding = BindUniformBlocksIfNotNull(Handle, FreeBinding, Current.Geometry);
|
|
|
|
FreeBinding = BindUniformBlocksIfNotNull(Handle, FreeBinding, Current.Fragment);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ShadingLanguage.SPIRV:
|
|
|
|
{
|
|
|
|
for (int Stage = 0; Stage < 5; Stage++)
|
|
|
|
{
|
|
|
|
for (int Cbuf = 0; Cbuf < BuffersPerStage; Cbuf++)
|
|
|
|
{
|
|
|
|
OGLStreamBuffer Buffer = Buffers[Stage][Cbuf];
|
|
|
|
|
|
|
|
int Binding = Shader.UniformBinding.Get((GalShaderType)Stage, Cbuf);
|
|
|
|
|
|
|
|
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, Binding, Buffer.Handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-06-20 18:30:18 +02:00
|
|
|
}
|
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
Programs.Add(Current, Handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
GL.UseProgram(Handle);
|
|
|
|
|
|
|
|
CurrentProgramHandle = Handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void AttachIfNotNull(int ProgramHandle, ShaderStage Stage)
|
|
|
|
{
|
|
|
|
if (Stage != null)
|
|
|
|
{
|
|
|
|
Stage.Compile();
|
|
|
|
|
|
|
|
GL.AttachShader(ProgramHandle, Stage.Handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-23 20:05:22 +02:00
|
|
|
private int BindUniformBlocksIfNotNull(int ProgramHandle, int FreeBinding, ShaderStage Stage)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-06-20 18:30:18 +02:00
|
|
|
if (Stage != null)
|
|
|
|
{
|
|
|
|
foreach (ShaderDeclInfo DeclInfo in Stage.UniformUsage)
|
|
|
|
{
|
|
|
|
int BlockIndex = GL.GetUniformBlockIndex(ProgramHandle, DeclInfo.Name);
|
|
|
|
|
|
|
|
if (BlockIndex < 0)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
|
2018-06-23 20:05:22 +02:00
|
|
|
GL.UniformBlockBinding(ProgramHandle, BlockIndex, FreeBinding);
|
|
|
|
|
|
|
|
OGLStreamBuffer Buffer = Buffers[(int)Stage.Type][DeclInfo.Cbuf];
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-06-23 20:05:22 +02:00
|
|
|
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, FreeBinding, Buffer.Handle);
|
|
|
|
|
|
|
|
FreeBinding++;
|
2018-06-20 18:30:18 +02:00
|
|
|
}
|
|
|
|
}
|
2018-06-23 20:05:22 +02:00
|
|
|
|
|
|
|
return FreeBinding;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void CheckCompilation(int Handle)
|
|
|
|
{
|
|
|
|
int Status = 0;
|
|
|
|
|
|
|
|
GL.GetShader(Handle, ShaderParameter.CompileStatus, out Status);
|
|
|
|
|
|
|
|
if (Status == 0)
|
|
|
|
{
|
|
|
|
throw new ShaderException(GL.GetShaderInfoLog(Handle));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void CheckProgramLink(int Handle)
|
|
|
|
{
|
|
|
|
int Status = 0;
|
|
|
|
|
|
|
|
GL.GetProgram(Handle, GetProgramParameterName.LinkStatus, out Status);
|
|
|
|
|
|
|
|
if (Status == 0)
|
|
|
|
{
|
|
|
|
throw new ShaderException(GL.GetProgramInfoLog(Handle));
|
|
|
|
}
|
|
|
|
}
|
2018-06-20 18:30:18 +02:00
|
|
|
|
|
|
|
private static bool HasSPIRV()
|
|
|
|
{
|
|
|
|
int ExtensionCount = GL.GetInteger(GetPName.NumExtensions);
|
|
|
|
|
|
|
|
for (int i = 0; i < ExtensionCount; i++)
|
|
|
|
{
|
|
|
|
if (GL.GetString(StringNameIndexed.Extensions, i) == "GL_ARB_gl_spirv")
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|