From b39526ca9061f1dab347a192f4159c39edd731fe Mon Sep 17 00:00:00 2001 From: TheSpydog Date: Tue, 31 Jan 2023 20:27:26 +0000 Subject: [PATCH] Textures now have a sample count, not render passes (#45) Co-authored-by: Caleb Cornett Reviewed-on: https://gitea.moonside.games/MoonsideGames/MoonWorks/pulls/45 Co-authored-by: TheSpydog Co-committed-by: TheSpydog --- src/Graphics/CommandBuffer.cs | 18 +++++++++--------- src/Graphics/RefreshStructs.cs | 12 ++---------- src/Graphics/Resources/Texture.cs | 19 +++++++++++-------- src/Graphics/State/TextureCreateInfo.cs | 2 ++ 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/Graphics/CommandBuffer.cs b/src/Graphics/CommandBuffer.cs index 1b4e1c6a..2218e34d 100644 --- a/src/Graphics/CommandBuffer.cs +++ b/src/Graphics/CommandBuffer.cs @@ -71,7 +71,7 @@ namespace MoonWorks.Graphics #if DEBUG renderPassActive = true; - currentSampleCount = colorAttachmentInfo.SampleCount; + currentSampleCount = colorAttachmentInfo.Texture.SampleCount; colorFormatOne = colorAttachmentInfo.Texture.Format; #endif } @@ -111,7 +111,7 @@ namespace MoonWorks.Graphics #if DEBUG renderPassActive = true; - currentSampleCount = colorAttachmentInfoOne.SampleCount; + currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; #endif @@ -159,7 +159,7 @@ namespace MoonWorks.Graphics #if DEBUG renderPassActive = true; - currentSampleCount = colorAttachmentInfoOne.SampleCount; + currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatThree = colorAttachmentInfoThree.Texture.Format; @@ -215,7 +215,7 @@ namespace MoonWorks.Graphics #if DEBUG renderPassActive = true; - currentSampleCount = colorAttachmentInfoOne.SampleCount; + currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatThree = colorAttachmentInfoThree.Texture.Format; @@ -285,7 +285,7 @@ namespace MoonWorks.Graphics #if DEBUG renderPassActive = true; - currentSampleCount = colorAttachmentInfo.SampleCount; + currentSampleCount = colorAttachmentInfo.Texture.SampleCount; colorFormatOne = colorAttachmentInfo.Texture.Format; depthStencilFormat = depthStencilAttachmentInfo.Texture.Format; #endif @@ -332,7 +332,7 @@ namespace MoonWorks.Graphics #if DEBUG renderPassActive = true; - currentSampleCount = colorAttachmentInfoOne.SampleCount; + currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; depthStencilFormat = depthStencilAttachmentInfo.Texture.Format; @@ -387,7 +387,7 @@ namespace MoonWorks.Graphics #if DEBUG renderPassActive = true; - currentSampleCount = colorAttachmentInfoOne.SampleCount; + currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatThree = colorAttachmentInfoThree.Texture.Format; @@ -450,7 +450,7 @@ namespace MoonWorks.Graphics #if DEBUG renderPassActive = true; - currentSampleCount = colorAttachmentInfoOne.SampleCount; + currentSampleCount = colorAttachmentInfoOne.Texture.SampleCount; colorFormatOne = colorAttachmentInfoOne.Texture.Format; colorFormatTwo = colorAttachmentInfoTwo.Texture.Format; colorFormatThree = colorAttachmentInfoThree.Texture.Format; @@ -2046,7 +2046,7 @@ namespace MoonWorks.Graphics private void AssertSameSampleCount(ColorAttachmentInfo a, ColorAttachmentInfo b) { - if (a.SampleCount != b.SampleCount) + if (a.Texture.SampleCount != b.Texture.SampleCount) { throw new System.ArgumentException("All color attachments in a render pass must have the same SampleCount!"); } diff --git a/src/Graphics/RefreshStructs.cs b/src/Graphics/RefreshStructs.cs index 9d8502cf..d2b84073 100644 --- a/src/Graphics/RefreshStructs.cs +++ b/src/Graphics/RefreshStructs.cs @@ -181,7 +181,6 @@ namespace MoonWorks.Graphics public uint Depth; public uint Layer; public uint Level; - public SampleCount SampleCount; public Color ClearColor; public LoadOp LoadOp; public StoreOp StoreOp; @@ -189,15 +188,12 @@ namespace MoonWorks.Graphics public ColorAttachmentInfo( Texture texture, Color clearColor, - SampleCount sampleCount = SampleCount.One, StoreOp storeOp = StoreOp.Store - ) - { + ) { Texture = texture; Depth = 0; Layer = 0; Level = 0; - SampleCount = sampleCount; ClearColor = clearColor; LoadOp = LoadOp.Clear; StoreOp = storeOp; @@ -206,15 +202,12 @@ namespace MoonWorks.Graphics public ColorAttachmentInfo( Texture texture, LoadOp loadOp = LoadOp.DontCare, - SampleCount sampleCount = SampleCount.One, StoreOp storeOp = StoreOp.Store - ) - { + ) { Texture = texture; Depth = 0; Layer = 0; Level = 0; - SampleCount = sampleCount; ClearColor = Color.White; LoadOp = loadOp; StoreOp = storeOp; @@ -228,7 +221,6 @@ namespace MoonWorks.Graphics depth = Depth, layer = Layer, level = Level, - sampleCount = (Refresh.SampleCount) SampleCount, clearColor = new Refresh.Vec4 { x = ClearColor.R / 255f, diff --git a/src/Graphics/Resources/Texture.cs b/src/Graphics/Resources/Texture.cs index 2781e555..48a57a1c 100644 --- a/src/Graphics/Resources/Texture.cs +++ b/src/Graphics/Resources/Texture.cs @@ -15,6 +15,7 @@ namespace MoonWorks.Graphics public TextureFormat Format { get; internal set; } public bool IsCube { get; } public uint LevelCount { get; } + public SampleCount SampleCount { get; } public TextureUsageFlags UsageFlags { get; } // FIXME: this allocates a delegate instance @@ -39,13 +40,14 @@ namespace MoonWorks.Graphics var byteCount = (uint) (width * height * channels); - TextureCreateInfo textureCreateInfo; + TextureCreateInfo textureCreateInfo = new TextureCreateInfo(); textureCreateInfo.Width = (uint) width; textureCreateInfo.Height = (uint) height; textureCreateInfo.Depth = 1; textureCreateInfo.Format = TextureFormat.R8G8B8A8; textureCreateInfo.IsCube = false; textureCreateInfo.LevelCount = 1; + textureCreateInfo.SampleCount = SampleCount.One; textureCreateInfo.UsageFlags = TextureUsageFlags.Sampler; var texture = new Texture(device, textureCreateInfo); @@ -130,9 +132,9 @@ namespace MoonWorks.Graphics uint height, TextureFormat format, TextureUsageFlags usageFlags, - uint levelCount = 1 - ) - { + uint levelCount = 1, + SampleCount sampleCount = SampleCount.One + ) { var textureCreateInfo = new TextureCreateInfo { Width = width, @@ -140,6 +142,7 @@ namespace MoonWorks.Graphics Depth = 1, IsCube = false, LevelCount = levelCount, + SampleCount = sampleCount, Format = format, UsageFlags = usageFlags }; @@ -165,8 +168,7 @@ namespace MoonWorks.Graphics TextureFormat format, TextureUsageFlags usageFlags, uint levelCount = 1 - ) - { + ) { var textureCreateInfo = new TextureCreateInfo { Width = width, @@ -195,8 +197,7 @@ namespace MoonWorks.Graphics TextureFormat format, TextureUsageFlags usageFlags, uint levelCount = 1 - ) - { + ) { var textureCreateInfo = new TextureCreateInfo { Width = size, @@ -232,6 +233,7 @@ namespace MoonWorks.Graphics Depth = textureCreateInfo.Depth; IsCube = textureCreateInfo.IsCube; LevelCount = textureCreateInfo.LevelCount; + SampleCount = textureCreateInfo.SampleCount; UsageFlags = textureCreateInfo.UsageFlags; } @@ -255,6 +257,7 @@ namespace MoonWorks.Graphics Depth = 1; IsCube = false; LevelCount = 1; + SampleCount = SampleCount.One; UsageFlags = TextureUsageFlags.ColorTarget; } diff --git a/src/Graphics/State/TextureCreateInfo.cs b/src/Graphics/State/TextureCreateInfo.cs index c4f7225e..9d15aa3b 100644 --- a/src/Graphics/State/TextureCreateInfo.cs +++ b/src/Graphics/State/TextureCreateInfo.cs @@ -9,6 +9,7 @@ namespace MoonWorks.Graphics public uint Depth; public bool IsCube; public uint LevelCount; + public SampleCount SampleCount; public TextureFormat Format; public TextureUsageFlags UsageFlags; @@ -21,6 +22,7 @@ namespace MoonWorks.Graphics depth = Depth, isCube = Conversions.BoolToByte(IsCube), levelCount = LevelCount, + sampleCount = (Refresh.SampleCount) SampleCount, format = (Refresh.TextureFormat) Format, usageFlags = (Refresh.TextureUsageFlags) UsageFlags };