From 654e617fe78b0f5cc86d0bcf0625301abff168f5 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 29 Dec 2019 14:41:50 -0300 Subject: Some code cleanup --- Ryujinx.Graphics.GAL/AddressMode.cs | 14 + Ryujinx.Graphics.GAL/Blend/BlendDescriptor.cs | 32 -- Ryujinx.Graphics.GAL/Blend/BlendFactor.cs | 41 --- Ryujinx.Graphics.GAL/Blend/BlendOp.cs | 17 - Ryujinx.Graphics.GAL/BlendDescriptor.cs | 32 ++ Ryujinx.Graphics.GAL/BlendFactor.cs | 41 +++ Ryujinx.Graphics.GAL/BlendOp.cs | 17 + Ryujinx.Graphics.GAL/Color/ColorF.cs | 18 -- Ryujinx.Graphics.GAL/Color/ColorSI.cs | 18 -- Ryujinx.Graphics.GAL/Color/ColorUI.cs | 18 -- Ryujinx.Graphics.GAL/ColorF.cs | 18 ++ Ryujinx.Graphics.GAL/CompareMode.cs | 8 + .../DepthStencil/DepthStencilState.cs | 47 --- .../DepthStencil/DepthTestDescriptor.cs | 20 -- Ryujinx.Graphics.GAL/DepthStencil/StencilOp.cs | 14 - .../DepthStencil/StencilTestDescriptor.cs | 56 ---- Ryujinx.Graphics.GAL/DepthStencilMode.cs | 8 + Ryujinx.Graphics.GAL/DepthStencilState.cs | 47 +++ Ryujinx.Graphics.GAL/DepthTestDescriptor.cs | 20 ++ Ryujinx.Graphics.GAL/IPipeline.cs | 44 ++- Ryujinx.Graphics.GAL/IRenderer.cs | 2 - Ryujinx.Graphics.GAL/ITexture.cs | 1 - .../InputAssembler/VertexAttribDescriptor.cs | 17 - .../InputAssembler/VertexBufferDescriptor.cs | 17 - Ryujinx.Graphics.GAL/MagFilter.cs | 8 + Ryujinx.Graphics.GAL/MinFilter.cs | 12 + Ryujinx.Graphics.GAL/Sampler/AddressMode.cs | 14 - Ryujinx.Graphics.GAL/Sampler/CompareMode.cs | 8 - Ryujinx.Graphics.GAL/Sampler/MagFilter.cs | 8 - Ryujinx.Graphics.GAL/Sampler/MinFilter.cs | 12 - Ryujinx.Graphics.GAL/Sampler/SamplerCreateInfo.cs | 52 --- Ryujinx.Graphics.GAL/SamplerCreateInfo.cs | 50 +++ Ryujinx.Graphics.GAL/StencilOp.cs | 14 + Ryujinx.Graphics.GAL/StencilTestDescriptor.cs | 56 ++++ Ryujinx.Graphics.GAL/SwizzleComponent.cs | 12 + Ryujinx.Graphics.GAL/Target.cs | 17 + Ryujinx.Graphics.GAL/Texture/DepthStencilMode.cs | 8 - Ryujinx.Graphics.GAL/Texture/SwizzleComponent.cs | 12 - Ryujinx.Graphics.GAL/Texture/Target.cs | 17 - Ryujinx.Graphics.GAL/Texture/TextureCreateInfo.cs | 120 ------- Ryujinx.Graphics.GAL/TextureCreateInfo.cs | 120 +++++++ Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs | 17 + Ryujinx.Graphics.GAL/VertexBufferDescriptor.cs | 17 + Ryujinx.Graphics.Gpu/Debugging.cs | 25 -- Ryujinx.Graphics.Gpu/Engine/Compute.cs | 30 +- Ryujinx.Graphics.Gpu/Engine/MethodClear.cs | 4 +- Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs | 2 +- Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs | 8 +- .../Engine/MethodUniformBufferBind.cs | 4 +- Ryujinx.Graphics.Gpu/Engine/Methods.cs | 91 +++--- Ryujinx.Graphics.Gpu/Image/Sampler.cs | 2 - Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs | 1 - Ryujinx.Graphics.Gpu/Image/Texture.cs | 247 +++++++------- Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs | 2 +- .../Image/TextureBindingsManager.cs | 6 +- Ryujinx.Graphics.Gpu/Image/TextureComponent.cs | 2 +- Ryujinx.Graphics.Gpu/Image/TextureInfo.cs | 2 +- Ryujinx.Graphics.Gpu/Image/TextureManager.cs | 1 - Ryujinx.Graphics.Gpu/Image/TexturePool.cs | 4 +- Ryujinx.Graphics.Gpu/Image/TextureTarget.cs | 2 +- Ryujinx.Graphics.Gpu/Memory/BufferManager.cs | 13 +- Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs | 4 +- Ryujinx.Graphics.Gpu/State/BlendState.cs | 2 +- Ryujinx.Graphics.Gpu/State/BlendStateCommon.cs | 2 +- Ryujinx.Graphics.Gpu/State/StencilBackTestState.cs | 1 - Ryujinx.Graphics.Gpu/State/StencilTestState.cs | 1 - Ryujinx.Graphics.Gpu/Window.cs | 9 +- Ryujinx.Graphics.OpenGL/EnumConversion.cs | 41 ++- Ryujinx.Graphics.OpenGL/Pipeline.cs | 356 +++++++++------------ Ryujinx.Graphics.OpenGL/Renderer.cs | 6 +- Ryujinx.Graphics.OpenGL/Sampler.cs | 3 +- Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs | 4 +- Ryujinx.Graphics.OpenGL/TextureStorage.cs | 5 +- Ryujinx.Graphics.OpenGL/TextureView.cs | 7 +- Ryujinx.Graphics.OpenGL/VertexArray.cs | 2 +- .../CodeGen/Glsl/CodeGenContext.cs | 1 + .../CodeGen/Glsl/GlslGenerator.cs | 1 + Ryujinx.Graphics.Shader/ShaderConfig.cs | 106 ------ Ryujinx.Graphics.Shader/ShaderHeader.cs | 148 --------- .../Translation/ShaderConfig.cs | 105 ++++++ .../Translation/ShaderHeader.cs | 148 +++++++++ 81 files changed, 1190 insertions(+), 1349 deletions(-) create mode 100644 Ryujinx.Graphics.GAL/AddressMode.cs delete mode 100644 Ryujinx.Graphics.GAL/Blend/BlendDescriptor.cs delete mode 100644 Ryujinx.Graphics.GAL/Blend/BlendFactor.cs delete mode 100644 Ryujinx.Graphics.GAL/Blend/BlendOp.cs create mode 100644 Ryujinx.Graphics.GAL/BlendDescriptor.cs create mode 100644 Ryujinx.Graphics.GAL/BlendFactor.cs create mode 100644 Ryujinx.Graphics.GAL/BlendOp.cs delete mode 100644 Ryujinx.Graphics.GAL/Color/ColorF.cs delete mode 100644 Ryujinx.Graphics.GAL/Color/ColorSI.cs delete mode 100644 Ryujinx.Graphics.GAL/Color/ColorUI.cs create mode 100644 Ryujinx.Graphics.GAL/ColorF.cs create mode 100644 Ryujinx.Graphics.GAL/CompareMode.cs delete mode 100644 Ryujinx.Graphics.GAL/DepthStencil/DepthStencilState.cs delete mode 100644 Ryujinx.Graphics.GAL/DepthStencil/DepthTestDescriptor.cs delete mode 100644 Ryujinx.Graphics.GAL/DepthStencil/StencilOp.cs delete mode 100644 Ryujinx.Graphics.GAL/DepthStencil/StencilTestDescriptor.cs create mode 100644 Ryujinx.Graphics.GAL/DepthStencilMode.cs create mode 100644 Ryujinx.Graphics.GAL/DepthStencilState.cs create mode 100644 Ryujinx.Graphics.GAL/DepthTestDescriptor.cs delete mode 100644 Ryujinx.Graphics.GAL/InputAssembler/VertexAttribDescriptor.cs delete mode 100644 Ryujinx.Graphics.GAL/InputAssembler/VertexBufferDescriptor.cs create mode 100644 Ryujinx.Graphics.GAL/MagFilter.cs create mode 100644 Ryujinx.Graphics.GAL/MinFilter.cs delete mode 100644 Ryujinx.Graphics.GAL/Sampler/AddressMode.cs delete mode 100644 Ryujinx.Graphics.GAL/Sampler/CompareMode.cs delete mode 100644 Ryujinx.Graphics.GAL/Sampler/MagFilter.cs delete mode 100644 Ryujinx.Graphics.GAL/Sampler/MinFilter.cs delete mode 100644 Ryujinx.Graphics.GAL/Sampler/SamplerCreateInfo.cs create mode 100644 Ryujinx.Graphics.GAL/SamplerCreateInfo.cs create mode 100644 Ryujinx.Graphics.GAL/StencilOp.cs create mode 100644 Ryujinx.Graphics.GAL/StencilTestDescriptor.cs create mode 100644 Ryujinx.Graphics.GAL/SwizzleComponent.cs create mode 100644 Ryujinx.Graphics.GAL/Target.cs delete mode 100644 Ryujinx.Graphics.GAL/Texture/DepthStencilMode.cs delete mode 100644 Ryujinx.Graphics.GAL/Texture/SwizzleComponent.cs delete mode 100644 Ryujinx.Graphics.GAL/Texture/Target.cs delete mode 100644 Ryujinx.Graphics.GAL/Texture/TextureCreateInfo.cs create mode 100644 Ryujinx.Graphics.GAL/TextureCreateInfo.cs create mode 100644 Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs create mode 100644 Ryujinx.Graphics.GAL/VertexBufferDescriptor.cs delete mode 100644 Ryujinx.Graphics.Gpu/Debugging.cs delete mode 100644 Ryujinx.Graphics.Shader/ShaderConfig.cs delete mode 100644 Ryujinx.Graphics.Shader/ShaderHeader.cs create mode 100644 Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs create mode 100644 Ryujinx.Graphics.Shader/Translation/ShaderHeader.cs diff --git a/Ryujinx.Graphics.GAL/AddressMode.cs b/Ryujinx.Graphics.GAL/AddressMode.cs new file mode 100644 index 00000000..153925b1 --- /dev/null +++ b/Ryujinx.Graphics.GAL/AddressMode.cs @@ -0,0 +1,14 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum AddressMode + { + Repeat, + MirroredRepeat, + ClampToEdge, + ClampToBorder, + Clamp, + MirrorClampToEdge, + MirrorClampToBorder, + MirrorClamp + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Blend/BlendDescriptor.cs b/Ryujinx.Graphics.GAL/Blend/BlendDescriptor.cs deleted file mode 100644 index d7ef8004..00000000 --- a/Ryujinx.Graphics.GAL/Blend/BlendDescriptor.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Blend -{ - public struct BlendDescriptor - { - public bool Enable { get; } - - public BlendOp ColorOp { get; } - public BlendFactor ColorSrcFactor { get; } - public BlendFactor ColorDstFactor { get; } - public BlendOp AlphaOp { get; } - public BlendFactor AlphaSrcFactor { get; } - public BlendFactor AlphaDstFactor { get; } - - public BlendDescriptor( - bool enable, - BlendOp colorOp, - BlendFactor colorSrcFactor, - BlendFactor colorDstFactor, - BlendOp alphaOp, - BlendFactor alphaSrcFactor, - BlendFactor alphaDstFactor) - { - Enable = enable; - ColorOp = colorOp; - ColorSrcFactor = colorSrcFactor; - ColorDstFactor = colorDstFactor; - AlphaOp = alphaOp; - AlphaSrcFactor = alphaSrcFactor; - AlphaDstFactor = alphaDstFactor; - } - } -} diff --git a/Ryujinx.Graphics.GAL/Blend/BlendFactor.cs b/Ryujinx.Graphics.GAL/Blend/BlendFactor.cs deleted file mode 100644 index f92e5b3a..00000000 --- a/Ryujinx.Graphics.GAL/Blend/BlendFactor.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Blend -{ - public enum BlendFactor - { - Zero = 1, - One, - SrcColor, - OneMinusSrcColor, - SrcAlpha, - OneMinusSrcAlpha, - DstAlpha, - OneMinusDstAlpha, - DstColor, - OneMinusDstColor, - SrcAlphaSaturate, - Src1Color = 0x10, - OneMinusSrc1Color, - Src1Alpha, - OneMinusSrc1Alpha, - ConstantColor = 0xc001, - OneMinusConstantColor, - ConstantAlpha, - OneMinusConstantAlpha, - - ZeroGl = 0x4000, - OneGl = 0x4001, - SrcColorGl = 0x4300, - OneMinusSrcColorGl = 0x4301, - SrcAlphaGl = 0x4302, - OneMinusSrcAlphaGl = 0x4303, - DstAlphaGl = 0x4304, - OneMinusDstAlphaGl = 0x4305, - DstColorGl = 0x4306, - OneMinusDstColorGl = 0x4307, - SrcAlphaSaturateGl = 0x4308, - Src1ColorGl = 0xc900, - OneMinusSrc1ColorGl = 0xc901, - Src1AlphaGl = 0xc902, - OneMinusSrc1AlphaGl = 0xc903 - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Blend/BlendOp.cs b/Ryujinx.Graphics.GAL/Blend/BlendOp.cs deleted file mode 100644 index 566dafd9..00000000 --- a/Ryujinx.Graphics.GAL/Blend/BlendOp.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Blend -{ - public enum BlendOp - { - Add = 1, - Subtract, - ReverseSubtract, - Minimum, - Maximum, - - AddGl = 0x8006, - SubtractGl = 0x8007, - ReverseSubtractGl = 0x8008, - MinimumGl = 0x800a, - MaximumGl = 0x800b - } -} diff --git a/Ryujinx.Graphics.GAL/BlendDescriptor.cs b/Ryujinx.Graphics.GAL/BlendDescriptor.cs new file mode 100644 index 00000000..b35a0169 --- /dev/null +++ b/Ryujinx.Graphics.GAL/BlendDescriptor.cs @@ -0,0 +1,32 @@ +namespace Ryujinx.Graphics.GAL +{ + public struct BlendDescriptor + { + public bool Enable { get; } + + public BlendOp ColorOp { get; } + public BlendFactor ColorSrcFactor { get; } + public BlendFactor ColorDstFactor { get; } + public BlendOp AlphaOp { get; } + public BlendFactor AlphaSrcFactor { get; } + public BlendFactor AlphaDstFactor { get; } + + public BlendDescriptor( + bool enable, + BlendOp colorOp, + BlendFactor colorSrcFactor, + BlendFactor colorDstFactor, + BlendOp alphaOp, + BlendFactor alphaSrcFactor, + BlendFactor alphaDstFactor) + { + Enable = enable; + ColorOp = colorOp; + ColorSrcFactor = colorSrcFactor; + ColorDstFactor = colorDstFactor; + AlphaOp = alphaOp; + AlphaSrcFactor = alphaSrcFactor; + AlphaDstFactor = alphaDstFactor; + } + } +} diff --git a/Ryujinx.Graphics.GAL/BlendFactor.cs b/Ryujinx.Graphics.GAL/BlendFactor.cs new file mode 100644 index 00000000..135873e9 --- /dev/null +++ b/Ryujinx.Graphics.GAL/BlendFactor.cs @@ -0,0 +1,41 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum BlendFactor + { + Zero = 1, + One, + SrcColor, + OneMinusSrcColor, + SrcAlpha, + OneMinusSrcAlpha, + DstAlpha, + OneMinusDstAlpha, + DstColor, + OneMinusDstColor, + SrcAlphaSaturate, + Src1Color = 0x10, + OneMinusSrc1Color, + Src1Alpha, + OneMinusSrc1Alpha, + ConstantColor = 0xc001, + OneMinusConstantColor, + ConstantAlpha, + OneMinusConstantAlpha, + + ZeroGl = 0x4000, + OneGl = 0x4001, + SrcColorGl = 0x4300, + OneMinusSrcColorGl = 0x4301, + SrcAlphaGl = 0x4302, + OneMinusSrcAlphaGl = 0x4303, + DstAlphaGl = 0x4304, + OneMinusDstAlphaGl = 0x4305, + DstColorGl = 0x4306, + OneMinusDstColorGl = 0x4307, + SrcAlphaSaturateGl = 0x4308, + Src1ColorGl = 0xc900, + OneMinusSrc1ColorGl = 0xc901, + Src1AlphaGl = 0xc902, + OneMinusSrc1AlphaGl = 0xc903 + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/BlendOp.cs b/Ryujinx.Graphics.GAL/BlendOp.cs new file mode 100644 index 00000000..de1ab67d --- /dev/null +++ b/Ryujinx.Graphics.GAL/BlendOp.cs @@ -0,0 +1,17 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum BlendOp + { + Add = 1, + Subtract, + ReverseSubtract, + Minimum, + Maximum, + + AddGl = 0x8006, + SubtractGl = 0x8007, + ReverseSubtractGl = 0x8008, + MinimumGl = 0x800a, + MaximumGl = 0x800b + } +} diff --git a/Ryujinx.Graphics.GAL/Color/ColorF.cs b/Ryujinx.Graphics.GAL/Color/ColorF.cs deleted file mode 100644 index bc4b32b8..00000000 --- a/Ryujinx.Graphics.GAL/Color/ColorF.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Color -{ - public struct ColorF - { - public float Red { get; } - public float Green { get; } - public float Blue { get; } - public float Alpha { get; } - - public ColorF(float red, float green, float blue, float alpha) - { - Red = red; - Green = green; - Blue = blue; - Alpha = alpha; - } - } -} diff --git a/Ryujinx.Graphics.GAL/Color/ColorSI.cs b/Ryujinx.Graphics.GAL/Color/ColorSI.cs deleted file mode 100644 index 9cde0406..00000000 --- a/Ryujinx.Graphics.GAL/Color/ColorSI.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Color -{ - public struct ColorSI - { - public int Red { get; } - public int Green { get; } - public int Blue { get; } - public int Alpha { get; } - - public ColorSI(int red, int green, int blue, int alpha) - { - Red = red; - Green = green; - Blue = blue; - Alpha = alpha; - } - } -} diff --git a/Ryujinx.Graphics.GAL/Color/ColorUI.cs b/Ryujinx.Graphics.GAL/Color/ColorUI.cs deleted file mode 100644 index 3bac84ef..00000000 --- a/Ryujinx.Graphics.GAL/Color/ColorUI.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Color -{ - public struct ColorUI - { - public uint Red { get; } - public uint Green { get; } - public uint Blue { get; } - public uint Alpha { get; } - - public ColorUI(uint red, uint green, uint blue, uint alpha) - { - Red = red; - Green = green; - Blue = blue; - Alpha = alpha; - } - } -} diff --git a/Ryujinx.Graphics.GAL/ColorF.cs b/Ryujinx.Graphics.GAL/ColorF.cs new file mode 100644 index 00000000..2e971a62 --- /dev/null +++ b/Ryujinx.Graphics.GAL/ColorF.cs @@ -0,0 +1,18 @@ +namespace Ryujinx.Graphics.GAL +{ + public struct ColorF + { + public float Red { get; } + public float Green { get; } + public float Blue { get; } + public float Alpha { get; } + + public ColorF(float red, float green, float blue, float alpha) + { + Red = red; + Green = green; + Blue = blue; + Alpha = alpha; + } + } +} diff --git a/Ryujinx.Graphics.GAL/CompareMode.cs b/Ryujinx.Graphics.GAL/CompareMode.cs new file mode 100644 index 00000000..7a64d9bb --- /dev/null +++ b/Ryujinx.Graphics.GAL/CompareMode.cs @@ -0,0 +1,8 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum CompareMode + { + None, + CompareRToTexture + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/DepthStencil/DepthStencilState.cs b/Ryujinx.Graphics.GAL/DepthStencil/DepthStencilState.cs deleted file mode 100644 index 93b8d50e..00000000 --- a/Ryujinx.Graphics.GAL/DepthStencil/DepthStencilState.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace Ryujinx.Graphics.GAL.DepthStencil -{ - public struct DepthStencilState - { - public bool DepthTestEnable { get; } - public bool DepthWriteEnable { get; } - public bool StencilTestEnable { get; } - - public CompareOp DepthFunc { get; } - public CompareOp StencilFrontFunc { get; } - public StencilOp StencilFrontSFail { get; } - public StencilOp StencilFrontDpPass { get; } - public StencilOp StencilFrontDpFail { get; } - public CompareOp StencilBackFunc { get; } - public StencilOp StencilBackSFail { get; } - public StencilOp StencilBackDpPass { get; } - public StencilOp StencilBackDpFail { get; } - - public DepthStencilState( - bool depthTestEnable, - bool depthWriteEnable, - bool stencilTestEnable, - CompareOp depthFunc, - CompareOp stencilFrontFunc, - StencilOp stencilFrontSFail, - StencilOp stencilFrontDpPass, - StencilOp stencilFrontDpFail, - CompareOp stencilBackFunc, - StencilOp stencilBackSFail, - StencilOp stencilBackDpPass, - StencilOp stencilBackDpFail) - { - DepthTestEnable = depthTestEnable; - DepthWriteEnable = depthWriteEnable; - StencilTestEnable = stencilTestEnable; - DepthFunc = depthFunc; - StencilFrontFunc = stencilFrontFunc; - StencilFrontSFail = stencilFrontSFail; - StencilFrontDpPass = stencilFrontDpPass; - StencilFrontDpFail = stencilFrontDpFail; - StencilBackFunc = stencilBackFunc; - StencilBackSFail = stencilBackSFail; - StencilBackDpPass = stencilBackDpPass; - StencilBackDpFail = stencilBackDpFail; - } - } -} diff --git a/Ryujinx.Graphics.GAL/DepthStencil/DepthTestDescriptor.cs b/Ryujinx.Graphics.GAL/DepthStencil/DepthTestDescriptor.cs deleted file mode 100644 index 98b1429b..00000000 --- a/Ryujinx.Graphics.GAL/DepthStencil/DepthTestDescriptor.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Ryujinx.Graphics.GAL.DepthStencil -{ - public struct DepthTestDescriptor - { - public bool TestEnable { get; } - public bool WriteEnable { get; } - - public CompareOp Func { get; } - - public DepthTestDescriptor( - bool testEnable, - bool writeEnable, - CompareOp func) - { - TestEnable = testEnable; - WriteEnable = writeEnable; - Func = func; - } - } -} diff --git a/Ryujinx.Graphics.GAL/DepthStencil/StencilOp.cs b/Ryujinx.Graphics.GAL/DepthStencil/StencilOp.cs deleted file mode 100644 index 3818c6a5..00000000 --- a/Ryujinx.Graphics.GAL/DepthStencil/StencilOp.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Ryujinx.Graphics.GAL.DepthStencil -{ - public enum StencilOp - { - Keep = 1, - Zero, - Replace, - IncrementAndClamp, - DecrementAndClamp, - Invert, - IncrementAndWrap, - DecrementAndWrap - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/DepthStencil/StencilTestDescriptor.cs b/Ryujinx.Graphics.GAL/DepthStencil/StencilTestDescriptor.cs deleted file mode 100644 index 2db53172..00000000 --- a/Ryujinx.Graphics.GAL/DepthStencil/StencilTestDescriptor.cs +++ /dev/null @@ -1,56 +0,0 @@ -namespace Ryujinx.Graphics.GAL.DepthStencil -{ - public struct StencilTestDescriptor - { - public bool TestEnable { get; } - - public CompareOp FrontFunc { get; } - public StencilOp FrontSFail { get; } - public StencilOp FrontDpPass { get; } - public StencilOp FrontDpFail { get; } - public int FrontFuncRef { get; } - public int FrontFuncMask { get; } - public int FrontMask { get; } - public CompareOp BackFunc { get; } - public StencilOp BackSFail { get; } - public StencilOp BackDpPass { get; } - public StencilOp BackDpFail { get; } - public int BackFuncRef { get; } - public int BackFuncMask { get; } - public int BackMask { get; } - - public StencilTestDescriptor( - bool testEnable, - CompareOp frontFunc, - StencilOp frontSFail, - StencilOp frontDpPass, - StencilOp frontDpFail, - int frontFuncRef, - int frontFuncMask, - int frontMask, - CompareOp backFunc, - StencilOp backSFail, - StencilOp backDpPass, - StencilOp backDpFail, - int backFuncRef, - int backFuncMask, - int backMask) - { - TestEnable = testEnable; - FrontFunc = frontFunc; - FrontSFail = frontSFail; - FrontDpPass = frontDpPass; - FrontDpFail = frontDpFail; - FrontFuncRef = frontFuncRef; - FrontFuncMask = frontFuncMask; - FrontMask = frontMask; - BackFunc = backFunc; - BackSFail = backSFail; - BackDpPass = backDpPass; - BackDpFail = backDpFail; - BackFuncRef = backFuncRef; - BackFuncMask = backFuncMask; - BackMask = backMask; - } - } -} diff --git a/Ryujinx.Graphics.GAL/DepthStencilMode.cs b/Ryujinx.Graphics.GAL/DepthStencilMode.cs new file mode 100644 index 00000000..e80d0d4b --- /dev/null +++ b/Ryujinx.Graphics.GAL/DepthStencilMode.cs @@ -0,0 +1,8 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum DepthStencilMode + { + Depth, + Stencil + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/DepthStencilState.cs b/Ryujinx.Graphics.GAL/DepthStencilState.cs new file mode 100644 index 00000000..d81e8436 --- /dev/null +++ b/Ryujinx.Graphics.GAL/DepthStencilState.cs @@ -0,0 +1,47 @@ +namespace Ryujinx.Graphics.GAL +{ + public struct DepthStencilState + { + public bool DepthTestEnable { get; } + public bool DepthWriteEnable { get; } + public bool StencilTestEnable { get; } + + public CompareOp DepthFunc { get; } + public CompareOp StencilFrontFunc { get; } + public StencilOp StencilFrontSFail { get; } + public StencilOp StencilFrontDpPass { get; } + public StencilOp StencilFrontDpFail { get; } + public CompareOp StencilBackFunc { get; } + public StencilOp StencilBackSFail { get; } + public StencilOp StencilBackDpPass { get; } + public StencilOp StencilBackDpFail { get; } + + public DepthStencilState( + bool depthTestEnable, + bool depthWriteEnable, + bool stencilTestEnable, + CompareOp depthFunc, + CompareOp stencilFrontFunc, + StencilOp stencilFrontSFail, + StencilOp stencilFrontDpPass, + StencilOp stencilFrontDpFail, + CompareOp stencilBackFunc, + StencilOp stencilBackSFail, + StencilOp stencilBackDpPass, + StencilOp stencilBackDpFail) + { + DepthTestEnable = depthTestEnable; + DepthWriteEnable = depthWriteEnable; + StencilTestEnable = stencilTestEnable; + DepthFunc = depthFunc; + StencilFrontFunc = stencilFrontFunc; + StencilFrontSFail = stencilFrontSFail; + StencilFrontDpPass = stencilFrontDpPass; + StencilFrontDpFail = stencilFrontDpFail; + StencilBackFunc = stencilBackFunc; + StencilBackSFail = stencilBackSFail; + StencilBackDpPass = stencilBackDpPass; + StencilBackDpFail = stencilBackDpFail; + } + } +} diff --git a/Ryujinx.Graphics.GAL/DepthTestDescriptor.cs b/Ryujinx.Graphics.GAL/DepthTestDescriptor.cs new file mode 100644 index 00000000..c835e941 --- /dev/null +++ b/Ryujinx.Graphics.GAL/DepthTestDescriptor.cs @@ -0,0 +1,20 @@ +namespace Ryujinx.Graphics.GAL +{ + public struct DepthTestDescriptor + { + public bool TestEnable { get; } + public bool WriteEnable { get; } + + public CompareOp Func { get; } + + public DepthTestDescriptor( + bool testEnable, + bool writeEnable, + CompareOp func) + { + TestEnable = testEnable; + WriteEnable = writeEnable; + Func = func; + } + } +} diff --git a/Ryujinx.Graphics.GAL/IPipeline.cs b/Ryujinx.Graphics.GAL/IPipeline.cs index 7211fbe0..1a502913 100644 --- a/Ryujinx.Graphics.GAL/IPipeline.cs +++ b/Ryujinx.Graphics.GAL/IPipeline.cs @@ -1,33 +1,10 @@ -using Ryujinx.Graphics.GAL.Blend; -using Ryujinx.Graphics.GAL.Color; -using Ryujinx.Graphics.GAL.DepthStencil; -using Ryujinx.Graphics.GAL.InputAssembler; using Ryujinx.Graphics.Shader; namespace Ryujinx.Graphics.GAL { public interface IPipeline { - void BindBlendState(int index, BlendDescriptor blend); - - void BindIndexBuffer(BufferRange buffer, IndexType type); - - void BindImage(int index, ShaderStage stage, ITexture texture); - - void BindProgram(IProgram program); - - void BindSampler(int index, ShaderStage stage, ISampler sampler); - void BindTexture(int index, ShaderStage stage, ITexture texture); - - void BindStorageBuffer(int index, ShaderStage stage, BufferRange buffer); - void BindUniformBuffer(int index, ShaderStage stage, BufferRange buffer); - - void BindVertexAttribs(VertexAttribDescriptor[] vertexAttribs); - void BindVertexBuffers(VertexBufferDescriptor[] vertexBuffers); - void ClearRenderTargetColor(int index, uint componentMask, ColorF color); - void ClearRenderTargetColor(int index, uint componentMask, ColorSI color); - void ClearRenderTargetColor(int index, uint componentMask, ColorUI color); void ClearRenderTargetDepthStencil( float depthValue, @@ -35,7 +12,7 @@ namespace Ryujinx.Graphics.GAL int stencilValue, int stencilMask); - void Dispatch(int groupsX, int groupsY, int groupsZ); + void DispatchCompute(int groupsX, int groupsY, int groupsZ); void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance); void DrawIndexed( @@ -45,6 +22,8 @@ namespace Ryujinx.Graphics.GAL int firstVertex, int firstInstance); + void SetBlendState(int index, BlendDescriptor blend); + void SetBlendColor(ColorF color); void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp); @@ -57,16 +36,33 @@ namespace Ryujinx.Graphics.GAL void SetFrontFace(FrontFace frontFace); + void SetIndexBuffer(BufferRange buffer, IndexType type); + + void SetImage(int index, ShaderStage stage, ITexture texture); + void SetPrimitiveRestart(bool enable, int index); void SetPrimitiveTopology(PrimitiveTopology topology); + void SetProgram(IProgram program); + void SetRenderTargetColorMasks(uint[] componentMask); void SetRenderTargets(ITexture[] colors, ITexture depthStencil); + void SetSampler(int index, ShaderStage stage, ISampler sampler); + void SetStencilTest(StencilTestDescriptor stencilTest); + void SetStorageBuffer(int index, ShaderStage stage, BufferRange buffer); + + void SetTexture(int index, ShaderStage stage, ITexture texture); + + void SetUniformBuffer(int index, ShaderStage stage, BufferRange buffer); + + void SetVertexAttribs(VertexAttribDescriptor[] vertexAttribs); + void SetVertexBuffers(VertexBufferDescriptor[] vertexBuffers); + void SetViewports(int first, Viewport[] viewports); void TextureBarrier(); diff --git a/Ryujinx.Graphics.GAL/IRenderer.cs b/Ryujinx.Graphics.GAL/IRenderer.cs index ebe6785c..4f9e5bc9 100644 --- a/Ryujinx.Graphics.GAL/IRenderer.cs +++ b/Ryujinx.Graphics.GAL/IRenderer.cs @@ -1,5 +1,3 @@ -using Ryujinx.Graphics.GAL.Sampler; -using Ryujinx.Graphics.GAL.Texture; using Ryujinx.Graphics.Shader; namespace Ryujinx.Graphics.GAL diff --git a/Ryujinx.Graphics.GAL/ITexture.cs b/Ryujinx.Graphics.GAL/ITexture.cs index 592c0482..7664f89c 100644 --- a/Ryujinx.Graphics.GAL/ITexture.cs +++ b/Ryujinx.Graphics.GAL/ITexture.cs @@ -1,4 +1,3 @@ -using Ryujinx.Graphics.GAL.Texture; using System; namespace Ryujinx.Graphics.GAL diff --git a/Ryujinx.Graphics.GAL/InputAssembler/VertexAttribDescriptor.cs b/Ryujinx.Graphics.GAL/InputAssembler/VertexAttribDescriptor.cs deleted file mode 100644 index cba3a9a4..00000000 --- a/Ryujinx.Graphics.GAL/InputAssembler/VertexAttribDescriptor.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Ryujinx.Graphics.GAL.InputAssembler -{ - public struct VertexAttribDescriptor - { - public int BufferIndex { get; } - public int Offset { get; } - - public Format Format { get; } - - public VertexAttribDescriptor(int bufferIndex, int offset, Format format) - { - BufferIndex = bufferIndex; - Offset = offset; - Format = format; - } - } -} diff --git a/Ryujinx.Graphics.GAL/InputAssembler/VertexBufferDescriptor.cs b/Ryujinx.Graphics.GAL/InputAssembler/VertexBufferDescriptor.cs deleted file mode 100644 index eb428f8e..00000000 --- a/Ryujinx.Graphics.GAL/InputAssembler/VertexBufferDescriptor.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Ryujinx.Graphics.GAL.InputAssembler -{ - public struct VertexBufferDescriptor - { - public BufferRange Buffer { get; } - - public int Stride { get; } - public int Divisor { get; } - - public VertexBufferDescriptor(BufferRange buffer, int stride, int divisor) - { - Buffer = buffer; - Stride = stride; - Divisor = divisor; - } - } -} diff --git a/Ryujinx.Graphics.GAL/MagFilter.cs b/Ryujinx.Graphics.GAL/MagFilter.cs new file mode 100644 index 00000000..f20d095e --- /dev/null +++ b/Ryujinx.Graphics.GAL/MagFilter.cs @@ -0,0 +1,8 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum MagFilter + { + Nearest = 1, + Linear + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/MinFilter.cs b/Ryujinx.Graphics.GAL/MinFilter.cs new file mode 100644 index 00000000..b7a0740b --- /dev/null +++ b/Ryujinx.Graphics.GAL/MinFilter.cs @@ -0,0 +1,12 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum MinFilter + { + Nearest = 1, + Linear, + NearestMipmapNearest, + LinearMipmapNearest, + NearestMipmapLinear, + LinearMipmapLinear + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Sampler/AddressMode.cs b/Ryujinx.Graphics.GAL/Sampler/AddressMode.cs deleted file mode 100644 index 4f56d892..00000000 --- a/Ryujinx.Graphics.GAL/Sampler/AddressMode.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Sampler -{ - public enum AddressMode - { - Repeat, - MirroredRepeat, - ClampToEdge, - ClampToBorder, - Clamp, - MirrorClampToEdge, - MirrorClampToBorder, - MirrorClamp - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Sampler/CompareMode.cs b/Ryujinx.Graphics.GAL/Sampler/CompareMode.cs deleted file mode 100644 index ca4b09a0..00000000 --- a/Ryujinx.Graphics.GAL/Sampler/CompareMode.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Sampler -{ - public enum CompareMode - { - None, - CompareRToTexture - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Sampler/MagFilter.cs b/Ryujinx.Graphics.GAL/Sampler/MagFilter.cs deleted file mode 100644 index 3c9c9de6..00000000 --- a/Ryujinx.Graphics.GAL/Sampler/MagFilter.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Sampler -{ - public enum MagFilter - { - Nearest = 1, - Linear - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Sampler/MinFilter.cs b/Ryujinx.Graphics.GAL/Sampler/MinFilter.cs deleted file mode 100644 index d012f695..00000000 --- a/Ryujinx.Graphics.GAL/Sampler/MinFilter.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Sampler -{ - public enum MinFilter - { - Nearest = 1, - Linear, - NearestMipmapNearest, - LinearMipmapNearest, - NearestMipmapLinear, - LinearMipmapLinear - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Sampler/SamplerCreateInfo.cs b/Ryujinx.Graphics.GAL/Sampler/SamplerCreateInfo.cs deleted file mode 100644 index 3f42742b..00000000 --- a/Ryujinx.Graphics.GAL/Sampler/SamplerCreateInfo.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Ryujinx.Graphics.GAL.Color; - -namespace Ryujinx.Graphics.GAL.Sampler -{ - public struct SamplerCreateInfo - { - public MinFilter MinFilter { get; } - public MagFilter MagFilter { get; } - - public AddressMode AddressU { get; } - public AddressMode AddressV { get; } - public AddressMode AddressP { get; } - - public CompareMode CompareMode { get; } - public CompareOp CompareOp { get; } - - public ColorF BorderColor { get; } - - public float MinLod { get; } - public float MaxLod { get; } - public float MipLodBias { get; } - public float MaxAnisotropy { get; } - - public SamplerCreateInfo( - MinFilter minFilter, - MagFilter magFilter, - AddressMode addressU, - AddressMode addressV, - AddressMode addressP, - CompareMode compareMode, - CompareOp compareOp, - ColorF borderColor, - float minLod, - float maxLod, - float mipLodBias, - float maxAnisotropy) - { - MinFilter = minFilter; - MagFilter = magFilter; - AddressU = addressU; - AddressV = addressV; - AddressP = addressP; - CompareMode = compareMode; - CompareOp = compareOp; - BorderColor = borderColor; - MinLod = minLod; - MaxLod = maxLod; - MipLodBias = mipLodBias; - MaxAnisotropy = maxAnisotropy; - } - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/SamplerCreateInfo.cs b/Ryujinx.Graphics.GAL/SamplerCreateInfo.cs new file mode 100644 index 00000000..33d80af5 --- /dev/null +++ b/Ryujinx.Graphics.GAL/SamplerCreateInfo.cs @@ -0,0 +1,50 @@ +namespace Ryujinx.Graphics.GAL +{ + public struct SamplerCreateInfo + { + public MinFilter MinFilter { get; } + public MagFilter MagFilter { get; } + + public AddressMode AddressU { get; } + public AddressMode AddressV { get; } + public AddressMode AddressP { get; } + + public CompareMode CompareMode { get; } + public CompareOp CompareOp { get; } + + public ColorF BorderColor { get; } + + public float MinLod { get; } + public float MaxLod { get; } + public float MipLodBias { get; } + public float MaxAnisotropy { get; } + + public SamplerCreateInfo( + MinFilter minFilter, + MagFilter magFilter, + AddressMode addressU, + AddressMode addressV, + AddressMode addressP, + CompareMode compareMode, + CompareOp compareOp, + ColorF borderColor, + float minLod, + float maxLod, + float mipLodBias, + float maxAnisotropy) + { + MinFilter = minFilter; + MagFilter = magFilter; + AddressU = addressU; + AddressV = addressV; + AddressP = addressP; + CompareMode = compareMode; + CompareOp = compareOp; + BorderColor = borderColor; + MinLod = minLod; + MaxLod = maxLod; + MipLodBias = mipLodBias; + MaxAnisotropy = maxAnisotropy; + } + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/StencilOp.cs b/Ryujinx.Graphics.GAL/StencilOp.cs new file mode 100644 index 00000000..f0ac829e --- /dev/null +++ b/Ryujinx.Graphics.GAL/StencilOp.cs @@ -0,0 +1,14 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum StencilOp + { + Keep = 1, + Zero, + Replace, + IncrementAndClamp, + DecrementAndClamp, + Invert, + IncrementAndWrap, + DecrementAndWrap + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/StencilTestDescriptor.cs b/Ryujinx.Graphics.GAL/StencilTestDescriptor.cs new file mode 100644 index 00000000..8c9d1644 --- /dev/null +++ b/Ryujinx.Graphics.GAL/StencilTestDescriptor.cs @@ -0,0 +1,56 @@ +namespace Ryujinx.Graphics.GAL +{ + public struct StencilTestDescriptor + { + public bool TestEnable { get; } + + public CompareOp FrontFunc { get; } + public StencilOp FrontSFail { get; } + public StencilOp FrontDpPass { get; } + public StencilOp FrontDpFail { get; } + public int FrontFuncRef { get; } + public int FrontFuncMask { get; } + public int FrontMask { get; } + public CompareOp BackFunc { get; } + public StencilOp BackSFail { get; } + public StencilOp BackDpPass { get; } + public StencilOp BackDpFail { get; } + public int BackFuncRef { get; } + public int BackFuncMask { get; } + public int BackMask { get; } + + public StencilTestDescriptor( + bool testEnable, + CompareOp frontFunc, + StencilOp frontSFail, + StencilOp frontDpPass, + StencilOp frontDpFail, + int frontFuncRef, + int frontFuncMask, + int frontMask, + CompareOp backFunc, + StencilOp backSFail, + StencilOp backDpPass, + StencilOp backDpFail, + int backFuncRef, + int backFuncMask, + int backMask) + { + TestEnable = testEnable; + FrontFunc = frontFunc; + FrontSFail = frontSFail; + FrontDpPass = frontDpPass; + FrontDpFail = frontDpFail; + FrontFuncRef = frontFuncRef; + FrontFuncMask = frontFuncMask; + FrontMask = frontMask; + BackFunc = backFunc; + BackSFail = backSFail; + BackDpPass = backDpPass; + BackDpFail = backDpFail; + BackFuncRef = backFuncRef; + BackFuncMask = backFuncMask; + BackMask = backMask; + } + } +} diff --git a/Ryujinx.Graphics.GAL/SwizzleComponent.cs b/Ryujinx.Graphics.GAL/SwizzleComponent.cs new file mode 100644 index 00000000..a405bd13 --- /dev/null +++ b/Ryujinx.Graphics.GAL/SwizzleComponent.cs @@ -0,0 +1,12 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum SwizzleComponent + { + Zero, + One, + Red, + Green, + Blue, + Alpha + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Target.cs b/Ryujinx.Graphics.GAL/Target.cs new file mode 100644 index 00000000..73f77f43 --- /dev/null +++ b/Ryujinx.Graphics.GAL/Target.cs @@ -0,0 +1,17 @@ +namespace Ryujinx.Graphics.GAL +{ + public enum Target + { + Texture1D, + Texture2D, + Texture3D, + Texture1DArray, + Texture2DArray, + Texture2DMultisample, + Texture2DMultisampleArray, + Rectangle, + Cubemap, + CubemapArray, + TextureBuffer + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Texture/DepthStencilMode.cs b/Ryujinx.Graphics.GAL/Texture/DepthStencilMode.cs deleted file mode 100644 index d7a379d8..00000000 --- a/Ryujinx.Graphics.GAL/Texture/DepthStencilMode.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Texture -{ - public enum DepthStencilMode - { - Depth, - Stencil - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Texture/SwizzleComponent.cs b/Ryujinx.Graphics.GAL/Texture/SwizzleComponent.cs deleted file mode 100644 index fd7d50e3..00000000 --- a/Ryujinx.Graphics.GAL/Texture/SwizzleComponent.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Texture -{ - public enum SwizzleComponent - { - Zero, - One, - Red, - Green, - Blue, - Alpha - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Texture/Target.cs b/Ryujinx.Graphics.GAL/Texture/Target.cs deleted file mode 100644 index b9cc1105..00000000 --- a/Ryujinx.Graphics.GAL/Texture/Target.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Ryujinx.Graphics.GAL.Texture -{ - public enum Target - { - Texture1D, - Texture2D, - Texture3D, - Texture1DArray, - Texture2DArray, - Texture2DMultisample, - Texture2DMultisampleArray, - Rectangle, - Cubemap, - CubemapArray, - TextureBuffer - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.GAL/Texture/TextureCreateInfo.cs b/Ryujinx.Graphics.GAL/Texture/TextureCreateInfo.cs deleted file mode 100644 index c6a73d91..00000000 --- a/Ryujinx.Graphics.GAL/Texture/TextureCreateInfo.cs +++ /dev/null @@ -1,120 +0,0 @@ -using Ryujinx.Common; -using System; - -namespace Ryujinx.Graphics.GAL.Texture -{ - public struct TextureCreateInfo - { - public int Width { get; } - public int Height { get; } - public int Depth { get; } - public int Levels { get; } - public int Samples { get; } - public int BlockWidth { get; } - public int BlockHeight { get; } - public int BytesPerPixel { get; } - - public bool IsCompressed => (BlockWidth | BlockHeight) != 1; - - public Format Format { get; } - - public DepthStencilMode DepthStencilMode { get; } - - public Target Target { get; } - - public SwizzleComponent SwizzleR { get; } - public SwizzleComponent SwizzleG { get; } - public SwizzleComponent SwizzleB { get; } - public SwizzleComponent SwizzleA { get; } - - public TextureCreateInfo( - int width, - int height, - int depth, - int levels, - int samples, - int blockWidth, - int blockHeight, - int bytesPerPixel, - Format format, - DepthStencilMode depthStencilMode, - Target target, - SwizzleComponent swizzleR, - SwizzleComponent swizzleG, - SwizzleComponent swizzleB, - SwizzleComponent swizzleA) - { - Width = width; - Height = height; - Depth = depth; - Levels = levels; - Samples = samples; - BlockWidth = blockWidth; - BlockHeight = blockHeight; - BytesPerPixel = bytesPerPixel; - Format = format; - DepthStencilMode = depthStencilMode; - Target = target; - SwizzleR = swizzleR; - SwizzleG = swizzleG; - SwizzleB = swizzleB; - SwizzleA = swizzleA; - } - - public int GetMipSize(int level) - { - return GetMipStride(level) * GetLevelHeight(level) * GetLevelDepth(level); - } - - public int GetMipSize2D(int level) - { - return GetMipStride(level) * GetLevelHeight(level); - } - - public int GetMipStride(int level) - { - return BitUtils.AlignUp(GetLevelWidth(level) * BytesPerPixel, 4); - } - - private int GetLevelWidth(int level) - { - return BitUtils.DivRoundUp(GetLevelSize(Width, level), BlockWidth); - } - - private int GetLevelHeight(int level) - { - return BitUtils.DivRoundUp(GetLevelSize(Height, level), BlockHeight); - } - - private int GetLevelDepth(int level) - { - return Target == Target.Texture3D ? GetLevelSize(Depth, level) : GetLayers(); - } - - public int GetDepthOrLayers() - { - return Target == Target.Texture3D ? Depth : GetLayers(); - } - - public int GetLayers() - { - if (Target == Target.Texture2DArray || - Target == Target.Texture2DMultisampleArray || - Target == Target.CubemapArray) - { - return Depth; - } - else if (Target == Target.Cubemap) - { - return 6; - } - - return 1; - } - - private static int GetLevelSize(int size, int level) - { - return Math.Max(1, size >> level); - } - } -} diff --git a/Ryujinx.Graphics.GAL/TextureCreateInfo.cs b/Ryujinx.Graphics.GAL/TextureCreateInfo.cs new file mode 100644 index 00000000..8e8c5ff7 --- /dev/null +++ b/Ryujinx.Graphics.GAL/TextureCreateInfo.cs @@ -0,0 +1,120 @@ +using Ryujinx.Common; +using System; + +namespace Ryujinx.Graphics.GAL +{ + public struct TextureCreateInfo + { + public int Width { get; } + public int Height { get; } + public int Depth { get; } + public int Levels { get; } + public int Samples { get; } + public int BlockWidth { get; } + public int BlockHeight { get; } + public int BytesPerPixel { get; } + + public bool IsCompressed => (BlockWidth | BlockHeight) != 1; + + public Format Format { get; } + + public DepthStencilMode DepthStencilMode { get; } + + public Target Target { get; } + + public SwizzleComponent SwizzleR { get; } + public SwizzleComponent SwizzleG { get; } + public SwizzleComponent SwizzleB { get; } + public SwizzleComponent SwizzleA { get; } + + public TextureCreateInfo( + int width, + int height, + int depth, + int levels, + int samples, + int blockWidth, + int blockHeight, + int bytesPerPixel, + Format format, + DepthStencilMode depthStencilMode, + Target target, + SwizzleComponent swizzleR, + SwizzleComponent swizzleG, + SwizzleComponent swizzleB, + SwizzleComponent swizzleA) + { + Width = width; + Height = height; + Depth = depth; + Levels = levels; + Samples = samples; + BlockWidth = blockWidth; + BlockHeight = blockHeight; + BytesPerPixel = bytesPerPixel; + Format = format; + DepthStencilMode = depthStencilMode; + Target = target; + SwizzleR = swizzleR; + SwizzleG = swizzleG; + SwizzleB = swizzleB; + SwizzleA = swizzleA; + } + + public int GetMipSize(int level) + { + return GetMipStride(level) * GetLevelHeight(level) * GetLevelDepth(level); + } + + public int GetMipSize2D(int level) + { + return GetMipStride(level) * GetLevelHeight(level); + } + + public int GetMipStride(int level) + { + return BitUtils.AlignUp(GetLevelWidth(level) * BytesPerPixel, 4); + } + + private int GetLevelWidth(int level) + { + return BitUtils.DivRoundUp(GetLevelSize(Width, level), BlockWidth); + } + + private int GetLevelHeight(int level) + { + return BitUtils.DivRoundUp(GetLevelSize(Height, level), BlockHeight); + } + + private int GetLevelDepth(int level) + { + return Target == Target.Texture3D ? GetLevelSize(Depth, level) : GetLayers(); + } + + public int GetDepthOrLayers() + { + return Target == Target.Texture3D ? Depth : GetLayers(); + } + + public int GetLayers() + { + if (Target == Target.Texture2DArray || + Target == Target.Texture2DMultisampleArray || + Target == Target.CubemapArray) + { + return Depth; + } + else if (Target == Target.Cubemap) + { + return 6; + } + + return 1; + } + + private static int GetLevelSize(int size, int level) + { + return Math.Max(1, size >> level); + } + } +} diff --git a/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs b/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs new file mode 100644 index 00000000..18774aae --- /dev/null +++ b/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs @@ -0,0 +1,17 @@ +namespace Ryujinx.Graphics.GAL +{ + public struct VertexAttribDescriptor + { + public int BufferIndex { get; } + public int Offset { get; } + + public Format Format { get; } + + public VertexAttribDescriptor(int bufferIndex, int offset, Format format) + { + BufferIndex = bufferIndex; + Offset = offset; + Format = format; + } + } +} diff --git a/Ryujinx.Graphics.GAL/VertexBufferDescriptor.cs b/Ryujinx.Graphics.GAL/VertexBufferDescriptor.cs new file mode 100644 index 00000000..bcd3b28f --- /dev/null +++ b/Ryujinx.Graphics.GAL/VertexBufferDescriptor.cs @@ -0,0 +1,17 @@ +namespace Ryujinx.Graphics.GAL +{ + public struct VertexBufferDescriptor + { + public BufferRange Buffer { get; } + + public int Stride { get; } + public int Divisor { get; } + + public VertexBufferDescriptor(BufferRange buffer, int stride, int divisor) + { + Buffer = buffer; + Stride = stride; + Divisor = divisor; + } + } +} diff --git a/Ryujinx.Graphics.Gpu/Debugging.cs b/Ryujinx.Graphics.Gpu/Debugging.cs deleted file mode 100644 index cb99cee1..00000000 --- a/Ryujinx.Graphics.Gpu/Debugging.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace Ryujinx.Graphics.Gpu -{ - static class Debugging - { - public static void PrintTexInfo(string prefix, Image.Texture tex) - { - if (tex == null) - { - Console.WriteLine(prefix + " null"); - - return; - } - - string range = $"{tex.Address:X}..{(tex.Address + tex.Size):X}"; - - int debugId = tex.HostTexture.GetStorageDebugId(); - - string str = $"{prefix} p {debugId:X8} {tex.Info.Target} {tex.Info.FormatInfo.Format} {tex.Info.Width}x{tex.Info.Height}x{tex.Info.DepthOrLayers} mips {tex.Info.Levels} addr {range}"; - - Console.WriteLine(str); - } - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.Gpu/Engine/Compute.cs b/Ryujinx.Graphics.Gpu/Engine/Compute.cs index d0df85a0..f3f8d3ca 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Compute.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Compute.cs @@ -1,4 +1,4 @@ -using Ryujinx.Graphics.GAL.Texture; +using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Gpu.Image; using Ryujinx.Graphics.Gpu.Shader; using Ryujinx.Graphics.Gpu.State; @@ -30,17 +30,17 @@ namespace Ryujinx.Graphics.Gpu.Engine dispatchParams.UnpackBlockSizeY(), dispatchParams.UnpackBlockSizeZ()); - _context.Renderer.Pipeline.BindProgram(cs.HostProgram); + _context.Renderer.Pipeline.SetProgram(cs.HostProgram); var samplerPool = state.Get(MethodOffset.SamplerPoolState); - _textureManager.SetComputeSamplerPool(samplerPool.Address.Pack(), samplerPool.MaximumId, dispatchParams.SamplerIndex); + TextureManager.SetComputeSamplerPool(samplerPool.Address.Pack(), samplerPool.MaximumId, dispatchParams.SamplerIndex); var texturePool = state.Get(MethodOffset.TexturePoolState); - _textureManager.SetComputeTexturePool(texturePool.Address.Pack(), texturePool.MaximumId); + TextureManager.SetComputeTexturePool(texturePool.Address.Pack(), texturePool.MaximumId); - _textureManager.SetComputeTextureBufferIndex(state.Get(MethodOffset.TextureBufferIndex)); + TextureManager.SetComputeTextureBufferIndex(state.Get(MethodOffset.TextureBufferIndex)); ShaderProgramInfo info = cs.Shader.Program.Info; @@ -57,7 +57,7 @@ namespace Ryujinx.Graphics.Gpu.Engine ulong gpuVa = dispatchParams.UniformBuffers[index].PackAddress(); ulong size = dispatchParams.UniformBuffers[index].UnpackSize(); - _bufferManager.SetComputeUniformBuffer(index, gpuVa, size); + BufferManager.SetComputeUniformBuffer(index, gpuVa, size); } for (int index = 0; index < info.SBuffers.Count; index++) @@ -66,7 +66,7 @@ namespace Ryujinx.Graphics.Gpu.Engine sbEnableMask |= 1u << sb.Slot; - ulong sbDescAddress = _bufferManager.GetComputeUniformBufferAddress(0); + ulong sbDescAddress = BufferManager.GetComputeUniformBufferAddress(0); int sbDescOffset = 0x310 + sb.Slot * 0x10; @@ -76,7 +76,7 @@ namespace Ryujinx.Graphics.Gpu.Engine SbDescriptor sbDescriptor = MemoryMarshal.Cast(sbDescriptorData)[0]; - _bufferManager.SetComputeStorageBuffer(sb.Slot, sbDescriptor.PackAddress(), (uint)sbDescriptor.Size); + BufferManager.SetComputeStorageBuffer(sb.Slot, sbDescriptor.PackAddress(), (uint)sbDescriptor.Size); } ubEnableMask = 0; @@ -86,8 +86,8 @@ namespace Ryujinx.Graphics.Gpu.Engine ubEnableMask |= 1u << info.CBuffers[index].Slot; } - _bufferManager.SetComputeStorageBufferEnableMask(sbEnableMask); - _bufferManager.SetComputeUniformBufferEnableMask(ubEnableMask); + BufferManager.SetComputeStorageBufferEnableMask(sbEnableMask); + BufferManager.SetComputeUniformBufferEnableMask(ubEnableMask); var textureBindings = new TextureBindingInfo[info.Textures.Count]; @@ -107,7 +107,7 @@ namespace Ryujinx.Graphics.Gpu.Engine } } - _textureManager.SetComputeTextures(textureBindings); + TextureManager.SetComputeTextures(textureBindings); var imageBindings = new TextureBindingInfo[info.Images.Count]; @@ -120,12 +120,12 @@ namespace Ryujinx.Graphics.Gpu.Engine imageBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex); } - _textureManager.SetComputeImages(imageBindings); + TextureManager.SetComputeImages(imageBindings); - _bufferManager.CommitComputeBindings(); - _textureManager.CommitComputeBindings(); + BufferManager.CommitComputeBindings(); + TextureManager.CommitComputeBindings(); - _context.Renderer.Pipeline.Dispatch( + _context.Renderer.Pipeline.DispatchCompute( dispatchParams.UnpackGridSizeX(), dispatchParams.UnpackGridSizeY(), dispatchParams.UnpackGridSizeZ()); diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs b/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs index 43f8b25d..906ae225 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs @@ -1,4 +1,4 @@ -using Ryujinx.Graphics.GAL.Color; +using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Gpu.State; namespace Ryujinx.Graphics.Gpu.Engine @@ -9,7 +9,7 @@ namespace Ryujinx.Graphics.Gpu.Engine { UpdateRenderTargetState(state, useControl: false); - _textureManager.CommitGraphicsBindings(); + TextureManager.CommitGraphicsBindings(); bool clearDepth = (argument & 1) != 0; bool clearStencil = (argument & 2) != 0; diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs b/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs index 0bf836e1..1f84916a 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodCopyBuffer.cs @@ -68,7 +68,7 @@ namespace Ryujinx.Graphics.Gpu.Engine else { // Buffer to buffer copy. - _bufferManager.CopyBuffer(cbp.SrcAddress, cbp.DstAddress, (uint)size); + BufferManager.CopyBuffer(cbp.SrcAddress, cbp.DstAddress, (uint)size); } } } diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs b/Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs index 1b47eac2..cdfd36df 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodCopyTexture.cs @@ -3,6 +3,8 @@ using Ryujinx.Graphics.Gpu.State; namespace Ryujinx.Graphics.Gpu.Engine { + using Texture = Image.Texture; + partial class Methods { private void CopyTexture(GpuState state, int argument) @@ -10,7 +12,7 @@ namespace Ryujinx.Graphics.Gpu.Engine var dstCopyTexture = state.Get(MethodOffset.CopyDstTexture); var srcCopyTexture = state.Get(MethodOffset.CopySrcTexture); - Image.Texture srcTexture = _textureManager.FindOrCreateTexture(srcCopyTexture); + Texture srcTexture = TextureManager.FindOrCreateTexture(srcCopyTexture); if (srcTexture == null) { @@ -25,7 +27,7 @@ namespace Ryujinx.Graphics.Gpu.Engine dstCopyTexture.Format = RtFormat.D32Float; } - Image.Texture dstTexture = _textureManager.FindOrCreateTexture(dstCopyTexture); + Texture dstTexture = TextureManager.FindOrCreateTexture(dstCopyTexture); if (dstTexture == null) { @@ -76,7 +78,7 @@ namespace Ryujinx.Graphics.Gpu.Engine { srcCopyTexture.Height++; - srcTexture = _textureManager.FindOrCreateTexture(srcCopyTexture); + srcTexture = TextureManager.FindOrCreateTexture(srcCopyTexture); srcRegion = new Extents2D( srcRegion.X1 - srcTexture.Info.Width, diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodUniformBufferBind.cs b/Ryujinx.Graphics.Gpu/Engine/MethodUniformBufferBind.cs index 87d9612b..6232c0b6 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodUniformBufferBind.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodUniformBufferBind.cs @@ -41,11 +41,11 @@ namespace Ryujinx.Graphics.Gpu.Engine ulong address = uniformBuffer.Address.Pack(); - _bufferManager.SetGraphicsUniformBuffer((int)type, index, address, (uint)uniformBuffer.Size); + BufferManager.SetGraphicsUniformBuffer((int)type, index, address, (uint)uniformBuffer.Size); } else { - _bufferManager.SetGraphicsUniformBuffer((int)type, index, 0, 0); + BufferManager.SetGraphicsUniformBuffer((int)type, index, 0, 0); } } } diff --git a/Ryujinx.Graphics.Gpu/Engine/Methods.cs b/Ryujinx.Graphics.Gpu/Engine/Methods.cs index 0c103e0d..95a25f5c 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Methods.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Methods.cs @@ -1,8 +1,5 @@ +using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Blend; -using Ryujinx.Graphics.GAL.DepthStencil; -using Ryujinx.Graphics.GAL.InputAssembler; -using Ryujinx.Graphics.GAL.Texture; using Ryujinx.Graphics.Gpu.Image; using Ryujinx.Graphics.Gpu.Memory; using Ryujinx.Graphics.Gpu.Shader; @@ -13,19 +10,18 @@ using System.Runtime.InteropServices; namespace Ryujinx.Graphics.Gpu.Engine { + using Texture = Image.Texture; + partial class Methods { - private GpuContext _context; - - private ShaderCache _shaderCache; + private readonly GpuContext _context; - private ShaderProgramInfo[] _currentProgramInfo; + private readonly ShaderCache _shaderCache; - private BufferManager _bufferManager; - private TextureManager _textureManager; + private readonly ShaderProgramInfo[] _currentProgramInfo; - public BufferManager BufferManager => _bufferManager; - public TextureManager TextureManager => _textureManager; + public BufferManager BufferManager { get; } + public TextureManager TextureManager { get; } private bool _isAnyVbInstanced; private bool _vsUsesInstanceId; @@ -38,8 +34,8 @@ namespace Ryujinx.Graphics.Gpu.Engine _currentProgramInfo = new ShaderProgramInfo[Constants.TotalShaderStages]; - _bufferManager = new BufferManager(context); - _textureManager = new TextureManager(context); + BufferManager = new BufferManager(context); + TextureManager = new TextureManager(context); } public void RegisterCallbacks(GpuState state) @@ -183,8 +179,8 @@ namespace Ryujinx.Graphics.Gpu.Engine { UpdateStorageBuffers(); - _bufferManager.CommitBindings(); - _textureManager.CommitGraphicsBindings(); + BufferManager.CommitBindings(); + TextureManager.CommitGraphicsBindings(); } private void UpdateStorageBuffers() @@ -202,7 +198,7 @@ namespace Ryujinx.Graphics.Gpu.Engine { BufferDescriptor sb = info.SBuffers[index]; - ulong sbDescAddress = _bufferManager.GetGraphicsUniformBufferAddress(stage, 0); + ulong sbDescAddress = BufferManager.GetGraphicsUniformBufferAddress(stage, 0); int sbDescOffset = 0x110 + stage * 0x100 + sb.Slot * 0x10; @@ -212,7 +208,7 @@ namespace Ryujinx.Graphics.Gpu.Engine SbDescriptor sbDescriptor = MemoryMarshal.Cast(sbDescriptorData)[0]; - _bufferManager.SetGraphicsStorageBuffer(stage, sb.Slot, sbDescriptor.PackAddress(), (uint)sbDescriptor.Size); + BufferManager.SetGraphicsStorageBuffer(stage, sb.Slot, sbDescriptor.PackAddress(), (uint)sbDescriptor.Size); } } } @@ -236,17 +232,14 @@ namespace Ryujinx.Graphics.Gpu.Engine if (index >= count || !IsRtEnabled(colorState)) { - _textureManager.SetRenderTargetColor(index, null); + TextureManager.SetRenderTargetColor(index, null); continue; } - Image.Texture color = _textureManager.FindOrCreateTexture( - colorState, - samplesInX, - samplesInY); + Texture color = TextureManager.FindOrCreateTexture(colorState, samplesInX, samplesInY); - _textureManager.SetRenderTargetColor(index, color); + TextureManager.SetRenderTargetColor(index, color); if (color != null) { @@ -256,21 +249,17 @@ namespace Ryujinx.Graphics.Gpu.Engine bool dsEnable = state.Get(MethodOffset.RtDepthStencilEnable); - Image.Texture depthStencil = null; + Texture depthStencil = null; if (dsEnable) { var dsState = state.Get(MethodOffset.RtDepthStencilState); var dsSize = state.Get (MethodOffset.RtDepthStencilSize); - depthStencil = _textureManager.FindOrCreateTexture( - dsState, - dsSize, - samplesInX, - samplesInY); + depthStencil = TextureManager.FindOrCreateTexture(dsState, dsSize, samplesInX, samplesInY); } - _textureManager.SetRenderTargetDepthStencil(depthStencil); + TextureManager.SetRenderTargetDepthStencil(depthStencil); if (depthStencil != null) { @@ -335,8 +324,8 @@ namespace Ryujinx.Graphics.Gpu.Engine // the maximum supported viewport dimensions. // This must be compensated on the shader, by dividing the vertex position // by the maximum viewport dimensions. - float maxSize = (float)_context.Capabilities.MaximumViewportDimensions; - float halfMaxSize = (float)_context.Capabilities.MaximumViewportDimensions * 0.5f; + float maxSize = _context.Capabilities.MaximumViewportDimensions; + float halfMaxSize = _context.Capabilities.MaximumViewportDimensions * 0.5f; region = new RectangleF(-halfMaxSize, -halfMaxSize, maxSize, maxSize * yFlip); } @@ -362,7 +351,7 @@ namespace Ryujinx.Graphics.Gpu.Engine float units = state.Get(MethodOffset.DepthBiasUnits); float clamp = state.Get(MethodOffset.DepthBiasClamp); - PolygonModeMask enables = 0; + PolygonModeMask enables; enables = (depthBias.PointEnable ? PolygonModeMask.Point : 0); enables |= (depthBias.LineEnable ? PolygonModeMask.Line : 0); @@ -435,16 +424,16 @@ namespace Ryujinx.Graphics.Gpu.Engine ? texturePool.MaximumId : samplerPool.MaximumId; - _textureManager.SetGraphicsSamplerPool(samplerPool.Address.Pack(), maximumId, samplerIndex); + TextureManager.SetGraphicsSamplerPool(samplerPool.Address.Pack(), maximumId, samplerIndex); } private void UpdateTexturePoolState(GpuState state) { var texturePool = state.Get(MethodOffset.TexturePoolState); - _textureManager.SetGraphicsTexturePool(texturePool.Address.Pack(), texturePool.MaximumId); + TextureManager.SetGraphicsTexturePool(texturePool.Address.Pack(), texturePool.MaximumId); - _textureManager.SetGraphicsTextureBufferIndex(state.Get(MethodOffset.TextureBufferIndex)); + TextureManager.SetGraphicsTextureBufferIndex(state.Get(MethodOffset.TextureBufferIndex)); } private void UpdateVertexAttribState(GpuState state) @@ -457,7 +446,7 @@ namespace Ryujinx.Graphics.Gpu.Engine if (!FormatTable.TryGetAttribFormat(vertexAttrib.UnpackFormat(), out Format format)) { - // TODO: warning. + Logger.PrintError(LogClass.Gpu, $"Invalid attribute format 0x{vertexAttrib.UnpackFormat():X}."); format = Format.R32G32B32A32Float; } @@ -468,7 +457,7 @@ namespace Ryujinx.Graphics.Gpu.Engine format); } - _context.Renderer.Pipeline.BindVertexAttribs(vertexAttribs); + _context.Renderer.Pipeline.SetVertexAttribs(vertexAttribs); } private void UpdatePrimitiveRestartState(GpuState state) @@ -504,7 +493,7 @@ namespace Ryujinx.Graphics.Gpu.Engine case IndexType.UInt: size *= 4; break; } - _bufferManager.SetIndexBuffer(gpuVa, size, indexBuffer.Type); + BufferManager.SetIndexBuffer(gpuVa, size, indexBuffer.Type); // The index buffer affects the vertex buffer size calculation, we // need to ensure that they are updated. @@ -521,7 +510,7 @@ namespace Ryujinx.Graphics.Gpu.Engine if (!vertexBuffer.UnpackEnable()) { - _bufferManager.SetVertexBuffer(index, 0, 0, 0, 0); + BufferManager.SetVertexBuffer(index, 0, 0, 0, 0); continue; } @@ -557,7 +546,7 @@ namespace Ryujinx.Graphics.Gpu.Engine size = (ulong)((firstInstance + drawState.First + drawState.Count) * stride); } - _bufferManager.SetVertexBuffer(index, address, size, stride, divisor); + BufferManager.SetVertexBuffer(index, address, size, stride, divisor); } } @@ -580,7 +569,7 @@ namespace Ryujinx.Graphics.Gpu.Engine { var colorMask = state.Get(MethodOffset.RtColorMask, rtColorMaskShared ? 0 : index); - uint componentMask = 0; + uint componentMask; componentMask = (colorMask.UnpackRed() ? 1u : 0u); componentMask |= (colorMask.UnpackGreen() ? 2u : 0u); @@ -597,8 +586,6 @@ namespace Ryujinx.Graphics.Gpu.Engine { bool blendIndependent = state.Get(MethodOffset.BlendIndependent); - BlendState[] blends = new BlendState[8]; - for (int index = 0; index < 8; index++) { BlendDescriptor descriptor; @@ -632,7 +619,7 @@ namespace Ryujinx.Graphics.Gpu.Engine blend.AlphaDstFactor); } - _context.Renderer.Pipeline.BindBlendState(index, descriptor); + _context.Renderer.Pipeline.SetBlendState(index, descriptor); } } @@ -704,7 +691,7 @@ namespace Ryujinx.Graphics.Gpu.Engine } } - _textureManager.SetGraphicsTextures(stage, textureBindings); + TextureManager.SetGraphicsTextures(stage, textureBindings); var imageBindings = new TextureBindingInfo[info.Images.Count]; @@ -717,7 +704,7 @@ namespace Ryujinx.Graphics.Gpu.Engine imageBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex); } - _textureManager.SetGraphicsImages(stage, imageBindings); + TextureManager.SetGraphicsImages(stage, imageBindings); uint sbEnableMask = 0; uint ubEnableMask = 0; @@ -732,11 +719,11 @@ namespace Ryujinx.Graphics.Gpu.Engine ubEnableMask |= 1u << info.CBuffers[index].Slot; } - _bufferManager.SetGraphicsStorageBufferEnableMask(stage, sbEnableMask); - _bufferManager.SetGraphicsUniformBufferEnableMask(stage, ubEnableMask); + BufferManager.SetGraphicsStorageBufferEnableMask(stage, sbEnableMask); + BufferManager.SetGraphicsUniformBufferEnableMask(stage, ubEnableMask); } - _context.Renderer.Pipeline.BindProgram(gs.HostProgram); + _context.Renderer.Pipeline.SetProgram(gs.HostProgram); } public bool GetViewportTransformEnable(GpuState state) @@ -796,7 +783,7 @@ namespace Ryujinx.Graphics.Gpu.Engine private void InvalidateTextures(GpuState state, int argument) { - _textureManager.Flush(); + TextureManager.Flush(); } private void TextureBarrierTiled(GpuState state, int argument) diff --git a/Ryujinx.Graphics.Gpu/Image/Sampler.cs b/Ryujinx.Graphics.Gpu/Image/Sampler.cs index 06fedd8a..80790bd5 100644 --- a/Ryujinx.Graphics.Gpu/Image/Sampler.cs +++ b/Ryujinx.Graphics.Gpu/Image/Sampler.cs @@ -1,6 +1,4 @@ using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Color; -using Ryujinx.Graphics.GAL.Sampler; using System; namespace Ryujinx.Graphics.Gpu.Image diff --git a/Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs b/Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs index c94473a2..00b4ecb4 100644 --- a/Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs +++ b/Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs @@ -1,5 +1,4 @@ using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Sampler; namespace Ryujinx.Graphics.Gpu.Image { diff --git a/Ryujinx.Graphics.Gpu/Image/Texture.cs b/Ryujinx.Graphics.Gpu/Image/Texture.cs index 04657f39..544c49af 100644 --- a/Ryujinx.Graphics.Gpu/Image/Texture.cs +++ b/Ryujinx.Graphics.Gpu/Image/Texture.cs @@ -1,7 +1,6 @@ using Ryujinx.Common; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Texture; using Ryujinx.Graphics.Gpu.Memory; using Ryujinx.Graphics.Texture; using Ryujinx.Graphics.Texture.Astc; @@ -15,18 +14,16 @@ namespace Ryujinx.Graphics.Gpu.Image { private GpuContext _context; - private TextureInfo _info; - private SizeInfo _sizeInfo; - public Format Format => _info.FormatInfo.Format; + public Format Format => Info.FormatInfo.Format; - public TextureInfo Info => _info; + public TextureInfo Info { get; private set; } private int _depth; private int _layers; - private int _firstLayer; - private int _firstLevel; + private readonly int _firstLayer; + private readonly int _firstLevel; private bool _hasData; @@ -43,8 +40,8 @@ namespace Ryujinx.Graphics.Gpu.Image public bool Modified { get; set; } - public ulong Address => _info.Address; - public ulong EndAddress => _info.Address + Size; + public ulong Address => Info.Address; + public ulong EndAddress => Info.Address + Size; public ulong Size => (ulong)_sizeInfo.TotalSize; @@ -127,13 +124,13 @@ namespace Ryujinx.Graphics.Gpu.Image width <<= _firstLevel; height <<= _firstLevel; - if (_info.Target == Target.Texture3D) + if (Info.Target == Target.Texture3D) { depthOrLayers <<= _firstLevel; } else { - depthOrLayers = _viewStorage._info.DepthOrLayers; + depthOrLayers = _viewStorage.Info.DepthOrLayers; } _viewStorage.RecreateStorageOrView(width, height, depthOrLayers); @@ -145,13 +142,13 @@ namespace Ryujinx.Graphics.Gpu.Image int viewDepthOrLayers; - if (view._info.Target == Target.Texture3D) + if (view.Info.Target == Target.Texture3D) { viewDepthOrLayers = Math.Max(1, depthOrLayers >> view._firstLevel); } else { - viewDepthOrLayers = view._info.DepthOrLayers; + viewDepthOrLayers = view.Info.DepthOrLayers; } view.RecreateStorageOrView(viewWidth, viewHeight, viewDepthOrLayers); @@ -161,27 +158,27 @@ namespace Ryujinx.Graphics.Gpu.Image private void RecreateStorageOrView(int width, int height, int depthOrLayers) { SetInfo(new TextureInfo( - _info.Address, + Info.Address, width, height, depthOrLayers, - _info.Levels, - _info.SamplesInX, - _info.SamplesInY, - _info.Stride, - _info.IsLinear, - _info.GobBlocksInY, - _info.GobBlocksInZ, - _info.GobBlocksInTileX, - _info.Target, - _info.FormatInfo, - _info.DepthStencilMode, - _info.SwizzleR, - _info.SwizzleG, - _info.SwizzleB, - _info.SwizzleA)); - - TextureCreateInfo createInfo = TextureManager.GetCreateInfo(_info, _context.Capabilities); + Info.Levels, + Info.SamplesInX, + Info.SamplesInY, + Info.Stride, + Info.IsLinear, + Info.GobBlocksInY, + Info.GobBlocksInZ, + Info.GobBlocksInTileX, + Info.Target, + Info.FormatInfo, + Info.DepthStencilMode, + Info.SwizzleR, + Info.SwizzleG, + Info.SwizzleB, + Info.SwizzleA)); + + TextureCreateInfo createInfo = TextureManager.GetCreateInfo(Info, _context.Capabilities); if (_viewStorage != this) { @@ -215,50 +212,50 @@ namespace Ryujinx.Graphics.Gpu.Image Span data = _context.PhysicalMemory.Read(Address, Size); - if (_info.IsLinear) + if (Info.IsLinear) { data = LayoutConverter.ConvertLinearStridedToLinear( - _info.Width, - _info.Height, - _info.FormatInfo.BlockWidth, - _info.FormatInfo.BlockHeight, - _info.Stride, - _info.FormatInfo.BytesPerPixel, + Info.Width, + Info.Height, + Info.FormatInfo.BlockWidth, + Info.FormatInfo.BlockHeight, + Info.Stride, + Info.FormatInfo.BytesPerPixel, data); } else { data = LayoutConverter.ConvertBlockLinearToLinear( - _info.Width, - _info.Height, + Info.Width, + Info.Height, _depth, - _info.Levels, + Info.Levels, _layers, - _info.FormatInfo.BlockWidth, - _info.FormatInfo.BlockHeight, - _info.FormatInfo.BytesPerPixel, - _info.GobBlocksInY, - _info.GobBlocksInZ, - _info.GobBlocksInTileX, + Info.FormatInfo.BlockWidth, + Info.FormatInfo.BlockHeight, + Info.FormatInfo.BytesPerPixel, + Info.GobBlocksInY, + Info.GobBlocksInZ, + Info.GobBlocksInTileX, _sizeInfo, data); } - if (!_context.Capabilities.SupportsAstcCompression && _info.FormatInfo.Format.IsAstc()) + if (!_context.Capabilities.SupportsAstcCompression && Info.FormatInfo.Format.IsAstc()) { if (!AstcDecoder.TryDecodeToRgba8( data.ToArray(), - _info.FormatInfo.BlockWidth, - _info.FormatInfo.BlockHeight, - _info.Width, - _info.Height, + Info.FormatInfo.BlockWidth, + Info.FormatInfo.BlockHeight, + Info.Width, + Info.Height, _depth, - _info.Levels, + Info.Levels, out Span decoded)) { - string texInfo = $"{_info.Target} {_info.FormatInfo.Format} {_info.Width}x{_info.Height}x{_info.DepthOrLayers} levels {_info.Levels}"; + string texInfo = $"{Info.Target} {Info.FormatInfo.Format} {Info.Width}x{Info.Height}x{Info.DepthOrLayers} levels {Info.Levels}"; - Logger.PrintError(LogClass.Gpu, $"Invalid ASTC texture at 0x{_info.Address:X} ({texInfo})."); + Logger.PrintError(LogClass.Gpu, $"Invalid ASTC texture at 0x{Info.Address:X} ({texInfo})."); } data = decoded; @@ -273,31 +270,31 @@ namespace Ryujinx.Graphics.Gpu.Image { Span data = HostTexture.GetData(); - if (_info.IsLinear) + if (Info.IsLinear) { data = LayoutConverter.ConvertLinearToLinearStrided( - _info.Width, - _info.Height, - _info.FormatInfo.BlockWidth, - _info.FormatInfo.BlockHeight, - _info.Stride, - _info.FormatInfo.BytesPerPixel, + Info.Width, + Info.Height, + Info.FormatInfo.BlockWidth, + Info.FormatInfo.BlockHeight, + Info.Stride, + Info.FormatInfo.BytesPerPixel, data); } else { data = LayoutConverter.ConvertLinearToBlockLinear( - _info.Width, - _info.Height, + Info.Width, + Info.Height, _depth, - _info.Levels, + Info.Levels, _layers, - _info.FormatInfo.BlockWidth, - _info.FormatInfo.BlockHeight, - _info.FormatInfo.BytesPerPixel, - _info.GobBlocksInY, - _info.GobBlocksInZ, - _info.GobBlocksInTileX, + Info.FormatInfo.BlockWidth, + Info.FormatInfo.BlockHeight, + Info.FormatInfo.BytesPerPixel, + Info.GobBlocksInY, + Info.GobBlocksInZ, + Info.GobBlocksInTileX, _sizeInfo, data); } @@ -332,8 +329,7 @@ namespace Ryujinx.Graphics.Gpu.Image if ((flags & TextureSearchFlags.IgnoreMs) != 0) { - bool msTargetCompatible = _info.Target == Target.Texture2DMultisample && - info.Target == Target.Texture2D; + bool msTargetCompatible = Info.Target == Target.Texture2DMultisample && info.Target == Target.Texture2D; if (!msTargetCompatible && !TargetAndSamplesCompatible(info)) { @@ -345,25 +341,24 @@ namespace Ryujinx.Graphics.Gpu.Image return false; } - return _info.Address == info.Address && _info.Levels == info.Levels; + return Info.Address == info.Address && Info.Levels == info.Levels; } private bool FormatMatches(TextureInfo info, bool strict) { // D32F and R32F texture have the same representation internally, // however the R32F format is used to sample from depth textures. - if (_info.FormatInfo.Format == Format.D32Float && - info.FormatInfo.Format == Format.R32Float && !strict) + if (Info.FormatInfo.Format == Format.D32Float && info.FormatInfo.Format == Format.R32Float && !strict) { return true; } - return _info.FormatInfo.Format == info.FormatInfo.Format; + return Info.FormatInfo.Format == info.FormatInfo.Format; } private bool LayoutMatches(TextureInfo info) { - if (_info.IsLinear != info.IsLinear) + if (Info.IsLinear != info.IsLinear) { return false; } @@ -372,12 +367,12 @@ namespace Ryujinx.Graphics.Gpu.Image // For block linear textures, the stride is ignored. if (info.IsLinear) { - return _info.Stride == info.Stride; + return Info.Stride == info.Stride; } else { - return _info.GobBlocksInY == info.GobBlocksInY && - _info.GobBlocksInZ == info.GobBlocksInZ; + return Info.GobBlocksInY == info.GobBlocksInY && + Info.GobBlocksInZ == info.GobBlocksInZ; } } @@ -388,21 +383,21 @@ namespace Ryujinx.Graphics.Gpu.Image public bool SizeMatches(TextureInfo info, int level) { - return Math.Max(1, _info.Width >> level) == info.Width && - Math.Max(1, _info.Height >> level) == info.Height && - Math.Max(1, _info.GetDepth() >> level) == info.GetDepth(); + return Math.Max(1, Info.Width >> level) == info.Width && + Math.Max(1, Info.Height >> level) == info.Height && + Math.Max(1, Info.GetDepth() >> level) == info.GetDepth(); } private bool SizeMatches(TextureInfo info, bool alignSizes) { - if (_info.GetLayers() != info.GetLayers()) + if (Info.GetLayers() != info.GetLayers()) { return false; } if (alignSizes) { - Size size0 = GetAlignedSize(_info); + Size size0 = GetAlignedSize(Info); Size size1 = GetAlignedSize(info); return size0.Width == size1.Width && @@ -411,26 +406,26 @@ namespace Ryujinx.Graphics.Gpu.Image } else { - return _info.Width == info.Width && - _info.Height == info.Height && - _info.GetDepth() == info.GetDepth(); + return Info.Width == info.Width && + Info.Height == info.Height && + Info.GetDepth() == info.GetDepth(); } } private bool SamplerParamsMatches(TextureInfo info) { - return _info.DepthStencilMode == info.DepthStencilMode && - _info.SwizzleR == info.SwizzleR && - _info.SwizzleG == info.SwizzleG && - _info.SwizzleB == info.SwizzleB && - _info.SwizzleA == info.SwizzleA; + return Info.DepthStencilMode == info.DepthStencilMode && + Info.SwizzleR == info.SwizzleR && + Info.SwizzleG == info.SwizzleG && + Info.SwizzleB == info.SwizzleB && + Info.SwizzleA == info.SwizzleA; } private bool TargetAndSamplesCompatible(TextureInfo info) { - return _info.Target == info.Target && - _info.SamplesInX == info.SamplesInX && - _info.SamplesInY == info.SamplesInY; + return Info.Target == info.Target && + Info.SamplesInX == info.SamplesInX && + Info.SamplesInY == info.SamplesInY; } public bool IsViewCompatible( @@ -485,13 +480,13 @@ namespace Ryujinx.Graphics.Gpu.Image return false; } - return _info.SamplesInX == info.SamplesInX && - _info.SamplesInY == info.SamplesInY; + return Info.SamplesInX == info.SamplesInX && + Info.SamplesInY == info.SamplesInY; } private bool ViewLayoutCompatible(TextureInfo info, int level) { - if (_info.IsLinear != info.IsLinear) + if (Info.IsLinear != info.IsLinear) { return false; } @@ -500,9 +495,9 @@ namespace Ryujinx.Graphics.Gpu.Image // For block linear textures, the stride is ignored. if (info.IsLinear) { - int width = Math.Max(1, _info.Width >> level); + int width = Math.Max(1, Info.Width >> level); - int stride = width * _info.FormatInfo.BytesPerPixel; + int stride = width * Info.FormatInfo.BytesPerPixel; stride = BitUtils.AlignUp(stride, 32); @@ -510,15 +505,15 @@ namespace Ryujinx.Graphics.Gpu.Image } else { - int height = Math.Max(1, _info.Height >> level); - int depth = Math.Max(1, _info.GetDepth() >> level); + int height = Math.Max(1, Info.Height >> level); + int depth = Math.Max(1, Info.GetDepth() >> level); (int gobBlocksInY, int gobBlocksInZ) = SizeCalculator.GetMipGobBlockSizes( height, depth, - _info.FormatInfo.BlockHeight, - _info.GobBlocksInY, - _info.GobBlocksInZ); + Info.FormatInfo.BlockHeight, + Info.GobBlocksInY, + Info.GobBlocksInZ); return gobBlocksInY == info.GobBlocksInY && gobBlocksInZ == info.GobBlocksInZ; @@ -527,12 +522,12 @@ namespace Ryujinx.Graphics.Gpu.Image private bool ViewFormatCompatible(TextureInfo info) { - return TextureCompatibility.FormatCompatible(_info.FormatInfo, info.FormatInfo); + return TextureCompatibility.FormatCompatible(Info.FormatInfo, info.FormatInfo); } private bool ViewSizeMatches(TextureInfo info, int level, bool isCopy) { - Size size = GetAlignedSize(_info, level); + Size size = GetAlignedSize(Info, level); Size otherSize = GetAlignedSize(info); @@ -549,7 +544,7 @@ namespace Ryujinx.Graphics.Gpu.Image private bool ViewTargetCompatible(TextureInfo info, bool isCopy) { - switch (_info.Target) + switch (Info.Target) { case Target.Texture1D: case Target.Texture1DArray: @@ -621,7 +616,7 @@ namespace Ryujinx.Graphics.Gpu.Image public ITexture GetTargetTexture(Target target) { - if (target == _info.Target) + if (target == Info.Target) { return HostTexture; } @@ -629,21 +624,21 @@ namespace Ryujinx.Graphics.Gpu.Image if (_arrayViewTexture == null && IsSameDimensionsTarget(target)) { TextureCreateInfo createInfo = new TextureCreateInfo( - _info.Width, - _info.Height, + Info.Width, + Info.Height, target == Target.CubemapArray ? 6 : 1, - _info.Levels, - _info.Samples, - _info.FormatInfo.BlockWidth, - _info.FormatInfo.BlockHeight, - _info.FormatInfo.BytesPerPixel, - _info.FormatInfo.Format, - _info.DepthStencilMode, + Info.Levels, + Info.Samples, + Info.FormatInfo.BlockWidth, + Info.FormatInfo.BlockHeight, + Info.FormatInfo.BytesPerPixel, + Info.FormatInfo.Format, + Info.DepthStencilMode, target, - _info.SwizzleR, - _info.SwizzleG, - _info.SwizzleB, - _info.SwizzleA); + Info.SwizzleR, + Info.SwizzleG, + Info.SwizzleB, + Info.SwizzleA); ITexture viewTexture = HostTexture.CreateView(createInfo, 0, 0); @@ -662,7 +657,7 @@ namespace Ryujinx.Graphics.Gpu.Image private bool IsSameDimensionsTarget(Target target) { - switch (_info.Target) + switch (Info.Target) { case Target.Texture1D: case Target.Texture1DArray: @@ -702,7 +697,7 @@ namespace Ryujinx.Graphics.Gpu.Image private void SetInfo(TextureInfo info) { - _info = info; + Info = info; _depth = info.GetDepth(); _layers = info.GetLayers(); diff --git a/Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs b/Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs index 042635ee..cf922ac5 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs @@ -1,4 +1,4 @@ -using Ryujinx.Graphics.GAL.Texture; +using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.Gpu.Image { diff --git a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs index 0c09661f..0ea7aec2 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs @@ -178,7 +178,7 @@ namespace Ryujinx.Graphics.Gpu.Image { _textureState[stageIndex][index].Texture = hostTexture; - _context.Renderer.Pipeline.BindTexture(index, stage, hostTexture); + _context.Renderer.Pipeline.SetTexture(index, stage, hostTexture); } Sampler sampler = _samplerPool.Get(samplerId); @@ -189,7 +189,7 @@ namespace Ryujinx.Graphics.Gpu.Image { _textureState[stageIndex][index].Sampler = hostSampler; - _context.Renderer.Pipeline.BindSampler(index, stage, hostSampler); + _context.Renderer.Pipeline.SetSampler(index, stage, hostSampler); } } } @@ -217,7 +217,7 @@ namespace Ryujinx.Graphics.Gpu.Image { _imageState[stageIndex][index].Texture = hostTexture; - _context.Renderer.Pipeline.BindImage(index, stage, hostTexture); + _context.Renderer.Pipeline.SetImage(index, stage, hostTexture); } } } diff --git a/Ryujinx.Graphics.Gpu/Image/TextureComponent.cs b/Ryujinx.Graphics.Gpu/Image/TextureComponent.cs index 37b3f65e..db9b9dae 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureComponent.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureComponent.cs @@ -1,4 +1,4 @@ -using Ryujinx.Graphics.GAL.Texture; +using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.Gpu.Image { diff --git a/Ryujinx.Graphics.Gpu/Image/TextureInfo.cs b/Ryujinx.Graphics.Gpu/Image/TextureInfo.cs index 639abdd8..19110dcf 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureInfo.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureInfo.cs @@ -1,4 +1,4 @@ -using Ryujinx.Graphics.GAL.Texture; +using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.Gpu.Image { diff --git a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs index 73067249..6e1b8c60 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs @@ -1,6 +1,5 @@ using Ryujinx.Common; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Texture; using Ryujinx.Graphics.Gpu.Image; using Ryujinx.Graphics.Gpu.Memory; using Ryujinx.Graphics.Gpu.State; diff --git a/Ryujinx.Graphics.Gpu/Image/TexturePool.cs b/Ryujinx.Graphics.Gpu/Image/TexturePool.cs index 47fa01b6..f6fa5069 100644 --- a/Ryujinx.Graphics.Gpu/Image/TexturePool.cs +++ b/Ryujinx.Graphics.Gpu/Image/TexturePool.cs @@ -1,5 +1,5 @@ +using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Texture; using Ryujinx.Graphics.Gpu.Memory; using System; using System.Collections.Generic; @@ -128,7 +128,7 @@ namespace Ryujinx.Graphics.Gpu.Image if (!FormatTable.TryGetTextureFormat(format, srgb, out FormatInfo formatInfo)) { - // TODO: Warning. + Logger.PrintError(LogClass.Gpu, $"Invalid texture format 0x{format:X} (sRGB: {srgb})."); formatInfo = FormatInfo.Default; } diff --git a/Ryujinx.Graphics.Gpu/Image/TextureTarget.cs b/Ryujinx.Graphics.Gpu/Image/TextureTarget.cs index d42d1e77..96a814c6 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureTarget.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureTarget.cs @@ -1,4 +1,4 @@ -using Ryujinx.Graphics.GAL.Texture; +using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.Gpu.Image { diff --git a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs index 83ca5db5..d02146b4 100644 --- a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs @@ -1,6 +1,5 @@ using Ryujinx.Common; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.InputAssembler; using Ryujinx.Graphics.Gpu.State; using Ryujinx.Graphics.Shader; using System; @@ -305,7 +304,7 @@ namespace Ryujinx.Graphics.Gpu.Memory BufferRange buffer = GetBufferRange(bounds.Address, bounds.Size); - _context.Renderer.Pipeline.BindStorageBuffer(index, ShaderStage.Compute, buffer); + _context.Renderer.Pipeline.SetStorageBuffer(index, ShaderStage.Compute, buffer); } enableMask = _cpUniformBuffers.EnableMask; @@ -326,7 +325,7 @@ namespace Ryujinx.Graphics.Gpu.Memory BufferRange buffer = GetBufferRange(bounds.Address, bounds.Size); - _context.Renderer.Pipeline.BindUniformBuffer(index, ShaderStage.Compute, buffer); + _context.Renderer.Pipeline.SetUniformBuffer(index, ShaderStage.Compute, buffer); } // Force rebind after doing compute work. @@ -343,7 +342,7 @@ namespace Ryujinx.Graphics.Gpu.Memory { BufferRange buffer = GetBufferRange(_indexBuffer.Address, _indexBuffer.Size); - _context.Renderer.Pipeline.BindIndexBuffer(buffer, _indexBuffer.Type); + _context.Renderer.Pipeline.SetIndexBuffer(buffer, _indexBuffer.Type); } } else if (_indexBuffer.Address != 0) @@ -373,7 +372,7 @@ namespace Ryujinx.Graphics.Gpu.Memory vertexBuffers[index] = new VertexBufferDescriptor(buffer, vb.Stride, vb.Divisor); } - _context.Renderer.Pipeline.BindVertexBuffers(vertexBuffers); + _context.Renderer.Pipeline.SetVertexBuffers(vertexBuffers); } else { @@ -468,11 +467,11 @@ namespace Ryujinx.Graphics.Gpu.Memory if (isStorage) { - _context.Renderer.Pipeline.BindStorageBuffer(index, stage, buffer); + _context.Renderer.Pipeline.SetStorageBuffer(index, stage, buffer); } else { - _context.Renderer.Pipeline.BindUniformBuffer(index, stage, buffer); + _context.Renderer.Pipeline.SetUniformBuffer(index, stage, buffer); } } diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index 422cc597..bd3229bd 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -9,6 +9,8 @@ using System.Runtime.InteropServices; namespace Ryujinx.Graphics.Gpu.Shader { + using TextureDescriptor = Image.TextureDescriptor; + class ShaderCache { private const int MaxProgramSize = 0x100000; @@ -374,7 +376,7 @@ namespace Ryujinx.Graphics.Gpu.Shader return !descriptor.UnpackTextureCoordNormalized() && is2DTexture; } - private Image.TextureDescriptor GetTextureDescriptor(GpuState state, int stageIndex, int index) + private TextureDescriptor GetTextureDescriptor(GpuState state, int stageIndex, int index) { return _context.Methods.TextureManager.GetGraphicsTextureDescriptor(state, stageIndex, index); } diff --git a/Ryujinx.Graphics.Gpu/State/BlendState.cs b/Ryujinx.Graphics.Gpu/State/BlendState.cs index 7029ed6c..a98f2b03 100644 --- a/Ryujinx.Graphics.Gpu/State/BlendState.cs +++ b/Ryujinx.Graphics.Gpu/State/BlendState.cs @@ -1,4 +1,4 @@ -using Ryujinx.Graphics.GAL.Blend; +using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.Gpu.State { diff --git a/Ryujinx.Graphics.Gpu/State/BlendStateCommon.cs b/Ryujinx.Graphics.Gpu/State/BlendStateCommon.cs index 96465a25..16584531 100644 --- a/Ryujinx.Graphics.Gpu/State/BlendStateCommon.cs +++ b/Ryujinx.Graphics.Gpu/State/BlendStateCommon.cs @@ -1,4 +1,4 @@ -using Ryujinx.Graphics.GAL.Blend; +using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.Gpu.State { diff --git a/Ryujinx.Graphics.Gpu/State/StencilBackTestState.cs b/Ryujinx.Graphics.Gpu/State/StencilBackTestState.cs index f9f47b40..842ffa0e 100644 --- a/Ryujinx.Graphics.Gpu/State/StencilBackTestState.cs +++ b/Ryujinx.Graphics.Gpu/State/StencilBackTestState.cs @@ -1,5 +1,4 @@ using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.DepthStencil; namespace Ryujinx.Graphics.Gpu.State { diff --git a/Ryujinx.Graphics.Gpu/State/StencilTestState.cs b/Ryujinx.Graphics.Gpu/State/StencilTestState.cs index 1169a358..f76f77a7 100644 --- a/Ryujinx.Graphics.Gpu/State/StencilTestState.cs +++ b/Ryujinx.Graphics.Gpu/State/StencilTestState.cs @@ -1,5 +1,4 @@ using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.DepthStencil; namespace Ryujinx.Graphics.Gpu.State { diff --git a/Ryujinx.Graphics.Gpu/Window.cs b/Ryujinx.Graphics.Gpu/Window.cs index a3dc3b26..d5494aa4 100644 --- a/Ryujinx.Graphics.Gpu/Window.cs +++ b/Ryujinx.Graphics.Gpu/Window.cs @@ -1,14 +1,15 @@ using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Texture; using Ryujinx.Graphics.Gpu.Image; using System; using System.Collections.Concurrent; namespace Ryujinx.Graphics.Gpu { + using Texture = Image.Texture; + public class Window { - private GpuContext _context; + private readonly GpuContext _context; private struct PresentationTexture { @@ -30,7 +31,7 @@ namespace Ryujinx.Graphics.Gpu } } - private ConcurrentQueue _frameQueue; + private readonly ConcurrentQueue _frameQueue; public Window(GpuContext context) { @@ -79,7 +80,7 @@ namespace Ryujinx.Graphics.Gpu if (_frameQueue.TryDequeue(out PresentationTexture pt)) { - Image.Texture texture = _context.Methods.TextureManager.FindOrCreateTexture(pt.Info); + Texture texture = _context.Methods.TextureManager.FindOrCreateTexture(pt.Info); texture.SynchronizeMemory(); diff --git a/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/Ryujinx.Graphics.OpenGL/EnumConversion.cs index 99ed0404..fdd1f972 100644 --- a/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -1,9 +1,6 @@ using OpenTK.Graphics.OpenGL; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Blend; -using Ryujinx.Graphics.GAL.Sampler; -using Ryujinx.Graphics.GAL.Texture; namespace Ryujinx.Graphics.OpenGL { @@ -334,31 +331,31 @@ namespace Ryujinx.Graphics.OpenGL return PrimitiveType.Points; } - public static StencilOp Convert(this GAL.DepthStencil.StencilOp op) + public static OpenTK.Graphics.OpenGL.StencilOp Convert(this GAL.StencilOp op) { switch (op) { - case GAL.DepthStencil.StencilOp.Keep: - return StencilOp.Keep; - case GAL.DepthStencil.StencilOp.Zero: - return StencilOp.Zero; - case GAL.DepthStencil.StencilOp.Replace: - return StencilOp.Replace; - case GAL.DepthStencil.StencilOp.IncrementAndClamp: - return StencilOp.Incr; - case GAL.DepthStencil.StencilOp.DecrementAndClamp: - return StencilOp.Decr; - case GAL.DepthStencil.StencilOp.Invert: - return StencilOp.Invert; - case GAL.DepthStencil.StencilOp.IncrementAndWrap: - return StencilOp.IncrWrap; - case GAL.DepthStencil.StencilOp.DecrementAndWrap: - return StencilOp.DecrWrap; + case GAL.StencilOp.Keep: + return OpenTK.Graphics.OpenGL.StencilOp.Keep; + case GAL.StencilOp.Zero: + return OpenTK.Graphics.OpenGL.StencilOp.Zero; + case GAL.StencilOp.Replace: + return OpenTK.Graphics.OpenGL.StencilOp.Replace; + case GAL.StencilOp.IncrementAndClamp: + return OpenTK.Graphics.OpenGL.StencilOp.Incr; + case GAL.StencilOp.DecrementAndClamp: + return OpenTK.Graphics.OpenGL.StencilOp.Decr; + case GAL.StencilOp.Invert: + return OpenTK.Graphics.OpenGL.StencilOp.Invert; + case GAL.StencilOp.IncrementAndWrap: + return OpenTK.Graphics.OpenGL.StencilOp.IncrWrap; + case GAL.StencilOp.DecrementAndWrap: + return OpenTK.Graphics.OpenGL.StencilOp.DecrWrap; } - Logger.PrintError(LogClass.Gpu, $"Invalid {nameof(GAL.DepthStencil.StencilOp)} enum value: {op}."); + Logger.PrintError(LogClass.Gpu, $"Invalid {nameof(GAL.StencilOp)} enum value: {op}."); - return StencilOp.Keep; + return OpenTK.Graphics.OpenGL.StencilOp.Keep; } public static All Convert(this SwizzleComponent swizzleComponent) diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs index 64705862..c7d96edd 100644 --- a/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -1,10 +1,6 @@ using OpenTK.Graphics.OpenGL; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Blend; -using Ryujinx.Graphics.GAL.Color; -using Ryujinx.Graphics.GAL.DepthStencil; -using Ryujinx.Graphics.GAL.InputAssembler; using Ryujinx.Graphics.Shader; using System; @@ -41,166 +37,6 @@ namespace Ryujinx.Graphics.OpenGL _clipDepthMode = ClipDepthMode.NegativeOneToOne; } - public void BindBlendState(int index, BlendDescriptor blend) - { - if (!blend.Enable) - { - GL.Disable(IndexedEnableCap.Blend, index); - - return; - } - - GL.BlendEquationSeparate( - index, - blend.ColorOp.Convert(), - blend.AlphaOp.Convert()); - - GL.BlendFuncSeparate( - index, - (BlendingFactorSrc) blend.ColorSrcFactor.Convert(), - (BlendingFactorDest)blend.ColorDstFactor.Convert(), - (BlendingFactorSrc) blend.AlphaSrcFactor.Convert(), - (BlendingFactorDest)blend.AlphaDstFactor.Convert()); - - GL.Enable(IndexedEnableCap.Blend, index); - } - - public void BindImage(int index, ShaderStage stage, ITexture texture) - { - int unit = _program.GetImageUnit(stage, index); - - if (unit != -1 && texture != null) - { - TextureView view = (TextureView)texture; - - FormatInfo formatInfo = FormatTable.GetFormatInfo(view.Format); - - SizedInternalFormat format = (SizedInternalFormat)formatInfo.PixelInternalFormat; - - GL.BindImageTexture( - unit, - view.Handle, - 0, - true, - 0, - TextureAccess.ReadWrite, - format); - } - } - - public void BindIndexBuffer(BufferRange buffer, IndexType type) - { - _elementsType = type.Convert(); - - _indexBaseOffset = (IntPtr)buffer.Offset; - - EnsureVertexArray(); - - _vertexArray.SetIndexBuffer((Buffer)buffer.Buffer); - } - - public void BindProgram(IProgram program) - { - _program = (Program)program; - - _program.Bind(); - } - - public void BindSampler(int index, ShaderStage stage, ISampler sampler) - { - int unit = _program.GetTextureUnit(stage, index); - - if (unit != -1 && sampler != null) - { - ((Sampler)sampler).Bind(unit); - } - else if (unit == -1) - { - Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}."); - } - } - - public void BindTexture(int index, ShaderStage stage, ITexture texture) - { - int unit = _program.GetTextureUnit(stage, index); - - if (unit != -1 && texture != null) - { - if (unit == 0) - { - _unit0Texture = ((TextureView)texture); - } - else - { - ((TextureView)texture).Bind(unit); - } - } - else if (unit == -1) - { - Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}."); - } - } - - public void BindStorageBuffer(int index, ShaderStage stage, BufferRange buffer) - { - BindBuffer(index, stage, buffer, isStorage: true); - } - - public void BindUniformBuffer(int index, ShaderStage stage, BufferRange buffer) - { - BindBuffer(index, stage, buffer, isStorage: false); - } - - private void BindBuffer(int index, ShaderStage stage, BufferRange buffer, bool isStorage) - { - int bindingPoint = isStorage - ? _program.GetStorageBufferBindingPoint(stage, index) - : _program.GetUniformBufferBindingPoint(stage, index); - - if (bindingPoint == -1) - { - Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}."); - - return; - } - - BufferRangeTarget target = isStorage - ? BufferRangeTarget.ShaderStorageBuffer - : BufferRangeTarget.UniformBuffer; - - if (buffer.Buffer == null) - { - GL.BindBufferRange(target, bindingPoint, 0, IntPtr.Zero, 0); - - return; - } - - int bufferHandle = ((Buffer)buffer.Buffer).Handle; - - IntPtr bufferOffset = (IntPtr)buffer.Offset; - - GL.BindBufferRange( - target, - bindingPoint, - bufferHandle, - bufferOffset, - buffer.Size); - } - - public void BindVertexAttribs(VertexAttribDescriptor[] vertexAttribs) - { - EnsureVertexArray(); - - _vertexArray.SetVertexAttributes(vertexAttribs); - } - - public void BindVertexBuffers(VertexBufferDescriptor[] vertexBuffers) - { - EnsureVertexArray(); - - _vertexArray.SetVertexBuffers(vertexBuffers); - } - public void ClearRenderTargetColor(int index, uint componentMask, ColorF color) { GL.ColorMask( @@ -217,43 +53,7 @@ namespace Ryujinx.Graphics.OpenGL RestoreComponentMask(index); } - public void ClearRenderTargetColor(int index, uint componentMask, ColorSI color) - { - GL.ColorMask( - index, - (componentMask & 1u) != 0, - (componentMask & 2u) != 0, - (componentMask & 4u) != 0, - (componentMask & 8u) != 0); - - int[] colors = new int[] { color.Red, color.Green, color.Blue, color.Alpha }; - - GL.ClearBuffer(ClearBuffer.Color, index, colors); - - RestoreComponentMask(index); - } - - public void ClearRenderTargetColor(int index, uint componentMask, ColorUI color) - { - GL.ColorMask( - index, - (componentMask & 1u) != 0, - (componentMask & 2u) != 0, - (componentMask & 4u) != 0, - (componentMask & 8u) != 0); - - uint[] colors = new uint[] { color.Red, color.Green, color.Blue, color.Alpha }; - - GL.ClearBuffer(ClearBuffer.Color, index, colors); - - RestoreComponentMask(index); - } - - public void ClearRenderTargetDepthStencil( - float depthValue, - bool depthMask, - int stencilValue, - int stencilMask) + public void ClearRenderTargetDepthStencil(float depthValue, bool depthMask, int stencilValue, int stencilMask) { bool stencilMaskChanged = stencilMask != 0 && @@ -295,7 +95,7 @@ namespace Ryujinx.Graphics.OpenGL } } - public void Dispatch(int groupsX, int groupsY, int groupsZ) + public void DispatchCompute(int groupsX, int groupsY, int groupsZ) { if (!_program.IsLinked) { @@ -607,19 +407,33 @@ namespace Ryujinx.Graphics.OpenGL } } - public void DrawIndirect(BufferRange buffer, ulong offset, int drawCount, int stride) + public void SetBlendColor(ColorF color) { - + GL.BlendColor(color.Red, color.Green, color.Blue, color.Alpha); } - public void DrawIndexedIndirect(BufferRange buffer, ulong offset, int drawCount, int stride) + public void SetBlendState(int index, BlendDescriptor blend) { + if (!blend.Enable) + { + GL.Disable(IndexedEnableCap.Blend, index); - } + return; + } - public void SetBlendColor(ColorF color) - { - GL.BlendColor(color.Red, color.Green, color.Blue, color.Alpha); + GL.BlendEquationSeparate( + index, + blend.ColorOp.Convert(), + blend.AlphaOp.Convert()); + + GL.BlendFuncSeparate( + index, + (BlendingFactorSrc)blend.ColorSrcFactor.Convert(), + (BlendingFactorDest)blend.ColorDstFactor.Convert(), + (BlendingFactorSrc)blend.AlphaSrcFactor.Convert(), + (BlendingFactorDest)blend.AlphaDstFactor.Convert()); + + GL.Enable(IndexedEnableCap.Blend, index); } public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp) @@ -701,6 +515,33 @@ namespace Ryujinx.Graphics.OpenGL GL.FrontFace(frontFace.Convert()); } + public void SetImage(int index, ShaderStage stage, ITexture texture) + { + int unit = _program.GetImageUnit(stage, index); + + if (unit != -1 && texture != null) + { + TextureView view = (TextureView)texture; + + FormatInfo formatInfo = FormatTable.GetFormatInfo(view.Format); + + SizedInternalFormat format = (SizedInternalFormat)formatInfo.PixelInternalFormat; + + GL.BindImageTexture(unit, view.Handle, 0, true, 0, TextureAccess.ReadWrite, format); + } + } + + public void SetIndexBuffer(BufferRange buffer, IndexType type) + { + _elementsType = type.Convert(); + + _indexBaseOffset = (IntPtr)buffer.Offset; + + EnsureVertexArray(); + + _vertexArray.SetIndexBuffer((Buffer)buffer.Buffer); + } + public void SetPrimitiveRestart(bool enable, int index) { if (!enable) @@ -720,6 +561,13 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType = topology.Convert(); } + public void SetProgram(IProgram program) + { + _program = (Program)program; + + _program.Bind(); + } + public void SetRenderTargetColorMasks(uint[] componentMasks) { _componentMasks = (uint[])componentMasks.Clone(); @@ -752,6 +600,20 @@ namespace Ryujinx.Graphics.OpenGL UpdateDepthTest(); } + public void SetSampler(int index, ShaderStage stage, ISampler sampler) + { + int unit = _program.GetTextureUnit(stage, index); + + if (unit != -1 && sampler != null) + { + ((Sampler)sampler).Bind(unit); + } + else if (unit == -1) + { + Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}."); + } + } + public void SetStencilTest(StencilTestDescriptor stencilTest) { if (!stencilTest.TestEnable) @@ -794,6 +656,51 @@ namespace Ryujinx.Graphics.OpenGL _stencilFrontMask = stencilTest.FrontMask; } + public void SetStorageBuffer(int index, ShaderStage stage, BufferRange buffer) + { + SetBuffer(index, stage, buffer, isStorage: true); + } + + public void SetTexture(int index, ShaderStage stage, ITexture texture) + { + int unit = _program.GetTextureUnit(stage, index); + + if (unit != -1 && texture != null) + { + if (unit == 0) + { + _unit0Texture = ((TextureView)texture); + } + else + { + ((TextureView)texture).Bind(unit); + } + } + else if (unit == -1) + { + Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}."); + } + } + + public void SetUniformBuffer(int index, ShaderStage stage, BufferRange buffer) + { + SetBuffer(index, stage, buffer, isStorage: false); + } + + public void SetVertexAttribs(VertexAttribDescriptor[] vertexAttribs) + { + EnsureVertexArray(); + + _vertexArray.SetVertexAttributes(vertexAttribs); + } + + public void SetVertexBuffers(VertexBufferDescriptor[] vertexBuffers) + { + EnsureVertexArray(); + + _vertexArray.SetVertexBuffers(vertexBuffers); + } + public void SetViewports(int first, Viewport[] viewports) { bool flipY = false; @@ -848,6 +755,37 @@ namespace Ryujinx.Graphics.OpenGL GL.MemoryBarrier(MemoryBarrierFlags.TextureFetchBarrierBit); } + private void SetBuffer(int index, ShaderStage stage, BufferRange buffer, bool isStorage) + { + int bindingPoint = isStorage + ? _program.GetStorageBufferBindingPoint(stage, index) + : _program.GetUniformBufferBindingPoint(stage, index); + + if (bindingPoint == -1) + { + Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}."); + + return; + } + + BufferRangeTarget target = isStorage + ? BufferRangeTarget.ShaderStorageBuffer + : BufferRangeTarget.UniformBuffer; + + if (buffer.Buffer == null) + { + GL.BindBufferRange(target, bindingPoint, 0, IntPtr.Zero, 0); + + return; + } + + int bufferHandle = ((Buffer)buffer.Buffer).Handle; + + IntPtr bufferOffset = (IntPtr)buffer.Offset; + + GL.BindBufferRange(target, bindingPoint, bufferHandle, bufferOffset, buffer.Size); + } + private void SetOrigin(ClipOrigin origin) { if (_clipOrigin != origin) diff --git a/Ryujinx.Graphics.OpenGL/Renderer.cs b/Ryujinx.Graphics.OpenGL/Renderer.cs index ac16a37f..7cb69a78 100644 --- a/Ryujinx.Graphics.OpenGL/Renderer.cs +++ b/Ryujinx.Graphics.OpenGL/Renderer.cs @@ -1,7 +1,5 @@ using OpenTK.Graphics.OpenGL; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Sampler; -using Ryujinx.Graphics.GAL.Texture; using Ryujinx.Graphics.Shader; namespace Ryujinx.Graphics.OpenGL @@ -10,9 +8,9 @@ namespace Ryujinx.Graphics.OpenGL { public IPipeline Pipeline { get; } - private Counters _counters; + private readonly Counters _counters; - private Window _window; + private readonly Window _window; public IWindow Window => _window; diff --git a/Ryujinx.Graphics.OpenGL/Sampler.cs b/Ryujinx.Graphics.OpenGL/Sampler.cs index 9b9f09a1..674fc797 100644 --- a/Ryujinx.Graphics.OpenGL/Sampler.cs +++ b/Ryujinx.Graphics.OpenGL/Sampler.cs @@ -1,6 +1,5 @@ -using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Sampler; using OpenTK.Graphics.OpenGL; +using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.OpenGL { diff --git a/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs b/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs index dae492d9..2597214a 100644 --- a/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs +++ b/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs @@ -1,6 +1,6 @@ -using Ryujinx.Common; -using Ryujinx.Graphics.GAL.Texture; using OpenTK.Graphics.OpenGL; +using Ryujinx.Common; +using Ryujinx.Graphics.GAL; using System; namespace Ryujinx.Graphics.OpenGL diff --git a/Ryujinx.Graphics.OpenGL/TextureStorage.cs b/Ryujinx.Graphics.OpenGL/TextureStorage.cs index 482189ca..ec40a487 100644 --- a/Ryujinx.Graphics.OpenGL/TextureStorage.cs +++ b/Ryujinx.Graphics.OpenGL/TextureStorage.cs @@ -1,7 +1,6 @@ using OpenTK.Graphics.OpenGL; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Texture; namespace Ryujinx.Graphics.OpenGL { @@ -9,9 +8,9 @@ namespace Ryujinx.Graphics.OpenGL { public int Handle { get; private set; } - private Renderer _renderer; + private readonly Renderer _renderer; - private TextureCreateInfo _info; + private readonly TextureCreateInfo _info; public Target Target => _info.Target; diff --git a/Ryujinx.Graphics.OpenGL/TextureView.cs b/Ryujinx.Graphics.OpenGL/TextureView.cs index 2fd23d4c..f533404b 100644 --- a/Ryujinx.Graphics.OpenGL/TextureView.cs +++ b/Ryujinx.Graphics.OpenGL/TextureView.cs @@ -1,6 +1,5 @@ using OpenTK.Graphics.OpenGL; using Ryujinx.Graphics.GAL; -using Ryujinx.Graphics.GAL.Texture; using System; namespace Ryujinx.Graphics.OpenGL @@ -9,13 +8,13 @@ namespace Ryujinx.Graphics.OpenGL { public int Handle { get; private set; } - private Renderer _renderer; + private readonly Renderer _renderer; - private TextureStorage _parent; + private readonly TextureStorage _parent; private TextureView _emulatedViewParent; - private TextureCreateInfo _info; + private readonly TextureCreateInfo _info; private int _firstLayer; private int _firstLevel; diff --git a/Ryujinx.Graphics.OpenGL/VertexArray.cs b/Ryujinx.Graphics.OpenGL/VertexArray.cs index c3c37813..26e63364 100644 --- a/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -1,5 +1,5 @@ using OpenTK.Graphics.OpenGL; -using Ryujinx.Graphics.GAL.InputAssembler; +using Ryujinx.Graphics.GAL; using System; namespace Ryujinx.Graphics.OpenGL diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/CodeGenContext.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/CodeGenContext.cs index 5222fc7d..da557cfa 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/CodeGenContext.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/CodeGenContext.cs @@ -1,3 +1,4 @@ +using Ryujinx.Graphics.Shader.Translation; using System.Collections.Generic; using System.Text; diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs index b1b9afad..1465338e 100644 --- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs +++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/GlslGenerator.cs @@ -1,6 +1,7 @@ using Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions; using Ryujinx.Graphics.Shader.IntermediateRepresentation; using Ryujinx.Graphics.Shader.StructuredIr; +using Ryujinx.Graphics.Shader.Translation; using System; using static Ryujinx.Graphics.Shader.CodeGen.Glsl.TypeConversion; diff --git a/Ryujinx.Graphics.Shader/ShaderConfig.cs b/Ryujinx.Graphics.Shader/ShaderConfig.cs deleted file mode 100644 index 6b3640df..00000000 --- a/Ryujinx.Graphics.Shader/ShaderConfig.cs +++ /dev/null @@ -1,106 +0,0 @@ -using Ryujinx.Graphics.Shader.Translation; -using System; - -namespace Ryujinx.Graphics.Shader -{ - struct ShaderConfig - { - public ShaderStage Stage { get; } - - public OutputTopology OutputTopology { get; } - - public int MaxOutputVertices { get; } - - public OutputMapTarget[] OmapTargets { get; } - public bool OmapSampleMask { get; } - public bool OmapDepth { get; } - - public TranslationFlags Flags { get; } - - private QueryInfoCallback _queryInfoCallback; - - public ShaderConfig(TranslationFlags flags, QueryInfoCallback queryInfoCallback) - { - Stage = ShaderStage.Compute; - OutputTopology = OutputTopology.PointList; - MaxOutputVertices = 0; - OmapTargets = null; - OmapSampleMask = false; - OmapDepth = false; - Flags = flags; - _queryInfoCallback = queryInfoCallback; - } - - public ShaderConfig(ShaderHeader header, TranslationFlags flags, QueryInfoCallback queryInfoCallback) - { - Stage = header.Stage; - OutputTopology = header.OutputTopology; - MaxOutputVertices = header.MaxOutputVertexCount; - OmapTargets = header.OmapTargets; - OmapSampleMask = header.OmapSampleMask; - OmapDepth = header.OmapDepth; - Flags = flags; - _queryInfoCallback = queryInfoCallback; - } - - public int GetDepthRegister() - { - int count = 0; - - for (int index = 0; index < OmapTargets.Length; index++) - { - for (int component = 0; component < 4; component++) - { - if (OmapTargets[index].ComponentEnabled(component)) - { - count++; - } - } - } - - // The depth register is always two registers after the last color output. - return count + 1; - } - - public bool QueryInfoBool(QueryInfoName info, int index = 0) - { - return Convert.ToBoolean(QueryInfo(info, index)); - } - - public int QueryInfo(QueryInfoName info, int index = 0) - { - if (_queryInfoCallback != null) - { - return _queryInfoCallback(info, index); - } - else - { - switch (info) - { - case QueryInfoName.ComputeLocalSizeX: - case QueryInfoName.ComputeLocalSizeY: - case QueryInfoName.ComputeLocalSizeZ: - return 1; - case QueryInfoName.ComputeSharedMemorySize: - return 0xc000; - case QueryInfoName.IsTextureBuffer: - return Convert.ToInt32(false); - case QueryInfoName.IsTextureRectangle: - return Convert.ToInt32(false); - case QueryInfoName.MaximumViewportDimensions: - return 0x8000; - case QueryInfoName.PrimitiveTopology: - return (int)InputTopology.Points; - case QueryInfoName.StorageBufferOffsetAlignment: - return 16; - case QueryInfoName.SupportsNonConstantTextureOffset: - return Convert.ToInt32(true); - case QueryInfoName.ViewportTransformEnable: - return Convert.ToInt32(true); - } - } - - return 0; - } - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/ShaderHeader.cs b/Ryujinx.Graphics.Shader/ShaderHeader.cs deleted file mode 100644 index a8d01086..00000000 --- a/Ryujinx.Graphics.Shader/ShaderHeader.cs +++ /dev/null @@ -1,148 +0,0 @@ -using Ryujinx.Graphics.Shader.Decoders; -using System; -using System.Runtime.InteropServices; - -namespace Ryujinx.Graphics.Shader -{ - struct OutputMapTarget - { - public bool Red { get; } - public bool Green { get; } - public bool Blue { get; } - public bool Alpha { get; } - - public bool Enabled => Red || Green || Blue || Alpha; - - public OutputMapTarget(bool red, bool green, bool blue, bool alpha) - { - Red = red; - Green = green; - Blue = blue; - Alpha = alpha; - } - - public bool ComponentEnabled(int component) - { - switch (component) - { - case 0: return Red; - case 1: return Green; - case 2: return Blue; - case 3: return Alpha; - } - - throw new ArgumentOutOfRangeException(nameof(component)); - } - } - - class ShaderHeader - { - public int SphType { get; } - public int Version { get; } - - public ShaderStage Stage { get; } - - public bool MrtEnable { get; } - - public bool KillsPixels { get; } - - public bool DoesGlobalStore { get; } - - public int SassVersion { get; } - - public bool DoesLoadOrStore { get; } - public bool DoesFp64 { get; } - - public int StreamOutMask { get; } - - public int ShaderLocalMemoryLowSize { get; } - - public int PerPatchAttributeCount { get; } - - public int ShaderLocalMemoryHighSize { get; } - - public int ThreadsPerInputPrimitive { get; } - - public int ShaderLocalMemoryCrsSize { get; } - - public OutputTopology OutputTopology { get; } - - public int MaxOutputVertexCount { get; } - - public int StoreReqStart { get; } - public int StoreReqEnd { get; } - - public OutputMapTarget[] OmapTargets { get; } - public bool OmapSampleMask { get; } - public bool OmapDepth { get; } - - public ShaderHeader(Span code) - { - Span header = MemoryMarshal.Cast(code); - - int commonWord0 = header[0]; - int commonWord1 = header[1]; - int commonWord2 = header[2]; - int commonWord3 = header[3]; - int commonWord4 = header[4]; - - SphType = commonWord0.Extract(0, 5); - Version = commonWord0.Extract(5, 5); - - Stage = (ShaderStage)commonWord0.Extract(10, 4); - - // Invalid. - if (Stage == ShaderStage.Compute) - { - Stage = ShaderStage.Vertex; - } - - MrtEnable = commonWord0.Extract(14); - - KillsPixels = commonWord0.Extract(15); - - DoesGlobalStore = commonWord0.Extract(16); - - SassVersion = commonWord0.Extract(17, 4); - - DoesLoadOrStore = commonWord0.Extract(26); - DoesFp64 = commonWord0.Extract(27); - - StreamOutMask = commonWord0.Extract(28, 4); - - ShaderLocalMemoryLowSize = commonWord1.Extract(0, 24); - - PerPatchAttributeCount = commonWord1.Extract(24, 8); - - ShaderLocalMemoryHighSize = commonWord2.Extract(0, 24); - - ThreadsPerInputPrimitive = commonWord2.Extract(24, 8); - - ShaderLocalMemoryCrsSize = commonWord3.Extract(0, 24); - - OutputTopology = (OutputTopology)commonWord3.Extract(24, 4); - - MaxOutputVertexCount = commonWord4.Extract(0, 12); - - StoreReqStart = commonWord4.Extract(12, 8); - StoreReqEnd = commonWord4.Extract(24, 8); - - int type2OmapTarget = header[18]; - int type2Omap = header[19]; - - OmapTargets = new OutputMapTarget[8]; - - for (int offset = 0; offset < OmapTargets.Length * 4; offset += 4) - { - OmapTargets[offset >> 2] = new OutputMapTarget( - type2OmapTarget.Extract(offset + 0), - type2OmapTarget.Extract(offset + 1), - type2OmapTarget.Extract(offset + 2), - type2OmapTarget.Extract(offset + 3)); - } - - OmapSampleMask = type2Omap.Extract(0); - OmapDepth = type2Omap.Extract(1); - } - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs new file mode 100644 index 00000000..78dcde49 --- /dev/null +++ b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs @@ -0,0 +1,105 @@ +using System; + +namespace Ryujinx.Graphics.Shader.Translation +{ + struct ShaderConfig + { + public ShaderStage Stage { get; } + + public OutputTopology OutputTopology { get; } + + public int MaxOutputVertices { get; } + + public OutputMapTarget[] OmapTargets { get; } + public bool OmapSampleMask { get; } + public bool OmapDepth { get; } + + public TranslationFlags Flags { get; } + + private QueryInfoCallback _queryInfoCallback; + + public ShaderConfig(TranslationFlags flags, QueryInfoCallback queryInfoCallback) + { + Stage = ShaderStage.Compute; + OutputTopology = OutputTopology.PointList; + MaxOutputVertices = 0; + OmapTargets = null; + OmapSampleMask = false; + OmapDepth = false; + Flags = flags; + _queryInfoCallback = queryInfoCallback; + } + + public ShaderConfig(ShaderHeader header, TranslationFlags flags, QueryInfoCallback queryInfoCallback) + { + Stage = header.Stage; + OutputTopology = header.OutputTopology; + MaxOutputVertices = header.MaxOutputVertexCount; + OmapTargets = header.OmapTargets; + OmapSampleMask = header.OmapSampleMask; + OmapDepth = header.OmapDepth; + Flags = flags; + _queryInfoCallback = queryInfoCallback; + } + + public int GetDepthRegister() + { + int count = 0; + + for (int index = 0; index < OmapTargets.Length; index++) + { + for (int component = 0; component < 4; component++) + { + if (OmapTargets[index].ComponentEnabled(component)) + { + count++; + } + } + } + + // The depth register is always two registers after the last color output. + return count + 1; + } + + public bool QueryInfoBool(QueryInfoName info, int index = 0) + { + return Convert.ToBoolean(QueryInfo(info, index)); + } + + public int QueryInfo(QueryInfoName info, int index = 0) + { + if (_queryInfoCallback != null) + { + return _queryInfoCallback(info, index); + } + else + { + switch (info) + { + case QueryInfoName.ComputeLocalSizeX: + case QueryInfoName.ComputeLocalSizeY: + case QueryInfoName.ComputeLocalSizeZ: + return 1; + case QueryInfoName.ComputeSharedMemorySize: + return 0xc000; + case QueryInfoName.IsTextureBuffer: + return Convert.ToInt32(false); + case QueryInfoName.IsTextureRectangle: + return Convert.ToInt32(false); + case QueryInfoName.MaximumViewportDimensions: + return 0x8000; + case QueryInfoName.PrimitiveTopology: + return (int)InputTopology.Points; + case QueryInfoName.StorageBufferOffsetAlignment: + return 16; + case QueryInfoName.SupportsNonConstantTextureOffset: + return Convert.ToInt32(true); + case QueryInfoName.ViewportTransformEnable: + return Convert.ToInt32(true); + } + } + + return 0; + } + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/Translation/ShaderHeader.cs b/Ryujinx.Graphics.Shader/Translation/ShaderHeader.cs new file mode 100644 index 00000000..0c56132d --- /dev/null +++ b/Ryujinx.Graphics.Shader/Translation/ShaderHeader.cs @@ -0,0 +1,148 @@ +using Ryujinx.Graphics.Shader.Decoders; +using System; +using System.Runtime.InteropServices; + +namespace Ryujinx.Graphics.Shader.Translation +{ + struct OutputMapTarget + { + public bool Red { get; } + public bool Green { get; } + public bool Blue { get; } + public bool Alpha { get; } + + public bool Enabled => Red || Green || Blue || Alpha; + + public OutputMapTarget(bool red, bool green, bool blue, bool alpha) + { + Red = red; + Green = green; + Blue = blue; + Alpha = alpha; + } + + public bool ComponentEnabled(int component) + { + switch (component) + { + case 0: return Red; + case 1: return Green; + case 2: return Blue; + case 3: return Alpha; + } + + throw new ArgumentOutOfRangeException(nameof(component)); + } + } + + class ShaderHeader + { + public int SphType { get; } + public int Version { get; } + + public ShaderStage Stage { get; } + + public bool MrtEnable { get; } + + public bool KillsPixels { get; } + + public bool DoesGlobalStore { get; } + + public int SassVersion { get; } + + public bool DoesLoadOrStore { get; } + public bool DoesFp64 { get; } + + public int StreamOutMask { get; } + + public int ShaderLocalMemoryLowSize { get; } + + public int PerPatchAttributeCount { get; } + + public int ShaderLocalMemoryHighSize { get; } + + public int ThreadsPerInputPrimitive { get; } + + public int ShaderLocalMemoryCrsSize { get; } + + public OutputTopology OutputTopology { get; } + + public int MaxOutputVertexCount { get; } + + public int StoreReqStart { get; } + public int StoreReqEnd { get; } + + public OutputMapTarget[] OmapTargets { get; } + public bool OmapSampleMask { get; } + public bool OmapDepth { get; } + + public ShaderHeader(Span code) + { + Span header = MemoryMarshal.Cast(code); + + int commonWord0 = header[0]; + int commonWord1 = header[1]; + int commonWord2 = header[2]; + int commonWord3 = header[3]; + int commonWord4 = header[4]; + + SphType = commonWord0.Extract(0, 5); + Version = commonWord0.Extract(5, 5); + + Stage = (ShaderStage)commonWord0.Extract(10, 4); + + // Invalid. + if (Stage == ShaderStage.Compute) + { + Stage = ShaderStage.Vertex; + } + + MrtEnable = commonWord0.Extract(14); + + KillsPixels = commonWord0.Extract(15); + + DoesGlobalStore = commonWord0.Extract(16); + + SassVersion = commonWord0.Extract(17, 4); + + DoesLoadOrStore = commonWord0.Extract(26); + DoesFp64 = commonWord0.Extract(27); + + StreamOutMask = commonWord0.Extract(28, 4); + + ShaderLocalMemoryLowSize = commonWord1.Extract(0, 24); + + PerPatchAttributeCount = commonWord1.Extract(24, 8); + + ShaderLocalMemoryHighSize = commonWord2.Extract(0, 24); + + ThreadsPerInputPrimitive = commonWord2.Extract(24, 8); + + ShaderLocalMemoryCrsSize = commonWord3.Extract(0, 24); + + OutputTopology = (OutputTopology)commonWord3.Extract(24, 4); + + MaxOutputVertexCount = commonWord4.Extract(0, 12); + + StoreReqStart = commonWord4.Extract(12, 8); + StoreReqEnd = commonWord4.Extract(24, 8); + + int type2OmapTarget = header[18]; + int type2Omap = header[19]; + + OmapTargets = new OutputMapTarget[8]; + + for (int offset = 0; offset < OmapTargets.Length * 4; offset += 4) + { + OmapTargets[offset >> 2] = new OutputMapTarget( + type2OmapTarget.Extract(offset + 0), + type2OmapTarget.Extract(offset + 1), + type2OmapTarget.Extract(offset + 2), + type2OmapTarget.Extract(offset + 3)); + } + + OmapSampleMask = type2Omap.Extract(0); + OmapDepth = type2Omap.Extract(1); + } + } +} \ No newline at end of file -- cgit v1.2.3