aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Vulkan/HelperShader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Ryujinx.Graphics.Vulkan/HelperShader.cs')
-rw-r--r--src/Ryujinx.Graphics.Vulkan/HelperShader.cs148
1 files changed, 77 insertions, 71 deletions
diff --git a/src/Ryujinx.Graphics.Vulkan/HelperShader.cs b/src/Ryujinx.Graphics.Vulkan/HelperShader.cs
index 43214be4..648afcd6 100644
--- a/src/Ryujinx.Graphics.Vulkan/HelperShader.cs
+++ b/src/Ryujinx.Graphics.Vulkan/HelperShader.cs
@@ -6,6 +6,12 @@ using Silk.NET.Vulkan;
using System;
using System.Collections.Generic;
using System.Numerics;
+using CompareOp = Ryujinx.Graphics.GAL.CompareOp;
+using Format = Ryujinx.Graphics.GAL.Format;
+using PrimitiveTopology = Ryujinx.Graphics.GAL.PrimitiveTopology;
+using SamplerCreateInfo = Ryujinx.Graphics.GAL.SamplerCreateInfo;
+using StencilOp = Ryujinx.Graphics.GAL.StencilOp;
+using Viewport = Ryujinx.Graphics.GAL.Viewport;
using VkFormat = Silk.NET.Vulkan.Format;
namespace Ryujinx.Graphics.Vulkan
@@ -14,7 +20,7 @@ namespace Ryujinx.Graphics.Vulkan
{
Float,
SignedInteger,
- UnsignedInteger
+ UnsignedInteger,
}
class HelperShader : IDisposable
@@ -52,8 +58,8 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline = new PipelineHelperShader(gd, device);
_pipeline.Initialize();
- _samplerLinear = gd.CreateSampler(GAL.SamplerCreateInfo.Create(MinFilter.Linear, MagFilter.Linear));
- _samplerNearest = gd.CreateSampler(GAL.SamplerCreateInfo.Create(MinFilter.Nearest, MagFilter.Nearest));
+ _samplerLinear = gd.CreateSampler(SamplerCreateInfo.Create(MinFilter.Linear, MagFilter.Linear));
+ _samplerNearest = gd.CreateSampler(SamplerCreateInfo.Create(MinFilter.Nearest, MagFilter.Nearest));
var blitResourceLayout = new ResourceLayoutBuilder()
.Add(ResourceStages.Vertex, ResourceType.UniformBuffer, 1)
@@ -416,7 +422,7 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, new BufferRange(bufferHandle, 0, RegionBufferSize)) });
- Span<GAL.Viewport> viewports = stackalloc GAL.Viewport[1];
+ Span<Viewport> viewports = stackalloc Viewport[1];
var rect = new Rectangle<float>(
MathF.Min(dstRegion.X1, dstRegion.X2),
@@ -424,7 +430,7 @@ namespace Ryujinx.Graphics.Vulkan
MathF.Abs(dstRegion.X2 - dstRegion.X1),
MathF.Abs(dstRegion.Y2 - dstRegion.Y1));
- viewports[0] = new GAL.Viewport(
+ viewports[0] = new Viewport(
rect,
ViewportSwizzle.PositiveX,
ViewportSwizzle.PositiveY,
@@ -440,7 +446,7 @@ namespace Ryujinx.Graphics.Vulkan
if (dstIsDepthOrStencil)
{
_pipeline.SetProgram(src.Info.Target.IsMultisample() ? _programDepthBlitMs : _programDepthBlit);
- _pipeline.SetDepthTest(new DepthTestDescriptor(true, true, GAL.CompareOp.Always));
+ _pipeline.SetDepthTest(new DepthTestDescriptor(true, true, CompareOp.Always));
}
else if (src.Info.Target.IsMultisample())
{
@@ -465,12 +471,12 @@ namespace Ryujinx.Graphics.Vulkan
}
_pipeline.SetViewports(viewports, false);
- _pipeline.SetPrimitiveTopology(GAL.PrimitiveTopology.TriangleStrip);
+ _pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
_pipeline.Draw(4, 1, 0, 0);
if (dstIsDepthOrStencil)
{
- _pipeline.SetDepthTest(new DepthTestDescriptor(false, false, GAL.CompareOp.Always));
+ _pipeline.SetDepthTest(new DepthTestDescriptor(false, false, CompareOp.Always));
}
_pipeline.Finish(gd, cbs);
@@ -517,7 +523,7 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, new BufferRange(bufferHandle, 0, RegionBufferSize)) });
- Span<GAL.Viewport> viewports = stackalloc GAL.Viewport[1];
+ Span<Viewport> viewports = stackalloc Viewport[1];
var rect = new Rectangle<float>(
MathF.Min(dstRegion.X1, dstRegion.X2),
@@ -525,7 +531,7 @@ namespace Ryujinx.Graphics.Vulkan
MathF.Abs(dstRegion.X2 - dstRegion.X1),
MathF.Abs(dstRegion.Y2 - dstRegion.Y1));
- viewports[0] = new GAL.Viewport(
+ viewports[0] = new Viewport(
rect,
ViewportSwizzle.PositiveX,
ViewportSwizzle.PositiveY,
@@ -541,7 +547,7 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetRenderTarget(dst, (uint)dstWidth, (uint)dstHeight, (uint)dstSamples, true, dstFormat);
_pipeline.SetScissors(scissors);
_pipeline.SetViewports(viewports, false);
- _pipeline.SetPrimitiveTopology(GAL.PrimitiveTopology.TriangleStrip);
+ _pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
var aspectFlags = src.Info.Format.ConvertAspectFlags();
@@ -606,7 +612,7 @@ namespace Ryujinx.Graphics.Vulkan
if (isDepth)
{
_pipeline.SetProgram(src.Info.Target.IsMultisample() ? _programDepthBlitMs : _programDepthBlit);
- _pipeline.SetDepthTest(new DepthTestDescriptor(true, true, GAL.CompareOp.Always));
+ _pipeline.SetDepthTest(new DepthTestDescriptor(true, true, CompareOp.Always));
}
else
{
@@ -618,7 +624,7 @@ namespace Ryujinx.Graphics.Vulkan
if (isDepth)
{
- _pipeline.SetDepthTest(new DepthTestDescriptor(false, false, GAL.CompareOp.Always));
+ _pipeline.SetDepthTest(new DepthTestDescriptor(false, false, CompareOp.Always));
}
else
{
@@ -630,17 +636,17 @@ namespace Ryujinx.Graphics.Vulkan
{
return new StencilTestDescriptor(
enabled,
- GAL.CompareOp.Always,
- GAL.StencilOp.Replace,
- GAL.StencilOp.Replace,
- GAL.StencilOp.Replace,
+ CompareOp.Always,
+ StencilOp.Replace,
+ StencilOp.Replace,
+ StencilOp.Replace,
0,
0xff,
0xff,
- GAL.CompareOp.Always,
- GAL.StencilOp.Replace,
- GAL.StencilOp.Replace,
- GAL.StencilOp.Replace,
+ CompareOp.Always,
+ StencilOp.Replace,
+ StencilOp.Replace,
+ StencilOp.Replace,
0,
0xff,
0xff);
@@ -667,13 +673,13 @@ namespace Ryujinx.Graphics.Vulkan
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, ClearColorBufferSize);
- gd.BufferManager.SetData<float>(bufferHandle, 0, clearColor);
+ gd.BufferManager.SetData(bufferHandle, 0, clearColor);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, new BufferRange(bufferHandle, 0, ClearColorBufferSize)) });
- Span<GAL.Viewport> viewports = stackalloc GAL.Viewport[1];
+ Span<Viewport> viewports = stackalloc Viewport[1];
- viewports[0] = new GAL.Viewport(
+ viewports[0] = new Viewport(
new Rectangle<float>(0, 0, dstWidth, dstHeight),
ViewportSwizzle.PositiveX,
ViewportSwizzle.PositiveY,
@@ -703,10 +709,10 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetProgram(program);
_pipeline.SetRenderTarget(dst, (uint)dstWidth, (uint)dstHeight, false, dstFormat);
- _pipeline.SetRenderTargetColorMasks(new uint[] { componentMask });
+ _pipeline.SetRenderTargetColorMasks(new[] { componentMask });
_pipeline.SetViewports(viewports, false);
_pipeline.SetScissors(scissors);
- _pipeline.SetPrimitiveTopology(GAL.PrimitiveTopology.TriangleStrip);
+ _pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
_pipeline.Draw(4, 1, 0, 0);
_pipeline.Finish();
@@ -748,7 +754,7 @@ namespace Ryujinx.Graphics.Vulkan
pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, new BufferRange(bufferHandle, 0, RegionBufferSize)) });
- Span<GAL.Viewport> viewports = stackalloc GAL.Viewport[1];
+ Span<Viewport> viewports = stackalloc Viewport[1];
var rect = new Rectangle<float>(
MathF.Min(dstRegion.X1, dstRegion.X2),
@@ -756,7 +762,7 @@ namespace Ryujinx.Graphics.Vulkan
MathF.Abs(dstRegion.X2 - dstRegion.X1),
MathF.Abs(dstRegion.Y2 - dstRegion.Y1));
- viewports[0] = new GAL.Viewport(
+ viewports[0] = new Viewport(
rect,
ViewportSwizzle.PositiveX,
ViewportSwizzle.PositiveY,
@@ -769,13 +775,13 @@ namespace Ryujinx.Graphics.Vulkan
pipeline.SetProgram(_programColorBlit);
pipeline.SetViewports(viewports, false);
- pipeline.SetPrimitiveTopology(GAL.PrimitiveTopology.TriangleStrip);
+ pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
pipeline.Draw(4, 1, 0, 0);
gd.BufferManager.Delete(bufferHandle);
}
- public unsafe void ConvertI8ToI16(VulkanRenderer gd, CommandBufferScoped cbs, BufferHolder src, BufferHolder dst, int srcOffset, int size)
+ public void ConvertI8ToI16(VulkanRenderer gd, CommandBufferScoped cbs, BufferHolder src, BufferHolder dst, int srcOffset, int size)
{
ChangeStride(gd, cbs, src, dst, srcOffset, size, 1, 2);
}
@@ -1093,11 +1099,11 @@ namespace Ryujinx.Graphics.Vulkan
{
// We can't use compute for this case because compute can't modify depth textures.
- Span<GAL.Viewport> viewports = stackalloc GAL.Viewport[1];
+ Span<Viewport> viewports = stackalloc Viewport[1];
var rect = new Rectangle<float>(0, 0, dst.Width, dst.Height);
- viewports[0] = new GAL.Viewport(
+ viewports[0] = new Viewport(
rect,
ViewportSwizzle.PositiveX,
ViewportSwizzle.PositiveY,
@@ -1112,7 +1118,7 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetScissors(scissors);
_pipeline.SetViewports(viewports, false);
- _pipeline.SetPrimitiveTopology(GAL.PrimitiveTopology.TriangleStrip);
+ _pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
for (int z = 0; z < depth; z++)
{
@@ -1120,7 +1126,7 @@ namespace Ryujinx.Graphics.Vulkan
var dstView = Create2DLayerView(dst, dstLayer + z, 0);
_pipeline.SetRenderTarget(
- ((TextureView)dstView).GetImageViewForAttachment(),
+ dstView.GetImageViewForAttachment(),
(uint)dst.Width,
(uint)dst.Height,
true,
@@ -1225,11 +1231,11 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetCommandBuffer(cbs);
- Span<GAL.Viewport> viewports = stackalloc GAL.Viewport[1];
+ Span<Viewport> viewports = stackalloc Viewport[1];
var rect = new Rectangle<float>(0, 0, dst.Width, dst.Height);
- viewports[0] = new GAL.Viewport(
+ viewports[0] = new Viewport(
rect,
ViewportSwizzle.PositiveX,
ViewportSwizzle.PositiveY,
@@ -1245,7 +1251,7 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetRenderTargetColorMasks(new uint[] { 0xf });
_pipeline.SetScissors(scissors);
_pipeline.SetViewports(viewports, false);
- _pipeline.SetPrimitiveTopology(GAL.PrimitiveTopology.TriangleStrip);
+ _pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, new BufferRange(bufferHandle, 0, ParamsBufferSize)) });
@@ -1257,7 +1263,7 @@ namespace Ryujinx.Graphics.Vulkan
var dstView = Create2DLayerView(dst, dstLayer + z, 0);
_pipeline.SetRenderTarget(
- ((TextureView)dstView).GetImageViewForAttachment(),
+ dstView.GetImageViewForAttachment(),
(uint)dst.Width,
(uint)dst.Height,
(uint)samples,
@@ -1291,7 +1297,7 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetTextureAndSamplerIdentitySwizzle(ShaderStage.Fragment, 0, srcView, null);
_pipeline.SetRenderTarget(
- ((TextureView)dstView).GetView(format).GetImageViewForAttachment(),
+ dstView.GetView(format).GetImageViewForAttachment(),
(uint)dst.Width,
(uint)dst.Height,
(uint)samples,
@@ -1365,7 +1371,7 @@ namespace Ryujinx.Graphics.Vulkan
if (isDepth)
{
_pipeline.SetProgram(fromMS ? _programDepthDrawToNonMs : _programDepthDrawToMs);
- _pipeline.SetDepthTest(new DepthTestDescriptor(true, true, GAL.CompareOp.Always));
+ _pipeline.SetDepthTest(new DepthTestDescriptor(true, true, CompareOp.Always));
}
else
{
@@ -1377,7 +1383,7 @@ namespace Ryujinx.Graphics.Vulkan
if (isDepth)
{
- _pipeline.SetDepthTest(new DepthTestDescriptor(false, false, GAL.CompareOp.Always));
+ _pipeline.SetDepthTest(new DepthTestDescriptor(false, false, CompareOp.Always));
}
else
{
@@ -1420,7 +1426,7 @@ namespace Ryujinx.Graphics.Vulkan
return (samplesInXLog2, samplesInYLog2);
}
- private static TextureView Create2DLayerView(TextureView from, int layer, int level, GAL.Format? format = null)
+ private static TextureView Create2DLayerView(TextureView from, int layer, int level, Format? format = null)
{
if (from.Info.Target == Target.Texture2D && level == 0 && (format == null || format.Value == from.Info.Format))
{
@@ -1431,7 +1437,7 @@ namespace Ryujinx.Graphics.Vulkan
{
Target.Texture1DArray => Target.Texture1D,
Target.Texture2DMultisampleArray => Target.Texture2DMultisample,
- _ => Target.Texture2D
+ _ => Target.Texture2D,
};
var info = new TextureCreateInfo(
@@ -1454,55 +1460,55 @@ namespace Ryujinx.Graphics.Vulkan
return from.CreateViewImpl(info, layer, level);
}
- private static GAL.Format GetFormat(int bytesPerPixel)
+ private static Format GetFormat(int bytesPerPixel)
{
return bytesPerPixel switch
{
- 1 => GAL.Format.R8Uint,
- 2 => GAL.Format.R16Uint,
- 4 => GAL.Format.R32Uint,
- 8 => GAL.Format.R32G32Uint,
- 16 => GAL.Format.R32G32B32A32Uint,
- _ => throw new ArgumentException($"Invalid bytes per pixel {bytesPerPixel}.")
+ 1 => Format.R8Uint,
+ 2 => Format.R16Uint,
+ 4 => Format.R32Uint,
+ 8 => Format.R32G32Uint,
+ 16 => Format.R32G32B32A32Uint,
+ _ => throw new ArgumentException($"Invalid bytes per pixel {bytesPerPixel}."),
};
}
- private static GAL.Format GetFormat(int componentSize, int componentsCount)
+ private static Format GetFormat(int componentSize, int componentsCount)
{
if (componentSize == 1)
{
return componentsCount switch
{
- 1 => GAL.Format.R8Uint,
- 2 => GAL.Format.R8G8Uint,
- 4 => GAL.Format.R8G8B8A8Uint,
- _ => throw new ArgumentException($"Invalid components count {componentsCount}.")
+ 1 => Format.R8Uint,
+ 2 => Format.R8G8Uint,
+ 4 => Format.R8G8B8A8Uint,
+ _ => throw new ArgumentException($"Invalid components count {componentsCount}."),
};
}
- else if (componentSize == 2)
+
+ if (componentSize == 2)
{
return componentsCount switch
{
- 1 => GAL.Format.R16Uint,
- 2 => GAL.Format.R16G16Uint,
- 4 => GAL.Format.R16G16B16A16Uint,
- _ => throw new ArgumentException($"Invalid components count {componentsCount}.")
+ 1 => Format.R16Uint,
+ 2 => Format.R16G16Uint,
+ 4 => Format.R16G16B16A16Uint,
+ _ => throw new ArgumentException($"Invalid components count {componentsCount}."),
};
}
- else if (componentSize == 4)
+
+ if (componentSize == 4)
{
return componentsCount switch
{
- 1 => GAL.Format.R32Uint,
- 2 => GAL.Format.R32G32Uint,
- 4 => GAL.Format.R32G32B32A32Uint,
- _ => throw new ArgumentException($"Invalid components count {componentsCount}.")
+ 1 => Format.R32Uint,
+ 2 => Format.R32G32Uint,
+ 4 => Format.R32G32B32A32Uint,
+ _ => throw new ArgumentException($"Invalid components count {componentsCount}."),
};
}
- else
- {
- throw new ArgumentException($"Invalid component size {componentSize}.");
- }
+
+ throw new ArgumentException($"Invalid component size {componentSize}.");
}
public void ConvertIndexBufferIndirect(
@@ -1524,7 +1530,7 @@ namespace Ryujinx.Graphics.Vulkan
{
// TODO: Support conversion with primitive restart enabled.
- BufferRange drawCountBufferAligned = new BufferRange(
+ BufferRange drawCountBufferAligned = new(
drawCountBuffer.Handle,
drawCountBuffer.Offset & ~(UniformBufferAlignment - 1),
UniformBufferAlignment);
@@ -1562,7 +1568,7 @@ namespace Ryujinx.Graphics.Vulkan
shaderParams[22] = indirectDataStride / 4;
shaderParams[23] = srcIndirectBufferOffset / 4;
- pattern.OffsetIndex.CopyTo(shaderParams.Slice(0, pattern.OffsetIndex.Length));
+ pattern.OffsetIndex.CopyTo(shaderParams[..pattern.OffsetIndex.Length]);
var patternBufferHandle = gd.BufferManager.CreateWithHandle(gd, ParamsBufferSize, out var patternBuffer);
var patternBufferAuto = patternBuffer.GetBuffer();