Add InstancingAndOffsets test

pull/2/head
Caleb Cornett 2023-01-22 15:14:23 -05:00
parent 4bd34a387a
commit eb09cf3bb9
7 changed files with 168 additions and 21 deletions

View File

@ -66,10 +66,6 @@ namespace MoonWorks.Test
{
0, 1, 2,
0, 2, 3,
// For testing index offsets
8, 9, 10,
8, 10, 11,
}
);
@ -165,7 +161,7 @@ namespace MoonWorks.Test
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textureCopy, sampler));
cmdbuf.DrawIndexedPrimitives(4, 0, 2, 0, 0);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textureSmallCopy, sampler));
cmdbuf.DrawIndexedPrimitives(0, 6, 2, 0, 0);
cmdbuf.DrawIndexedPrimitives(8, 0, 2, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\MoonWorks\MoonWorks.csproj" />
<ProjectReference Include="..\MoonWorks.Test.Common\MoonWorks.Test.Common.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
</PropertyGroup>
<Import Project="$(SolutionDir)NativeAOT_Console.targets" Condition="Exists('$(SolutionDir)NativeAOT_Console.targets')" />
</Project>

View File

@ -0,0 +1,108 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
namespace MoonWorks.Test
{
class InstancingAndOffsetsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private bool useVertexOffset;
private bool useIndexOffset;
public InstancingAndOffsetsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
Logger.LogInfo("Press Left to toggle vertex offset\nPress Right to toggle index offset");
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColorVertInstanced"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor"));
// Create the graphics pipeline
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
MainWindow.SwapchainFormat,
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.VertexInputState = VertexInputState.CreateSingleBinding<PositionColorVertex>();
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the vertex and index buffers
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 9);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
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.Orange),
new PositionColorVertex(new Vector3(1, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0, -1, 0), Color.Aqua),
new PositionColorVertex(new Vector3(-1, 1, 0), Color.White),
new PositionColorVertex(new Vector3(1, 1, 0), Color.White),
new PositionColorVertex(new Vector3(0, -1, 0), Color.White),
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2,
3, 4, 5,
}
);
GraphicsDevice.Submit(cmdbuf);
GraphicsDevice.Wait();
}
protected override void Update(System.TimeSpan delta)
{
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Left))
{
useVertexOffset = !useVertexOffset;
Logger.LogInfo("Using vertex offset: " + useVertexOffset);
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
useIndexOffset = !useIndexOffset;
Logger.LogInfo("Using index offset: " + useIndexOffset);
}
}
protected override void Draw(double alpha)
{
uint vertexOffset = useVertexOffset ? 3u : 0;
uint indexOffset = useIndexOffset ? 3u : 0;
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.DrawInstancedPrimitives(vertexOffset, indexOffset, 1, 16, 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)
{
InstancingAndOffsetsGame p = new InstancingAndOffsetsGame();
p.Run();
}
}
}

View File

@ -0,0 +1,16 @@
#version 450
layout (location = 0) in vec3 Position;
layout (location = 1) in vec4 Color;
layout (location = 0) out vec4 outColor;
void main()
{
outColor = Color;
vec3 pos = (Position * 0.25) - vec3(0.75, 0.75, 0);
pos.x += (gl_InstanceIndex % 4) * 0.5;
pos.y += floor(gl_InstanceIndex / 4) * 0.5;
gl_Position = vec4(pos, 1);
}

View File

@ -37,7 +37,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompressedTextures", "Compr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CopyTexture", "CopyTexture\CopyTexture.csproj", "{CF25A5A2-A0BD-4C9B-BB07-19CCD97C1C4E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VideoPlayer", "VideoPlayer\VideoPlayer.csproj", "{FCD63849-9D3C-4D48-A8BD-39671096F03A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VideoPlayer", "VideoPlayer\VideoPlayer.csproj", "{FCD63849-9D3C-4D48-A8BD-39671096F03A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InstancingAndOffsets", "Instancing\InstancingAndOffsets.csproj", "{01427BDA-45E2-46C0-B116-024EBE541D45}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -91,32 +93,36 @@ Global
{1695B1D8-4935-490C-A5EC-E2F2AA94B150}.Release|x64.Build.0 = Release|x64
{C3808AFD-23DD-4622-BFA7-981A344D0C19}.Debug|x64.ActiveCfg = Debug|x64
{C3808AFD-23DD-4622-BFA7-981A344D0C19}.Debug|x64.Build.0 = Debug|x64
{C3808AFD-23DD-4622-BFA7-981A344D0C19}.Release|x64.ActiveCfg = Release|Any CPU
{C3808AFD-23DD-4622-BFA7-981A344D0C19}.Release|x64.Build.0 = Release|Any CPU
{C3808AFD-23DD-4622-BFA7-981A344D0C19}.Release|x64.ActiveCfg = Release|x64
{C3808AFD-23DD-4622-BFA7-981A344D0C19}.Release|x64.Build.0 = Release|x64
{68D47057-BBCB-4F86-9C0A-D6D730B18D9E}.Debug|x64.ActiveCfg = Debug|x64
{68D47057-BBCB-4F86-9C0A-D6D730B18D9E}.Debug|x64.Build.0 = Debug|x64
{68D47057-BBCB-4F86-9C0A-D6D730B18D9E}.Release|x64.ActiveCfg = Release|Any CPU
{68D47057-BBCB-4F86-9C0A-D6D730B18D9E}.Release|x64.Build.0 = Release|Any CPU
{68D47057-BBCB-4F86-9C0A-D6D730B18D9E}.Release|x64.ActiveCfg = Release|x64
{68D47057-BBCB-4F86-9C0A-D6D730B18D9E}.Release|x64.Build.0 = Release|x64
{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}.Debug|x64.ActiveCfg = Debug|x64
{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}.Debug|x64.Build.0 = Debug|x64
{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}.Release|x64.ActiveCfg = Release|Any CPU
{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}.Release|x64.Build.0 = Release|Any CPU
{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}.Release|x64.ActiveCfg = Release|x64
{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}.Release|x64.Build.0 = Release|x64
{CA6E0ACF-3698-452F-B71F-51286EB5E1B2}.Debug|x64.ActiveCfg = Debug|x64
{CA6E0ACF-3698-452F-B71F-51286EB5E1B2}.Debug|x64.Build.0 = Debug|x64
{CA6E0ACF-3698-452F-B71F-51286EB5E1B2}.Release|x64.ActiveCfg = Release|Any CPU
{CA6E0ACF-3698-452F-B71F-51286EB5E1B2}.Release|x64.Build.0 = Release|Any CPU
{CA6E0ACF-3698-452F-B71F-51286EB5E1B2}.Release|x64.ActiveCfg = Release|x64
{CA6E0ACF-3698-452F-B71F-51286EB5E1B2}.Release|x64.Build.0 = Release|x64
{E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Debug|x64.ActiveCfg = Debug|x64
{E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Debug|x64.Build.0 = Debug|x64
{E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Release|x64.ActiveCfg = Release|Any CPU
{E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Release|x64.Build.0 = Release|Any CPU
{E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Release|x64.ActiveCfg = Release|x64
{E90D236C-BD0F-4420-ADD0-867D21F4DCA5}.Release|x64.Build.0 = Release|x64
{CF25A5A2-A0BD-4C9B-BB07-19CCD97C1C4E}.Debug|x64.ActiveCfg = Debug|x64
{CF25A5A2-A0BD-4C9B-BB07-19CCD97C1C4E}.Debug|x64.Build.0 = Debug|x64
{CF25A5A2-A0BD-4C9B-BB07-19CCD97C1C4E}.Release|x64.ActiveCfg = Release|Any CPU
{CF25A5A2-A0BD-4C9B-BB07-19CCD97C1C4E}.Release|x64.Build.0 = Release|Any CPU
{CF25A5A2-A0BD-4C9B-BB07-19CCD97C1C4E}.Release|x64.ActiveCfg = Release|x64
{CF25A5A2-A0BD-4C9B-BB07-19CCD97C1C4E}.Release|x64.Build.0 = Release|x64
{FCD63849-9D3C-4D48-A8BD-39671096F03A}.Debug|x64.ActiveCfg = Debug|x64
{FCD63849-9D3C-4D48-A8BD-39671096F03A}.Debug|x64.Build.0 = Debug|x64
{FCD63849-9D3C-4D48-A8BD-39671096F03A}.Release|x64.ActiveCfg = Release|Any CPU
{FCD63849-9D3C-4D48-A8BD-39671096F03A}.Release|x64.Build.0 = Release|Any CPU
{FCD63849-9D3C-4D48-A8BD-39671096F03A}.Release|x64.ActiveCfg = Release|x64
{FCD63849-9D3C-4D48-A8BD-39671096F03A}.Release|x64.Build.0 = Release|x64
{01427BDA-45E2-46C0-B116-024EBE541D45}.Debug|x64.ActiveCfg = Debug|x64
{01427BDA-45E2-46C0-B116-024EBE541D45}.Debug|x64.Build.0 = Debug|x64
{01427BDA-45E2-46C0-B116-024EBE541D45}.Release|x64.ActiveCfg = Release|x64
{01427BDA-45E2-46C0-B116-024EBE541D45}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -52,13 +52,17 @@ Uses a compute pipeline to fill a texture with a color gradient. Tests compute u
Draws two triangles via indirect commands. Tests DrawPrimitivesIndirect.
**InstancingAndOffsets**
Draws 16 instanced triangles. Tests DrawPrimitivesInstanced, vertex offsets, and index offsets.
**CompressedTextures**
Loads a series of compressed textures, then displays them for viewing. Tests compressed texture loading.
**CopyTexture**
Loads an image, then makes three copies of the image. One is a 1:1 scale image, another is a half-sized image (to test linear/nearest blitting), and the final copy is to a buffer. The buffer bytes are then compared with the original texture bytes to verify the copy's correctness. Tests CopyTextureToTexture, CopyTextureToBuffer, vertex offsets, and index offsets.
Loads an image, then makes three copies of the image. One is a 1:1 scale image, another is a half-sized image (to test linear/nearest blitting), and the final copy is to a buffer. The buffer bytes are then compared with the original texture bytes to verify the copy's correctness. Tests CopyTextureToTexture and CopyTextureToBuffer.
**VideoPlayer**