Compare commits

...

2 Commits

3 changed files with 43 additions and 15 deletions

View File

@ -100,8 +100,8 @@ namespace MoonWorks.Test
cmdbuf.BindComputePipeline(gradientTextureComputePipeline);
cmdbuf.BindComputeTextures(texture);
cmdbuf.PushComputeShaderUniforms(gradientUniforms);
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1, 0);
uint offset = cmdbuf.PushComputeShaderUniforms(gradientUniforms);
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1, offset);
GraphicsDevice.Submit(cmdbuf);
GraphicsDevice.Wait();

View File

@ -32,7 +32,7 @@ namespace MoonWorks.Test
// Create and populate the vertex buffer
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6);
drawBuffer = Buffer.Create<DrawIndirectCommand>(GraphicsDevice, BufferUsageFlags.Indirect, 2);
drawBuffer = Buffer.Create<IndirectDrawCommand>(GraphicsDevice, BufferUsageFlags.Indirect, 2);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
@ -50,10 +50,10 @@ namespace MoonWorks.Test
);
cmdbuf.SetBufferData(
drawBuffer,
new DrawIndirectCommand[]
new IndirectDrawCommand[]
{
new DrawIndirectCommand(3, 1, 3, 0),
new DrawIndirectCommand(3, 1, 0, 0),
new IndirectDrawCommand(3, 1, 3, 0),
new IndirectDrawCommand(3, 1, 0, 0),
}
);
GraphicsDevice.Submit(cmdbuf);
@ -71,7 +71,7 @@ namespace MoonWorks.Test
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.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf<IndirectDrawCommand>(), 0, 0);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -49,6 +49,7 @@ namespace MoonWorks.Test
vertShaderModule,
fragShaderModule
);
pipelineCreateInfo.AttachmentInfo.ColorAttachmentDescriptions[0].BlendState = ColorAttachmentBlendState.AlphaBlend;
pipelineCreateInfo.VertexInputState = new VertexInputState(
VertexBinding.Create<PositionTextureVertex>(),
VertexAttribute.Create<PositionTextureVertex>("Position", 0),
@ -68,10 +69,10 @@ namespace MoonWorks.Test
vertexBuffer,
new PositionTextureVertex[]
{
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)),
new PositionTextureVertex(new Vector3(-0.5f, -0.5f, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3(0.5f, -0.5f, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3(0.5f, 0.5f, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-0.5f, 0.5f, 0), new Vector2(0, 1)),
}
);
cmdbuf.SetBufferData(
@ -94,8 +95,9 @@ namespace MoonWorks.Test
protected override void Draw(double alpha)
{
VertexUniforms vertUniforms = new VertexUniforms(Matrix4x4.CreateRotationZ(t));
FragmentUniforms fragUniforms = new FragmentUniforms(new Vector4(1f, 0.5f + System.MathF.Sin(t) * 0.5f, 1f, 1f));
VertexUniforms vertUniforms;
FragmentUniforms fragUniforms;
uint vertParamOffset, fragParamOffset;
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
@ -106,9 +108,35 @@ namespace MoonWorks.Test
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
uint vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniforms);
// Top-left
vertUniforms = new VertexUniforms(Matrix4x4.CreateRotationZ(t) * Matrix4x4.CreateTranslation(new Vector3(-0.5f, -0.5f, 0)));
fragUniforms = new FragmentUniforms(new Vector4(1f, 0.5f + System.MathF.Sin(t) * 0.5f, 1f, 1f));
vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, fragParamOffset);
// Top-right
vertUniforms = new VertexUniforms(Matrix4x4.CreateRotationZ((2 * System.MathF.PI) - t) * Matrix4x4.CreateTranslation(new Vector3(0.5f, -0.5f, 0)));
fragUniforms = new FragmentUniforms(new Vector4(1f, 0.5f + System.MathF.Cos(t) * 0.5f, 1f, 1f));
vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, fragParamOffset);
// Bottom-left
vertUniforms = new VertexUniforms(Matrix4x4.CreateRotationZ(t) * Matrix4x4.CreateTranslation(new Vector3(-0.5f, 0.5f, 0)));
fragUniforms = new FragmentUniforms(new Vector4(1f, 0.5f + System.MathF.Sin(t) * 0.2f, 1f, 1f));
vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, fragParamOffset);
// Bottom-right
vertUniforms = new VertexUniforms(Matrix4x4.CreateRotationZ(t) * Matrix4x4.CreateTranslation(new Vector3(0.5f, 0.5f, 0)));
fragUniforms = new FragmentUniforms(new Vector4(1f, 0.5f + System.MathF.Cos(t) * 1f, 1f, 1f));
vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, fragParamOffset);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);