misc: chore: Use explicit types in OpenGL project

This commit is contained in:
Evan Husted 2025-01-25 14:12:37 -06:00
parent 2d1a4c3ce5
commit 58c1ab7989
14 changed files with 65 additions and 63 deletions

View File

@ -41,7 +41,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
private void Initialize()
{
var scalingShader = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/area_scaling.glsl");
string scalingShader = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/area_scaling.glsl");
_scalingShaderProgram = CompileProgram(scalingShader, ShaderType.ComputeShader);

View File

@ -57,10 +57,10 @@ namespace Ryujinx.Graphics.OpenGL.Effects
private void Initialize()
{
var scalingShader = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/fsr_scaling.glsl");
var sharpeningShader = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/fsr_sharpening.glsl");
var fsrA = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/ffx_a.h");
var fsr1 = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/ffx_fsr1.h");
string scalingShader = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/fsr_scaling.glsl");
string sharpeningShader = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/fsr_sharpening.glsl");
string fsrA = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/ffx_a.h");
string fsr1 = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/ffx_fsr1.h");
scalingShader = scalingShader.Replace("#include \"ffx_a.h\"", fsrA);
scalingShader = scalingShader.Replace("#include \"ffx_fsr1.h\"", fsr1);
@ -97,8 +97,8 @@ namespace Ryujinx.Graphics.OpenGL.Effects
if (_intermediaryTexture == null || _intermediaryTexture.Info.Width != width || _intermediaryTexture.Info.Height != height)
{
_intermediaryTexture?.Dispose();
var originalInfo = view.Info;
var info = new TextureCreateInfo(width,
TextureCreateInfo originalInfo = view.Info;
TextureCreateInfo info = new TextureCreateInfo(width,
height,
originalInfo.Depth,
originalInfo.Levels,
@ -118,7 +118,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
_intermediaryTexture.CreateDefaultView();
}
var textureView = _intermediaryTexture.CreateView(_intermediaryTexture.Info, 0, 0) as TextureView;
TextureView textureView = _intermediaryTexture.CreateView(_intermediaryTexture.Info, 0, 0) as TextureView;
int previousProgram = GL.GetInteger(GetPName.CurrentProgram);
int previousUnit = GL.GetInteger(GetPName.ActiveTexture);

View File

@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
_textureStorage.CreateDefaultView();
}
var textureView = _textureStorage.CreateView(view.Info, 0, 0) as TextureView;
TextureView textureView = _textureStorage.CreateView(view.Info, 0, 0) as TextureView;
int previousProgram = GL.GetInteger(GetPName.CurrentProgram);
int previousUnit = GL.GetInteger(GetPName.ActiveTexture);
@ -57,8 +57,8 @@ namespace Ryujinx.Graphics.OpenGL.Effects
GL.BindImageTexture(0, textureView.Handle, 0, false, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8);
GL.UseProgram(_shaderProgram);
var dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize);
var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize);
int dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize);
int dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize);
view.Bind(0);
GL.Uniform1(_inputUniform, 0);

View File

@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
public static int CompileProgram(string[] shaders, ShaderType shaderType)
{
var shader = GL.CreateShader(shaderType);
int shader = GL.CreateShader(shaderType);
GL.ShaderSource(shader, shaders.Length, shaders, (int[])null);
GL.CompileShader(shader);
@ -25,7 +25,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
return 0;
}
var program = GL.CreateProgram();
int program = GL.CreateProgram();
GL.AttachShader(program, shader);
GL.LinkProgram(program);

View File

@ -1,5 +1,6 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Common;
using Ryujinx.Common.Memory;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.OpenGL.Image;
using System;
@ -78,7 +79,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
private unsafe void RecreateShaders(int width, int height)
{
string baseShader = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/smaa.hlsl");
var pixelSizeDefine = $"#define SMAA_RT_METRICS float4(1.0 / {width}.0, 1.0 / {height}.0, {width}, {height}) \n";
string pixelSizeDefine = $"#define SMAA_RT_METRICS float4(1.0 / {width}.0, 1.0 / {height}.0, {width}, {height}) \n";
_edgeShaderPrograms = new int[_qualities.Length];
_blendShaderPrograms = new int[_qualities.Length];
@ -86,20 +87,20 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
for (int i = 0; i < +_edgeShaderPrograms.Length; i++)
{
var presets = $"#version 430 core \n#define {_qualities[i]} 1 \n{pixelSizeDefine}#define SMAA_GLSL_4 1 \nlayout (local_size_x = 16, local_size_y = 16) in;\n{baseShader}";
string presets = $"#version 430 core \n#define {_qualities[i]} 1 \n{pixelSizeDefine}#define SMAA_GLSL_4 1 \nlayout (local_size_x = 16, local_size_y = 16) in;\n{baseShader}";
var edgeShaderData = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/smaa_edge.glsl");
var blendShaderData = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/smaa_blend.glsl");
var neighbourShaderData = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/smaa_neighbour.glsl");
string edgeShaderData = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/smaa_edge.glsl");
string blendShaderData = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/smaa_blend.glsl");
string neighbourShaderData = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/smaa_neighbour.glsl");
var shaders = new string[] { presets, edgeShaderData };
var edgeProgram = ShaderHelper.CompileProgram(shaders, ShaderType.ComputeShader);
string[] shaders = new string[] { presets, edgeShaderData };
int edgeProgram = ShaderHelper.CompileProgram(shaders, ShaderType.ComputeShader);
shaders[1] = blendShaderData;
var blendProgram = ShaderHelper.CompileProgram(shaders, ShaderType.ComputeShader);
int blendProgram = ShaderHelper.CompileProgram(shaders, ShaderType.ComputeShader);
shaders[1] = neighbourShaderData;
var neighbourProgram = ShaderHelper.CompileProgram(shaders, ShaderType.ComputeShader);
int neighbourProgram = ShaderHelper.CompileProgram(shaders, ShaderType.ComputeShader);
_edgeShaderPrograms[i] = edgeProgram;
_blendShaderPrograms[i] = blendProgram;
@ -116,7 +117,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
private void Initialize()
{
var areaInfo = new TextureCreateInfo(AreaWidth,
TextureCreateInfo areaInfo = new TextureCreateInfo(AreaWidth,
AreaHeight,
1,
1,
@ -132,7 +133,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
SwizzleComponent.Blue,
SwizzleComponent.Alpha);
var searchInfo = new TextureCreateInfo(SearchWidth,
TextureCreateInfo searchInfo = new TextureCreateInfo(SearchWidth,
SearchHeight,
1,
1,
@ -151,11 +152,11 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
_areaTexture = new TextureStorage(_renderer, areaInfo);
_searchTexture = new TextureStorage(_renderer, searchInfo);
var areaTexture = EmbeddedResources.ReadFileToRentedMemory("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaAreaTexture.bin");
var searchTexture = EmbeddedResources.ReadFileToRentedMemory("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaSearchTexture.bin");
MemoryOwner<byte> areaTexture = EmbeddedResources.ReadFileToRentedMemory("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaAreaTexture.bin");
MemoryOwner<byte> searchTexture = EmbeddedResources.ReadFileToRentedMemory("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaSearchTexture.bin");
var areaView = _areaTexture.CreateDefaultView();
var searchView = _searchTexture.CreateDefaultView();
ITexture areaView = _areaTexture.CreateDefaultView();
ITexture searchView = _searchTexture.CreateDefaultView();
areaView.SetData(areaTexture);
searchView.SetData(searchTexture);
@ -178,13 +179,13 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
RecreateShaders(view.Width, view.Height);
}
var textureView = _outputTexture.CreateView(view.Info, 0, 0) as TextureView;
var edgeOutput = _edgeOutputTexture.DefaultView as TextureView;
var blendOutput = _blendOutputTexture.DefaultView as TextureView;
var areaTexture = _areaTexture.DefaultView as TextureView;
var searchTexture = _searchTexture.DefaultView as TextureView;
TextureView textureView = _outputTexture.CreateView(view.Info, 0, 0) as TextureView;
TextureView edgeOutput = _edgeOutputTexture.DefaultView as TextureView;
TextureView blendOutput = _blendOutputTexture.DefaultView as TextureView;
TextureView areaTexture = _areaTexture.DefaultView as TextureView;
TextureView searchTexture = _searchTexture.DefaultView as TextureView;
var previousFramebuffer = GL.GetInteger(GetPName.FramebufferBinding);
int previousFramebuffer = GL.GetInteger(GetPName.FramebufferBinding);
int previousUnit = GL.GetInteger(GetPName.ActiveTexture);
GL.ActiveTexture(TextureUnit.Texture0);
int previousTextureBinding0 = GL.GetInteger(GetPName.TextureBinding2D);
@ -193,7 +194,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
GL.ActiveTexture(TextureUnit.Texture2);
int previousTextureBinding2 = GL.GetInteger(GetPName.TextureBinding2D);
var framebuffer = new Framebuffer();
Framebuffer framebuffer = new Framebuffer();
framebuffer.Bind();
framebuffer.AttachColor(0, edgeOutput);
GL.Clear(ClearBufferMask.ColorBufferBit);
@ -206,8 +207,8 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
framebuffer.Dispose();
var dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize);
var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize);
int dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize);
int dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize);
int previousProgram = GL.GetInteger(GetPName.CurrentProgram);
GL.BindImageTexture(0, edgeOutput.Handle, 0, false, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8);

View File

@ -19,7 +19,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
if (Avx2.IsSupported)
{
var mask = Vector256.Create(
Vector256<byte> mask = Vector256.Create(
(byte)3, (byte)0, (byte)1, (byte)2,
(byte)7, (byte)4, (byte)5, (byte)6,
(byte)11, (byte)8, (byte)9, (byte)10,
@ -35,7 +35,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{
for (uint i = 0; i < sizeAligned; i += 32)
{
var dataVec = Avx.LoadVector256(pInput + i);
Vector256<byte> dataVec = Avx.LoadVector256(pInput + i);
dataVec = Avx2.Shuffle(dataVec, mask);
@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
}
else if (Ssse3.IsSupported)
{
var mask = Vector128.Create(
Vector128<byte> mask = Vector128.Create(
(byte)3, (byte)0, (byte)1, (byte)2,
(byte)7, (byte)4, (byte)5, (byte)6,
(byte)11, (byte)8, (byte)9, (byte)10,
@ -59,7 +59,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{
for (uint i = 0; i < sizeAligned; i += 16)
{
var dataVec = Sse2.LoadVector128(pInput + i);
Vector128<byte> dataVec = Sse2.LoadVector128(pInput + i);
dataVec = Ssse3.Shuffle(dataVec, mask);
@ -70,8 +70,8 @@ namespace Ryujinx.Graphics.OpenGL.Image
start = sizeAligned;
}
var outSpan = MemoryMarshal.Cast<byte, uint>(output);
var dataSpan = MemoryMarshal.Cast<byte, uint>(data);
Span<uint> outSpan = MemoryMarshal.Cast<byte, uint>(output);
ReadOnlySpan<uint> dataSpan = MemoryMarshal.Cast<byte, uint>(data);
for (int i = start / sizeof(uint); i < dataSpan.Length; i++)
{
outSpan[i] = BitOperations.RotateLeft(dataSpan[i], 8);
@ -88,7 +88,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
if (Avx2.IsSupported)
{
var mask = Vector256.Create(
Vector256<byte> mask = Vector256.Create(
(byte)1, (byte)2, (byte)3, (byte)0,
(byte)5, (byte)6, (byte)7, (byte)4,
(byte)9, (byte)10, (byte)11, (byte)8,
@ -104,7 +104,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{
for (uint i = 0; i < sizeAligned; i += 32)
{
var dataVec = Avx.LoadVector256(pInput + i);
Vector256<byte> dataVec = Avx.LoadVector256(pInput + i);
dataVec = Avx2.Shuffle(dataVec, mask);
@ -116,7 +116,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
}
else if (Ssse3.IsSupported)
{
var mask = Vector128.Create(
Vector128<byte> mask = Vector128.Create(
(byte)1, (byte)2, (byte)3, (byte)0,
(byte)5, (byte)6, (byte)7, (byte)4,
(byte)9, (byte)10, (byte)11, (byte)8,
@ -128,7 +128,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{
for (uint i = 0; i < sizeAligned; i += 16)
{
var dataVec = Sse2.LoadVector128(pInput + i);
Vector128<byte> dataVec = Sse2.LoadVector128(pInput + i);
dataVec = Ssse3.Shuffle(dataVec, mask);
@ -139,8 +139,8 @@ namespace Ryujinx.Graphics.OpenGL.Image
start = sizeAligned;
}
var outSpan = MemoryMarshal.Cast<byte, uint>(output);
var dataSpan = MemoryMarshal.Cast<byte, uint>(data);
Span<uint> outSpan = MemoryMarshal.Cast<byte, uint>(output);
ReadOnlySpan<uint> dataSpan = MemoryMarshal.Cast<byte, uint>(data);
for (int i = start / sizeof(uint); i < dataSpan.Length; i++)
{
outSpan[i] = BitOperations.RotateRight(dataSpan[i], 8);

View File

@ -57,7 +57,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
/// <inheritdoc/>
public void SetData(MemoryOwner<byte> data)
{
var dataSpan = data.Span;
Span<byte> dataSpan = data.Span;
Buffer.SetData(_buffer, _bufferOffset, dataSpan[..Math.Min(dataSpan.Length, _bufferSize)]);

View File

@ -91,8 +91,8 @@ void main()
int srcComponentsCount = srcBpp / componentSize;
int dstComponentsCount = dstBpp / componentSize;
var srcFormat = GetFormat(componentSize, srcComponentsCount);
var dstFormat = GetFormat(componentSize, dstComponentsCount);
SizedInternalFormat srcFormat = GetFormat(componentSize, srcComponentsCount);
SizedInternalFormat dstFormat = GetFormat(componentSize, dstComponentsCount);
GL.UseProgram(srcBpp < dstBpp
? GetWideningShader(componentSize, srcComponentsCount, dstComponentsCount)

View File

@ -454,7 +454,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{
unsafe
{
var dataSpan = data.Span;
Span<byte> dataSpan = data.Span;
fixed (byte* ptr = dataSpan)
{
ReadFrom((nint)ptr, dataSpan.Length);

View File

@ -6,6 +6,7 @@ using Ryujinx.Graphics.OpenGL.Image;
using Ryujinx.Graphics.OpenGL.Queries;
using Ryujinx.Graphics.Shader.Translation;
using System;
using BufferAccess = Ryujinx.Graphics.GAL.BufferAccess;
namespace Ryujinx.Graphics.OpenGL
{
@ -63,7 +64,7 @@ namespace Ryujinx.Graphics.OpenGL
{
BufferCount++;
var memType = access & GAL.BufferAccess.MemoryTypeMask;
BufferAccess memType = access & GAL.BufferAccess.MemoryTypeMask;
if (memType == GAL.BufferAccess.HostMemory)
{

View File

@ -1205,7 +1205,7 @@ namespace Ryujinx.Graphics.OpenGL
{
int vIndex = index * 4;
var region = regions[index];
Rectangle<int> region = regions[index];
bool enabled = (region.X | region.Y) != 0 || region.Width != 0xffff || region.Height != 0xffff;
uint mask = 1u << index;

View File

@ -35,7 +35,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public void Update()
{
foreach (var queue in _counterQueues)
foreach (CounterQueue queue in _counterQueues)
{
queue.Flush(false);
}
@ -48,7 +48,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public void Dispose()
{
foreach (var queue in _counterQueues)
foreach (CounterQueue queue in _counterQueues)
{
queue.Dispose();
}

View File

@ -177,7 +177,7 @@ namespace Ryujinx.Graphics.OpenGL
{
int vbIndex = BitOperations.TrailingZeroCount(buffersInUse);
ref var vb = ref _vertexBuffers[vbIndex];
ref VertexBufferDescriptor vb = ref _vertexBuffers[vbIndex];
int requiredSize = vertexCount * vb.Stride;
@ -232,7 +232,7 @@ namespace Ryujinx.Graphics.OpenGL
{
int vbIndex = BitOperations.TrailingZeroCount(buffersLimited);
ref var vb = ref _vertexBuffers[vbIndex];
ref VertexBufferDescriptor vb = ref _vertexBuffers[vbIndex];
GL.BindVertexBuffer(vbIndex, vb.Buffer.Handle.ToInt32(), (nint)vb.Buffer.Offset, vb.Stride);

View File

@ -76,13 +76,13 @@ namespace Ryujinx.Graphics.OpenGL
if (_antiAliasing != null)
{
var oldView = viewConverted;
TextureView oldView = viewConverted;
viewConverted = _antiAliasing.Run(viewConverted, _width, _height);
if (viewConverted.Format.IsBgr())
{
var swappedView = _renderer.TextureCopy.BgraSwap(viewConverted);
TextureView swappedView = _renderer.TextureCopy.BgraSwap(viewConverted);
viewConverted?.Dispose();
@ -330,7 +330,7 @@ namespace Ryujinx.Graphics.OpenGL
case AntiAliasing.SmaaMedium:
case AntiAliasing.SmaaHigh:
case AntiAliasing.SmaaUltra:
var quality = _currentAntiAliasing - AntiAliasing.SmaaLow;
int quality = _currentAntiAliasing - AntiAliasing.SmaaLow;
if (_antiAliasing is SmaaPostProcessingEffect smaa)
{
smaa.Quality = quality;
@ -394,7 +394,7 @@ namespace Ryujinx.Graphics.OpenGL
{
_upscaledTexture?.Dispose();
var info = new TextureCreateInfo(
TextureCreateInfo info = new TextureCreateInfo(
_width,
_height,
1,