mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-01-07 16:33:05 +00:00
Image Subclasses
This commit is contained in:
parent
4301dbaca6
commit
5f1c880805
5 changed files with 121 additions and 115 deletions
|
@ -6,8 +6,8 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
||||||
{
|
{
|
||||||
ITextureInfo Storage { get; }
|
ITextureInfo Storage { get; }
|
||||||
uint Handle { get; }
|
uint Handle { get; }
|
||||||
int FirstLayer => 0;
|
uint FirstLayer => 0;
|
||||||
int FirstLevel => 0;
|
uint FirstLevel => 0;
|
||||||
|
|
||||||
TextureCreateInfo Info { get; }
|
TextureCreateInfo Info { get; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,16 +245,16 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
||||||
_api.CopyImageSubData(
|
_api.CopyImageSubData(
|
||||||
src.Storage.Handle,
|
src.Storage.Handle,
|
||||||
src.Storage.Info.Target.ConvertToImageTarget(),
|
src.Storage.Info.Target.ConvertToImageTarget(),
|
||||||
src.FirstLevel + srcLevel + level,
|
(int)src.FirstLevel + srcLevel + level,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
src.FirstLayer + srcLayer,
|
(int)src.FirstLayer + srcLayer,
|
||||||
dst.Storage.Handle,
|
dst.Storage.Handle,
|
||||||
dst.Storage.Info.Target.ConvertToImageTarget(),
|
dst.Storage.Info.Target.ConvertToImageTarget(),
|
||||||
dst.FirstLevel + dstLevel + level,
|
(int)dst.FirstLevel + dstLevel + level,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
dst.FirstLayer + dstLayer,
|
(int)dst.FirstLayer + dstLayer,
|
||||||
(uint)copyWidth,
|
(uint)copyWidth,
|
||||||
(uint)copyHeight,
|
(uint)copyHeight,
|
||||||
(uint)depth);
|
(uint)depth);
|
||||||
|
|
|
@ -67,15 +67,17 @@ void main()
|
||||||
imageStore(dst, ivec2(coords), uvec4(r, g, b, a));
|
imageStore(dst, ivec2(coords), uvec4(r, g, b, a));
|
||||||
}";
|
}";
|
||||||
|
|
||||||
|
private readonly GL _api;
|
||||||
private readonly OpenGLRenderer _renderer;
|
private readonly OpenGLRenderer _renderer;
|
||||||
private readonly Dictionary<int, int> _shorteningProgramHandles;
|
private readonly Dictionary<int, uint> _shorteningProgramHandles;
|
||||||
private readonly Dictionary<int, int> _wideningProgramHandles;
|
private readonly Dictionary<int, uint> _wideningProgramHandles;
|
||||||
|
|
||||||
public TextureCopyIncompatible(OpenGLRenderer renderer)
|
public TextureCopyIncompatible(GL api, OpenGLRenderer renderer)
|
||||||
{
|
{
|
||||||
|
_api = api;
|
||||||
_renderer = renderer;
|
_renderer = renderer;
|
||||||
_shorteningProgramHandles = new Dictionary<int, int>();
|
_shorteningProgramHandles = new Dictionary<int, uint>();
|
||||||
_wideningProgramHandles = new Dictionary<int, int>();
|
_wideningProgramHandles = new Dictionary<int, uint>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyIncompatibleFormats(ITextureInfo src, ITextureInfo dst, int srcLayer, int dstLayer, int srcLevel, int dstLevel, int depth, int levels)
|
public void CopyIncompatibleFormats(ITextureInfo src, ITextureInfo dst, int srcLayer, int dstLayer, int srcLevel, int dstLevel, int depth, int levels)
|
||||||
|
@ -91,10 +93,10 @@ void main()
|
||||||
int srcComponentsCount = srcBpp / componentSize;
|
int srcComponentsCount = srcBpp / componentSize;
|
||||||
int dstComponentsCount = dstBpp / componentSize;
|
int dstComponentsCount = dstBpp / componentSize;
|
||||||
|
|
||||||
var srcFormat = GetFormat(componentSize, srcComponentsCount);
|
var srcFormat = (InternalFormat)GetFormat(componentSize, srcComponentsCount);
|
||||||
var dstFormat = GetFormat(componentSize, dstComponentsCount);
|
var dstFormat = (InternalFormat)GetFormat(componentSize, dstComponentsCount);
|
||||||
|
|
||||||
GL.UseProgram(srcBpp < dstBpp
|
_api.UseProgram(srcBpp < dstBpp
|
||||||
? GetWideningShader(componentSize, srcComponentsCount, dstComponentsCount)
|
? GetWideningShader(componentSize, srcComponentsCount, dstComponentsCount)
|
||||||
: GetShorteningShader(componentSize, srcComponentsCount, dstComponentsCount));
|
: GetShorteningShader(componentSize, srcComponentsCount, dstComponentsCount));
|
||||||
|
|
||||||
|
@ -106,15 +108,15 @@ void main()
|
||||||
int dstWidth = Math.Max(1, dst.Info.Width >> l);
|
int dstWidth = Math.Max(1, dst.Info.Width >> l);
|
||||||
int dstHeight = Math.Max(1, dst.Info.Height >> l);
|
int dstHeight = Math.Max(1, dst.Info.Height >> l);
|
||||||
|
|
||||||
int width = Math.Min(srcWidth, dstWidth);
|
uint width = (uint)Math.Min(srcWidth, dstWidth);
|
||||||
int height = Math.Min(srcHeight, dstHeight);
|
uint height = (uint)Math.Min(srcHeight, dstHeight);
|
||||||
|
|
||||||
for (int z = 0; z < depth; z++)
|
for (int z = 0; z < depth; z++)
|
||||||
{
|
{
|
||||||
GL.BindImageTexture(0, src.Handle, srcLevel + l, false, srcLayer + z, BufferAccessARB.ReadOnly, srcFormat);
|
_api.BindImageTexture(0, src.Handle, srcLevel + l, false, srcLayer + z, BufferAccessARB.ReadOnly, srcFormat);
|
||||||
GL.BindImageTexture(1, dst.Handle, dstLevel + l, false, dstLayer + z, BufferAccessARB.WriteOnly, dstFormat);
|
_api.BindImageTexture(1, dst.Handle, dstLevel + l, false, dstLayer + z, BufferAccessARB.WriteOnly, dstFormat);
|
||||||
|
|
||||||
GL.DispatchCompute((width + 31) / 32, (height + 31) / 32, 1);
|
_api.DispatchCompute((width + 31) / 32, (height + 31) / 32, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,19 +164,19 @@ void main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetShorteningShader(int componentSize, int srcComponentsCount, int dstComponentsCount)
|
private uint GetShorteningShader(int componentSize, int srcComponentsCount, int dstComponentsCount)
|
||||||
{
|
{
|
||||||
return GetShader(ComputeShaderShortening, _shorteningProgramHandles, componentSize, srcComponentsCount, dstComponentsCount);
|
return GetShader(ComputeShaderShortening, _shorteningProgramHandles, componentSize, srcComponentsCount, dstComponentsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetWideningShader(int componentSize, int srcComponentsCount, int dstComponentsCount)
|
private uint GetWideningShader(int componentSize, int srcComponentsCount, int dstComponentsCount)
|
||||||
{
|
{
|
||||||
return GetShader(ComputeShaderWidening, _wideningProgramHandles, componentSize, srcComponentsCount, dstComponentsCount);
|
return GetShader(ComputeShaderWidening, _wideningProgramHandles, componentSize, srcComponentsCount, dstComponentsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetShader(
|
private uint GetShader(
|
||||||
string code,
|
string code,
|
||||||
Dictionary<int, int> programHandles,
|
Dictionary<int, uint> programHandles,
|
||||||
int componentSize,
|
int componentSize,
|
||||||
int srcComponentsCount,
|
int srcComponentsCount,
|
||||||
int dstComponentsCount)
|
int dstComponentsCount)
|
||||||
|
@ -186,9 +188,9 @@ void main()
|
||||||
|
|
||||||
int key = srcIndex | (dstIndex << 8);
|
int key = srcIndex | (dstIndex << 8);
|
||||||
|
|
||||||
if (!programHandles.TryGetValue(key, out int programHandle))
|
if (!programHandles.TryGetValue(key, out uint programHandle))
|
||||||
{
|
{
|
||||||
int csHandle = GL.CreateShader(ShaderType.ComputeShader);
|
uint csHandle = _api.CreateShader(ShaderType.ComputeShader);
|
||||||
|
|
||||||
string[] formatTable = new[] { "r8ui", "r16ui", "r32ui", "rg8ui", "rg16ui", "rg32ui", "rgba8ui", "rgba16ui", "rgba32ui" };
|
string[] formatTable = new[] { "r8ui", "r16ui", "r32ui", "rg8ui", "rg16ui", "rg32ui", "rgba8ui", "rgba16ui", "rgba32ui" };
|
||||||
|
|
||||||
|
@ -201,25 +203,25 @@ void main()
|
||||||
int ratio = srcBpp < dstBpp ? dstBpp / srcBpp : srcBpp / dstBpp;
|
int ratio = srcBpp < dstBpp ? dstBpp / srcBpp : srcBpp / dstBpp;
|
||||||
int ratioLog2 = BitOperations.Log2((uint)ratio);
|
int ratioLog2 = BitOperations.Log2((uint)ratio);
|
||||||
|
|
||||||
GL.ShaderSource(csHandle, code
|
_api.ShaderSource(csHandle, code
|
||||||
.Replace("$SRC_FORMAT$", srcFormat)
|
.Replace("$SRC_FORMAT$", srcFormat)
|
||||||
.Replace("$DST_FORMAT$", dstFormat)
|
.Replace("$DST_FORMAT$", dstFormat)
|
||||||
.Replace("$RATIO_LOG2$", ratioLog2.ToString(CultureInfo.InvariantCulture)));
|
.Replace("$RATIO_LOG2$", ratioLog2.ToString(CultureInfo.InvariantCulture)));
|
||||||
|
|
||||||
GL.CompileShader(csHandle);
|
_api.CompileShader(csHandle);
|
||||||
|
|
||||||
programHandle = GL.CreateProgram();
|
programHandle = _api.CreateProgram();
|
||||||
|
|
||||||
GL.AttachShader(programHandle, csHandle);
|
_api.AttachShader(programHandle, csHandle);
|
||||||
GL.LinkProgram(programHandle);
|
_api.LinkProgram(programHandle);
|
||||||
GL.DetachShader(programHandle, csHandle);
|
_api.DetachShader(programHandle, csHandle);
|
||||||
GL.DeleteShader(csHandle);
|
_api.DeleteShader(csHandle);
|
||||||
|
|
||||||
GL.GetProgram(programHandle, GetProgramParameterName.LinkStatus, out int status);
|
_api.GetProgram(programHandle, ProgramPropertyARB.LinkStatus, out int status);
|
||||||
|
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
{
|
{
|
||||||
throw new Exception(GL.GetProgramInfoLog(programHandle));
|
throw new Exception(_api.GetProgramInfoLog(programHandle));
|
||||||
}
|
}
|
||||||
|
|
||||||
programHandles.Add(key, programHandle);
|
programHandles.Add(key, programHandle);
|
||||||
|
@ -230,16 +232,16 @@ void main()
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
foreach (int handle in _shorteningProgramHandles.Values)
|
foreach (uint handle in _shorteningProgramHandles.Values)
|
||||||
{
|
{
|
||||||
GL.DeleteProgram(handle);
|
_api.DeleteProgram(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
_shorteningProgramHandles.Clear();
|
_shorteningProgramHandles.Clear();
|
||||||
|
|
||||||
foreach (int handle in _wideningProgramHandles.Values)
|
foreach (uint handle in _wideningProgramHandles.Values)
|
||||||
{
|
{
|
||||||
GL.DeleteProgram(handle);
|
_api.DeleteProgram(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
_wideningProgramHandles.Clear();
|
_wideningProgramHandles.Clear();
|
||||||
|
|
|
@ -93,12 +93,14 @@ void main()
|
||||||
imageStore(imgOut, ivec2(int(coords.x) >> samplesInXLog2, int(coords.y) >> samplesInYLog2), sampleIdx, value);
|
imageStore(imgOut, ivec2(int(coords.x) >> samplesInXLog2, int(coords.y) >> samplesInYLog2), sampleIdx, value);
|
||||||
}";
|
}";
|
||||||
|
|
||||||
|
private readonly GL _api;
|
||||||
private readonly OpenGLRenderer _renderer;
|
private readonly OpenGLRenderer _renderer;
|
||||||
private readonly uint[] _msToNonMSProgramHandles;
|
private readonly uint[] _msToNonMSProgramHandles;
|
||||||
private readonly uint[] _nonMSToMSProgramHandles;
|
private readonly uint[] _nonMSToMSProgramHandles;
|
||||||
|
|
||||||
public TextureCopyMS(OpenGLRenderer renderer)
|
public TextureCopyMS(GL api, OpenGLRenderer renderer)
|
||||||
{
|
{
|
||||||
|
_api = api;
|
||||||
_renderer = renderer;
|
_renderer = renderer;
|
||||||
_msToNonMSProgramHandles = new uint[5];
|
_msToNonMSProgramHandles = new uint[5];
|
||||||
_nonMSToMSProgramHandles = new uint[5];
|
_nonMSToMSProgramHandles = new uint[5];
|
||||||
|
@ -109,20 +111,20 @@ void main()
|
||||||
TextureCreateInfo srcInfo = src.Info;
|
TextureCreateInfo srcInfo = src.Info;
|
||||||
TextureCreateInfo dstInfo = dst.Info;
|
TextureCreateInfo dstInfo = dst.Info;
|
||||||
|
|
||||||
int srcHandle = CreateViewIfNeeded(src);
|
uint srcHandle = CreateViewIfNeeded(src);
|
||||||
int dstHandle = CreateViewIfNeeded(dst);
|
uint dstHandle = CreateViewIfNeeded(dst);
|
||||||
|
|
||||||
int dstWidth = dstInfo.Width;
|
uint dstWidth = (uint)dstInfo.Width;
|
||||||
int dstHeight = dstInfo.Height;
|
uint dstHeight = (uint)dstInfo.Height;
|
||||||
|
|
||||||
GL.UseProgram(GetMSToNonMSShader(srcInfo.BytesPerPixel));
|
_api.UseProgram(GetMSToNonMSShader(srcInfo.BytesPerPixel));
|
||||||
|
|
||||||
for (int z = 0; z < depth; z++)
|
for (int z = 0; z < depth; z++)
|
||||||
{
|
{
|
||||||
GL.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, GetFormat(srcInfo.BytesPerPixel));
|
_api.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, (InternalFormat)GetFormat(srcInfo.BytesPerPixel));
|
||||||
GL.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, GetFormat(dstInfo.BytesPerPixel));
|
_api.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, (InternalFormat)GetFormat(dstInfo.BytesPerPixel));
|
||||||
|
|
||||||
GL.DispatchCompute((dstWidth + 31) / 32, (dstHeight + 31) / 32, 1);
|
_api.DispatchCompute((dstWidth + 31) / 32, (dstHeight + 31) / 32, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipeline pipeline = (Pipeline)_renderer.Pipeline;
|
Pipeline pipeline = (Pipeline)_renderer.Pipeline;
|
||||||
|
@ -139,20 +141,20 @@ void main()
|
||||||
TextureCreateInfo srcInfo = src.Info;
|
TextureCreateInfo srcInfo = src.Info;
|
||||||
TextureCreateInfo dstInfo = dst.Info;
|
TextureCreateInfo dstInfo = dst.Info;
|
||||||
|
|
||||||
int srcHandle = CreateViewIfNeeded(src);
|
uint srcHandle = CreateViewIfNeeded(src);
|
||||||
int dstHandle = CreateViewIfNeeded(dst);
|
uint dstHandle = CreateViewIfNeeded(dst);
|
||||||
|
|
||||||
int srcWidth = srcInfo.Width;
|
uint srcWidth = (uint)srcInfo.Width;
|
||||||
int srcHeight = srcInfo.Height;
|
uint srcHeight = (uint)srcInfo.Height;
|
||||||
|
|
||||||
GL.UseProgram(GetNonMSToMSShader(srcInfo.BytesPerPixel));
|
_api.UseProgram(GetNonMSToMSShader(srcInfo.BytesPerPixel));
|
||||||
|
|
||||||
for (int z = 0; z < depth; z++)
|
for (int z = 0; z < depth; z++)
|
||||||
{
|
{
|
||||||
GL.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, GetFormat(srcInfo.BytesPerPixel));
|
_api.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, (InternalFormat)GetFormat(srcInfo.BytesPerPixel));
|
||||||
GL.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, GetFormat(dstInfo.BytesPerPixel));
|
_api.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, (InternalFormat)GetFormat(dstInfo.BytesPerPixel));
|
||||||
|
|
||||||
GL.DispatchCompute((srcWidth + 31) / 32, (srcHeight + 31) / 32, 1);
|
_api.DispatchCompute((srcWidth + 31) / 32, (srcHeight + 31) / 32, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pipeline pipeline = (Pipeline)_renderer.Pipeline;
|
Pipeline pipeline = (Pipeline)_renderer.Pipeline;
|
||||||
|
@ -177,23 +179,23 @@ void main()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static uint CreateViewIfNeeded(ITextureInfo texture)
|
private uint CreateViewIfNeeded(ITextureInfo texture)
|
||||||
{
|
{
|
||||||
// Binding sRGB textures as images doesn't work on NVIDIA,
|
// Binding sRGB textures as images doesn't work on NVIDIA,
|
||||||
// we need to create and bind a RGBA view for it to work.
|
// we need to create and bind a RGBA view for it to work.
|
||||||
if (texture.Info.Format == Format.R8G8B8A8Srgb)
|
if (texture.Info.Format == Format.R8G8B8A8Srgb)
|
||||||
{
|
{
|
||||||
int handle = GL.GenTexture();
|
uint handle = _api.GenTexture();
|
||||||
|
|
||||||
GL.TextureView(
|
_api.TextureView(
|
||||||
handle,
|
handle,
|
||||||
texture.Info.Target.Convert(),
|
texture.Info.Target.Convert(),
|
||||||
texture.Storage.Handle,
|
texture.Storage.Handle,
|
||||||
InternalFormat.Rgba8,
|
SizedInternalFormat.Rgba8,
|
||||||
texture.FirstLevel,
|
texture.FirstLevel,
|
||||||
1,
|
1,
|
||||||
texture.FirstLayer,
|
texture.FirstLayer,
|
||||||
texture.Info.GetLayers());
|
(uint)texture.Info.GetLayers());
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
@ -201,49 +203,49 @@ void main()
|
||||||
return texture.Handle;
|
return texture.Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DestroyViewIfNeeded(ITextureInfo info, int handle)
|
private void DestroyViewIfNeeded(ITextureInfo info, uint handle)
|
||||||
{
|
{
|
||||||
if (info.Handle != handle)
|
if (info.Handle != handle)
|
||||||
{
|
{
|
||||||
GL.DeleteTexture(handle);
|
_api.DeleteTexture(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetMSToNonMSShader(int bytesPerPixel)
|
private uint GetMSToNonMSShader(int bytesPerPixel)
|
||||||
{
|
{
|
||||||
return GetShader(ComputeShaderMSToNonMS, _msToNonMSProgramHandles, bytesPerPixel);
|
return GetShader(ComputeShaderMSToNonMS, _msToNonMSProgramHandles, bytesPerPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetNonMSToMSShader(int bytesPerPixel)
|
private uint GetNonMSToMSShader(int bytesPerPixel)
|
||||||
{
|
{
|
||||||
return GetShader(ComputeShaderNonMSToMS, _nonMSToMSProgramHandles, bytesPerPixel);
|
return GetShader(ComputeShaderNonMSToMS, _nonMSToMSProgramHandles, bytesPerPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetShader(string code, int[] programHandles, int bytesPerPixel)
|
private uint GetShader(string code, uint[] programHandles, int bytesPerPixel)
|
||||||
{
|
{
|
||||||
int index = BitOperations.Log2((uint)bytesPerPixel);
|
int index = BitOperations.Log2((uint)bytesPerPixel);
|
||||||
|
|
||||||
if (programHandles[index] == 0)
|
if (programHandles[index] == 0)
|
||||||
{
|
{
|
||||||
int csHandle = GL.CreateShader(ShaderType.ComputeShader);
|
uint csHandle = _api.CreateShader(ShaderType.ComputeShader);
|
||||||
|
|
||||||
string format = new[] { "r8ui", "r16ui", "r32ui", "rg32ui", "rgba32ui" }[index];
|
string format = new[] { "r8ui", "r16ui", "r32ui", "rg32ui", "rgba32ui" }[index];
|
||||||
|
|
||||||
GL.ShaderSource(csHandle, code.Replace("$FORMAT$", format));
|
_api.ShaderSource(csHandle, code.Replace("$FORMAT$", format));
|
||||||
GL.CompileShader(csHandle);
|
_api.CompileShader(csHandle);
|
||||||
|
|
||||||
int programHandle = GL.CreateProgram();
|
uint programHandle = _api.CreateProgram();
|
||||||
|
|
||||||
GL.AttachShader(programHandle, csHandle);
|
_api.AttachShader(programHandle, csHandle);
|
||||||
GL.LinkProgram(programHandle);
|
_api.LinkProgram(programHandle);
|
||||||
GL.DetachShader(programHandle, csHandle);
|
_api.DetachShader(programHandle, csHandle);
|
||||||
GL.DeleteShader(csHandle);
|
_api.DeleteShader(csHandle);
|
||||||
|
|
||||||
GL.GetProgram(programHandle, GetProgramParameterName.LinkStatus, out int status);
|
_api.GetProgram(programHandle, ProgramPropertyARB.LinkStatus, out int status);
|
||||||
|
|
||||||
if (status == 0)
|
if (status == 0)
|
||||||
{
|
{
|
||||||
throw new Exception(GL.GetProgramInfoLog(programHandle));
|
throw new Exception(_api.GetProgramInfoLog(programHandle));
|
||||||
}
|
}
|
||||||
|
|
||||||
programHandles[index] = programHandle;
|
programHandles[index] = programHandle;
|
||||||
|
@ -258,7 +260,7 @@ void main()
|
||||||
{
|
{
|
||||||
if (_msToNonMSProgramHandles[i] != 0)
|
if (_msToNonMSProgramHandles[i] != 0)
|
||||||
{
|
{
|
||||||
GL.DeleteProgram(_msToNonMSProgramHandles[i]);
|
_api.DeleteProgram(_msToNonMSProgramHandles[i]);
|
||||||
_msToNonMSProgramHandles[i] = 0;
|
_msToNonMSProgramHandles[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +269,7 @@ void main()
|
||||||
{
|
{
|
||||||
if (_nonMSToMSProgramHandles[i] != 0)
|
if (_nonMSToMSProgramHandles[i] != 0)
|
||||||
{
|
{
|
||||||
GL.DeleteProgram(_nonMSToMSProgramHandles[i]);
|
_api.DeleteProgram(_nonMSToMSProgramHandles[i]);
|
||||||
_nonMSToMSProgramHandles[i] = 0;
|
_nonMSToMSProgramHandles[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,17 +12,19 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
||||||
public TextureCreateInfo Info { get; }
|
public TextureCreateInfo Info { get; }
|
||||||
|
|
||||||
private readonly OpenGLRenderer _renderer;
|
private readonly OpenGLRenderer _renderer;
|
||||||
|
private readonly GL _api;
|
||||||
|
|
||||||
private int _viewsCount;
|
private int _viewsCount;
|
||||||
|
|
||||||
internal ITexture DefaultView { get; private set; }
|
internal ITexture DefaultView { get; private set; }
|
||||||
|
|
||||||
public TextureStorage(OpenGLRenderer renderer, TextureCreateInfo info)
|
public TextureStorage(GL api, OpenGLRenderer renderer, TextureCreateInfo info)
|
||||||
{
|
{
|
||||||
|
_api = api;
|
||||||
_renderer = renderer;
|
_renderer = renderer;
|
||||||
Info = info;
|
Info = info;
|
||||||
|
|
||||||
Handle = GL.GenTexture();
|
Handle = _api.GenTexture();
|
||||||
|
|
||||||
CreateImmutableStorage();
|
CreateImmutableStorage();
|
||||||
}
|
}
|
||||||
|
@ -31,9 +33,9 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
||||||
{
|
{
|
||||||
TextureTarget target = Info.Target.Convert();
|
TextureTarget target = Info.Target.Convert();
|
||||||
|
|
||||||
GL.ActiveTexture(TextureUnit.Texture0);
|
_api.ActiveTexture(TextureUnit.Texture0);
|
||||||
|
|
||||||
GL.BindTexture(target, Handle);
|
_api.BindTexture(target, Handle);
|
||||||
|
|
||||||
FormatInfo format = FormatTable.GetFormatInfo(Info.Format);
|
FormatInfo format = FormatTable.GetFormatInfo(Info.Format);
|
||||||
|
|
||||||
|
@ -48,94 +50,94 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
||||||
internalFormat = (SizedInternalFormat)format.InternalFormat;
|
internalFormat = (SizedInternalFormat)format.InternalFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
int levels = Info.GetLevelsClamped();
|
uint levels = (uint)Info.GetLevelsClamped();
|
||||||
|
|
||||||
switch (Info.Target)
|
switch (Info.Target)
|
||||||
{
|
{
|
||||||
case Target.Texture1D:
|
case Target.Texture1D:
|
||||||
GL.TexStorage1D(
|
_api.TexStorage1D(
|
||||||
TextureTarget.Texture1D,
|
TextureTarget.Texture1D,
|
||||||
levels,
|
levels,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
Info.Width);
|
(uint)Info.Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Target.Texture1DArray:
|
case Target.Texture1DArray:
|
||||||
GL.TexStorage2D(
|
_api.TexStorage2D(
|
||||||
TextureTarget.Texture1DArray,
|
TextureTarget.Texture1DArray,
|
||||||
levels,
|
levels,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
Info.Width,
|
(uint)Info.Width,
|
||||||
Info.Height);
|
(uint)Info.Height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Target.Texture2D:
|
case Target.Texture2D:
|
||||||
GL.TexStorage2D(
|
_api.TexStorage2D(
|
||||||
TextureTarget.Texture2D,
|
TextureTarget.Texture2D,
|
||||||
levels,
|
levels,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
Info.Width,
|
(uint)Info.Width,
|
||||||
Info.Height);
|
(uint)Info.Height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Target.Texture2DArray:
|
case Target.Texture2DArray:
|
||||||
GL.TexStorage3D(
|
_api.TexStorage3D(
|
||||||
TextureTarget.Texture2DArray,
|
TextureTarget.Texture2DArray,
|
||||||
levels,
|
levels,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
Info.Width,
|
(uint)Info.Width,
|
||||||
Info.Height,
|
(uint)Info.Height,
|
||||||
Info.Depth);
|
(uint)Info.Depth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Target.Texture2DMultisample:
|
case Target.Texture2DMultisample:
|
||||||
GL.TexStorage2DMultisample(
|
_api.TexStorage2DMultisample(
|
||||||
TextureTarget.Texture2DMultisample,
|
TextureTarget.Texture2DMultisample,
|
||||||
Info.Samples,
|
(uint)Info.Samples,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
Info.Width,
|
(uint)Info.Width,
|
||||||
Info.Height,
|
(uint)Info.Height,
|
||||||
true);
|
true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Target.Texture2DMultisampleArray:
|
case Target.Texture2DMultisampleArray:
|
||||||
GL.TexStorage3DMultisample(
|
_api.TexStorage3DMultisample(
|
||||||
TextureTarget.Texture2DMultisampleArray,
|
TextureTarget.Texture2DMultisampleArray,
|
||||||
Info.Samples,
|
(uint)Info.Samples,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
Info.Width,
|
(uint)Info.Width,
|
||||||
Info.Height,
|
(uint)Info.Height,
|
||||||
Info.Depth,
|
(uint)Info.Depth,
|
||||||
true);
|
true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Target.Texture3D:
|
case Target.Texture3D:
|
||||||
GL.TexStorage3D(
|
_api.TexStorage3D(
|
||||||
TextureTarget.Texture3D,
|
TextureTarget.Texture3D,
|
||||||
levels,
|
levels,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
Info.Width,
|
(uint)Info.Width,
|
||||||
Info.Height,
|
(uint)Info.Height,
|
||||||
Info.Depth);
|
(uint)Info.Depth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Target.Cubemap:
|
case Target.Cubemap:
|
||||||
GL.TexStorage2D(
|
_api.TexStorage2D(
|
||||||
TextureTarget.TextureCubeMap,
|
TextureTarget.TextureCubeMap,
|
||||||
levels,
|
levels,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
Info.Width,
|
(uint)Info.Width,
|
||||||
Info.Height);
|
(uint)Info.Height);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Target.CubemapArray:
|
case Target.CubemapArray:
|
||||||
GL.TexStorage3D(
|
_api.TexStorage3D(
|
||||||
TextureTarget.TextureCubeMapArray,
|
TextureTarget.TextureCubeMapArray,
|
||||||
levels,
|
levels,
|
||||||
internalFormat,
|
internalFormat,
|
||||||
Info.Width,
|
(uint)Info.Width,
|
||||||
Info.Height,
|
(uint)Info.Height,
|
||||||
Info.Depth);
|
(uint)Info.Depth);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -201,7 +203,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
|
||||||
|
|
||||||
if (Handle != 0)
|
if (Handle != 0)
|
||||||
{
|
{
|
||||||
GL.DeleteTexture(Handle);
|
_api.DeleteTexture(Handle);
|
||||||
|
|
||||||
Handle = 0;
|
Handle = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue