Added DrawIndirect test
parent
5ccfa7da7e
commit
e9ffc97e1b
|
@ -0,0 +1,15 @@
|
||||||
|
<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>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<Platforms>x64</Platforms>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,86 @@
|
||||||
|
using MoonWorks;
|
||||||
|
using MoonWorks.Graphics;
|
||||||
|
using MoonWorks.Math.Float;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace MoonWorks.Test
|
||||||
|
{
|
||||||
|
class DrawIndirectGame : Game
|
||||||
|
{
|
||||||
|
private GraphicsPipeline graphicsPipeline;
|
||||||
|
private Buffer vertexBuffer;
|
||||||
|
private Buffer drawBuffer;
|
||||||
|
|
||||||
|
public DrawIndirectGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||||
|
{
|
||||||
|
// Load the shaders
|
||||||
|
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColorVert.spv"));
|
||||||
|
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.spv"));
|
||||||
|
|
||||||
|
// Create the graphics pipeline
|
||||||
|
GraphicsPipelineCreateInfo pipelineCreateInfo = TestUtils.GetStandardGraphicsPipelineCreateInfo(
|
||||||
|
MainWindow.SwapchainFormat,
|
||||||
|
vertShaderModule,
|
||||||
|
fragShaderModule
|
||||||
|
);
|
||||||
|
pipelineCreateInfo.VertexInputState = new VertexInputState(
|
||||||
|
VertexBinding.Create<PositionColorVertex>(),
|
||||||
|
VertexAttribute.Create<PositionColorVertex>("Position", 0),
|
||||||
|
VertexAttribute.Create<PositionColorVertex>("Color", 1)
|
||||||
|
);
|
||||||
|
graphicsPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
|
||||||
|
|
||||||
|
// Create and populate the vertex buffer
|
||||||
|
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6);
|
||||||
|
drawBuffer = Buffer.Create<DrawIndirectCommand>(GraphicsDevice, BufferUsageFlags.Indirect, 2);
|
||||||
|
|
||||||
|
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
||||||
|
cmdbuf.SetBufferData(
|
||||||
|
vertexBuffer,
|
||||||
|
new PositionColorVertex[]
|
||||||
|
{
|
||||||
|
new PositionColorVertex(new Vector3(-0.5f, -1, 0), Color.Blue),
|
||||||
|
new PositionColorVertex(new Vector3(-1f, 1, 0), Color.Green),
|
||||||
|
new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red),
|
||||||
|
|
||||||
|
new PositionColorVertex(new Vector3(.5f, -1, 0), Color.Blue),
|
||||||
|
new PositionColorVertex(new Vector3(1f, 1, 0), Color.Green),
|
||||||
|
new PositionColorVertex(new Vector3(0f, 1, 0), Color.Red),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
cmdbuf.SetBufferData(
|
||||||
|
drawBuffer,
|
||||||
|
new DrawIndirectCommand[]
|
||||||
|
{
|
||||||
|
new DrawIndirectCommand(3, 1, 3, 0),
|
||||||
|
new DrawIndirectCommand(3, 1, 0, 0),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
GraphicsDevice.Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
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, Color.CornflowerBlue));
|
||||||
|
cmdbuf.BindGraphicsPipeline(graphicsPipeline);
|
||||||
|
cmdbuf.BindVertexBuffers(new BufferBinding(vertexBuffer, 0));
|
||||||
|
cmdbuf.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf<DrawIndirectCommand>(), 0, 0);
|
||||||
|
cmdbuf.EndRenderPass();
|
||||||
|
}
|
||||||
|
GraphicsDevice.Submit(cmdbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
DrawIndirectGame game = new DrawIndirectGame();
|
||||||
|
game.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cube", "Cube\Cube.csproj",
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicCompute", "BasicCompute\BasicCompute.csproj", "{68D47057-BBCB-4F86-9C0A-D6D730B18D9E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicCompute", "BasicCompute\BasicCompute.csproj", "{68D47057-BBCB-4F86-9C0A-D6D730B18D9E}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeUniforms", "ComputeUniforms\ComputeUniforms.csproj", "{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeUniforms", "ComputeUniforms\ComputeUniforms.csproj", "{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DrawIndirect", "DrawIndirect\DrawIndirect.csproj", "{CA6E0ACF-3698-452F-B71F-51286EB5E1B2}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
@ -93,6 +95,10 @@ Global
|
||||||
{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}.Debug|x64.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}.Release|x64.Build.0 = Release|Any CPU
|
{5F8BBD49-6C39-4186-A4A3-91D6662D3ABD}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{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
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -47,3 +47,7 @@ Uses compute pipelines to (1) fill a texture with yellow pixels then display it
|
||||||
**ComputeUniforms**
|
**ComputeUniforms**
|
||||||
|
|
||||||
Uses a compute pipeline to fill a texture with a color gradient. Tests compute uniforms.
|
Uses a compute pipeline to fill a texture with a color gradient. Tests compute uniforms.
|
||||||
|
|
||||||
|
**DrawIndirect**
|
||||||
|
|
||||||
|
Draws two triangles via indirect commands. Tests DrawPrimitivesIndirect.
|
||||||
|
|
Loading…
Reference in New Issue