aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.GAL/Texture
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2019-10-13 03:02:07 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commit1876b346fea647e8284a66bb6d62c38801035cff (patch)
tree6eeff094298cda84d1613dc5ec0691e51d7b35f1 /Ryujinx.Graphics.GAL/Texture
parentf617fb542a0e3d36012d77a4b5acbde7b08902f2 (diff)
Initial work
Diffstat (limited to 'Ryujinx.Graphics.GAL/Texture')
-rw-r--r--Ryujinx.Graphics.GAL/Texture/DepthStencilMode.cs8
-rw-r--r--Ryujinx.Graphics.GAL/Texture/SwizzleComponent.cs12
-rw-r--r--Ryujinx.Graphics.GAL/Texture/Target.cs17
-rw-r--r--Ryujinx.Graphics.GAL/Texture/TextureCreateInfo.cs115
4 files changed, 152 insertions, 0 deletions
diff --git a/Ryujinx.Graphics.GAL/Texture/DepthStencilMode.cs b/Ryujinx.Graphics.GAL/Texture/DepthStencilMode.cs
new file mode 100644
index 00000000..d7a379d8
--- /dev/null
+++ b/Ryujinx.Graphics.GAL/Texture/DepthStencilMode.cs
@@ -0,0 +1,8 @@
+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
new file mode 100644
index 00000000..fd7d50e3
--- /dev/null
+++ b/Ryujinx.Graphics.GAL/Texture/SwizzleComponent.cs
@@ -0,0 +1,12 @@
+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
new file mode 100644
index 00000000..b9cc1105
--- /dev/null
+++ b/Ryujinx.Graphics.GAL/Texture/Target.cs
@@ -0,0 +1,17 @@
+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
new file mode 100644
index 00000000..ad365f6b
--- /dev/null
+++ b/Ryujinx.Graphics.GAL/Texture/TextureCreateInfo.cs
@@ -0,0 +1,115 @@
+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 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);
+ }
+ }
+}