From 0855bf6e2690d5090f315dc349060f188a1a9c62 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 1 Mar 2024 15:03:29 -0800 Subject: [PATCH] update bindings and WriteOptions API --- BasicCompute/BasicComputeGame.cs | 8 +- BasicStencil/BasicStencilGame.cs | 4 +- BasicTriangle/BasicTriangleGame.cs | 2 +- ClearScreen/ClearScreenGame.cs | 2 +- .../ClearScreen_MultiWindowGame.cs | 4 +- CompressedTextures/CompressedTexturesGame.cs | 2 +- ComputeUniforms/ComputeUniformsGame.cs | 4 +- CopyTexture/CopyTextureGame.cs | 13 +- Cube/CubeGame.cs | 297 +++++++++--------- CullFace/CullFaceGame.cs | 2 +- DepthMSAA/DepthMSAAGame.cs | 57 +--- DrawIndirect/DrawIndirectGame.cs | 2 +- GetBufferData/GetBufferDataGame.cs | 17 +- .../InstancingAndOffsetsGame.cs | 2 +- MSAA/MSAAGame.cs | 4 +- MSAACube/MSAACubeGame.cs | 8 +- .../Compiled/TexturedQuad2DArray.frag.refresh | Bin 0 -> 969 bytes .../Shaders/Source/TexturedQuad2DArray.frag | 17 + MoonWorksGraphicsTests.sln | 8 +- RenderTexture2D/RenderTexture2DGame.cs | 10 +- .../RenderTexture2DArray.csproj | 0 .../RenderTexture2DArrayGame.cs | 30 +- RenderTextureCube/RenderTextureCubeGame.cs | 12 +- .../RenderTextureMipmapsGame.cs | 15 +- StoreLoad/StoreLoadGame.cs | 4 +- Texture3D/Texture3DGame.cs | 25 +- Texture3DCopy/Texture3DCopy.cs | 191 +++++++++++ Texture3DCopy/Texture3DCopy.csproj | 16 + TextureMipmaps/TextureMipmapsGame.cs | 16 +- .../TexturedAnimatedQuadGame.cs | 2 +- TexturedQuad/TexturedQuadGame.cs | 2 +- .../TriangleVertexBufferGame.cs | 2 +- VertexSampler/VertexSamplerGame.cs | 13 +- VideoPlayer/VideoPlayerGame.cs | 2 +- WindowResizing/WindowResizingGame.cs | 2 +- 35 files changed, 508 insertions(+), 287 deletions(-) create mode 100644 MoonWorks.Test.Common/Content/Shaders/Compiled/TexturedQuad2DArray.frag.refresh create mode 100644 MoonWorks.Test.Common/Content/Shaders/Source/TexturedQuad2DArray.frag rename RenderTexture3D/RenderTexture3D.csproj => RenderTexture2DArray/RenderTexture2DArray.csproj (100%) rename RenderTexture3D/RenderTexture3DGame.cs => RenderTexture2DArray/RenderTexture2DArrayGame.cs (81%) create mode 100644 Texture3DCopy/Texture3DCopy.cs create mode 100644 Texture3DCopy/Texture3DCopy.csproj diff --git a/BasicCompute/BasicComputeGame.cs b/BasicCompute/BasicComputeGame.cs index 123b8cd..88c9e31 100644 --- a/BasicCompute/BasicComputeGame.cs +++ b/BasicCompute/BasicComputeGame.cs @@ -105,18 +105,18 @@ namespace MoonWorks.Test // This should result in a bright yellow texture! cmdbuf.BindComputePipeline(fillTextureComputePipeline); - cmdbuf.BindComputeTextures(new TextureLevelBinding(texture, 0)); + cmdbuf.BindComputeTextures(new ComputeTextureBinding(texture, WriteOptions.SafeOverwrite)); cmdbuf.DispatchCompute(texture.Width / 8, texture.Height / 8, 1); // This calculates the squares of the first N integers! cmdbuf.BindComputePipeline(calculateSquaresComputePipeline); - cmdbuf.BindComputeBuffers(squaresBuffer); + cmdbuf.BindComputeBuffers(new ComputeBufferBinding(squaresBuffer, WriteOptions.SafeOverwrite)); cmdbuf.DispatchCompute((uint) squares.Length / 8, 1, 1); cmdbuf.EndComputePass(); cmdbuf.BeginCopyPass(); - cmdbuf.DownloadFromBuffer(squaresBuffer, transferBuffer); + cmdbuf.DownloadFromBuffer(squaresBuffer, transferBuffer, TransferOptions.Overwrite); cmdbuf.EndCopyPass(); var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); @@ -136,7 +136,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.CornflowerBlue)); cmdbuf.BindGraphicsPipeline(drawPipeline); cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler)); cmdbuf.BindVertexBuffers(vertexBuffer); diff --git a/BasicStencil/BasicStencilGame.cs b/BasicStencil/BasicStencilGame.cs index 3a195b3..ea30b1d 100644 --- a/BasicStencil/BasicStencilGame.cs +++ b/BasicStencil/BasicStencilGame.cs @@ -89,8 +89,8 @@ namespace MoonWorks.Test if (backbuffer != null) { cmdbuf.BeginRenderPass( - new DepthStencilAttachmentInfo(depthStencilTexture, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare), - new ColorAttachmentInfo(backbuffer, Color.Black) + new DepthStencilAttachmentInfo(depthStencilTexture, WriteOptions.SafeDiscard, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare), + new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black) ); cmdbuf.BindGraphicsPipeline(maskerPipeline); cmdbuf.BindVertexBuffers(vertexBuffer); diff --git a/BasicTriangle/BasicTriangleGame.cs b/BasicTriangle/BasicTriangleGame.cs index 73cfaaf..490d1f6 100644 --- a/BasicTriangle/BasicTriangleGame.cs +++ b/BasicTriangle/BasicTriangleGame.cs @@ -59,7 +59,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(useWireframeMode ? linePipeline : fillPipeline); if (useSmallViewport) diff --git a/ClearScreen/ClearScreenGame.cs b/ClearScreen/ClearScreenGame.cs index afbee93..811a923 100644 --- a/ClearScreen/ClearScreenGame.cs +++ b/ClearScreen/ClearScreenGame.cs @@ -15,7 +15,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.CornflowerBlue)); cmdbuf.EndRenderPass(); } GraphicsDevice.Submit(cmdbuf); diff --git a/ClearScreen_MultiWindow/ClearScreen_MultiWindowGame.cs b/ClearScreen_MultiWindow/ClearScreen_MultiWindowGame.cs index 618f7d3..b41d901 100644 --- a/ClearScreen_MultiWindow/ClearScreen_MultiWindowGame.cs +++ b/ClearScreen_MultiWindow/ClearScreen_MultiWindowGame.cs @@ -29,7 +29,7 @@ namespace MoonWorks.Test backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.CornflowerBlue)); cmdbuf.EndRenderPass(); } GraphicsDevice.Submit(cmdbuf); @@ -41,7 +41,7 @@ namespace MoonWorks.Test backbuffer = cmdbuf.AcquireSwapchainTexture(secondaryWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Aquamarine)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Aquamarine)); cmdbuf.EndRenderPass(); } GraphicsDevice.Submit(cmdbuf); diff --git a/CompressedTextures/CompressedTexturesGame.cs b/CompressedTextures/CompressedTexturesGame.cs index fdc83a0..c9234d9 100644 --- a/CompressedTextures/CompressedTexturesGame.cs +++ b/CompressedTextures/CompressedTexturesGame.cs @@ -111,7 +111,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/ComputeUniforms/ComputeUniformsGame.cs b/ComputeUniforms/ComputeUniformsGame.cs index 07de4b7..12596c2 100644 --- a/ComputeUniforms/ComputeUniformsGame.cs +++ b/ComputeUniforms/ComputeUniformsGame.cs @@ -97,7 +97,7 @@ namespace MoonWorks.Test cmdbuf.BeginComputePass(); cmdbuf.BindComputePipeline(gradientTextureComputePipeline); - cmdbuf.BindComputeTextures(new TextureLevelBinding(texture, 0)); + cmdbuf.BindComputeTextures(new ComputeTextureBinding(texture, 0)); cmdbuf.PushComputeShaderUniforms(gradientUniforms); cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1); cmdbuf.EndComputePass(); @@ -113,7 +113,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.CornflowerBlue)); cmdbuf.BindGraphicsPipeline(drawPipeline); cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler)); cmdbuf.BindVertexBuffers(vertexBuffer); diff --git a/CopyTexture/CopyTextureGame.cs b/CopyTexture/CopyTextureGame.cs index ec0fdb1..2b0f602 100644 --- a/CopyTexture/CopyTextureGame.cs +++ b/CopyTexture/CopyTextureGame.cs @@ -88,6 +88,7 @@ namespace MoonWorks.Test Height = originalTexture.Height, Depth = originalTexture.Depth, IsCube = originalTexture.IsCube, + LayerCount = originalTexture.LayerCount, LevelCount = originalTexture.LevelCount, SampleCount = originalTexture.SampleCount, Format = originalTexture.Format, @@ -100,7 +101,8 @@ namespace MoonWorks.Test cmdbuf.BeginCopyPass(); cmdbuf.CopyTextureToTexture( originalTexture, - textureCopy + textureCopy, + WriteOptions.SafeOverwrite ); cmdbuf.EndCopyPass(); @@ -111,16 +113,17 @@ namespace MoonWorks.Test textureSmallCopy = new Texture(GraphicsDevice, textureCreateInfo); // Render the half-size copy - cmdbuf.Blit(originalTexture, textureSmallCopy, Filter.Linear); + cmdbuf.Blit(originalTexture, textureSmallCopy, Filter.Linear, WriteOptions.SafeOverwrite); // Copy the texture to a transfer buffer TransferBuffer compareBuffer = new TransferBuffer(GraphicsDevice, byteCount); cmdbuf.BeginCopyPass(); cmdbuf.DownloadFromTexture( - new TextureSlice(originalTexture), + originalTexture, compareBuffer, - new BufferImageCopy(0, 0, 0) + new BufferImageCopy(0, 0, 0), + TransferOptions.Overwrite ); cmdbuf.EndCopyPass(); @@ -156,7 +159,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/Cube/CubeGame.cs b/Cube/CubeGame.cs index 70e71ac..05fa035 100644 --- a/Cube/CubeGame.cs +++ b/Cube/CubeGame.cs @@ -19,10 +19,10 @@ namespace MoonWorks.Test private Sampler depthSampler; private DepthUniforms depthUniforms; - private GpuBuffer cubeVertexBuffer; - private GpuBuffer skyboxVertexBuffer; - private GpuBuffer blitVertexBuffer; - private GpuBuffer indexBuffer; + private GpuBuffer cubeVertexBuffer; + private GpuBuffer skyboxVertexBuffer; + private GpuBuffer blitVertexBuffer; + private GpuBuffer indexBuffer; private TransferBuffer screenshotTransferBuffer; private Texture screenshotTexture; @@ -52,37 +52,39 @@ namespace MoonWorks.Test } } - // Upload cubemap layers one at a time to minimize transfer size - unsafe void LoadCubemap(string[] imagePaths) - { + // Upload cubemap layers one at a time to minimize transfer size + unsafe void LoadCubemap(string[] imagePaths) + { var cubemapUploader = new ResourceUploader(GraphicsDevice); - for (uint i = 0; i < imagePaths.Length; i++) - { - var textureSlice = new TextureSlice - { - Texture = skyboxTexture, - MipLevel = 0, - BaseLayer = i, - LayerCount = 1, - X = 0, - Y = 0, - Z = 0, - Width = skyboxTexture.Width, - Height = skyboxTexture.Height, - Depth = 1 - }; + for (uint i = 0; i < imagePaths.Length; i++) + { + var textureRegion = new TextureRegion + { + TextureSlice = new TextureSlice + { + Texture = skyboxTexture, + MipLevel = 0, + Layer = i, + }, + X = 0, + Y = 0, + Z = 0, + Width = skyboxTexture.Width, + Height = skyboxTexture.Height, + Depth = 1 + }; cubemapUploader.SetTextureDataFromCompressed( - textureSlice, + textureRegion, imagePaths[i] ); cubemapUploader.UploadAndWait(); - } + } cubemapUploader.Dispose(); - } + } public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true) { @@ -131,27 +133,27 @@ namespace MoonWorks.Test ); skyboxSampler = new Sampler(GraphicsDevice, new SamplerCreateInfo()); - cubeVertexBuffer = GpuBuffer.Create( - GraphicsDevice, - BufferUsageFlags.Vertex, - 24 - ); - skyboxVertexBuffer = GpuBuffer.Create( - GraphicsDevice, - BufferUsageFlags.Vertex, - 24 - ); - indexBuffer = GpuBuffer.Create( - GraphicsDevice, - BufferUsageFlags.Index, - 36 - ); // Using uint here just to test IndexElementSize=32 + cubeVertexBuffer = GpuBuffer.Create( + GraphicsDevice, + BufferUsageFlags.Vertex, + 24 + ); + skyboxVertexBuffer = GpuBuffer.Create( + GraphicsDevice, + BufferUsageFlags.Vertex, + 24 + ); + indexBuffer = GpuBuffer.Create( + GraphicsDevice, + BufferUsageFlags.Index, + 36 + ); // Using uint here just to test IndexElementSize=32 - blitVertexBuffer = GpuBuffer.Create( - GraphicsDevice, - BufferUsageFlags.Vertex, - 6 - ); + blitVertexBuffer = GpuBuffer.Create( + GraphicsDevice, + BufferUsageFlags.Vertex, + 6 + ); screenshotTransferBuffer = new TransferBuffer(GraphicsDevice, MainWindow.Width * MainWindow.Height * 4); screenshotTexture = Texture.CreateTexture2D(GraphicsDevice, MainWindow.Width, MainWindow.Height, MainWindow.SwapchainFormat, TextureUsageFlags.Sampler); @@ -222,87 +224,87 @@ namespace MoonWorks.Test { Logger.LogInfo("Loading..."); - var cubeVertexData = new Span([ - new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0f)), - new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0f, 0f)), - new PositionColorVertex(new Vector3(1, 1, -1), new Color(1f, 0f, 0f)), - new PositionColorVertex(new Vector3(-1, 1, -1), new Color(1f, 0f, 0f)), + var cubeVertexData = new Span([ + new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0f)), + new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0f, 0f)), + new PositionColorVertex(new Vector3(1, 1, -1), new Color(1f, 0f, 0f)), + new PositionColorVertex(new Vector3(-1, 1, -1), new Color(1f, 0f, 0f)), - new PositionColorVertex(new Vector3(-1, -1, 1), new Color(0f, 1f, 0f)), - new PositionColorVertex(new Vector3(1, -1, 1), new Color(0f, 1f, 0f)), - new PositionColorVertex(new Vector3(1, 1, 1), new Color(0f, 1f, 0f)), - new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 1f, 0f)), + new PositionColorVertex(new Vector3(-1, -1, 1), new Color(0f, 1f, 0f)), + new PositionColorVertex(new Vector3(1, -1, 1), new Color(0f, 1f, 0f)), + new PositionColorVertex(new Vector3(1, 1, 1), new Color(0f, 1f, 0f)), + new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 1f, 0f)), - new PositionColorVertex(new Vector3(-1, -1, -1), new Color(0f, 0f, 1f)), - new PositionColorVertex(new Vector3(-1, 1, -1), new Color(0f, 0f, 1f)), - new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 0f, 1f)), - new PositionColorVertex(new Vector3(-1, -1, 1), new Color(0f, 0f, 1f)), + new PositionColorVertex(new Vector3(-1, -1, -1), new Color(0f, 0f, 1f)), + new PositionColorVertex(new Vector3(-1, 1, -1), new Color(0f, 0f, 1f)), + new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 0f, 1f)), + new PositionColorVertex(new Vector3(-1, -1, 1), new Color(0f, 0f, 1f)), - new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0.5f, 0f)), - new PositionColorVertex(new Vector3(1, 1, -1), new Color(1f, 0.5f, 0f)), - new PositionColorVertex(new Vector3(1, 1, 1), new Color(1f, 0.5f, 0f)), - new PositionColorVertex(new Vector3(1, -1, 1), new Color(1f, 0.5f, 0f)), + new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0.5f, 0f)), + new PositionColorVertex(new Vector3(1, 1, -1), new Color(1f, 0.5f, 0f)), + new PositionColorVertex(new Vector3(1, 1, 1), new Color(1f, 0.5f, 0f)), + new PositionColorVertex(new Vector3(1, -1, 1), new Color(1f, 0.5f, 0f)), - new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0.5f)), - new PositionColorVertex(new Vector3(-1, -1, 1), new Color(1f, 0f, 0.5f)), - new PositionColorVertex(new Vector3(1, -1, 1), new Color(1f, 0f, 0.5f)), - new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0f, 0.5f)), + new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0.5f)), + new PositionColorVertex(new Vector3(-1, -1, 1), new Color(1f, 0f, 0.5f)), + new PositionColorVertex(new Vector3(1, -1, 1), new Color(1f, 0f, 0.5f)), + new PositionColorVertex(new Vector3(1, -1, -1), new Color(1f, 0f, 0.5f)), - new PositionColorVertex(new Vector3(-1, 1, -1), new Color(0f, 0.5f, 0f)), - new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 0.5f, 0f)), - new PositionColorVertex(new Vector3(1, 1, 1), new Color(0f, 0.5f, 0f)), - new PositionColorVertex(new Vector3(1, 1, -1), new Color(0f, 0.5f, 0f)) - ]); + new PositionColorVertex(new Vector3(-1, 1, -1), new Color(0f, 0.5f, 0f)), + new PositionColorVertex(new Vector3(-1, 1, 1), new Color(0f, 0.5f, 0f)), + new PositionColorVertex(new Vector3(1, 1, 1), new Color(0f, 0.5f, 0f)), + new PositionColorVertex(new Vector3(1, 1, -1), new Color(0f, 0.5f, 0f)) + ]); - var skyboxVertexData = new Span([ - new PositionVertex(new Vector3(-10, -10, -10)), - new PositionVertex(new Vector3(10, -10, -10)), - new PositionVertex(new Vector3(10, 10, -10)), - new PositionVertex(new Vector3(-10, 10, -10)), + var skyboxVertexData = new Span([ + new PositionVertex(new Vector3(-10, -10, -10)), + new PositionVertex(new Vector3(10, -10, -10)), + new PositionVertex(new Vector3(10, 10, -10)), + new PositionVertex(new Vector3(-10, 10, -10)), - new PositionVertex(new Vector3(-10, -10, 10)), - new PositionVertex(new Vector3(10, -10, 10)), - new PositionVertex(new Vector3(10, 10, 10)), - new PositionVertex(new Vector3(-10, 10, 10)), + new PositionVertex(new Vector3(-10, -10, 10)), + new PositionVertex(new Vector3(10, -10, 10)), + new PositionVertex(new Vector3(10, 10, 10)), + new PositionVertex(new Vector3(-10, 10, 10)), - new PositionVertex(new Vector3(-10, -10, -10)), - new PositionVertex(new Vector3(-10, 10, -10)), - new PositionVertex(new Vector3(-10, 10, 10)), - new PositionVertex(new Vector3(-10, -10, 10)), + new PositionVertex(new Vector3(-10, -10, -10)), + new PositionVertex(new Vector3(-10, 10, -10)), + new PositionVertex(new Vector3(-10, 10, 10)), + new PositionVertex(new Vector3(-10, -10, 10)), - new PositionVertex(new Vector3(10, -10, -10)), - new PositionVertex(new Vector3(10, 10, -10)), - new PositionVertex(new Vector3(10, 10, 10)), - new PositionVertex(new Vector3(10, -10, 10)), + new PositionVertex(new Vector3(10, -10, -10)), + new PositionVertex(new Vector3(10, 10, -10)), + new PositionVertex(new Vector3(10, 10, 10)), + new PositionVertex(new Vector3(10, -10, 10)), - new PositionVertex(new Vector3(-10, -10, -10)), - new PositionVertex(new Vector3(-10, -10, 10)), - new PositionVertex(new Vector3(10, -10, 10)), - new PositionVertex(new Vector3(10, -10, -10)), + new PositionVertex(new Vector3(-10, -10, -10)), + new PositionVertex(new Vector3(-10, -10, 10)), + new PositionVertex(new Vector3(10, -10, 10)), + new PositionVertex(new Vector3(10, -10, -10)), - new PositionVertex(new Vector3(-10, 10, -10)), - new PositionVertex(new Vector3(-10, 10, 10)), - new PositionVertex(new Vector3(10, 10, 10)), - new PositionVertex(new Vector3(10, 10, -10)) - ]); + new PositionVertex(new Vector3(-10, 10, -10)), + new PositionVertex(new Vector3(-10, 10, 10)), + new PositionVertex(new Vector3(10, 10, 10)), + new PositionVertex(new Vector3(10, 10, -10)) + ]); - var indexData = new Span([ - 0, 1, 2, 0, 2, 3, - 6, 5, 4, 7, 6, 4, - 8, 9, 10, 8, 10, 11, - 14, 13, 12, 15, 14, 12, - 16, 17, 18, 16, 18, 19, - 22, 21, 20, 23, 22, 20 - ]); + var indexData = new Span([ + 0, 1, 2, 0, 2, 3, + 6, 5, 4, 7, 6, 4, + 8, 9, 10, 8, 10, 11, + 14, 13, 12, 15, 14, 12, + 16, 17, 18, 16, 18, 19, + 22, 21, 20, 23, 22, 20 + ]); - var blitVertexData = new Span([ - new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), - new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)), - new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)), - new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), - new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)), - new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)), - ]); + var blitVertexData = new Span([ + new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), + new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)), + new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)), + new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), + new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)), + new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)), + ]); var resourceUploader = new ResourceUploader(GraphicsDevice); @@ -314,15 +316,15 @@ namespace MoonWorks.Test resourceUploader.Upload(); resourceUploader.Dispose(); - LoadCubemap(new string[] - { - TestUtils.GetTexturePath("right.png"), - TestUtils.GetTexturePath("left.png"), - TestUtils.GetTexturePath("top.png"), - TestUtils.GetTexturePath("bottom.png"), - TestUtils.GetTexturePath("front.png"), - TestUtils.GetTexturePath("back.png") - }); + LoadCubemap(new string[] + { + TestUtils.GetTexturePath("right.png"), + TestUtils.GetTexturePath("left.png"), + TestUtils.GetTexturePath("top.png"), + TestUtils.GetTexturePath("bottom.png"), + TestUtils.GetTexturePath("front.png"), + TestUtils.GetTexturePath("back.png") + }); finishedLoading = true; Logger.LogInfo("Finished loading!"); @@ -398,7 +400,7 @@ namespace MoonWorks.Test Color clearColor = new Color(sine, sine, sine); // Just show a clear screen. - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, clearColor)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, WriteOptions.SafeDiscard, clearColor)); cmdbuf.EndRenderPass(); } else @@ -406,44 +408,44 @@ namespace MoonWorks.Test if (!depthOnlyEnabled) { cmdbuf.BeginRenderPass( - new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0)), - new ColorAttachmentInfo(swapchainTexture, LoadOp.DontCare) + new DepthStencilAttachmentInfo(depthTexture, WriteOptions.SafeDiscard, new DepthStencilValue(1f, 0)), + new ColorAttachmentInfo(swapchainTexture, WriteOptions.SafeDiscard, LoadOp.DontCare) ); } else { cmdbuf.BeginRenderPass( - new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0)) + new DepthStencilAttachmentInfo(depthTexture, WriteOptions.SafeDiscard, new DepthStencilValue(1f, 0), StoreOp.Store) ); } - // Draw cube - cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? cubePipelineDepthOnly : cubePipeline); - cmdbuf.BindVertexBuffers(cubeVertexBuffer); - cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo); - cmdbuf.PushVertexShaderUniforms(cubeUniforms); - cmdbuf.DrawIndexedPrimitives(0, 0, 12); + // Draw cube + cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? cubePipelineDepthOnly : cubePipeline); + cmdbuf.BindVertexBuffers(cubeVertexBuffer); + cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo); + cmdbuf.PushVertexShaderUniforms(cubeUniforms); + cmdbuf.DrawIndexedPrimitives(0, 0, 12); - // Draw skybox - cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? skyboxPipelineDepthOnly : skyboxPipeline); - cmdbuf.BindVertexBuffers(skyboxVertexBuffer); - cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo); - cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(skyboxTexture, skyboxSampler)); - cmdbuf.PushVertexShaderUniforms(skyboxUniforms); - cmdbuf.DrawIndexedPrimitives(0, 0, 12); + // Draw skybox + cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? skyboxPipelineDepthOnly : skyboxPipeline); + cmdbuf.BindVertexBuffers(skyboxVertexBuffer); + cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo); + cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(skyboxTexture, skyboxSampler)); + cmdbuf.PushVertexShaderUniforms(skyboxUniforms); + cmdbuf.DrawIndexedPrimitives(0, 0, 12); cmdbuf.EndRenderPass(); if (depthOnlyEnabled) { // Draw the depth buffer as a grayscale image - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, LoadOp.DontCare)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, WriteOptions.SafeOverwrite, LoadOp.Load)); - cmdbuf.BindGraphicsPipeline(blitPipeline); - cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(depthTexture, depthSampler)); - cmdbuf.BindVertexBuffers(blitVertexBuffer); - cmdbuf.PushFragmentShaderUniforms(depthUniforms); - cmdbuf.DrawPrimitives(0, 2); + cmdbuf.BindGraphicsPipeline(blitPipeline); + cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(depthTexture, depthSampler)); + cmdbuf.BindVertexBuffers(blitVertexBuffer); + cmdbuf.PushFragmentShaderUniforms(depthUniforms); + cmdbuf.DrawPrimitives(0, 2); cmdbuf.EndRenderPass(); } @@ -451,7 +453,7 @@ namespace MoonWorks.Test if (takeScreenshot) { cmdbuf.BeginCopyPass(); - cmdbuf.CopyTextureToTexture(swapchainTexture, screenshotTexture); + cmdbuf.CopyTextureToTexture(swapchainTexture, screenshotTexture, WriteOptions.SafeOverwrite); cmdbuf.EndCopyPass(); swapchainCopied = true; @@ -477,7 +479,8 @@ namespace MoonWorks.Test commandBuffer.BeginCopyPass(); commandBuffer.DownloadFromTexture( screenshotTexture, - screenshotTransferBuffer + screenshotTransferBuffer, + TransferOptions.Overwrite ); commandBuffer.EndCopyPass(); diff --git a/CullFace/CullFaceGame.cs b/CullFace/CullFaceGame.cs index 2cdd896..bba75c2 100644 --- a/CullFace/CullFaceGame.cs +++ b/CullFace/CullFaceGame.cs @@ -91,7 +91,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); // Need to bind a pipeline before binding vertex buffers cmdbuf.BindGraphicsPipeline(CW_CullNonePipeline); diff --git a/DepthMSAA/DepthMSAAGame.cs b/DepthMSAA/DepthMSAAGame.cs index 3b3a284..48d77fa 100644 --- a/DepthMSAA/DepthMSAAGame.cs +++ b/DepthMSAA/DepthMSAAGame.cs @@ -8,15 +8,11 @@ namespace MoonWorks.Test class DepthMSAAGame : Game { private GraphicsPipeline[] cubePipelines = new GraphicsPipeline[4]; - private GraphicsPipeline blitPipeline; private Texture[] renderTargets = new Texture[4]; private Texture[] depthRTs = new Texture[4]; - private Sampler rtSampler; private GpuBuffer cubeVertexBuffer1; private GpuBuffer cubeVertexBuffer2; private GpuBuffer cubeIndexBuffer; - private GpuBuffer quadVertexBuffer; - private GpuBuffer quadIndexBuffer; private float cubeTimer = 0f; private Quaternion cubeRotation = Quaternion.Identity; @@ -64,19 +60,6 @@ namespace MoonWorks.Test cubePipelines[i] = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); } - // Create the blit pipeline - ShaderModule blitVertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert")); - ShaderModule blitFragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag")); - - pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( - MainWindow.SwapchainFormat, - blitVertShaderModule, - blitFragShaderModule - ); - pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding(); - pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1; - blitPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); - // Create the MSAA render textures and depth textures for (int i = 0; i < renderTargets.Length; i += 1) { @@ -101,30 +84,9 @@ namespace MoonWorks.Test ); } - // Create the sampler - rtSampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp); - // Create the buffers var resourceUploader = new ResourceUploader(GraphicsDevice); - quadVertexBuffer = resourceUploader.CreateBuffer( - [ - new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), - new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)), - new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)), - new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)) - ], - BufferUsageFlags.Vertex - ); - - quadIndexBuffer = resourceUploader.CreateBuffer( - [ - 0, 1, 2, - 0, 2, 3, - ], - BufferUsageFlags.Index - ); - var cubeVertexData = new System.Span( [ new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0f)), @@ -248,8 +210,8 @@ namespace MoonWorks.Test // Begin the MSAA RT pass int index = (int) currentSampleCount; cmdbuf.BeginRenderPass( - new DepthStencilAttachmentInfo(depthRTs[index], new DepthStencilValue(1, 0)), - new ColorAttachmentInfo(renderTargets[index], Color.Black) + new DepthStencilAttachmentInfo(depthRTs[index], WriteOptions.SafeDiscard, new DepthStencilValue(1, 0)), + new ColorAttachmentInfo(renderTargets[index], WriteOptions.SafeDiscard, Color.Black) ); cmdbuf.BindGraphicsPipeline(cubePipelines[index]); @@ -267,14 +229,13 @@ namespace MoonWorks.Test cmdbuf.EndRenderPass(); - // Blit the MSAA RT to the backbuffer - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, LoadOp.DontCare)); - cmdbuf.BindGraphicsPipeline(blitPipeline); - cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(renderTargets[index], rtSampler)); - cmdbuf.BindVertexBuffers(quadVertexBuffer); - cmdbuf.BindIndexBuffer(quadIndexBuffer, IndexElementSize.Sixteen); - cmdbuf.DrawIndexedPrimitives(0, 0, 2); - cmdbuf.EndRenderPass(); + // Copy the MSAA RT to the backbuffer + cmdbuf.Blit( + renderTargets[index], + backbuffer, + Filter.Nearest, + WriteOptions.SafeOverwrite + ); } GraphicsDevice.Submit(cmdbuf); } diff --git a/DrawIndirect/DrawIndirectGame.cs b/DrawIndirect/DrawIndirectGame.cs index be2c00b..ad689f8 100644 --- a/DrawIndirect/DrawIndirectGame.cs +++ b/DrawIndirect/DrawIndirectGame.cs @@ -61,7 +61,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.CornflowerBlue)); cmdbuf.BindGraphicsPipeline(graphicsPipeline); cmdbuf.BindVertexBuffers(new BufferBinding(vertexBuffer, 0)); cmdbuf.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf()); diff --git a/GetBufferData/GetBufferDataGame.cs b/GetBufferData/GetBufferDataGame.cs index 5f52767..ae5ef67 100644 --- a/GetBufferData/GetBufferDataGame.cs +++ b/GetBufferData/GetBufferDataGame.cs @@ -41,7 +41,7 @@ namespace MoonWorks.Test CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); cmdbuf.BeginCopyPass(); - cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer); + cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer, TransferOptions.Overwrite); cmdbuf.EndCopyPass(); var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); @@ -60,9 +60,9 @@ namespace MoonWorks.Test // Change the first three vertices and upload cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - transferBuffer.SetData(otherVerts, SetDataOptions.Overwrite); + transferBuffer.SetData(otherVerts, TransferOptions.Overwrite); cmdbuf.BeginCopyPass(); - cmdbuf.UploadToBuffer(transferBuffer, vertexBuffer); + cmdbuf.UploadToBuffer(transferBuffer, vertexBuffer, WriteOptions.SafeOverwrite); cmdbuf.EndCopyPass(); fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); GraphicsDevice.WaitForFences(fence); @@ -71,7 +71,7 @@ namespace MoonWorks.Test // Download the data cmdbuf = GraphicsDevice.AcquireCommandBuffer(); cmdbuf.BeginCopyPass(); - cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer); + cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer, TransferOptions.Overwrite); cmdbuf.EndCopyPass(); fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); GraphicsDevice.WaitForFences(fence); @@ -88,14 +88,15 @@ namespace MoonWorks.Test // Change the last two vertices and upload cmdbuf = GraphicsDevice.AcquireCommandBuffer(); var lastTwoSpan = otherVerts.Slice(1, 2); - transferBuffer.SetData(lastTwoSpan, SetDataOptions.Overwrite); + transferBuffer.SetData(lastTwoSpan, TransferOptions.Overwrite); cmdbuf.BeginCopyPass(); cmdbuf.UploadToBuffer( transferBuffer, vertexBuffer, 0, (uint)(vertices.Length - 2), - 2 + 2, + WriteOptions.SafeOverwrite ); cmdbuf.EndCopyPass(); fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); @@ -104,7 +105,7 @@ namespace MoonWorks.Test cmdbuf = GraphicsDevice.AcquireCommandBuffer(); cmdbuf.BeginCopyPass(); - cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer); + cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer, TransferOptions.Overwrite); cmdbuf.EndCopyPass(); fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf); GraphicsDevice.WaitForFences(fence); @@ -127,7 +128,7 @@ namespace MoonWorks.Test Texture? swapchainTexture = cmdbuf.AcquireSwapchainTexture(MainWindow); if (swapchainTexture != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchainTexture, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.EndRenderPass(); } GraphicsDevice.Submit(cmdbuf); diff --git a/InstancingAndOffsets/InstancingAndOffsetsGame.cs b/InstancingAndOffsets/InstancingAndOffsetsGame.cs index b4a798f..45db9e0 100644 --- a/InstancingAndOffsets/InstancingAndOffsetsGame.cs +++ b/InstancingAndOffsets/InstancingAndOffsetsGame.cs @@ -86,7 +86,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/MSAA/MSAAGame.cs b/MSAA/MSAAGame.cs index f649ffd..409c9ce 100644 --- a/MSAA/MSAAGame.cs +++ b/MSAA/MSAAGame.cs @@ -126,12 +126,12 @@ namespace MoonWorks.Test { Texture rt = renderTargets[(int) currentSampleCount]; - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(rt, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(rt, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(msaaPipelines[(int) currentSampleCount]); cmdbuf.DrawPrimitives(0, 1); cmdbuf.EndRenderPass(); - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, LoadOp.DontCare)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, LoadOp.DontCare)); cmdbuf.BindGraphicsPipeline(blitPipeline); cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, rtSampler)); cmdbuf.BindVertexBuffers(quadVertexBuffer); diff --git a/MSAACube/MSAACubeGame.cs b/MSAACube/MSAACubeGame.cs index f233ebd..ea2b220 100644 --- a/MSAACube/MSAACubeGame.cs +++ b/MSAACube/MSAACubeGame.cs @@ -67,7 +67,8 @@ namespace MoonWorks.Test LevelCount = 1, SampleCount = (SampleCount)i, UsageFlags = TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler, - IsCube = true + IsCube = true, + LayerCount = 6 }; renderTargets[i] = new Texture(GraphicsDevice, cubeCreateInfo); } @@ -185,13 +186,14 @@ namespace MoonWorks.Test Texture rt = renderTargets[rtIndex]; ColorAttachmentInfo rtAttachmentInfo = new ColorAttachmentInfo( rt, + WriteOptions.SafeDiscard, Color.Black ); // Render a triangle to each slice of the cubemap for (uint i = 0; i < 6; i += 1) { - rtAttachmentInfo.Layer = i; + rtAttachmentInfo.TextureSlice.Layer = i; cmdbuf.BeginRenderPass(rtAttachmentInfo); cmdbuf.BindGraphicsPipeline(msaaPipelines[rtIndex]); @@ -199,7 +201,7 @@ namespace MoonWorks.Test cmdbuf.EndRenderPass(); } - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(cubemapPipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/MoonWorks.Test.Common/Content/Shaders/Compiled/TexturedQuad2DArray.frag.refresh b/MoonWorks.Test.Common/Content/Shaders/Compiled/TexturedQuad2DArray.frag.refresh new file mode 100644 index 0000000000000000000000000000000000000000..3587389d3175b0ca0fc1f3e8d11df5ddec70e2ce GIT binary patch literal 969 zcmZ9KNlU|U5XGmqsr$a~RgXgPpdyHZipE31rHaQ;nyA6FDQOk`cH*bh2X$+ z{`2O|n%-ViFLR%HvwYuHzgfsG3ja=YV~clUN+jF}Q8aK^3Q z3bJUU7B*#UP&z4{5D#1p^vbKM*_VwY+xcBMQ7IYzCemCPBRu zz6J0GGQ6-^k6!&O!4V_d*D)vUeUa3j&f+Le)DO<6Y_-;CML{CpNoTtY-p}GV@f8wM zv}xJzvHC&pb6ux}xb?2%CR8I!ULKJ!jV zne{|0YA;Hehn{fgvm^z-5eI)oN*>a~R`mvB?rX7_i~j^%V$^t0KHq3v${fUxH6`B) J>_^!L(qG`DLl^)6 literal 0 HcmV?d00001 diff --git a/MoonWorks.Test.Common/Content/Shaders/Source/TexturedQuad2DArray.frag b/MoonWorks.Test.Common/Content/Shaders/Source/TexturedQuad2DArray.frag new file mode 100644 index 0000000..6390b29 --- /dev/null +++ b/MoonWorks.Test.Common/Content/Shaders/Source/TexturedQuad2DArray.frag @@ -0,0 +1,17 @@ +#version 450 + +layout (location = 0) in vec2 TexCoord; + +layout (location = 0) out vec4 FragColor; + +layout(binding = 0, set = 1) uniform sampler2DArray Sampler; + +layout (binding = 0, set = 3) uniform UniformBlock +{ + float depth; +}; + +void main() +{ + FragColor = texture(Sampler, vec3(TexCoord, depth)); +} diff --git a/MoonWorksGraphicsTests.sln b/MoonWorksGraphicsTests.sln index 70b2b9f..b84b76d 100644 --- a/MoonWorksGraphicsTests.sln +++ b/MoonWorksGraphicsTests.sln @@ -45,7 +45,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InstancingAndOffsets", "Ins EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VertexSampler", "VertexSampler\VertexSampler.csproj", "{C525B6DE-3003-45D5-BB83-89679B108C08}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenderTexture3D", "RenderTexture3D\RenderTexture3D.csproj", "{6D625A4C-8618-4DFC-A6AD-AA3BE3488D70}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenderTexture2DArray", "RenderTexture2DArray\RenderTexture2DArray.csproj", "{6D625A4C-8618-4DFC-A6AD-AA3BE3488D70}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenderTextureCube", "RenderTextureCube\RenderTextureCube.csproj", "{D7A8452F-123F-4965-8716-9E39F677A831}" EndProject @@ -65,6 +65,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenderTexture2D", "RenderTe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSAACube", "MSAACube\MSAACube.csproj", "{A1568AAF-DD02-4A6E-9C68-9AE07130A60D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Texture3DCopy", "Texture3DCopy\Texture3DCopy.csproj", "{A18B6D92-A699-480C-9ABC-4000A3FE4B94}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -195,6 +197,10 @@ Global {A1568AAF-DD02-4A6E-9C68-9AE07130A60D}.Debug|Any CPU.Build.0 = Debug|Any CPU {A1568AAF-DD02-4A6E-9C68-9AE07130A60D}.Release|Any CPU.ActiveCfg = Release|Any CPU {A1568AAF-DD02-4A6E-9C68-9AE07130A60D}.Release|Any CPU.Build.0 = Release|Any CPU + {A18B6D92-A699-480C-9ABC-4000A3FE4B94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A18B6D92-A699-480C-9ABC-4000A3FE4B94}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A18B6D92-A699-480C-9ABC-4000A3FE4B94}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A18B6D92-A699-480C-9ABC-4000A3FE4B94}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RenderTexture2D/RenderTexture2DGame.cs b/RenderTexture2D/RenderTexture2DGame.cs index 2c7b526..102d714 100644 --- a/RenderTexture2D/RenderTexture2DGame.cs +++ b/RenderTexture2D/RenderTexture2DGame.cs @@ -92,19 +92,19 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[0], Color.Red)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[0], WriteOptions.SafeDiscard, Color.Red)); cmdbuf.EndRenderPass(); - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[1], Color.Blue)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[1], WriteOptions.SafeDiscard, Color.Blue)); cmdbuf.EndRenderPass(); - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[2], Color.Green)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[2], WriteOptions.SafeDiscard, Color.Green)); cmdbuf.EndRenderPass(); - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[3], Color.Yellow)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[3], WriteOptions.SafeDiscard, Color.Yellow)); cmdbuf.EndRenderPass(); - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/RenderTexture3D/RenderTexture3D.csproj b/RenderTexture2DArray/RenderTexture2DArray.csproj similarity index 100% rename from RenderTexture3D/RenderTexture3D.csproj rename to RenderTexture2DArray/RenderTexture2DArray.csproj diff --git a/RenderTexture3D/RenderTexture3DGame.cs b/RenderTexture2DArray/RenderTexture2DArrayGame.cs similarity index 81% rename from RenderTexture3D/RenderTexture3DGame.cs rename to RenderTexture2DArray/RenderTexture2DArrayGame.cs index 654e435..aff33cd 100644 --- a/RenderTexture3D/RenderTexture3DGame.cs +++ b/RenderTexture2DArray/RenderTexture2DArrayGame.cs @@ -1,9 +1,10 @@ -using MoonWorks.Graphics; +using System; +using MoonWorks.Graphics; using MoonWorks.Math.Float; namespace MoonWorks.Test { - class RenderTexture3DGame : Game + class RenderTexture2DArrayGame : Game { private GraphicsPipeline pipeline; private GpuBuffer vertexBuffer; @@ -29,11 +30,11 @@ namespace MoonWorks.Test } } - public RenderTexture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true) + public RenderTexture2DArrayGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true) { // Load the shaders ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert")); - ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad3D.frag")); + ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad2DArray.frag")); // Create the graphics pipeline GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( @@ -46,7 +47,7 @@ namespace MoonWorks.Test pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); // Create samplers - sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap); + sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointWrap); // Create and populate the GPU resources var resourceUploader = new ResourceUploader(GraphicsDevice); @@ -72,7 +73,7 @@ namespace MoonWorks.Test resourceUploader.Upload(); resourceUploader.Dispose(); - rt = Texture.CreateTexture3D( + rt = Texture.CreateTexture2DArray( GraphicsDevice, 16, 16, @@ -88,11 +89,13 @@ namespace MoonWorks.Test { ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo { - Texture = rt, + TextureSlice = new TextureSlice + { + Texture = rt, + Layer = i, + MipLevel = 0 + }, ClearColor = colors[i], - Depth = i, - Layer = 0, - Level = 0, LoadOp = LoadOp.Clear, StoreOp = StoreOp.Store }; @@ -108,13 +111,14 @@ namespace MoonWorks.Test protected override void Draw(double alpha) { t += 0.01f; - FragUniform fragUniform = new FragUniform(t); + t %= 3; + FragUniform fragUniform = new FragUniform(MathF.Floor(t)); CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); @@ -128,7 +132,7 @@ namespace MoonWorks.Test public static void Main(string[] args) { - RenderTexture3DGame game = new RenderTexture3DGame(); + RenderTexture2DArrayGame game = new RenderTexture2DArrayGame(); game.Run(); } } diff --git a/RenderTextureCube/RenderTextureCubeGame.cs b/RenderTextureCube/RenderTextureCubeGame.cs index 7be5e5f..df341a1 100644 --- a/RenderTextureCube/RenderTextureCubeGame.cs +++ b/RenderTextureCube/RenderTextureCubeGame.cs @@ -114,11 +114,13 @@ namespace MoonWorks.Test { ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo { - Texture = cubemap, + TextureSlice = new TextureSlice + { + Texture = cubemap, + Layer = i, + MipLevel = 0 + }, ClearColor = colors[i], - Depth = 0, - Layer = i, - Level = 0, LoadOp = LoadOp.Clear, StoreOp = StoreOp.Store }; @@ -156,7 +158,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/RenderTextureMipmaps/RenderTextureMipmapsGame.cs b/RenderTextureMipmaps/RenderTextureMipmapsGame.cs index 0674d1d..43a0f51 100644 --- a/RenderTextureMipmaps/RenderTextureMipmapsGame.cs +++ b/RenderTextureMipmaps/RenderTextureMipmapsGame.cs @@ -121,13 +121,16 @@ namespace MoonWorks.Test { ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo { - Texture = texture, + TextureSlice = new TextureSlice + { + Texture = texture, + Layer = 0, + MipLevel = i + }, ClearColor = colors[i], - Depth = 0, - Layer = 0, - Level = i, LoadOp = LoadOp.Clear, - StoreOp = StoreOp.Store + StoreOp = StoreOp.Store, + WriteOption = WriteOptions.SafeOverwrite }; cmdbuf.BeginRenderPass(attachmentInfo); cmdbuf.EndRenderPass(); @@ -163,7 +166,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/StoreLoad/StoreLoadGame.cs b/StoreLoad/StoreLoadGame.cs index c3783a8..1ceea8f 100644 --- a/StoreLoad/StoreLoadGame.cs +++ b/StoreLoad/StoreLoadGame.cs @@ -31,11 +31,11 @@ namespace MoonWorks.Test Texture? swapchain = cmdbuf.AcquireSwapchainTexture(MainWindow); if (swapchain != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, Color.Blue)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, WriteOptions.SafeDiscard, Color.Blue)); cmdbuf.BindGraphicsPipeline(fillPipeline); cmdbuf.DrawPrimitives(0, 1); cmdbuf.EndRenderPass(); - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, LoadOp.Load, StoreOp.Store)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, WriteOptions.SafeOverwrite, LoadOp.Load, StoreOp.Store)); cmdbuf.EndRenderPass(); } GraphicsDevice.Submit(cmdbuf); diff --git a/Texture3D/Texture3DGame.cs b/Texture3D/Texture3DGame.cs index 4cd7ee5..e45cc38 100644 --- a/Texture3D/Texture3DGame.cs +++ b/Texture3D/Texture3DGame.cs @@ -65,17 +65,26 @@ namespace MoonWorks.Test BufferUsageFlags.Index ); - texture = Texture.CreateTexture3D(GraphicsDevice, 16, 16, 7, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler); + texture = Texture.CreateTexture3D( + GraphicsDevice, + 16, + 16, + 7, + TextureFormat.R8G8B8A8, + TextureUsageFlags.Sampler + ); // Load each depth subimage of the 3D texture for (uint i = 0; i < texture.Depth; i += 1) { - TextureSlice slice = new TextureSlice + var region = new TextureRegion { - Texture = texture, - MipLevel = 0, - BaseLayer = 0, - LayerCount = 1, + TextureSlice = new TextureSlice + { + Texture = texture, + MipLevel = 0, + Layer = 0 + }, X = 0, Y = 0, Z = i, @@ -85,7 +94,7 @@ namespace MoonWorks.Test }; resourceUploader.SetTextureDataFromCompressed( - slice, + region, TestUtils.GetTexturePath($"tex3d_{i}.png") ); } @@ -130,7 +139,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/Texture3DCopy/Texture3DCopy.cs b/Texture3DCopy/Texture3DCopy.cs new file mode 100644 index 0000000..2683d76 --- /dev/null +++ b/Texture3DCopy/Texture3DCopy.cs @@ -0,0 +1,191 @@ +using MoonWorks.Graphics; +using MoonWorks.Math.Float; + +namespace MoonWorks.Test +{ + class RenderTexture3DGame : Game + { + private GraphicsPipeline pipeline; + private GpuBuffer vertexBuffer; + private GpuBuffer indexBuffer; + private Texture rt; + private Texture texture3D; + private Sampler sampler; + + private float t; + private Color[] colors = new Color[] + { + Color.Red, + Color.Green, + Color.Blue, + }; + + struct FragUniform + { + public float Depth; + + public FragUniform(float depth) + { + Depth = depth; + } + } + + public RenderTexture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true) + { + // Load the shaders + ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert")); + ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad3D.frag")); + + // Create the graphics pipeline + GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( + MainWindow.SwapchainFormat, + vertShaderModule, + fragShaderModule + ); + pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding(); + pipelineCreateInfo.FragmentShaderInfo = GraphicsShaderInfo.Create(fragShaderModule, "main", 1); + pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); + + // Create samplers + sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap); + + // Create and populate the GPU resources + var resourceUploader = new ResourceUploader(GraphicsDevice); + + vertexBuffer = resourceUploader.CreateBuffer( + [ + new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)), + new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(1, 0)), + new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)), + new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)), + ], + BufferUsageFlags.Vertex + ); + + indexBuffer = resourceUploader.CreateBuffer( + [ + 0, 1, 2, + 0, 2, 3, + ], + BufferUsageFlags.Index + ); + + resourceUploader.Upload(); + resourceUploader.Dispose(); + + rt = Texture.CreateTexture2DArray( + GraphicsDevice, + 16, + 16, + (uint) colors.Length, + TextureFormat.R8G8B8A8, + TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler + ); + + texture3D = new Texture(GraphicsDevice, new TextureCreateInfo + { + Width = 16, + Height = 16, + Depth = 3, + IsCube = false, + LayerCount = 1, + LevelCount = 1, + SampleCount = SampleCount.One, + Format = TextureFormat.R8G8B8A8, + UsageFlags = TextureUsageFlags.Sampler + }); + + CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + + // Clear each layer slice of the RT to a different color + for (uint i = 0; i < colors.Length; i += 1) + { + ColorAttachmentInfo attachmentInfo = new ColorAttachmentInfo + { + TextureSlice = new TextureSlice + { + Texture = rt, + Layer = i, + MipLevel = 0 + }, + ClearColor = colors[i], + LoadOp = LoadOp.Clear, + StoreOp = StoreOp.Store + }; + cmdbuf.BeginRenderPass(attachmentInfo); + cmdbuf.EndRenderPass(); + } + + // Copy each layer slice to a different 3D depth + cmdbuf.BeginCopyPass(); + for (var i = 0; i < 3; i += 1) + { + cmdbuf.CopyTextureToTexture( + new TextureRegion + { + TextureSlice = new TextureSlice + { + Texture = rt, + Layer = (uint) i, + MipLevel = 0 + }, + X = 0, + Y = 0, + Z = 0, + Width = 16, + Height = 16, + Depth = 1 + }, + new TextureRegion + { + TextureSlice = new TextureSlice + { + Texture = texture3D, + Layer = 0, + MipLevel = 0 + }, + X = 0, + Y = 0, + Z = (uint) i, + Width = 16, + Height = 16, + Depth = 1 + }, + WriteOptions.SafeOverwrite + ); + } + cmdbuf.EndCopyPass(); + + GraphicsDevice.Submit(cmdbuf); + } + + protected override void Update(System.TimeSpan delta) { } + + protected override void Draw(double alpha) + { + t += 0.01f; + FragUniform fragUniform = new FragUniform(t); + + CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); + if (backbuffer != null) + { + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); + cmdbuf.BindGraphicsPipeline(pipeline); + cmdbuf.BindVertexBuffers(vertexBuffer); + cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); + cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture3D, sampler)); + cmdbuf.PushFragmentShaderUniforms(fragUniform); + cmdbuf.DrawIndexedPrimitives(0, 0, 2); + cmdbuf.EndRenderPass(); + } + GraphicsDevice.Submit(cmdbuf); + } + + public static void Main(string[] args) + { + RenderTexture3DGame game = new RenderTexture3DGame(); + game.Run(); + } + } +} diff --git a/Texture3DCopy/Texture3DCopy.csproj b/Texture3DCopy/Texture3DCopy.csproj new file mode 100644 index 0000000..5c541ff --- /dev/null +++ b/Texture3DCopy/Texture3DCopy.csproj @@ -0,0 +1,16 @@ + + + + + + + + + Exe + net8.0 + enable + + + + + diff --git a/TextureMipmaps/TextureMipmapsGame.cs b/TextureMipmaps/TextureMipmapsGame.cs index 1d91123..f699726 100644 --- a/TextureMipmaps/TextureMipmapsGame.cs +++ b/TextureMipmaps/TextureMipmapsGame.cs @@ -69,12 +69,14 @@ namespace MoonWorks.Test { var w = texture.Width >> (int) i; var h = texture.Height >> (int) i; - var slice = new TextureSlice + var region = new TextureRegion { - Texture = texture, - MipLevel = i, - BaseLayer = 0, - LayerCount = 1, + TextureSlice = new TextureSlice + { + Texture = texture, + Layer = 0, + MipLevel = i + }, X = 0, Y = 0, Z = 0, @@ -84,7 +86,7 @@ namespace MoonWorks.Test }; resourceUploader.SetTextureDataFromCompressed( - slice, + region, TestUtils.GetTexturePath($"mip{i}.png") ); } @@ -114,7 +116,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/TexturedAnimatedQuad/TexturedAnimatedQuadGame.cs b/TexturedAnimatedQuad/TexturedAnimatedQuadGame.cs index d6ee025..8d0a729 100644 --- a/TexturedAnimatedQuad/TexturedAnimatedQuadGame.cs +++ b/TexturedAnimatedQuad/TexturedAnimatedQuadGame.cs @@ -86,7 +86,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/TexturedQuad/TexturedQuadGame.cs b/TexturedQuad/TexturedQuadGame.cs index 9cd8660..820d587 100644 --- a/TexturedQuad/TexturedQuadGame.cs +++ b/TexturedQuad/TexturedQuadGame.cs @@ -145,7 +145,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/TriangleVertexBuffer/TriangleVertexBufferGame.cs b/TriangleVertexBuffer/TriangleVertexBufferGame.cs index 7976036..58671e0 100644 --- a/TriangleVertexBuffer/TriangleVertexBufferGame.cs +++ b/TriangleVertexBuffer/TriangleVertexBufferGame.cs @@ -48,7 +48,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.DrawPrimitives(0, 1); diff --git a/VertexSampler/VertexSamplerGame.cs b/VertexSampler/VertexSamplerGame.cs index 0ed61fc..cc2572b 100644 --- a/VertexSampler/VertexSamplerGame.cs +++ b/VertexSampler/VertexSamplerGame.cs @@ -1,4 +1,5 @@ -using MoonWorks; +using System; +using MoonWorks; using MoonWorks.Graphics; using MoonWorks.Math.Float; @@ -28,7 +29,6 @@ namespace MoonWorks.Test pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); // Create and populate the GPU resources - texture = Texture.CreateTexture2D(GraphicsDevice, 3, 1, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler); sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp); var resourceUploader = new ResourceUploader(GraphicsDevice); @@ -42,9 +42,10 @@ namespace MoonWorks.Test BufferUsageFlags.Vertex ); - resourceUploader.SetTextureData( - texture, - [Color.Yellow, Color.Indigo, Color.HotPink] + texture = resourceUploader.CreateTexture2D( + new Span([Color.Yellow, Color.Indigo, Color.HotPink]), + 3, + 1 ); resourceUploader.Upload(); @@ -59,7 +60,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindVertexSamplers(new TextureSamplerBinding(texture, sampler)); diff --git a/VideoPlayer/VideoPlayerGame.cs b/VideoPlayer/VideoPlayerGame.cs index 7b56694..589b5d7 100644 --- a/VideoPlayer/VideoPlayerGame.cs +++ b/VideoPlayer/VideoPlayerGame.cs @@ -78,7 +78,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.CornflowerBlue)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.BindVertexBuffers(vertexBuffer); cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); diff --git a/WindowResizing/WindowResizingGame.cs b/WindowResizing/WindowResizingGame.cs index 84507de..4d9dff7 100644 --- a/WindowResizing/WindowResizingGame.cs +++ b/WindowResizing/WindowResizingGame.cs @@ -68,7 +68,7 @@ namespace MoonWorks.Test Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); if (backbuffer != null) { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black)); + cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)); cmdbuf.BindGraphicsPipeline(pipeline); cmdbuf.DrawPrimitives(0, 1); cmdbuf.EndRenderPass();