diff --git a/Common/Content/Shaders/Compiled/CalculateSquares.comp.refresh b/Common/Content/Shaders/Compiled/CalculateSquares.comp.refresh deleted file mode 100644 index 651c75a..0000000 Binary files a/Common/Content/Shaders/Compiled/CalculateSquares.comp.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/CalculateSquares.comp.spv b/Common/Content/Shaders/Compiled/CalculateSquares.comp.spv new file mode 100644 index 0000000..ede2b14 Binary files /dev/null and b/Common/Content/Shaders/Compiled/CalculateSquares.comp.spv differ diff --git a/Common/Content/Shaders/Compiled/FillTexture.comp.refresh b/Common/Content/Shaders/Compiled/FillTexture.comp.refresh deleted file mode 100644 index be505ec..0000000 Binary files a/Common/Content/Shaders/Compiled/FillTexture.comp.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/FillTexture.comp.spv b/Common/Content/Shaders/Compiled/FillTexture.comp.spv new file mode 100644 index 0000000..1cefa51 Binary files /dev/null and b/Common/Content/Shaders/Compiled/FillTexture.comp.spv differ diff --git a/Common/Content/Shaders/Compiled/GradientTexture.comp.refresh b/Common/Content/Shaders/Compiled/GradientTexture.comp.refresh deleted file mode 100644 index 8fb7703..0000000 Binary files a/Common/Content/Shaders/Compiled/GradientTexture.comp.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/GradientTexture.comp.spv b/Common/Content/Shaders/Compiled/GradientTexture.comp.spv new file mode 100644 index 0000000..5cb6514 Binary files /dev/null and b/Common/Content/Shaders/Compiled/GradientTexture.comp.spv differ diff --git a/Common/Content/Shaders/Compiled/PositionColor.vert.refresh b/Common/Content/Shaders/Compiled/PositionColor.vert.refresh deleted file mode 100644 index 26b8c1b..0000000 Binary files a/Common/Content/Shaders/Compiled/PositionColor.vert.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/PositionColor.vert.spv b/Common/Content/Shaders/Compiled/PositionColor.vert.spv new file mode 100644 index 0000000..828a621 Binary files /dev/null and b/Common/Content/Shaders/Compiled/PositionColor.vert.spv differ diff --git a/Common/Content/Shaders/Compiled/PositionColorInstanced.vert.refresh b/Common/Content/Shaders/Compiled/PositionColorInstanced.vert.refresh deleted file mode 100644 index 06c77f4..0000000 Binary files a/Common/Content/Shaders/Compiled/PositionColorInstanced.vert.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/PositionColorInstanced.vert.spv b/Common/Content/Shaders/Compiled/PositionColorInstanced.vert.spv new file mode 100644 index 0000000..e79d719 Binary files /dev/null and b/Common/Content/Shaders/Compiled/PositionColorInstanced.vert.spv differ diff --git a/Common/Content/Shaders/Compiled/PositionColorWithMatrix.vert.refresh b/Common/Content/Shaders/Compiled/PositionColorWithMatrix.vert.refresh deleted file mode 100644 index 3f3df4c..0000000 Binary files a/Common/Content/Shaders/Compiled/PositionColorWithMatrix.vert.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/PositionColorWithMatrix.vert.spv b/Common/Content/Shaders/Compiled/PositionColorWithMatrix.vert.spv new file mode 100644 index 0000000..622555a Binary files /dev/null and b/Common/Content/Shaders/Compiled/PositionColorWithMatrix.vert.spv differ diff --git a/Common/Content/Shaders/Compiled/PositionSampler.vert.refresh b/Common/Content/Shaders/Compiled/PositionSampler.vert.refresh deleted file mode 100644 index 2e5a0cb..0000000 Binary files a/Common/Content/Shaders/Compiled/PositionSampler.vert.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/PositionSampler.vert.spv b/Common/Content/Shaders/Compiled/PositionSampler.vert.spv new file mode 100644 index 0000000..adf679e Binary files /dev/null and b/Common/Content/Shaders/Compiled/PositionSampler.vert.spv differ diff --git a/Common/Content/Shaders/Compiled/RawTriangle.vert.refresh b/Common/Content/Shaders/Compiled/RawTriangle.vert.refresh deleted file mode 100644 index 1d63c88..0000000 Binary files a/Common/Content/Shaders/Compiled/RawTriangle.vert.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/RawTriangle.vert.spv b/Common/Content/Shaders/Compiled/RawTriangle.vert.spv new file mode 100644 index 0000000..a4a9b48 Binary files /dev/null and b/Common/Content/Shaders/Compiled/RawTriangle.vert.spv differ diff --git a/Common/Content/Shaders/Compiled/Skybox.frag.refresh b/Common/Content/Shaders/Compiled/Skybox.frag.refresh deleted file mode 100644 index 2c3754f..0000000 Binary files a/Common/Content/Shaders/Compiled/Skybox.frag.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/Skybox.frag.spv b/Common/Content/Shaders/Compiled/Skybox.frag.spv new file mode 100644 index 0000000..b5ab7c5 Binary files /dev/null and b/Common/Content/Shaders/Compiled/Skybox.frag.spv differ diff --git a/Common/Content/Shaders/Compiled/Skybox.vert.refresh b/Common/Content/Shaders/Compiled/Skybox.vert.refresh deleted file mode 100644 index 6e9f6ef..0000000 Binary files a/Common/Content/Shaders/Compiled/Skybox.vert.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/Skybox.vert.spv b/Common/Content/Shaders/Compiled/Skybox.vert.spv new file mode 100644 index 0000000..79660f5 Binary files /dev/null and b/Common/Content/Shaders/Compiled/Skybox.vert.spv differ diff --git a/Common/Content/Shaders/Compiled/SolidColor.frag.refresh b/Common/Content/Shaders/Compiled/SolidColor.frag.refresh deleted file mode 100644 index 764fd5b..0000000 Binary files a/Common/Content/Shaders/Compiled/SolidColor.frag.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/SolidColor.frag.spv b/Common/Content/Shaders/Compiled/SolidColor.frag.spv new file mode 100644 index 0000000..0e27a74 Binary files /dev/null and b/Common/Content/Shaders/Compiled/SolidColor.frag.spv differ diff --git a/Common/Content/Shaders/Compiled/TexturedDepthQuad.frag.refresh b/Common/Content/Shaders/Compiled/TexturedDepthQuad.frag.spv similarity index 50% rename from Common/Content/Shaders/Compiled/TexturedDepthQuad.frag.refresh rename to Common/Content/Shaders/Compiled/TexturedDepthQuad.frag.spv index b1b7821..1284b0e 100644 Binary files a/Common/Content/Shaders/Compiled/TexturedDepthQuad.frag.refresh and b/Common/Content/Shaders/Compiled/TexturedDepthQuad.frag.spv differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuad.frag.refresh b/Common/Content/Shaders/Compiled/TexturedQuad.frag.refresh deleted file mode 100644 index f3ba937..0000000 Binary files a/Common/Content/Shaders/Compiled/TexturedQuad.frag.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuad.frag.spv b/Common/Content/Shaders/Compiled/TexturedQuad.frag.spv new file mode 100644 index 0000000..d156867 Binary files /dev/null and b/Common/Content/Shaders/Compiled/TexturedQuad.frag.spv differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuad.vert.refresh b/Common/Content/Shaders/Compiled/TexturedQuad.vert.refresh deleted file mode 100644 index aa9f296..0000000 Binary files a/Common/Content/Shaders/Compiled/TexturedQuad.vert.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuad.vert.spv b/Common/Content/Shaders/Compiled/TexturedQuad.vert.spv new file mode 100644 index 0000000..87ce0ba Binary files /dev/null and b/Common/Content/Shaders/Compiled/TexturedQuad.vert.spv differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuad2DArray.frag.refresh b/Common/Content/Shaders/Compiled/TexturedQuad2DArray.frag.refresh deleted file mode 100644 index a8aac42..0000000 Binary files a/Common/Content/Shaders/Compiled/TexturedQuad2DArray.frag.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuad2DArray.frag.spv b/Common/Content/Shaders/Compiled/TexturedQuad2DArray.frag.spv new file mode 100644 index 0000000..c7ecf6d Binary files /dev/null and b/Common/Content/Shaders/Compiled/TexturedQuad2DArray.frag.spv differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuad3D.frag.refresh b/Common/Content/Shaders/Compiled/TexturedQuad3D.frag.refresh deleted file mode 100644 index 6f6d422..0000000 Binary files a/Common/Content/Shaders/Compiled/TexturedQuad3D.frag.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuad3D.frag.spv b/Common/Content/Shaders/Compiled/TexturedQuad3D.frag.spv new file mode 100644 index 0000000..5d2f91b Binary files /dev/null and b/Common/Content/Shaders/Compiled/TexturedQuad3D.frag.spv differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuadWithMatrix.vert.refresh b/Common/Content/Shaders/Compiled/TexturedQuadWithMatrix.vert.refresh deleted file mode 100644 index e82af5a..0000000 Binary files a/Common/Content/Shaders/Compiled/TexturedQuadWithMatrix.vert.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuadWithMatrix.vert.spv b/Common/Content/Shaders/Compiled/TexturedQuadWithMatrix.vert.spv new file mode 100644 index 0000000..83647f1 Binary files /dev/null and b/Common/Content/Shaders/Compiled/TexturedQuadWithMatrix.vert.spv differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuadWithMultiplyColor.frag.refresh b/Common/Content/Shaders/Compiled/TexturedQuadWithMultiplyColor.frag.refresh deleted file mode 100644 index 615b0f3..0000000 Binary files a/Common/Content/Shaders/Compiled/TexturedQuadWithMultiplyColor.frag.refresh and /dev/null differ diff --git a/Common/Content/Shaders/Compiled/TexturedQuadWithMultiplyColor.frag.spv b/Common/Content/Shaders/Compiled/TexturedQuadWithMultiplyColor.frag.spv new file mode 100644 index 0000000..2b906c6 Binary files /dev/null and b/Common/Content/Shaders/Compiled/TexturedQuadWithMultiplyColor.frag.spv differ diff --git a/Common/Content/Shaders/Source/CalculateSquares.comp b/Common/Content/Shaders/Source/CalculateSquares.comp index 888772a..b8e2180 100644 --- a/Common/Content/Shaders/Source/CalculateSquares.comp +++ b/Common/Content/Shaders/Source/CalculateSquares.comp @@ -1,7 +1,7 @@ #version 450 layout (local_size_x = 8) in; -layout (set = 0, binding = 0) buffer outBuffer +layout (set = 1, binding = 0) buffer outBuffer { uint squares[]; }; diff --git a/Common/Content/Shaders/Source/GradientTexture.comp b/Common/Content/Shaders/Source/GradientTexture.comp index 5541446..bf43ea9 100644 --- a/Common/Content/Shaders/Source/GradientTexture.comp +++ b/Common/Content/Shaders/Source/GradientTexture.comp @@ -1,23 +1,19 @@ #version 450 -#define LOCAL_SIZE 8 - -layout (local_size_x = LOCAL_SIZE, local_size_y = LOCAL_SIZE, local_size_z = 1) in; +layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in; layout (set = 1, binding = 0, rgba8) uniform writeonly image2D outImage; -layout(set = 2, binding = 0) uniform UBO +layout (set = 2, binding = 0) uniform UBO { - uvec2 workgroupSize; + float time; } ubo; void main() { + vec2 size = imageSize(outImage); vec2 coord = gl_GlobalInvocationID.xy; - vec2 totalWorkgroupSize = vec2(ubo.workgroupSize) * vec2(LOCAL_SIZE); - vec4 col = vec4( - coord.x / totalWorkgroupSize.x, - coord.y / totalWorkgroupSize.y, - 1.0, - 1.0 - ); - imageStore(outImage, ivec2(coord), col); + vec2 uv = coord / size; + + vec3 col = 0.5 + 0.5*cos(ubo.time + uv.xyx + vec3(0, 2, 4)); + + imageStore(outImage, ivec2(coord), vec4(col, 1.0)); } diff --git a/Common/Content/Shaders/Source/PositionColorWithMatrix.vert b/Common/Content/Shaders/Source/PositionColorWithMatrix.vert index 899c06a..3cca094 100644 --- a/Common/Content/Shaders/Source/PositionColorWithMatrix.vert +++ b/Common/Content/Shaders/Source/PositionColorWithMatrix.vert @@ -5,7 +5,7 @@ layout (location = 1) in vec4 Color; layout (location = 0) out vec4 outColor; -layout (binding = 0, set = 2) uniform UniformBlock +layout (set = 1, binding = 0) uniform UniformBlock { mat4x4 MatrixTransform; }; diff --git a/Common/Content/Shaders/Source/PositionSampler.vert b/Common/Content/Shaders/Source/PositionSampler.vert index f0fa89c..ae5c530 100644 --- a/Common/Content/Shaders/Source/PositionSampler.vert +++ b/Common/Content/Shaders/Source/PositionSampler.vert @@ -5,7 +5,7 @@ layout (location = 1) in vec2 TexCoord; layout (location = 0) out vec4 outColor; -layout(binding = 0, set = 0) uniform sampler2D Sampler; +layout(set = 0, binding = 0) uniform sampler2D Sampler; void main() { diff --git a/Common/Content/Shaders/Source/RawTriangle.vert b/Common/Content/Shaders/Source/RawTriangle.vert index fba105d..d1e740e 100644 --- a/Common/Content/Shaders/Source/RawTriangle.vert +++ b/Common/Content/Shaders/Source/RawTriangle.vert @@ -8,17 +8,17 @@ void main() if (gl_VertexIndex == 0) { - pos = vec2(-1, 1); + pos = vec2(-1, -1); outColor = vec4(1, 0, 0, 1); } else if (gl_VertexIndex == 1) { - pos = vec2(1, 1); + pos = vec2(1, -1); outColor = vec4(0, 1, 0, 1); } else if (gl_VertexIndex == 2) { - pos = vec2(0, -1); + pos = vec2(0, 1); outColor = vec4(0, 0, 1, 1); } diff --git a/Common/Content/Shaders/Source/Skybox.frag b/Common/Content/Shaders/Source/Skybox.frag index 905b196..e1d156e 100644 --- a/Common/Content/Shaders/Source/Skybox.frag +++ b/Common/Content/Shaders/Source/Skybox.frag @@ -3,7 +3,7 @@ layout(location = 0) in vec3 TexCoord; layout(location = 0) out vec4 FragColor; -layout(binding = 0, set = 1) uniform samplerCube SkyboxSampler; +layout(set = 2, binding = 0) uniform samplerCube SkyboxSampler; void main() { diff --git a/Common/Content/Shaders/Source/Skybox.vert b/Common/Content/Shaders/Source/Skybox.vert index 9cd3885..8b7d4e9 100644 --- a/Common/Content/Shaders/Source/Skybox.vert +++ b/Common/Content/Shaders/Source/Skybox.vert @@ -3,7 +3,7 @@ layout(location = 0) in vec3 inPos; layout(location = 0) out vec3 vPos; -layout(set = 2, binding = 0) uniform UBO +layout(set = 1, binding = 0) uniform UBO { mat4 ViewProjection; } ubo; diff --git a/Common/Content/Shaders/Source/TexturedDepthQuad.frag b/Common/Content/Shaders/Source/TexturedDepthQuad.frag index 07feffe..fe32863 100644 --- a/Common/Content/Shaders/Source/TexturedDepthQuad.frag +++ b/Common/Content/Shaders/Source/TexturedDepthQuad.frag @@ -1,12 +1,11 @@ #version 450 layout (location = 0) in vec2 TexCoord; - layout (location = 0) out vec4 FragColor; -layout(binding = 0, set = 1) uniform sampler2D Sampler; +layout(set = 2, binding = 0) uniform sampler2D Sampler; -layout (binding = 0, set = 3) uniform UniformBlock +layout (set = 3, binding = 0) uniform UniformBlock { float zNear; float zFar; diff --git a/Common/Content/Shaders/Source/TexturedQuad.frag b/Common/Content/Shaders/Source/TexturedQuad.frag index c4237bd..f0d8a33 100644 --- a/Common/Content/Shaders/Source/TexturedQuad.frag +++ b/Common/Content/Shaders/Source/TexturedQuad.frag @@ -4,7 +4,7 @@ layout (location = 0) in vec2 TexCoord; layout (location = 0) out vec4 FragColor; -layout(binding = 0, set = 1) uniform sampler2D Sampler; +layout(set = 2, binding = 0) uniform sampler2D Sampler; void main() { diff --git a/Common/Content/Shaders/Source/TexturedQuad2DArray.frag b/Common/Content/Shaders/Source/TexturedQuad2DArray.frag index 6390b29..9ae90df 100644 --- a/Common/Content/Shaders/Source/TexturedQuad2DArray.frag +++ b/Common/Content/Shaders/Source/TexturedQuad2DArray.frag @@ -4,9 +4,9 @@ layout (location = 0) in vec2 TexCoord; layout (location = 0) out vec4 FragColor; -layout(binding = 0, set = 1) uniform sampler2DArray Sampler; +layout(set = 2, binding = 0) uniform sampler2DArray Sampler; -layout (binding = 0, set = 3) uniform UniformBlock +layout (set = 3, binding = 0) uniform UniformBlock { float depth; }; diff --git a/Common/Content/Shaders/Source/TexturedQuad3D.frag b/Common/Content/Shaders/Source/TexturedQuad3D.frag index 8a9119e..81ceb12 100644 --- a/Common/Content/Shaders/Source/TexturedQuad3D.frag +++ b/Common/Content/Shaders/Source/TexturedQuad3D.frag @@ -4,9 +4,9 @@ layout (location = 0) in vec2 TexCoord; layout (location = 0) out vec4 FragColor; -layout(binding = 0, set = 1) uniform sampler3D Sampler; +layout(set = 2, binding = 0) uniform sampler3D Sampler; -layout (binding = 0, set = 3) uniform UniformBlock +layout (set = 3, binding = 0) uniform UniformBlock { float depth; }; diff --git a/Common/Content/Shaders/Source/TexturedQuadWithMatrix.vert b/Common/Content/Shaders/Source/TexturedQuadWithMatrix.vert index 080dfb5..0efdb49 100644 --- a/Common/Content/Shaders/Source/TexturedQuadWithMatrix.vert +++ b/Common/Content/Shaders/Source/TexturedQuadWithMatrix.vert @@ -5,7 +5,7 @@ layout (location = 1) in vec2 TexCoord; layout (location = 0) out vec2 outTexCoord; -layout (binding = 0, set = 2) uniform UniformBlock +layout (set = 1, binding = 0) uniform UniformBlock { mat4x4 MatrixTransform; }; diff --git a/Common/Content/Shaders/Source/TexturedQuadWithMultiplyColor.frag b/Common/Content/Shaders/Source/TexturedQuadWithMultiplyColor.frag index 5e0db2e..7d395df 100644 --- a/Common/Content/Shaders/Source/TexturedQuadWithMultiplyColor.frag +++ b/Common/Content/Shaders/Source/TexturedQuadWithMultiplyColor.frag @@ -4,9 +4,9 @@ layout (location = 0) in vec2 TexCoord; layout (location = 0) out vec4 FragColor; -layout(binding = 0, set = 1) uniform sampler2D Sampler; +layout(set = 2, binding = 0) uniform sampler2D Sampler; -layout (binding = 0, set = 3) uniform UniformBlock +layout (set = 3, binding = 0) uniform UniformBlock { vec4 MultiplyColor; }; diff --git a/Common/TestUtils.cs b/Common/TestUtils.cs index bd378e3..f3fd896 100644 --- a/Common/TestUtils.cs +++ b/Common/TestUtils.cs @@ -53,7 +53,7 @@ public static class TestUtils public static string GetShaderPath(string shaderName) { - return SDL2.SDL.SDL_GetBasePath() + "Content/Shaders/Compiled/" + shaderName + ".refresh"; + return SDL2.SDL.SDL_GetBasePath() + "Content/Shaders/Compiled/" + shaderName + ".spv"; } public static string GetTexturePath(string textureName) @@ -73,7 +73,7 @@ public static class TestUtils Right // D/right arrow on keyboard, right face button on gamepad } - public static bool CheckButtonPressed(Input.Inputs inputs, ButtonType buttonType) + public static bool CheckButtonPressed(MoonWorks.Input.Inputs inputs, ButtonType buttonType) { bool pressed = false; @@ -81,28 +81,31 @@ public static class TestUtils { pressed = ( (inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsPressed) || - inputs.Keyboard.IsPressed(Input.KeyCode.Left) + inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.Left) || + inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.A) ); } else if (buttonType == ButtonType.Bottom) { pressed = ( (inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsPressed) || - inputs.Keyboard.IsPressed(Input.KeyCode.Down) + inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.Down) || + inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.S) ); } else if (buttonType == ButtonType.Right) { pressed = ( (inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsPressed) || - inputs.Keyboard.IsPressed(Input.KeyCode.Right) + inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.Right) || + inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.D) ); } return pressed; } - public static bool CheckButtonDown(Input.Inputs inputs, ButtonType buttonType) + public static bool CheckButtonDown(MoonWorks.Input.Inputs inputs, ButtonType buttonType) { bool down = false; @@ -110,24 +113,24 @@ public static class TestUtils { down = ( (inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadLeft.IsDown) || - inputs.Keyboard.IsDown(Input.KeyCode.A) || - inputs.Keyboard.IsDown(Input.KeyCode.Left) + inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.Left) || + inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.A) ); } else if (buttonType == ButtonType.Bottom) { down = ( (inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadDown.IsDown) || - inputs.Keyboard.IsDown(Input.KeyCode.S) || - inputs.Keyboard.IsDown(Input.KeyCode.Down) + inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.Down) || + inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.S) ); } else if (buttonType == ButtonType.Right) { down = ( (inputs.GamepadExists(0) && inputs.GetGamepad(0).DpadRight.IsDown) || - inputs.Keyboard.IsDown(Input.KeyCode.D) || - inputs.Keyboard.IsDown(Input.KeyCode.Right) + inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.Right) || + inputs.Keyboard.IsDown(MoonWorks.Input.KeyCode.D) ); } diff --git a/CopyMoonlibs.targets b/CopyMoonlibs.targets index 98312e8..3694e83 100644 --- a/CopyMoonlibs.targets +++ b/CopyMoonlibs.targets @@ -6,43 +6,43 @@ - + %(RecursiveDir)%(Filename)%(Extension) Always - + %(RecursiveDir)%(Filename)%(Extension) Always - + %(RecursiveDir)%(Filename)%(Extension) Always - + %(RecursiveDir)%(Filename)%(Extension) Always - + %(RecursiveDir)%(Filename)%(Extension) Always - + %(RecursiveDir)%(Filename)%(Extension) Always - + %(RecursiveDir)%(Filename)%(Extension) Always - + %(RecursiveDir)%(Filename)%(Extension) Always - + %(RecursiveDir)%(Filename)%(Extension) Always diff --git a/Examples/BasicComputeGame.cs b/Examples/BasicComputeExample.cs similarity index 97% rename from Examples/BasicComputeGame.cs rename to Examples/BasicComputeExample.cs index a4c204b..8c7b6cf 100644 --- a/Examples/BasicComputeGame.cs +++ b/Examples/BasicComputeExample.cs @@ -1,5 +1,6 @@ using MoonWorks; using MoonWorks.Graphics; +using MoonWorks.Input; using MoonWorks.Math.Float; namespace MoonWorksGraphicsTests; @@ -11,7 +12,7 @@ class BasicComputeExample : Example private Sampler Sampler; private GpuBuffer VertexBuffer; - public override void Init(Window window, GraphicsDevice graphicsDevice) + public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs) { Window = window; GraphicsDevice = graphicsDevice; @@ -73,7 +74,9 @@ class BasicComputeExample : Example fragShaderModule ); drawPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding(); - drawPipelineCreateInfo.FragmentShaderResourceInfo.SamplerCount = 1; + drawPipelineCreateInfo.FragmentShaderResourceInfo = new GraphicsPipelineResourceInfo{ + SamplerCount = 1 + }; DrawPipeline = new GraphicsPipeline( GraphicsDevice, diff --git a/Examples/BasicStencilGame.cs b/Examples/BasicStencilExample.cs similarity index 67% rename from Examples/BasicStencilGame.cs rename to Examples/BasicStencilExample.cs index 0fdbdf0..2b1efd3 100644 --- a/Examples/BasicStencilGame.cs +++ b/Examples/BasicStencilExample.cs @@ -1,21 +1,24 @@ using MoonWorks; using MoonWorks.Graphics; +using MoonWorks.Input; using MoonWorks.Math.Float; namespace MoonWorksGraphicsTests { - class BasicStencilGame : Example + class BasicStencilExample : Example { - private GraphicsPipeline maskerPipeline; - private GraphicsPipeline maskeePipeline; - private GpuBuffer vertexBuffer; - private Texture depthStencilTexture; + private GraphicsPipeline MaskerPipeline; + private GraphicsPipeline MaskeePipeline; + private GpuBuffer VertexBuffer; + private Texture DepthStencilTexture; - public override void Init(Window window, GraphicsDevice graphicsDevice) + public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs) { Window = window; GraphicsDevice = graphicsDevice; + Window.SetTitle("BasicStencil"); + // Load the shaders Shader vertShaderModule = new Shader( GraphicsDevice, @@ -52,7 +55,7 @@ namespace MoonWorksGraphicsTests Reference = 1, WriteMask = 0xFF }; - maskerPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); + MaskerPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); pipelineCreateInfo.DepthStencilState = new DepthStencilState { @@ -65,10 +68,10 @@ namespace MoonWorksGraphicsTests CompareMask = 0xFF, WriteMask = 0 }; - maskeePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); + MaskeePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); // Create and populate the GPU resources - depthStencilTexture = Texture.CreateTexture2D( + DepthStencilTexture = Texture.CreateTexture2D( GraphicsDevice, Window.Width, Window.Height, @@ -78,15 +81,15 @@ namespace MoonWorksGraphicsTests var resourceUploader = new ResourceUploader(GraphicsDevice); - vertexBuffer = resourceUploader.CreateBuffer( + VertexBuffer = resourceUploader.CreateBuffer( [ - new PositionColorVertex(new Vector3(-0.5f, 0.5f, 0), Color.Yellow), - new PositionColorVertex(new Vector3(0.5f, 0.5f, 0), Color.Yellow), - new PositionColorVertex(new Vector3(0, -0.5f, 0), Color.Yellow), + new PositionColorVertex(new Vector3(-0.5f, -0.5f, 0), Color.Yellow), + new PositionColorVertex(new Vector3( 0.5f, -0.5f, 0), Color.Yellow), + new PositionColorVertex(new Vector3( 0, 0.5f, 0), Color.Yellow), - new PositionColorVertex(new Vector3(-1, 1, 0), Color.Red), - new PositionColorVertex(new Vector3(1, 1, 0), Color.Lime), - new PositionColorVertex(new Vector3(0, -1, 0), Color.Blue), + new PositionColorVertex(new Vector3(-1, -1, 0), Color.Red), + new PositionColorVertex(new Vector3( 1, -1, 0), Color.Lime), + new PositionColorVertex(new Vector3( 0, 1, 0), Color.Blue), ], BufferUsageFlags.Vertex ); @@ -104,13 +107,13 @@ namespace MoonWorksGraphicsTests if (swapchainTexture != null) { var renderPass = cmdbuf.BeginRenderPass( - new DepthStencilAttachmentInfo(depthStencilTexture, true, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare), + new DepthStencilAttachmentInfo(DepthStencilTexture, true, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare), new ColorAttachmentInfo(swapchainTexture, false, Color.Black) ); - renderPass.BindGraphicsPipeline(maskerPipeline); - renderPass.BindVertexBuffer(vertexBuffer); + renderPass.BindGraphicsPipeline(MaskerPipeline); + renderPass.BindVertexBuffer(VertexBuffer); renderPass.DrawPrimitives(0, 1); - renderPass.BindGraphicsPipeline(maskeePipeline); + renderPass.BindGraphicsPipeline(MaskeePipeline); renderPass.DrawPrimitives(3, 1); cmdbuf.EndRenderPass(renderPass); } @@ -119,7 +122,10 @@ namespace MoonWorksGraphicsTests public override void Destroy() { - throw new System.NotImplementedException(); + MaskerPipeline.Dispose(); + MaskeePipeline.Dispose(); + VertexBuffer.Dispose(); + DepthStencilTexture.Dispose(); } } } diff --git a/Examples/BasicTriangleExample.cs b/Examples/BasicTriangleExample.cs new file mode 100644 index 0000000..4516fea --- /dev/null +++ b/Examples/BasicTriangleExample.cs @@ -0,0 +1,111 @@ +using MoonWorks; +using MoonWorks.Graphics; +using MoonWorks.Input; + +namespace MoonWorksGraphicsTests; + +class BasicTriangleExample : Example +{ + private GraphicsPipeline FillPipeline; + private GraphicsPipeline LinePipeline; + + private Viewport SmallViewport = new Viewport(160, 120, 320, 240); + private Rect ScissorRect = new Rect(320, 240, 320, 240); + + private bool UseWireframeMode; + private bool UseSmallViewport; + private bool UseScissorRect; + + public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs) + { + Window = window; + GraphicsDevice = graphicsDevice; + Inputs = inputs; + + Window.SetTitle("BasicTriangle"); + + Logger.LogInfo("Press Left to toggle wireframe mode\nPress Down to toggle small viewport\nPress Right to toggle scissor rect"); + + Shader vertShaderModule = new Shader( + GraphicsDevice, + TestUtils.GetShaderPath("RawTriangle.vert"), + "main", + ShaderStage.Vertex, + ShaderFormat.SPIRV + ); + + Shader fragShaderModule = new Shader( + GraphicsDevice, + TestUtils.GetShaderPath("SolidColor.frag"), + "main", + ShaderStage.Fragment, + ShaderFormat.SPIRV + ); + + GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( + Window.SwapchainFormat, + vertShaderModule, + fragShaderModule + ); + FillPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); + + pipelineCreateInfo.RasterizerState.FillMode = FillMode.Line; + LinePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); + } + + public override void Update(System.TimeSpan delta) + { + if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left)) + { + UseWireframeMode = !UseWireframeMode; + Logger.LogInfo("Using wireframe mode: " + UseWireframeMode); + } + + if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom)) + { + UseSmallViewport = !UseSmallViewport; + Logger.LogInfo("Using small viewport: " + UseSmallViewport); + } + + if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right)) + { + UseScissorRect = !UseScissorRect; + Logger.LogInfo("Using scissor rect: " + UseScissorRect); + } + } + + public override void Draw(double alpha) + { + CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window); + if (swapchainTexture != null) + { + var renderPass = cmdbuf.BeginRenderPass( + new ColorAttachmentInfo(swapchainTexture, false, Color.Black) + ); + + renderPass.BindGraphicsPipeline(UseWireframeMode ? LinePipeline : FillPipeline); + + if (UseSmallViewport) + { + renderPass.SetViewport(SmallViewport); + } + if (UseScissorRect) + { + renderPass.SetScissor(ScissorRect); + } + + renderPass.DrawPrimitives(0, 1); + + cmdbuf.EndRenderPass(renderPass); + } + + GraphicsDevice.Submit(cmdbuf); + } + + public override void Destroy() + { + FillPipeline.Dispose(); + LinePipeline.Dispose(); + } +} diff --git a/Examples/BasicTriangleGame.cs b/Examples/BasicTriangleGame.cs deleted file mode 100644 index dfde253..0000000 --- a/Examples/BasicTriangleGame.cs +++ /dev/null @@ -1,86 +0,0 @@ -using MoonWorks.Graphics; - -namespace MoonWorks.Test -{ - class BasicTriangleGame : Game - { - private GraphicsPipeline fillPipeline; - private GraphicsPipeline linePipeline; - - private Viewport smallViewport = new Viewport(160, 120, 320, 240); - private Rect scissorRect = new Rect(320, 240, 320, 240); - - private bool useWireframeMode; - private bool useSmallViewport; - private bool useScissorRect; - - public BasicTriangleGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true) - { - Logger.LogInfo("Press Left to toggle wireframe mode\nPress Down to toggle small viewport\nPress Right to toggle scissor rect"); - - ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert")); - ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag")); - - GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( - MainWindow.SwapchainFormat, - vertShaderModule, - fragShaderModule - ); - fillPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); - - pipelineCreateInfo.RasterizerState.FillMode = FillMode.Line; - linePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); - } - - protected override void Update(System.TimeSpan delta) - { - if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left)) - { - useWireframeMode = !useWireframeMode; - Logger.LogInfo("Using wireframe mode: " + useWireframeMode); - } - - if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Bottom)) - { - useSmallViewport = !useSmallViewport; - Logger.LogInfo("Using small viewport: " + useSmallViewport); - } - - if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right)) - { - useScissorRect = !useScissorRect; - Logger.LogInfo("Using scissor rect: " + useScissorRect); - } - } - - protected override void Draw(double alpha) - { - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); - if (backbuffer != null) - { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black)); - cmdbuf.BindGraphicsPipeline(useWireframeMode ? linePipeline : fillPipeline); - - if (useSmallViewport) - { - cmdbuf.SetViewport(smallViewport); - } - if (useScissorRect) - { - cmdbuf.SetScissor(scissorRect); - } - - cmdbuf.DrawPrimitives(0, 1); - cmdbuf.EndRenderPass(); - } - GraphicsDevice.Submit(cmdbuf); - } - - public static void Main(string[] args) - { - BasicTriangleGame game = new BasicTriangleGame(); - game.Run(); - } - } -} diff --git a/Examples/ClearScreenExample.cs b/Examples/ClearScreenExample.cs new file mode 100644 index 0000000..a02a3ff --- /dev/null +++ b/Examples/ClearScreenExample.cs @@ -0,0 +1,36 @@ +using MoonWorks; +using MoonWorks.Graphics; +using MoonWorks.Input; + +namespace MoonWorksGraphicsTests; + +class ClearScreenExample : Example +{ + public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs) + { + Window = window; + GraphicsDevice = graphicsDevice; + + Window.SetTitle("ClearScreen"); + } + + public override void Update(System.TimeSpan delta) { } + + public override void Draw(double alpha) + { + CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window); + if (swapchainTexture != null) + { + var renderPass = cmdbuf.BeginRenderPass( + new ColorAttachmentInfo(swapchainTexture, false, Color.CornflowerBlue) + ); + cmdbuf.EndRenderPass(renderPass); + } + GraphicsDevice.Submit(cmdbuf); + } + + public override void Destroy() + { + } +} diff --git a/Examples/ClearScreenGame.cs b/Examples/ClearScreenGame.cs deleted file mode 100644 index a523645..0000000 --- a/Examples/ClearScreenGame.cs +++ /dev/null @@ -1,30 +0,0 @@ -using MoonWorks; -using MoonWorks.Graphics; - -namespace MoonWorks.Test -{ - class ClearScreenGame : Game - { - public ClearScreenGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true) { } - - protected override void Update(System.TimeSpan delta) { } - - protected override void Draw(double alpha) - { - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); - if (backbuffer != null) - { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue)); - cmdbuf.EndRenderPass(); - } - GraphicsDevice.Submit(cmdbuf); - } - - public static void Main(string[] args) - { - ClearScreenGame game = new ClearScreenGame(); - game.Run(); - } - } -} diff --git a/Examples/ClearScreen_MultiWindowExample.cs b/Examples/ClearScreen_MultiWindowExample.cs new file mode 100644 index 0000000..df9d4d8 --- /dev/null +++ b/Examples/ClearScreen_MultiWindowExample.cs @@ -0,0 +1,71 @@ +using MoonWorks; +using MoonWorks.Graphics; +using MoonWorks.Input; + +namespace MoonWorksGraphicsTests +{ + class ClearScreen_MultiWindowExample : Example + { + private Window SecondaryWindow; + + public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs) + { + Window = window; + GraphicsDevice = graphicsDevice; + + var (windowX, windowY) = Window.Position; + Window.SetPosition(windowX - 360, windowY); + + SecondaryWindow = new Window( + new WindowCreateInfo("Secondary Window", 640, 480, ScreenMode.Windowed, SwapchainComposition.SDR, PresentMode.VSync, false, false), + SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN + ); + (windowX, windowY) = SecondaryWindow.Position; + SecondaryWindow.SetPosition(windowX + 360, windowY); + + GraphicsDevice.ClaimWindow(SecondaryWindow, SwapchainComposition.SDR, PresentMode.VSync); + } + + public override void Update(System.TimeSpan delta) { } + + public override void Draw(double alpha) + { + CommandBuffer cmdbuf; + Texture swapchainTexture; + + if (Window.Claimed) + { + cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window); + if (swapchainTexture != null) + { + var renderPass = cmdbuf.BeginRenderPass( + new ColorAttachmentInfo(swapchainTexture, false, Color.CornflowerBlue) + ); + cmdbuf.EndRenderPass(renderPass); + } + GraphicsDevice.Submit(cmdbuf); + } + + if (SecondaryWindow.Claimed) + { + cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + swapchainTexture = cmdbuf.AcquireSwapchainTexture(SecondaryWindow); + if (swapchainTexture != null) + { + var renderPass = cmdbuf.BeginRenderPass( + new ColorAttachmentInfo(swapchainTexture, false, Color.Aquamarine) + ); + cmdbuf.EndRenderPass(renderPass); + } + GraphicsDevice.Submit(cmdbuf); + } + } + + public override void Destroy() + { + GraphicsDevice.UnclaimWindow(SecondaryWindow); + SecondaryWindow.Dispose(); + } + } +} diff --git a/Examples/ClearScreen_MultiWindowGame.cs b/Examples/ClearScreen_MultiWindowGame.cs deleted file mode 100644 index 70e8efe..0000000 --- a/Examples/ClearScreen_MultiWindowGame.cs +++ /dev/null @@ -1,62 +0,0 @@ -using MoonWorks; -using MoonWorks.Graphics; - -namespace MoonWorks.Test -{ - class ClearScreen_MultiWindowGame : Game - { - private Window secondaryWindow; - - public ClearScreen_MultiWindowGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true) - { - var (windowX, windowY) = MainWindow.Position; - MainWindow.SetPosition(windowX - 360, windowY); - - secondaryWindow = new Window( - new WindowCreateInfo("Secondary Window", 640, 480, ScreenMode.Windowed, PresentMode.FIFO, false, false), - GraphicsDevice.WindowFlags - ); - (windowX, windowY) = secondaryWindow.Position; - secondaryWindow.SetPosition(windowX + 360, windowY); - GraphicsDevice.ClaimWindow(secondaryWindow, PresentMode.FIFO); - } - - protected override void Update(System.TimeSpan delta) { } - - protected override void Draw(double alpha) - { - CommandBuffer cmdbuf; - Texture? backbuffer; - - if (MainWindow.Claimed) - { - cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); - if (backbuffer != null) - { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue)); - cmdbuf.EndRenderPass(); - } - GraphicsDevice.Submit(cmdbuf); - } - - if (secondaryWindow.Claimed) - { - cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - backbuffer = cmdbuf.AcquireSwapchainTexture(secondaryWindow); - if (backbuffer != null) - { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Aquamarine)); - cmdbuf.EndRenderPass(); - } - GraphicsDevice.Submit(cmdbuf); - } - } - - public static void Main(string[] args) - { - ClearScreen_MultiWindowGame game = new ClearScreen_MultiWindowGame(); - game.Run(); - } - } -} diff --git a/Examples/CompressedTexturesExample.cs b/Examples/CompressedTexturesExample.cs new file mode 100644 index 0000000..e2b9aee --- /dev/null +++ b/Examples/CompressedTexturesExample.cs @@ -0,0 +1,160 @@ +using MoonWorks; +using MoonWorks.Graphics; +using MoonWorks.Input; +using MoonWorks.Math.Float; + +namespace MoonWorksGraphicsTests; + +class CompressedTexturesExample : Example +{ + private GraphicsPipeline Pipeline; + private GpuBuffer VertexBuffer; + private GpuBuffer IndexBuffer; + private Sampler Sampler; + private Texture[] Textures; + private string[] TextureNames = + [ + "BC1", + "BC2", + "BC3", + "BC7" + ]; + + private int CurrentTextureIndex; + + public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs) + { + Window = window; + GraphicsDevice = graphicsDevice; + Inputs = inputs; + + Logger.LogInfo("Press Left and Right to cycle between textures"); + Logger.LogInfo("Setting texture to: " + TextureNames[0]); + + // Load the shaders + Shader vertShaderModule = new Shader( + GraphicsDevice, + TestUtils.GetShaderPath("TexturedQuad.vert"), + "main", + ShaderStage.Vertex, + ShaderFormat.SPIRV + ); + + Shader fragShaderModule = new Shader( + GraphicsDevice, + TestUtils.GetShaderPath("TexturedQuad.frag"), + "main", + ShaderStage.Fragment, + ShaderFormat.SPIRV + ); + + // Create the graphics pipeline + GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( + Window.SwapchainFormat, + vertShaderModule, + fragShaderModule + ); + pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding(); + pipelineCreateInfo.FragmentShaderResourceInfo = new GraphicsPipelineResourceInfo + { + SamplerCount = 1 + }; + Pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); + + // Create sampler + Sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap); + + // Create texture array + Textures = new Texture[TextureNames.Length]; + + // 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 + ); + + for (int i = 0; i < TextureNames.Length; i += 1) + { + Logger.LogInfo(TextureNames[i]); + Textures[i] = resourceUploader.CreateTextureFromDDS(TestUtils.GetTexturePath(TextureNames[i] + ".dds")); + } + + resourceUploader.Upload(); + resourceUploader.Dispose(); + } + + public override void Update(System.TimeSpan delta) + { + int prevSamplerIndex = CurrentTextureIndex; + + if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left)) + { + CurrentTextureIndex -= 1; + if (CurrentTextureIndex < 0) + { + CurrentTextureIndex = TextureNames.Length - 1; + } + } + + if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right)) + { + CurrentTextureIndex += 1; + if (CurrentTextureIndex >= TextureNames.Length) + { + CurrentTextureIndex = 0; + } + } + + if (prevSamplerIndex != CurrentTextureIndex) + { + Logger.LogInfo("Setting texture to: " + TextureNames[CurrentTextureIndex]); + } + } + + public override void Draw(double alpha) + { + CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window); + if (swapchainTexture != null) + { + var renderPass = cmdbuf.BeginRenderPass( + new ColorAttachmentInfo(swapchainTexture, false, Color.Black) + ); + renderPass.BindGraphicsPipeline(Pipeline); + renderPass.BindVertexBuffer(VertexBuffer); + renderPass.BindIndexBuffer(IndexBuffer, IndexElementSize.Sixteen); + renderPass.BindFragmentSampler(new TextureSamplerBinding(Textures[CurrentTextureIndex], Sampler)); + renderPass.DrawIndexedPrimitives(0, 0, 2); + cmdbuf.EndRenderPass(renderPass); + } + GraphicsDevice.Submit(cmdbuf); + } + + public override void Destroy() + { + Pipeline.Dispose(); + VertexBuffer.Dispose(); + IndexBuffer.Dispose(); + Sampler.Dispose(); + + for (int i = 0; i < TextureNames.Length; i += 1) + { + Textures[i].Dispose(); + } + } +} diff --git a/Examples/CompressedTexturesGame.cs b/Examples/CompressedTexturesGame.cs deleted file mode 100644 index 729ccb6..0000000 --- a/Examples/CompressedTexturesGame.cs +++ /dev/null @@ -1,131 +0,0 @@ -using MoonWorks.Graphics; -using MoonWorks.Math.Float; -using System.IO; - -namespace MoonWorks.Test -{ - class CompressedTexturesGame : Game - { - private GraphicsPipeline pipeline; - private GpuBuffer vertexBuffer; - private GpuBuffer indexBuffer; - private Sampler sampler; - private Texture[] textures; - private string[] textureNames = new string[] - { - "BC1", - "BC2", - "BC3", - "BC7" - }; - - private int currentTextureIndex; - - public CompressedTexturesGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true) - { - Logger.LogInfo("Press Left and Right to cycle between textures"); - Logger.LogInfo("Setting texture to: " + textureNames[0]); - - // Load the shaders - ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert")); - ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.frag")); - - // Create the graphics pipeline - GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( - MainWindow.SwapchainFormat, - vertShaderModule, - fragShaderModule - ); - pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding(); - pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1; - pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo); - - // Create sampler - sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearWrap); - - // Create texture array - textures = new Texture[textureNames.Length]; - - // 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 - ); - - for (int i = 0; i < textureNames.Length; i += 1) - { - Logger.LogInfo(textureNames[i]); - textures[i] = resourceUploader.CreateTextureFromDDS(TestUtils.GetTexturePath(textureNames[i] + ".dds")); - } - - resourceUploader.Upload(); - resourceUploader.Dispose(); - } - - protected override void Update(System.TimeSpan delta) - { - int prevSamplerIndex = currentTextureIndex; - - if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left)) - { - currentTextureIndex -= 1; - if (currentTextureIndex < 0) - { - currentTextureIndex = textureNames.Length - 1; - } - } - - if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right)) - { - currentTextureIndex += 1; - if (currentTextureIndex >= textureNames.Length) - { - currentTextureIndex = 0; - } - } - - if (prevSamplerIndex != currentTextureIndex) - { - Logger.LogInfo("Setting texture to: " + textureNames[currentTextureIndex]); - } - } - - protected override void Draw(double alpha) - { - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); - if (backbuffer != null) - { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black)); - cmdbuf.BindGraphicsPipeline(pipeline); - cmdbuf.BindVertexBuffers(vertexBuffer); - cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen); - cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textures[currentTextureIndex], sampler)); - cmdbuf.DrawIndexedPrimitives(0, 0, 2); - cmdbuf.EndRenderPass(); - } - GraphicsDevice.Submit(cmdbuf); - } - - public static void Main(string[] args) - { - CompressedTexturesGame game = new CompressedTexturesGame(); - game.Run(); - } - } -} diff --git a/Examples/ComputeUniformsExample.cs b/Examples/ComputeUniformsExample.cs new file mode 100644 index 0000000..41edab6 --- /dev/null +++ b/Examples/ComputeUniformsExample.cs @@ -0,0 +1,84 @@ +using MoonWorks; +using MoonWorks.Graphics; +using MoonWorks.Input; + +namespace MoonWorksGraphicsTests; + +class ComputeUniformsExample : Example +{ + private ComputePipeline GradientPipeline; + private Texture RenderTexture; + + record struct GradientTextureComputeUniforms(float Time); + private GradientTextureComputeUniforms Uniforms; + + public override void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs) + { + Window = window; + GraphicsDevice = graphicsDevice; + + Window.SetTitle("ComputeUniforms"); + Uniforms.Time = 0; + + // Create the compute pipeline that writes texture data + Shader gradientTextureComputeShader = new Shader( + GraphicsDevice, + TestUtils.GetShaderPath("GradientTexture.comp"), + "main", + ShaderStage.Compute, + ShaderFormat.SPIRV + ); + + GradientPipeline = new ComputePipeline( + GraphicsDevice, + gradientTextureComputeShader, + new ComputePipelineResourceInfo { + ReadWriteStorageTextureCount = 1, + UniformBufferCount = 1 + } + ); + + gradientTextureComputeShader.Dispose(); + + RenderTexture = Texture.CreateTexture2D( + GraphicsDevice, + Window.Width, + Window.Height, + TextureFormat.R8G8B8A8, + TextureUsageFlags.ComputeStorageWrite | TextureUsageFlags.Sampler + ); + } + + public override void Update(System.TimeSpan delta) + { + Uniforms.Time += (float) delta.TotalSeconds; + } + + public override void Draw(double alpha) + { + CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); + Texture swapchainTexture = cmdbuf.AcquireSwapchainTexture(Window); + if (swapchainTexture != null) + { + var computePass = cmdbuf.BeginComputePass(new StorageTextureReadWriteBinding + { + TextureSlice = RenderTexture, + Cycle = true + }); + + computePass.BindComputePipeline(GradientPipeline); + computePass.PushUniformData(Uniforms); + computePass.Dispatch(RenderTexture.Width / 8, RenderTexture.Height / 8, 1); + cmdbuf.EndComputePass(computePass); + + cmdbuf.Blit(RenderTexture, swapchainTexture, Filter.Linear, false); + } + GraphicsDevice.Submit(cmdbuf); + } + + public override void Destroy() + { + GradientPipeline.Dispose(); + RenderTexture.Dispose(); + } +} diff --git a/Examples/ComputeUniformsGame.cs b/Examples/ComputeUniformsGame.cs deleted file mode 100644 index 9841b3a..0000000 --- a/Examples/ComputeUniformsGame.cs +++ /dev/null @@ -1,132 +0,0 @@ -using MoonWorks; -using MoonWorks.Graphics; -using MoonWorks.Math.Float; - -namespace MoonWorks.Test -{ - class ComputeUniformsGame : Game - { - private GraphicsPipeline drawPipeline; - private Texture texture; - private Sampler sampler; - private GpuBuffer vertexBuffer; - - struct GradientTextureComputeUniforms - { - public uint groupCountX; - public uint groupCountY; - - public GradientTextureComputeUniforms(uint w, uint h) - { - groupCountX = w; - groupCountY = h; - } - } - - public ComputeUniformsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true) - { - // Create the compute pipeline that writes texture data - ShaderModule gradientTextureComputeShaderModule = new ShaderModule( - GraphicsDevice, - TestUtils.GetShaderPath("GradientTexture.comp") - ); - - ComputePipeline gradientTextureComputePipeline = new ComputePipeline( - GraphicsDevice, - ComputeShaderInfo.Create(gradientTextureComputeShaderModule, "main", 0, 1) - ); - - // Create the graphics pipeline - ShaderModule vertShaderModule = new ShaderModule( - GraphicsDevice, - TestUtils.GetShaderPath("TexturedQuad.vert") - ); - - ShaderModule fragShaderModule = new ShaderModule( - GraphicsDevice, - TestUtils.GetShaderPath("TexturedQuad.frag") - ); - - GraphicsPipelineCreateInfo drawPipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo( - MainWindow.SwapchainFormat, - vertShaderModule, - fragShaderModule - ); - drawPipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding(); - drawPipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1; - - drawPipeline = new GraphicsPipeline( - GraphicsDevice, - drawPipelineCreateInfo - ); - - texture = Texture.CreateTexture2D( - GraphicsDevice, - MainWindow.Width, - MainWindow.Height, - TextureFormat.R8G8B8A8, - TextureUsageFlags.Compute | TextureUsageFlags.Sampler - ); - - sampler = new Sampler(GraphicsDevice, new SamplerCreateInfo()); - - // Upload GPU resources and dispatch compute work - - 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, 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 - ); - - resourceUploader.Upload(); - resourceUploader.Dispose(); - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - - GradientTextureComputeUniforms gradientUniforms = new GradientTextureComputeUniforms( - texture.Width / 8, - texture.Height / 8 - ); - - cmdbuf.BeginComputePass(); - cmdbuf.BindComputePipeline(gradientTextureComputePipeline); - cmdbuf.BindComputeTextures(new ComputeTextureBinding(texture, 0)); - cmdbuf.PushComputeShaderUniforms(gradientUniforms); - cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1); - cmdbuf.EndComputePass(); - - GraphicsDevice.Submit(cmdbuf); - } - - protected override void Update(System.TimeSpan delta) { } - - protected override void Draw(double alpha) - { - CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer(); - Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow); - if (backbuffer != null) - { - cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue)); - cmdbuf.BindGraphicsPipeline(drawPipeline); - cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler)); - cmdbuf.BindVertexBuffers(vertexBuffer); - cmdbuf.DrawPrimitives(0, 2); - cmdbuf.EndRenderPass(); - } - GraphicsDevice.Submit(cmdbuf); - } - - public static void Main(string[] args) - { - ComputeUniformsGame game = new ComputeUniformsGame(); - game.Run(); - } - } -} diff --git a/Examples/CopyTextureGame.cs b/Examples/CopyTextureGame.cs index 1c943e9..8f5a35a 100644 --- a/Examples/CopyTextureGame.cs +++ b/Examples/CopyTextureGame.cs @@ -2,7 +2,7 @@ using MoonWorks.Graphics; using MoonWorks.Math.Float; -namespace MoonWorks.Test +namespace MoonWorksGraphicsTests { class CopyTextureGame : Game { diff --git a/Examples/Example.cs b/Examples/Example.cs index 885a2e0..2539340 100644 --- a/Examples/Example.cs +++ b/Examples/Example.cs @@ -1,15 +1,17 @@ using System; using MoonWorks; using MoonWorks.Graphics; +using MoonWorks.Input; namespace MoonWorksGraphicsTests; public abstract class Example { protected Window Window; - protected GraphicsDevice GraphicsDevice; + public GraphicsDevice GraphicsDevice; + public Inputs Inputs; - public abstract void Init(Window window, GraphicsDevice graphicsDevice); + public abstract void Init(Window window, GraphicsDevice graphicsDevice, Inputs inputs); public abstract void Update(TimeSpan delta); public abstract void Draw(double alpha); public abstract void Destroy(); diff --git a/MoonWorksGraphicsTests.csproj b/MoonWorksGraphicsTests.csproj index cd114f5..272ad80 100644 --- a/MoonWorksGraphicsTests.csproj +++ b/MoonWorksGraphicsTests.csproj @@ -1,12 +1,13 @@ + Exe net8.0 true - + Content\%(RecursiveDir)%(Filename)%(Extension) Always @@ -16,6 +17,22 @@ + + + $(DefaultItemExcludes);Examples\**\* + + + + + + + + + + + + + diff --git a/Program.cs b/Program.cs index a264907..00d6fb0 100644 --- a/Program.cs +++ b/Program.cs @@ -1,7 +1,6 @@ using System; using MoonWorks; using MoonWorks.Graphics; -using MoonWorks.Test; namespace MoonWorksGraphicsTests; @@ -9,8 +8,13 @@ class Program : Game { Example[] Examples = [ + new ClearScreenExample(), + new ClearScreen_MultiWindowExample(), + new BasicStencilExample(), + new BasicTriangleExample(), + new CompressedTexturesExample(), new BasicComputeExample(), - new BasicStencilGame() + new ComputeUniformsExample() ]; int ExampleIndex = 0; @@ -23,11 +27,12 @@ class Program : Game bool debugMode = false ) : base(windowCreateInfo, frameLimiterSettings, preferredBackends, targetTimestep, debugMode) { + Examples[ExampleIndex].Init(MainWindow, GraphicsDevice, Inputs); } protected override void Update(TimeSpan delta) { - if (Inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.A)) + if (Inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.Q)) { Examples[ExampleIndex].Destroy(); @@ -37,15 +42,15 @@ class Program : Game ExampleIndex = Examples.Length - 1; } - Examples[ExampleIndex].Init(MainWindow, GraphicsDevice); + Examples[ExampleIndex].Init(MainWindow, GraphicsDevice, Inputs); } - else if (Inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.D)) + else if (Inputs.Keyboard.IsPressed(MoonWorks.Input.KeyCode.E)) { Examples[ExampleIndex].Destroy(); ExampleIndex = (ExampleIndex + 1) % Examples.Length; - Examples[ExampleIndex].Init(MainWindow, GraphicsDevice); + Examples[ExampleIndex].Init(MainWindow, GraphicsDevice, Inputs); } else { @@ -68,8 +73,8 @@ class Program : Game var windowCreateInfo = new WindowCreateInfo( "MoonWorksGraphicsTests", - 1280, - 720, + 640, + 480, ScreenMode.Windowed, SwapchainComposition.SDR, PresentMode.VSync