Compare commits

...

44 Commits

Author SHA1 Message Date
cosmonaut 75c13c3c6b Cube test debug names 2024-03-11 16:11:27 -07:00
cosmonaut 5782970ad8 go back to vulkan default 2024-03-11 10:22:59 -07:00
cosmonaut 39daf3cad4 update WriteOptions 2024-03-11 10:20:54 -07:00
cosmonaut b66dc20768 change default back to vulkan 2024-03-07 14:25:51 -08:00
cosmonaut b283df5d6b rename Discard to Cycle 2024-03-07 14:24:54 -08:00
cosmonaut 43cd8f0182 change backend selection behavior 2024-03-07 10:35:12 -08:00
cosmonaut f3eacbf776 comment on DepthMSAA 2024-03-07 00:03:42 -08:00
cosmonaut 17a321dcf7 change success message from error to info 2024-03-06 23:59:34 -08:00
cosmonaut 2435b4d226 rename TestUtils.DefaultBackend to just TestUtils.Backend 2024-03-06 14:31:22 -08:00
cosmonaut e4f4e53f2c more tests on D3D11 2024-03-06 14:23:06 -08:00
cosmonaut 5159442540 start converting tests to be D3D11-compatibility 2024-03-06 00:15:44 -08:00
cosmonaut beacd05925 fix BasicStencil 2024-03-02 23:10:52 -08:00
cosmonaut 0855bf6e26 update bindings and WriteOptions API 2024-03-01 15:03:29 -08:00
cosmonaut 52f4e361ae use element-wise buffer upload in GetBufferData 2024-02-23 15:40:18 -08:00
cosmonaut b8bbbe2327 update VideoPlayer 2024-02-23 15:29:03 -08:00
cosmonaut 844e330a48 update WindowResizing 2024-02-23 14:54:46 -08:00
cosmonaut 89dea810cc update examples that load from compressed image files 2024-02-23 14:54:01 -08:00
cosmonaut 347290bae2 update TextureMipmaps 2024-02-23 14:42:47 -08:00
cosmonaut b462f5d140 update TexturedAnimatedQuad 2024-02-23 14:37:45 -08:00
cosmonaut cd235b9172 rename ResourceInitializer to ResourceUploader 2024-02-23 14:32:56 -08:00
cosmonaut 795331c133 convert Cube test to use UploadAndWait 2024-02-23 14:30:53 -08:00
cosmonaut 1876258114 update Texture3DGame 2024-02-23 14:05:05 -08:00
cosmonaut 6b0f80119a update StoreLoad 2024-02-23 13:34:03 -08:00
cosmonaut 6c54808407 update RenderTextureMipmaps 2024-02-23 13:32:49 -08:00
cosmonaut 59d25a0ee7 update RenderTextureCube 2024-02-23 13:30:29 -08:00
cosmonaut ffd7f76843 update RenderTexture3D 2024-02-23 13:27:36 -08:00
cosmonaut d3ae483074 update RenderTexture2D 2024-02-23 13:25:21 -08:00
cosmonaut c2a029ce85 update MSAA 2024-02-23 13:09:23 -08:00
cosmonaut 683fffad16 update InstancingAndOffsets 2024-02-23 13:06:53 -08:00
cosmonaut c2f1a02ba3 update GetBufferData 2024-02-23 13:04:59 -08:00
cosmonaut c878a26b74 update DrawIndirect 2024-02-23 12:51:42 -08:00
cosmonaut f71917310d update DepthMSAA 2024-02-23 12:49:17 -08:00
cosmonaut 5534edb8fe update CullFace 2024-02-23 12:42:01 -08:00
cosmonaut 3299ff578f update CopyTexture 2024-02-23 12:40:12 -08:00
cosmonaut b9337fdbe6 update ComputeUniforms 2024-02-23 12:03:46 -08:00
cosmonaut 165af544de update CompressedTexture 2024-02-23 12:00:15 -08:00
cosmonaut 329f3c68f4 update ClearScreen_MultiWindow 2024-02-23 11:08:15 -08:00
cosmonaut b50df03dd7 update BasicTriangle 2024-02-23 11:03:04 -08:00
cosmonaut 94438c8991 update BasicStencil 2024-02-23 10:59:38 -08:00
cosmonaut d6ec93525e update BasicCompute 2024-02-23 10:57:54 -08:00
cosmonaut d8f402646a update CubeGame to use resourceInitializer 2024-02-23 10:12:47 -08:00
cosmonaut 91aecfd13c update TexturedQuad 2024-02-23 00:07:51 -08:00
cosmonaut 59c99daa9c re-add Cube screenshot feature 2024-02-22 22:51:01 -08:00
cosmonaut 110151ad56 update Cube for new API 2024-02-21 23:30:15 -08:00
55 changed files with 1197 additions and 902 deletions

View File

@ -9,9 +9,9 @@ namespace MoonWorks.Test
private GraphicsPipeline drawPipeline;
private Texture texture;
private Sampler sampler;
private Buffer vertexBuffer;
private GpuBuffer vertexBuffer;
public BasicComputeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public BasicComputeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Create the compute pipeline that writes texture data
ShaderModule fillTextureComputeShaderModule = new ShaderModule(
@ -61,16 +61,16 @@ namespace MoonWorks.Test
// Create buffers and textures
uint[] squares = new uint[64];
Buffer squaresBuffer = Buffer.Create<uint>(
GpuBuffer squaresBuffer = GpuBuffer.Create<uint>(
GraphicsDevice,
BufferUsageFlags.Compute,
(uint) squares.Length
);
vertexBuffer = Buffer.Create<PositionTextureVertex>(
TransferBuffer transferBuffer = new TransferBuffer(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
TransferUsage.Buffer,
squaresBuffer.Size
);
texture = Texture.CreateTexture2D(
@ -84,34 +84,45 @@ namespace MoonWorks.Test
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();
cmdbuf.SetBufferData(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, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
});
cmdbuf.BeginComputePass();
// This should result in a bright yellow texture!
cmdbuf.BindComputePipeline(fillTextureComputePipeline);
cmdbuf.BindComputeTextures(texture);
cmdbuf.DispatchCompute(texture.Width / 8, texture.Height / 8, 1, 0);
cmdbuf.BindComputeTextures(new ComputeTextureBinding(texture, WriteOptions.Unsafe));
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.DispatchCompute((uint) squares.Length / 8, 1, 1, 0);
cmdbuf.BindComputeBuffers(new ComputeBufferBinding(squaresBuffer, WriteOptions.Unsafe));
cmdbuf.DispatchCompute((uint) squares.Length / 8, 1, 1);
cmdbuf.EndComputePass();
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Print the squares!
squaresBuffer.GetData(squares);
GraphicsDevice.DownloadFromBuffer(squaresBuffer, transferBuffer, TransferOptions.Unsafe);
transferBuffer.GetData<uint>(squares, 0);
Logger.LogInfo("Squares of the first " + squares.Length + " integers: " + string.Join(", ", squares));
}
@ -123,11 +134,11 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
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, 0, 0);
cmdbuf.DrawPrimitives(0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -8,10 +8,10 @@ namespace MoonWorks.Test
{
private GraphicsPipeline maskerPipeline;
private GraphicsPipeline maskeePipeline;
private Buffer vertexBuffer;
private GpuBuffer vertexBuffer;
private Texture depthStencilTexture;
public BasicStencilGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public BasicStencilGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));
@ -31,11 +31,11 @@ namespace MoonWorks.Test
StencilTestEnable = true,
FrontStencilState = new StencilOpState
{
Reference = 1,
WriteMask = 0xFF,
CompareOp = CompareOp.Never,
FailOp = StencilOp.Replace,
}
},
Reference = 1,
WriteMask = 0xFF
};
maskerPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
@ -44,11 +44,11 @@ namespace MoonWorks.Test
StencilTestEnable = true,
FrontStencilState = new StencilOpState
{
Reference = 0,
CompareMask = 0xFF,
WriteMask = 0,
CompareOp = CompareOp.Equal,
}
},
Reference = 0,
CompareMask = 0xFF,
WriteMask = 0
};
maskeePipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
@ -60,13 +60,11 @@ namespace MoonWorks.Test
TextureFormat.D16S8,
TextureUsageFlags.DepthStencilTarget
);
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
var resourceUploader = new ResourceUploader(GraphicsDevice);
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),
@ -74,9 +72,12 @@ namespace MoonWorks.Test
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
);
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta) { }
@ -88,14 +89,14 @@ 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.Cycle, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare),
new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black)
);
cmdbuf.BindGraphicsPipeline(maskerPipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.BindGraphicsPipeline(maskeePipeline);
cmdbuf.DrawPrimitives(3, 1, 0, 0);
cmdbuf.DrawPrimitives(3, 1);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -1,5 +1,4 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Graphics;
namespace MoonWorks.Test
{
@ -15,7 +14,7 @@ namespace MoonWorks.Test
private bool useSmallViewport;
private bool useScissorRect;
public BasicTriangleGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
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");
@ -60,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.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(useWireframeMode ? linePipeline : fillPipeline);
if (useSmallViewport)
@ -72,7 +71,7 @@ namespace MoonWorks.Test
cmdbuf.SetScissor(scissorRect);
}
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -5,7 +5,7 @@ namespace MoonWorks.Test
{
class ClearScreenGame : Game
{
public ClearScreenGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true) { }
public ClearScreenGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true) { }
protected override void Update(System.TimeSpan delta) { }
@ -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.Cycle, Color.CornflowerBlue));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -7,12 +7,17 @@ namespace MoonWorks.Test
{
private Window secondaryWindow;
public ClearScreen_MultiWindowGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
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);
}
@ -23,23 +28,29 @@ namespace MoonWorks.Test
CommandBuffer cmdbuf;
Texture? backbuffer;
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
if (MainWindow.Claimed)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.EndRenderPass();
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
GraphicsDevice.Submit(cmdbuf);
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
backbuffer = cmdbuf.AcquireSwapchainTexture(secondaryWindow);
if (backbuffer != null)
if (secondaryWindow.Claimed)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Aquamarine));
cmdbuf.EndRenderPass();
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
backbuffer = cmdbuf.AcquireSwapchainTexture(secondaryWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Aquamarine));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
}
GraphicsDevice.Submit(cmdbuf);
}
public static void Main(string[] args)

View File

@ -1,5 +1,4 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
using System.IO;
@ -8,8 +7,8 @@ namespace MoonWorks.Test
class CompressedTexturesGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Sampler sampler;
private Texture[] textures;
private string[] textureNames = new string[]
@ -22,7 +21,7 @@ namespace MoonWorks.Test
private int currentTextureIndex;
public CompressedTexturesGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
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]);
@ -48,35 +47,34 @@ namespace MoonWorks.Test
textures = new Texture[textureNames.Length];
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
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)),
}
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1))
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
0, 2, 3,
}
],
BufferUsageFlags.Index
);
for (int i = 0; i < textureNames.Length; i += 1)
{
Logger.LogInfo(textureNames[i]);
using (FileStream fs = new FileStream(TestUtils.GetTexturePath(textureNames[i] + ".dds"), FileMode.Open, FileAccess.Read))
textures[i] = Texture.LoadDDS(GraphicsDevice, cmdbuf, fs);
textures[i] = resourceUploader.CreateTextureFromDDS(TestUtils.GetTexturePath(textureNames[i] + ".dds"));
}
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -113,12 +111,12 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
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, 0, 0);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -9,7 +9,7 @@ namespace MoonWorks.Test
private GraphicsPipeline drawPipeline;
private Texture texture;
private Sampler sampler;
private Buffer vertexBuffer;
private GpuBuffer vertexBuffer;
struct GradientTextureComputeUniforms
{
@ -23,7 +23,7 @@ namespace MoonWorks.Test
}
}
public ComputeUniformsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public ComputeUniformsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Create the compute pipeline that writes texture data
ShaderModule gradientTextureComputeShaderModule = new ShaderModule(
@ -60,13 +60,6 @@ namespace MoonWorks.Test
drawPipelineCreateInfo
);
// Create buffers and textures
vertexBuffer = Buffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
texture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
@ -78,26 +71,36 @@ namespace MoonWorks.Test
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();
cmdbuf.SetBufferData(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, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
});
GradientTextureComputeUniforms gradientUniforms = new GradientTextureComputeUniforms(
texture.Width / 8,
texture.Height / 8
);
cmdbuf.BeginComputePass();
cmdbuf.BindComputePipeline(gradientTextureComputePipeline);
cmdbuf.BindComputeTextures(texture);
uint offset = cmdbuf.PushComputeShaderUniforms(gradientUniforms);
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1, offset);
cmdbuf.BindComputeTextures(new ComputeTextureBinding(texture, 0));
cmdbuf.PushComputeShaderUniforms(gradientUniforms);
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1);
cmdbuf.EndComputePass();
GraphicsDevice.Submit(cmdbuf);
}
@ -110,11 +113,11 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
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, 0, 0);
cmdbuf.DrawPrimitives(0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -1,5 +1,4 @@
using System.Runtime.InteropServices;
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
@ -8,14 +7,14 @@ namespace MoonWorks.Test
class CopyTextureGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Texture originalTexture;
private Texture textureCopy;
private Texture textureSmallCopy;
private Sampler sampler;
public unsafe CopyTextureGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public unsafe CopyTextureGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
@ -36,15 +35,10 @@ namespace MoonWorks.Test
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 12);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 12);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
vertexBuffer = resourceUploader.CreateBuffer(
[
new PositionTextureVertex(new Vector3(-1f, 0f, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3( 0f, 0f, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3( 0f, 1f, 0), new Vector2(1, 1)),
@ -59,96 +53,100 @@ namespace MoonWorks.Test
new PositionTextureVertex(new Vector3( 0.5f, -1f, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3( 0.5f, 0f, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-0.5f, 0f, 0), new Vector2(0, 1))
}
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
0, 2, 3,
}
],
BufferUsageFlags.Index
);
// Load the texture. Storing the texture bytes so we can compare them.
var fileStream = new System.IO.FileStream(TestUtils.GetTexturePath("ravioli.png"), System.IO.FileMode.Open, System.IO.FileAccess.Read);
var fileLength = fileStream.Length;
var fileBuffer = NativeMemory.Alloc((nuint) fileLength);
var fileSpan = new System.Span<byte>(fileBuffer, (int) fileLength);
fileStream.ReadExactly(fileSpan);
originalTexture = resourceUploader.CreateTexture2DFromCompressed(
TestUtils.GetTexturePath("ravioli.png")
);
var pixels = RefreshCS.Refresh.Refresh_Image_Load(
(nint) fileBuffer,
(int) fileLength,
resourceUploader.Upload();
resourceUploader.Dispose();
// Load the texture bytes so we can compare them.
var pixels = ImageUtils.GetPixelDataFromFile(
TestUtils.GetTexturePath("ravioli.png"),
out var width,
out var height,
out var byteCount
);
NativeMemory.Free(fileBuffer);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
TextureCreateInfo textureCreateInfo = new TextureCreateInfo();
textureCreateInfo.Width = (uint) width;
textureCreateInfo.Height = (uint) height;
textureCreateInfo.Depth = 1;
textureCreateInfo.Format = TextureFormat.R8G8B8A8;
textureCreateInfo.IsCube = false;
textureCreateInfo.LevelCount = 1;
textureCreateInfo.UsageFlags = TextureUsageFlags.Sampler;
originalTexture = new Texture(GraphicsDevice, textureCreateInfo);
cmdbuf.SetTextureData(originalTexture, pixels, (uint) byteCount);
var textureCreateInfo = new TextureCreateInfo
{
Width = originalTexture.Width,
Height = originalTexture.Height,
Depth = originalTexture.Depth,
IsCube = originalTexture.IsCube,
LayerCount = originalTexture.LayerCount,
LevelCount = originalTexture.LevelCount,
SampleCount = originalTexture.SampleCount,
Format = originalTexture.Format,
UsageFlags = originalTexture.UsageFlags
};
// Create a 1:1 copy of the texture
textureCopy = new Texture(GraphicsDevice, textureCreateInfo);
cmdbuf.BeginCopyPass();
cmdbuf.CopyTextureToTexture(
new TextureSlice(originalTexture),
new TextureSlice(textureCopy),
Filter.Linear
originalTexture,
textureCopy,
WriteOptions.Unsafe
);
cmdbuf.EndCopyPass();
// Create a half-sized copy of this texture
textureCreateInfo.Width /= 2;
textureCreateInfo.Height /= 2;
textureCreateInfo.UsageFlags |= TextureUsageFlags.ColorTarget;
textureSmallCopy = new Texture(GraphicsDevice, textureCreateInfo);
cmdbuf.CopyTextureToTexture(
new TextureSlice(originalTexture),
new TextureSlice(
textureSmallCopy,
new Rect(
(int) textureCreateInfo.Width,
(int) textureCreateInfo.Height
)
),
Filter.Linear
);
// Copy the texture to a buffer
Buffer compareBuffer = Buffer.Create<byte>(GraphicsDevice, 0, (uint) byteCount);
cmdbuf.CopyTextureToBuffer(new TextureSlice(originalTexture), compareBuffer);
// Render the half-size copy
cmdbuf.Blit(originalTexture, textureSmallCopy, Filter.Linear, WriteOptions.Unsafe);
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Copy the texture to a transfer buffer
TransferBuffer compareBuffer = new TransferBuffer(GraphicsDevice, TransferUsage.Texture, byteCount);
GraphicsDevice.DownloadFromTexture(
textureCopy,
compareBuffer,
TransferOptions.Unsafe
);
// Compare the original bytes to the copied bytes.
var copiedBytes = NativeMemory.Alloc((nuint) byteCount);
var copiedSpan = new System.Span<byte>(copiedBytes, byteCount);
var copiedBytes = NativeMemory.Alloc(byteCount);
var copiedSpan = new System.Span<byte>(copiedBytes, (int) byteCount);
compareBuffer.GetData(copiedSpan);
var originalSpan = new System.Span<byte>((void*) pixels, byteCount);
var originalSpan = new System.Span<byte>((void*) pixels, (int)byteCount);
if (System.MemoryExtensions.SequenceEqual(originalSpan, copiedSpan))
{
Logger.LogError("SUCCESS! Original texture bytes and the bytes from CopyTextureToBuffer match!");
Logger.LogInfo("SUCCESS! Original texture bytes and the downloaded bytes match!");
}
else
{
Logger.LogError("FAIL! Original texture bytes do not match bytes from CopyTextureToBuffer!");
Logger.LogError("FAIL! Original texture bytes do not match downloaded bytes!");
}
RefreshCS.Refresh.Refresh_Image_Free(pixels);
NativeMemory.Free(copiedBytes);
}
protected override void Update(System.TimeSpan delta) { }
@ -159,16 +157,16 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(originalTexture, sampler));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textureCopy, sampler));
cmdbuf.DrawIndexedPrimitives(4, 0, 2, 0, 0);
cmdbuf.DrawIndexedPrimitives(4, 0, 2);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textureSmallCopy, sampler));
cmdbuf.DrawIndexedPrimitives(8, 0, 2, 0, 0);
cmdbuf.DrawIndexedPrimitives(8, 0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -9,6 +9,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<Import Project="$(SolutionDir)NativeAOT_Console.targets" Condition="Exists('$(SolutionDir)NativeAOT_Console.targets')" />

View File

@ -1,7 +1,8 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math;
using MoonWorks.Math.Float;
using System;
using System.IO;
using System.Threading.Tasks;
namespace MoonWorks.Test
@ -18,10 +19,14 @@ namespace MoonWorks.Test
private Sampler depthSampler;
private DepthUniforms depthUniforms;
private Buffer cubeVertexBuffer;
private Buffer skyboxVertexBuffer;
private Buffer blitVertexBuffer;
private Buffer indexBuffer;
private GpuBuffer cubeVertexBuffer;
private GpuBuffer skyboxVertexBuffer;
private GpuBuffer blitVertexBuffer;
private GpuBuffer indexBuffer;
private TransferBuffer screenshotTransferBuffer;
private Texture screenshotTexture;
private Fence? screenshotFence;
private Texture skyboxTexture;
private Sampler skyboxSampler;
@ -33,8 +38,9 @@ namespace MoonWorks.Test
private bool depthOnlyEnabled = false;
private Vector3 camPos = new Vector3(0, 1.5f, 4f);
private TaskFactory taskFactory = new TaskFactory();
private bool takeScreenshot;
private bool screenshotInProgress;
private bool swapchainCopied; // don't want to take screenshot if the swapchain was invalid
struct DepthUniforms
{
@ -48,23 +54,41 @@ namespace MoonWorks.Test
}
}
void LoadCubemap(CommandBuffer cmdbuf, 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(
skyboxTexture,
new Rect(0, 0, (int) skyboxTexture.Width, (int) skyboxTexture.Height),
0,
i,
0
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(
textureRegion,
imagePaths[i]
);
Texture.SetDataFromImageFile(cmdbuf, textureSlice, imagePaths[i]);
cubemapUploader.UploadAndWait();
}
cubemapUploader.Dispose();
}
public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
ShaderModule cubeVertShaderModule = new ShaderModule(
GraphicsDevice,
@ -100,6 +124,8 @@ namespace MoonWorks.Test
TextureFormat.D16,
TextureUsageFlags.DepthStencilTarget | TextureUsageFlags.Sampler
);
depthTexture.Name = "Depth Texture";
depthSampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
depthUniforms = new DepthUniforms(0.01f, 100f);
@ -109,29 +135,13 @@ namespace MoonWorks.Test
TextureFormat.R8G8B8A8,
TextureUsageFlags.Sampler
);
skyboxTexture.Name = "Skybox";
skyboxSampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
cubeVertexBuffer = Buffer.Create<PositionColorVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
skyboxVertexBuffer = Buffer.Create<PositionVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
indexBuffer = Buffer.Create<uint>(
GraphicsDevice,
BufferUsageFlags.Index,
36
); // Using uint here just to test IndexElementSize=32
blitVertexBuffer = Buffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
screenshotTransferBuffer = new TransferBuffer(GraphicsDevice, TransferUsage.Texture, MainWindow.Width * MainWindow.Height * 4);
screenshotTexture = Texture.CreateTexture2D(GraphicsDevice, MainWindow.Width, MainWindow.Height, MainWindow.SwapchainFormat, TextureUsageFlags.Sampler);
screenshotTexture.Name = "Screenshot";
Task loadingTask = Task.Run(() => UploadGPUAssets());
@ -199,107 +209,104 @@ namespace MoonWorks.Test
{
Logger.LogInfo("Loading...");
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
var cubeVertexData = new Span<PositionColorVertex>([
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)),
cmdbuf.SetBufferData(
cubeVertexBuffer,
new PositionColorVertex[]
{
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<PositionVertex>([
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)),
cmdbuf.SetBufferData(
skyboxVertexBuffer,
new PositionVertex[]
{
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<uint>([
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
]);
cmdbuf.SetBufferData(
indexBuffer,
new uint[]
{
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<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, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
]);
cmdbuf.SetBufferData(
blitVertexBuffer,
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, 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);
LoadCubemap(cmdbuf, new string[]
cubeVertexBuffer = resourceUploader.CreateBuffer(cubeVertexData, BufferUsageFlags.Vertex);
skyboxVertexBuffer = resourceUploader.CreateBuffer(skyboxVertexData, BufferUsageFlags.Vertex);
indexBuffer = resourceUploader.CreateBuffer(indexData, BufferUsageFlags.Index);
blitVertexBuffer = resourceUploader.CreateBuffer(blitVertexData, BufferUsageFlags.Vertex);
cubeVertexBuffer.Name = "Cube Vertices";
skyboxVertexBuffer.Name = "Skybox Vertices";
indexBuffer.Name = "Cube Indices";
blitVertexBuffer.Name = "Blit Vertices";
resourceUploader.Upload();
resourceUploader.Dispose();
LoadCubemap(new string[]
{
TestUtils.GetTexturePath("right.png"),
TestUtils.GetTexturePath("left.png"),
@ -309,8 +316,6 @@ namespace MoonWorks.Test
TestUtils.GetTexturePath("back.png")
});
GraphicsDevice.Submit(cmdbuf);
finishedLoading = true;
Logger.LogInfo("Finished loading!");
Logger.LogInfo("Press Left to toggle Depth-Only Mode");
@ -345,7 +350,7 @@ namespace MoonWorks.Test
Logger.LogInfo("Depth-Only Mode enabled: " + depthOnlyEnabled);
}
if (TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
if (!screenshotInProgress && TestUtils.CheckButtonPressed(Inputs, TestUtils.ButtonType.Right))
{
takeScreenshot = true;
}
@ -385,7 +390,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.Cycle, clearColor));
cmdbuf.EndRenderPass();
}
else
@ -393,14 +398,14 @@ namespace MoonWorks.Test
if (!depthOnlyEnabled)
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0)),
new ColorAttachmentInfo(swapchainTexture, LoadOp.DontCare)
new DepthStencilAttachmentInfo(depthTexture, WriteOptions.Cycle, new DepthStencilValue(1f, 0)),
new ColorAttachmentInfo(swapchainTexture, WriteOptions.Cycle, LoadOp.DontCare)
);
}
else
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0))
new DepthStencilAttachmentInfo(depthTexture, WriteOptions.Cycle, new DepthStencilValue(1f, 0), StoreOp.Store)
);
}
@ -408,55 +413,84 @@ namespace MoonWorks.Test
cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? cubePipelineDepthOnly : cubePipeline);
cmdbuf.BindVertexBuffers(cubeVertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo);
uint vertexParamOffset = cmdbuf.PushVertexShaderUniforms(cubeUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexParamOffset, 0);
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));
vertexParamOffset = cmdbuf.PushVertexShaderUniforms(skyboxUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexParamOffset, 0);
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.Safe, LoadOp.Load));
cmdbuf.BindGraphicsPipeline(blitPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(depthTexture, depthSampler));
cmdbuf.BindVertexBuffers(blitVertexBuffer);
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(depthUniforms);
cmdbuf.DrawPrimitives(0, 2, vertexParamOffset, fragParamOffset);
cmdbuf.PushFragmentShaderUniforms(depthUniforms);
cmdbuf.DrawPrimitives(0, 2);
cmdbuf.EndRenderPass();
}
if (takeScreenshot)
{
cmdbuf.BeginCopyPass();
cmdbuf.CopyTextureToTexture(swapchainTexture, screenshotTexture, WriteOptions.Unsafe);
cmdbuf.EndCopyPass();
swapchainCopied = true;
}
}
}
GraphicsDevice.Submit(cmdbuf);
if (takeScreenshot)
if (takeScreenshot && swapchainCopied)
{
if (swapchainTexture != null)
{
taskFactory.StartNew(TakeScreenshot, swapchainTexture);
}
screenshotFence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
Task.Run(TakeScreenshot);
takeScreenshot = false;
swapchainCopied = false;
}
else
{
GraphicsDevice.Submit(cmdbuf);
}
}
private System.Action<object?> TakeScreenshot = texture =>
private unsafe void TakeScreenshot()
{
if (texture != null)
{
((Texture) texture).SavePNG(System.IO.Path.Combine(System.AppContext.BaseDirectory, "screenshot.png"));
}
};
screenshotInProgress = true;
GraphicsDevice.WaitForFences(screenshotFence);
GraphicsDevice.DownloadFromTexture(
screenshotTexture,
screenshotTransferBuffer,
TransferOptions.Unsafe
);
ImageUtils.SavePNG(
Path.Combine(System.AppContext.BaseDirectory, "screenshot.png"),
screenshotTransferBuffer,
0,
(int) screenshotTexture.Width,
(int) screenshotTexture.Height,
screenshotTexture.Format == TextureFormat.B8G8R8A8
);
GraphicsDevice.ReleaseFence(screenshotFence);
screenshotFence = null;
screenshotInProgress = false;
}
public static void Main(string[] args)
{

View File

@ -12,12 +12,12 @@ namespace MoonWorks.Test
private GraphicsPipeline CCW_CullNonePipeline;
private GraphicsPipeline CCW_CullFrontPipeline;
private GraphicsPipeline CCW_CullBackPipeline;
private Buffer cwVertexBuffer;
private Buffer ccwVertexBuffer;
private GpuBuffer cwVertexBuffer;
private GpuBuffer ccwVertexBuffer;
private bool useClockwiseWinding;
public CullFaceGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public CullFaceGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Down to toggle the winding order of the triangles (default is counter-clockwise)");
@ -52,29 +52,28 @@ namespace MoonWorks.Test
CCW_CullBackPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the vertex buffers
cwVertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 3);
ccwVertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 3);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
cwVertexBuffer,
new PositionColorVertex[]
{
cwVertexBuffer = resourceUploader.CreateBuffer(
[
new PositionColorVertex(new Vector3(0, -1, 0), Color.Blue),
new PositionColorVertex(new Vector3(1, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(-1, 1, 0), Color.Red),
}
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
ccwVertexBuffer,
new PositionColorVertex[]
{
ccwVertexBuffer = resourceUploader.CreateBuffer(
[
new PositionColorVertex(new Vector3(-1, 1, 0), Color.Red),
new PositionColorVertex(new Vector3(1, 1, 0), Color.Green),
new PositionColorVertex(new Vector3(0, -1, 0), Color.Blue),
}
new PositionColorVertex(new Vector3(0, -1, 0), Color.Blue)
],
BufferUsageFlags.Vertex
);
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -92,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.Cycle, Color.Black));
// Need to bind a pipeline before binding vertex buffers
cmdbuf.BindGraphicsPipeline(CW_CullNonePipeline);
@ -106,27 +105,27 @@ namespace MoonWorks.Test
}
cmdbuf.SetViewport(new Viewport(0, 0, 213, 240));
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.SetViewport(new Viewport(213, 0, 213, 240));
cmdbuf.BindGraphicsPipeline(CW_CullFrontPipeline);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.SetViewport(new Viewport(426, 0, 213, 240));
cmdbuf.BindGraphicsPipeline(CW_CullBackPipeline);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.SetViewport(new Viewport(0, 240, 213, 240));
cmdbuf.BindGraphicsPipeline(CCW_CullNonePipeline);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.SetViewport(new Viewport(213, 240, 213, 240));
cmdbuf.BindGraphicsPipeline(CCW_CullFrontPipeline);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.SetViewport(new Viewport(426, 240, 213, 240));
cmdbuf.BindGraphicsPipeline(CCW_CullBackPipeline);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
}

View File

@ -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 Buffer cubeVertexBuffer1;
private Buffer cubeVertexBuffer2;
private Buffer cubeIndexBuffer;
private Buffer quadVertexBuffer;
private Buffer quadIndexBuffer;
private GpuBuffer cubeVertexBuffer1;
private GpuBuffer cubeVertexBuffer2;
private GpuBuffer cubeIndexBuffer;
private float cubeTimer = 0f;
private Quaternion cubeRotation = Quaternion.Identity;
@ -25,7 +21,7 @@ namespace MoonWorks.Test
private SampleCount currentSampleCount = SampleCount.Four;
public DepthMSAAGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public DepthMSAAGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between sample counts");
Logger.LogInfo("Setting sample count to: " + currentSampleCount);
@ -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<PositionTextureVertex>();
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,41 +84,11 @@ namespace MoonWorks.Test
);
}
// Create the sampler
rtSampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create the buffers
quadVertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
quadIndexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
var resourceUploader = new ResourceUploader(GraphicsDevice);
cubeVertexBuffer1 = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 24);
cubeVertexBuffer2 = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 24);
cubeIndexBuffer = Buffer.Create<uint>(GraphicsDevice, BufferUsageFlags.Index, 36);
// Populate the GPU resources
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
quadVertexBuffer,
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)),
}
);
cmdbuf.SetBufferData(
quadIndexBuffer,
new ushort[]
{
0, 1, 2,
0, 2, 3,
}
);
PositionColorVertex[] vertices = new PositionColorVertex[]
{
var cubeVertexData = new System.Span<PositionColorVertex>(
[
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)),
@ -165,36 +118,38 @@ namespace MoonWorks.Test
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))
};
cmdbuf.SetBufferData(
cubeVertexBuffer1,
vertices
]);
cubeVertexBuffer1 = resourceUploader.CreateBuffer(
cubeVertexData,
BufferUsageFlags.Vertex
);
// Scoot all the verts slightly for the second cube...
for (int i = 0; i < vertices.Length; i += 1)
for (int i = 0; i < cubeVertexData.Length; i += 1)
{
vertices[i].Position.Z += 3;
cubeVertexData[i].Position.Z += 3;
}
cmdbuf.SetBufferData(
cubeVertexBuffer2,
vertices
cubeVertexBuffer2 = resourceUploader.CreateBuffer(
cubeVertexData,
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
cubeIndexBuffer,
new uint[]
{
0, 1, 2, 0, 2, 3,
6, 5, 4, 7, 6, 4,
8, 9, 10, 8, 10, 11,
cubeIndexBuffer = resourceUploader.CreateBuffer<uint>(
[
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
}
],
BufferUsageFlags.Index
);
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -255,33 +210,33 @@ 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.Cycle, new DepthStencilValue(1, 0)),
new ColorAttachmentInfo(renderTargets[index], WriteOptions.Cycle, Color.Black)
);
cmdbuf.BindGraphicsPipeline(cubePipelines[index]);
// Draw the first cube
cmdbuf.BindVertexBuffers(cubeVertexBuffer1);
cmdbuf.BindIndexBuffer(cubeIndexBuffer, IndexElementSize.ThirtyTwo);
uint vertexParamOffset = cmdbuf.PushVertexShaderUniforms(cubeUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexParamOffset, 0);
cmdbuf.PushVertexShaderUniforms(cubeUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12);
// Draw the second cube
cmdbuf.BindVertexBuffers(cubeVertexBuffer2);
cmdbuf.BindIndexBuffer(cubeIndexBuffer, IndexElementSize.ThirtyTwo);
vertexParamOffset = cmdbuf.PushVertexShaderUniforms(cubeUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexParamOffset, 0);
cmdbuf.PushVertexShaderUniforms(cubeUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12);
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, 0, 0);
cmdbuf.EndRenderPass();
// A copy would work fine here as well
cmdbuf.Blit(
renderTargets[index],
backbuffer,
Filter.Nearest,
WriteOptions.Safe
);
}
GraphicsDevice.Submit(cmdbuf);
}

View File

@ -1,5 +1,4 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
using System.Runtime.InteropServices;
@ -8,10 +7,10 @@ namespace MoonWorks.Test
class DrawIndirectGame : Game
{
private GraphicsPipeline graphicsPipeline;
private Buffer vertexBuffer;
private Buffer drawBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer drawBuffer;
public DrawIndirectGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public DrawIndirectGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));
@ -27,14 +26,10 @@ namespace MoonWorks.Test
graphicsPipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the vertex buffer
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 6);
drawBuffer = Buffer.Create<IndirectDrawCommand>(GraphicsDevice, BufferUsageFlags.Indirect, 2);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
vertexBuffer = resourceUploader.CreateBuffer(
[
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),
@ -42,17 +37,20 @@ namespace MoonWorks.Test
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),
}
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
drawBuffer,
new IndirectDrawCommand[]
{
drawBuffer = resourceUploader.CreateBuffer(
[
new IndirectDrawCommand(3, 1, 3, 0),
new IndirectDrawCommand(3, 1, 0, 0),
}
],
BufferUsageFlags.Indirect
);
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta) { }
@ -63,10 +61,10 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(graphicsPipeline);
cmdbuf.BindVertexBuffers(new BufferBinding(vertexBuffer, 0));
cmdbuf.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf<IndirectDrawCommand>(), 0, 0);
cmdbuf.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf<IndirectDrawCommand>());
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -1,5 +1,4 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
using System.Runtime.InteropServices;
@ -7,11 +6,11 @@ namespace MoonWorks.Test
{
class GetBufferDataGame : Game
{
public GetBufferDataGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public GetBufferDataGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
PositionVertex[] vertices = new PositionVertex[]
{
new PositionVertex(new Vector3(0, 0, 0)),
var vertices = new System.Span<PositionVertex>(
[
new PositionVertex(new Vector3(0, 0, 0)),
new PositionVertex(new Vector3(0, 0, 1)),
new PositionVertex(new Vector3(0, 1, 0)),
new PositionVertex(new Vector3(0, 1, 1)),
@ -19,69 +18,93 @@ namespace MoonWorks.Test
new PositionVertex(new Vector3(1, 0, 1)),
new PositionVertex(new Vector3(1, 1, 0)),
new PositionVertex(new Vector3(1, 1, 1)),
};
]);
PositionVertex[] otherVerts = new PositionVertex[]
{
new PositionVertex(new Vector3(1, 2, 3)),
var otherVerts = new System.Span<PositionVertex>(
[
new PositionVertex(new Vector3(1, 2, 3)),
new PositionVertex(new Vector3(4, 5, 6)),
new PositionVertex(new Vector3(7, 8, 9))
};
]);
int vertexSize = Marshal.SizeOf<PositionVertex>();
Buffer vertexBuffer = Buffer.Create<PositionVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
(uint) vertices.Length
);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(vertexBuffer, vertices);
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
var vertexBuffer = resourceUploader.CreateBuffer(vertices, BufferUsageFlags.Vertex);
// Wait for the vertices to finish uploading...
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Wait for the vertices to finish copying...
resourceUploader.UploadAndWait();
resourceUploader.Dispose();
var transferBuffer = new TransferBuffer(GraphicsDevice, TransferUsage.Buffer, vertexBuffer.Size);
// Read back and print out the vertex values
GraphicsDevice.DownloadFromBuffer(
vertexBuffer,
transferBuffer,
TransferOptions.Unsafe
);
PositionVertex[] readbackVertices = new PositionVertex[vertices.Length];
vertexBuffer.GetData(readbackVertices);
transferBuffer.GetData<PositionVertex>(readbackVertices);
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
// Change the first three vertices
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(vertexBuffer, otherVerts);
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
// Change the first three vertices and upload
transferBuffer.SetData(otherVerts, TransferOptions.Unsafe);
var cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.BeginCopyPass();
cmdbuf.UploadToBuffer(transferBuffer, vertexBuffer, WriteOptions.Unsafe);
cmdbuf.EndCopyPass();
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Download the data
GraphicsDevice.DownloadFromBuffer(
vertexBuffer,
transferBuffer,
TransferOptions.Unsafe
);
// Read the updated buffer
vertexBuffer.GetData(readbackVertices);
transferBuffer.GetData<PositionVertex>(readbackVertices);
Logger.LogInfo("=== Change first three vertices ===");
for (int i = 0; i < readbackVertices.Length; i += 1)
{
Logger.LogInfo(readbackVertices[i].ToString());
}
// Change the last two vertices
// Change the last two vertices and upload
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
var lastTwoSpan = otherVerts.Slice(1, 2);
transferBuffer.SetData(lastTwoSpan, TransferOptions.Unsafe);
cmdbuf.BeginCopyPass();
cmdbuf.UploadToBuffer<PositionVertex>(
transferBuffer,
vertexBuffer,
otherVerts,
(uint) (vertexSize * (vertices.Length - 2)),
1,
2
0,
(uint)(vertices.Length - 2),
2,
WriteOptions.Unsafe
);
cmdbuf.EndCopyPass();
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
GraphicsDevice.DownloadFromBuffer(
vertexBuffer,
transferBuffer,
TransferOptions.Unsafe
);
// Read the updated buffer
vertexBuffer.GetData(readbackVertices);
transferBuffer.GetData<PositionVertex>(readbackVertices);
Logger.LogInfo("=== Change last two vertices ===");
for (int i = 0; i < readbackVertices.Length; i += 1)
{
@ -89,7 +112,6 @@ namespace MoonWorks.Test
}
}
protected override void Update(System.TimeSpan delta) { }
protected override void Draw(double alpha)
@ -98,7 +120,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.Cycle, Color.Black));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -7,13 +7,13 @@ namespace MoonWorks.Test
class InstancingAndOffsetsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private bool useVertexOffset;
private bool useIndexOffset;
public InstancingAndOffsetsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public InstancingAndOffsetsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Left to toggle vertex offset\nPress Right to toggle index offset");
@ -31,14 +31,10 @@ namespace MoonWorks.Test
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);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
vertexBuffer = resourceUploader.CreateBuffer(
[
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),
@ -50,17 +46,20 @@ namespace MoonWorks.Test
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),
}
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
3, 4, 5,
}
],
BufferUsageFlags.Index
);
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -87,11 +86,11 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.DrawInstancedPrimitives(vertexOffset, indexOffset, 1, 16, 0, 0);
cmdbuf.DrawInstancedPrimitives(vertexOffset, indexOffset, 1, 16);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -11,12 +11,12 @@ namespace MoonWorks.Test
private Texture[] renderTargets = new Texture[4];
private Sampler rtSampler;
private Buffer quadVertexBuffer;
private Buffer quadIndexBuffer;
private GpuBuffer quadVertexBuffer;
private GpuBuffer quadIndexBuffer;
private SampleCount currentSampleCount = SampleCount.Four;
public MSAAGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public MSAAGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between sample counts");
Logger.LogInfo("Setting sample count to: " + currentSampleCount);
@ -67,29 +67,28 @@ namespace MoonWorks.Test
rtSampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the vertex and index buffers
quadVertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
quadIndexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
quadVertexBuffer,
new PositionTextureVertex[]
{
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)),
}
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1))
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
quadIndexBuffer,
new ushort[]
{
quadIndexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
0, 2, 3,
}
0, 2, 3
],
BufferUsageFlags.Index
);
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -127,17 +126,17 @@ namespace MoonWorks.Test
{
Texture rt = renderTargets[(int) currentSampleCount];
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(rt, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(rt, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(msaaPipelines[(int) currentSampleCount]);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, LoadOp.DontCare));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, LoadOp.DontCare));
cmdbuf.BindGraphicsPipeline(blitPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, rtSampler));
cmdbuf.BindVertexBuffers(quadVertexBuffer);
cmdbuf.BindIndexBuffer(quadIndexBuffer, IndexElementSize.Sixteen);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -12,15 +12,15 @@ namespace MoonWorks.Test
private GraphicsPipeline cubemapPipeline;
private Texture[] renderTargets = new Texture[4];
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Sampler sampler;
private Vector3 camPos = new Vector3(0, 0, 4f);
private SampleCount currentSampleCount = SampleCount.Four;
public MSAACubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public MSAACubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Down to view the other side of the cubemap");
Logger.LogInfo("Press Left and Right to cycle between sample counts");
@ -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);
}
@ -76,14 +77,10 @@ namespace MoonWorks.Test
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 24);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 36);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionVertex[]
{
vertexBuffer = resourceUploader.CreateBuffer(
[
new PositionVertex(new Vector3(-10, -10, -10)),
new PositionVertex(new Vector3(10, -10, -10)),
new PositionVertex(new Vector3(10, 10, -10)),
@ -113,23 +110,24 @@ namespace MoonWorks.Test
new PositionVertex(new Vector3(-10, 10, 10)),
new PositionVertex(new Vector3(10, 10, 10)),
new PositionVertex(new Vector3(10, 10, -10))
}
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2, 0, 2, 3,
6, 5, 4, 7, 6, 4,
8, 9, 10, 8, 10, 11,
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
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
}
],
BufferUsageFlags.Index
);
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -188,27 +186,28 @@ namespace MoonWorks.Test
Texture rt = renderTargets[rtIndex];
ColorAttachmentInfo rtAttachmentInfo = new ColorAttachmentInfo(
rt,
WriteOptions.Cycle,
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]);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
}
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(cubemapPipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, sampler));
uint vertexUniformOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexUniformOffset, 0);
cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -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));
}

View File

@ -8,43 +8,43 @@
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))">
<Content Include="..\..\moonlibs\x64\FAudio.dll">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\moonlibs\x64\Refresh.dll">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\moonlibs\x64\SDL2.dll">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\moonlibs\x64\dav1dfile.dll">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))">
<Content Include="..\..\moonlibs\lib64\libFAudio.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\moonlibs\lib64\libRefresh.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\moonlibs\lib64\libSDL2-2.0.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\moonlibs\windows\libdav1dfile.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))">
<Content Include="..\..\moonlibs\osx\**\*.*" >
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

View File

@ -4,6 +4,9 @@ namespace MoonWorks.Test
{
public static class TestUtils
{
// change this to test different backends
public static Backend[] PreferredBackends = [Backend.Vulkan];
public static WindowCreateInfo GetStandardWindowCreateInfo()
{
return new WindowCreateInfo(

View File

@ -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

View File

@ -7,12 +7,12 @@ namespace MoonWorks.Test
class RenderTexture2DGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Texture[] textures = new Texture[4];
private Sampler sampler;
public RenderTexture2DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public RenderTexture2DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
@ -34,25 +34,10 @@ namespace MoonWorks.Test
sampler = new Sampler(GraphicsDevice, samplerCreateInfo);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 16);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
var resourceUploader = new ResourceUploader(GraphicsDevice);
for (int i = 0; i < textures.Length; i += 1)
{
textures[i] = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width / 4,
MainWindow.Height / 4,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
}
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
vertexBuffer = resourceUploader.CreateBuffer(
[
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3(0, -1, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3(0, 0, 0), new Vector2(1, 1)),
@ -72,18 +57,31 @@ namespace MoonWorks.Test
new PositionTextureVertex(new Vector3(1, 0, 0), new Vector2(1, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(1, 1)),
new PositionTextureVertex(new Vector3(0, 1, 0), new Vector2(0, 1)),
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2,
0, 2, 3,
}
],
BufferUsageFlags.Vertex
);
GraphicsDevice.Submit(cmdbuf);
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
0, 2, 3,
],
BufferUsageFlags.Index
);
resourceUploader.Upload();
resourceUploader.Dispose();
for (int i = 0; i < textures.Length; i += 1)
{
textures[i] = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width / 4,
MainWindow.Height / 4,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
}
}
protected override void Update(System.TimeSpan delta) { }
@ -94,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.Cycle, Color.Red));
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[1], Color.Blue));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[1], WriteOptions.Cycle, Color.Blue));
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[2], Color.Green));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[2], WriteOptions.Cycle, Color.Green));
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[3], Color.Yellow));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[3], WriteOptions.Cycle, Color.Yellow));
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
@ -114,7 +112,7 @@ namespace MoonWorks.Test
for (uint i = 0; i < textures.Length; i += 1)
{
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(textures[i], sampler));
cmdbuf.DrawIndexedPrimitives(4 * i, 0, 2, 0, 0);
cmdbuf.DrawIndexedPrimitives(4 * i, 0, 2);
}
cmdbuf.EndRenderPass();

View File

@ -1,15 +1,14 @@
using MoonWorks;
using System;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
using RefreshCS;
namespace MoonWorks.Test
{
class RenderTexture3DGame : Game
class RenderTexture2DArrayGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Texture rt;
private Sampler sampler;
@ -31,11 +30,11 @@ namespace MoonWorks.Test
}
}
public RenderTexture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public RenderTexture2DArrayGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 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(
@ -48,12 +47,33 @@ 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
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
rt = Texture.CreateTexture3D(
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<ushort>(
[
0, 1, 2,
0, 2, 3,
],
BufferUsageFlags.Index
);
resourceUploader.Upload();
resourceUploader.Dispose();
rt = Texture.CreateTexture2DArray(
GraphicsDevice,
16,
16,
@ -63,35 +83,19 @@ namespace MoonWorks.Test
);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
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)),
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2,
0, 2, 3,
}
);
// Clear each depth slice of the RT to a different color
for (uint i = 0; i < colors.Length; i += 1)
{
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
};
@ -107,19 +111,20 @@ 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.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, sampler));
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniform);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, fragParamOffset);
cmdbuf.PushFragmentShaderUniforms(fragUniform);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
@ -127,7 +132,7 @@ namespace MoonWorks.Test
public static void Main(string[] args)
{
RenderTexture3DGame game = new RenderTexture3DGame();
RenderTexture2DArrayGame game = new RenderTexture2DArrayGame();
game.Run();
}
}

View File

@ -1,5 +1,4 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
using MoonWorks.Math;
using System.Runtime.InteropServices;
@ -9,8 +8,8 @@ namespace MoonWorks.Test
class RenderTextureCubeGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Texture cubemap;
private Sampler sampler;
@ -26,7 +25,7 @@ namespace MoonWorks.Test
Color.Purple,
};
public RenderTextureCubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public RenderTextureCubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Down to view the other side of the cubemap");
@ -49,20 +48,10 @@ namespace MoonWorks.Test
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 24);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 36);
cubemap = Texture.CreateTextureCube(
GraphicsDevice,
16,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionVertex[]
{
vertexBuffer = resourceUploader.CreateBuffer(
[
new PositionVertex(new Vector3(-10, -10, -10)),
new PositionVertex(new Vector3(10, -10, -10)),
new PositionVertex(new Vector3(10, 10, -10)),
@ -92,32 +81,46 @@ namespace MoonWorks.Test
new PositionVertex(new Vector3(-10, 10, 10)),
new PositionVertex(new Vector3(10, 10, 10)),
new PositionVertex(new Vector3(10, 10, -10))
}
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2, 0, 2, 3,
6, 5, 4, 7, 6, 4,
8, 9, 10, 8, 10, 11,
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
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
}
],
BufferUsageFlags.Index
);
resourceUploader.Upload();
resourceUploader.Dispose();
cubemap = Texture.CreateTextureCube(
GraphicsDevice,
16,
TextureFormat.R8G8B8A8,
TextureUsageFlags.ColorTarget | TextureUsageFlags.Sampler
);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
// Clear each slice of the cubemap to a different color
for (uint i = 0; i < 6; i += 1)
{
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
};
@ -155,13 +158,13 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(cubemap, sampler));
uint vertexUniformOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12, vertexUniformOffset, 0);
cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -1,5 +1,4 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
namespace MoonWorks.Test
@ -7,8 +6,8 @@ namespace MoonWorks.Test
class RenderTextureMipmapsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Texture texture;
private Sampler[] samplers = new Sampler[5];
@ -42,7 +41,7 @@ namespace MoonWorks.Test
}
}
public RenderTextureMipmapsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public RenderTextureMipmapsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Left and Right to shrink/expand the scale of the quad");
Logger.LogInfo("Press Down to cycle through sampler states");
@ -83,8 +82,29 @@ namespace MoonWorks.Test
samplers[4] = new Sampler(GraphicsDevice, samplerCreateInfo);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
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<ushort>(
[
0, 1, 2,
0, 2, 3,
],
BufferUsageFlags.Index
);
resourceUploader.Upload();
resourceUploader.Dispose();
texture = Texture.CreateTexture2D(
GraphicsDevice,
MainWindow.Width,
@ -95,37 +115,22 @@ namespace MoonWorks.Test
);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
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)),
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2,
0, 2, 3,
}
);
// Clear each mip level to a different color
for (uint i = 0; i < texture.LevelCount; i += 1)
{
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.Safe
};
cmdbuf.BeginRenderPass(attachmentInfo);
cmdbuf.EndRenderPass();
@ -161,13 +166,13 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, samplers[currentSamplerIndex]));
uint vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, 0);
cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -7,7 +7,7 @@ namespace MoonWorks.Test
{
private GraphicsPipeline fillPipeline;
public StoreLoadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public StoreLoadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
@ -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.Cycle, Color.Blue));
cmdbuf.BindGraphicsPipeline(fillPipeline);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, LoadOp.Load, StoreOp.Store));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, WriteOptions.Safe, LoadOp.Load, StoreOp.Store));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -1,15 +1,13 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
using RefreshCS;
namespace MoonWorks.Test
{
class Texture3DGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Texture texture;
private Sampler sampler;
@ -25,7 +23,7 @@ namespace MoonWorks.Test
}
}
public Texture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public Texture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between depth slices");
@ -47,47 +45,62 @@ namespace MoonWorks.Test
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
texture = Texture.CreateTexture3D(GraphicsDevice, 16, 16, 7, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
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)),
}
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1))
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
0, 2, 3,
}
],
BufferUsageFlags.Index
);
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(
texture,
new Rect(0, 0, (int) texture.Width, (int) texture.Height),
i
);
var region = new TextureRegion
{
TextureSlice = new TextureSlice
{
Texture = texture,
MipLevel = 0,
Layer = 0
},
X = 0,
Y = 0,
Z = i,
Width = texture.Width,
Height = texture.Height,
Depth = 1
};
Texture.SetDataFromImageFile(
cmdbuf,
slice,
resourceUploader.SetTextureDataFromCompressed(
region,
TestUtils.GetTexturePath($"tex3d_{i}.png")
);
}
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -126,13 +139,13 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
uint fragParamOffset = cmdbuf.PushFragmentShaderUniforms(fragUniform);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, fragParamOffset);
cmdbuf.PushFragmentShaderUniforms(fragUniform);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -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(), TestUtils.PreferredBackends, 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<PositionTextureVertex>();
pipelineCreateInfo.FragmentShaderInfo = GraphicsShaderInfo.Create<FragUniform>(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<ushort>(
[
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.Unsafe
);
}
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.Cycle, 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();
}
}
}

View File

@ -0,0 +1,16 @@
<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>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<Import Project="$(SolutionDir)NativeAOT_Console.targets" Condition="Exists('$(SolutionDir)NativeAOT_Console.targets')" />
</Project>

View File

@ -1,21 +1,19 @@
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
using RefreshCS;
namespace MoonWorks.Test
{
class TextureMipmapsGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Texture texture;
private Sampler sampler;
private float scale = 0.5f;
public TextureMipmapsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public TextureMipmapsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Left and Right to shrink/expand the scale of the quad");
@ -34,10 +32,9 @@ namespace MoonWorks.Test
pipelineCreateInfo.FragmentShaderInfo.SamplerBindingCount = 1;
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the GPU resources
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
// Create and populate the GPU resources
texture = Texture.CreateTexture2D(
GraphicsDevice,
256,
@ -47,43 +44,55 @@ namespace MoonWorks.Test
4
);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
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
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
0, 2, 3,
}
0, 2, 3
],
BufferUsageFlags.Index
);
// Set the various mip levels
for (int i = 0; i < texture.LevelCount; i += 1)
for (uint i = 0; i < texture.LevelCount; i += 1)
{
int w = (int) texture.Width >> i;
int h = (int) texture.Height >> i;
TextureSlice slice = new TextureSlice(
texture,
new Rect(0, 0, w, h),
0,
0,
(uint) i
);
var w = texture.Width >> (int) i;
var h = texture.Height >> (int) i;
var region = new TextureRegion
{
TextureSlice = new TextureSlice
{
Texture = texture,
Layer = 0,
MipLevel = i
},
X = 0,
Y = 0,
Z = 0,
Width = w,
Height = h,
Depth = 1
};
Texture.SetDataFromImageFile(cmdbuf, slice, TestUtils.GetTexturePath($"mip{i}.png"));
resourceUploader.SetTextureDataFromCompressed(
region,
TestUtils.GetTexturePath($"mip{i}.png")
);
}
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -107,13 +116,13 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
uint vertParamOffset = cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2, vertParamOffset, 0);
cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -1,5 +1,4 @@
using System.Runtime.InteropServices;
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
@ -8,8 +7,8 @@ namespace MoonWorks.Test
class TexturedAnimatedQuadGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Texture texture;
private Sampler sampler;
@ -26,7 +25,7 @@ namespace MoonWorks.Test
}
}
public TexturedAnimatedQuadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public TexturedAnimatedQuadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuadWithMatrix.vert"));
@ -44,32 +43,33 @@ namespace MoonWorks.Test
pipelineCreateInfo.FragmentShaderInfo = GraphicsShaderInfo.Create<FragmentUniforms>(fragShaderModule, "main", 1);
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
// Create and populate the GPU resources
var resourceUploader = new ResourceUploader(GraphicsDevice);
vertexBuffer = resourceUploader.CreateBuffer(
[
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)),
}
],
BufferUsageFlags.Vertex
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
0, 2, 3,
}
],
BufferUsageFlags.Index
);
texture = Texture.FromImageFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.png"));
GraphicsDevice.Submit(cmdbuf);
texture = resourceUploader.CreateTexture2DFromCompressed(TestUtils.GetTexturePath("ravioli.png"));
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -81,13 +81,12 @@ namespace MoonWorks.Test
{
TransformVertexUniform vertUniforms;
FragmentUniforms fragUniforms;
uint vertParamOffset, fragParamOffset;
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.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
@ -96,30 +95,30 @@ namespace MoonWorks.Test
// Top-left
vertUniforms = new TransformVertexUniform(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);
cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.PushFragmentShaderUniforms(fragUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
// Top-right
vertUniforms = new TransformVertexUniform(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);
cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.PushFragmentShaderUniforms(fragUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
// Bottom-left
vertUniforms = new TransformVertexUniform(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);
cmdbuf.PushVertexShaderUniforms(vertUniforms);
cmdbuf.PushFragmentShaderUniforms(fragUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
// Bottom-right
vertUniforms = new TransformVertexUniform(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.PushVertexShaderUniforms(vertUniforms);
cmdbuf.PushFragmentShaderUniforms(fragUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass();
}

View File

@ -1,4 +1,4 @@
using MoonWorks;
using System;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
@ -7,8 +7,8 @@ namespace MoonWorks.Test
class TexturedQuadGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Sampler[] samplers = new Sampler[6];
private string[] samplerNames = new string[]
{
@ -35,7 +35,7 @@ namespace MoonWorks.Test
private System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
public TexturedQuadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public TexturedQuadGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between sampler states");
Logger.LogInfo("Setting sampler state to: " + samplerNames[0]);
@ -71,34 +71,32 @@ namespace MoonWorks.Test
samplers[4] = new Sampler(GraphicsDevice, SamplerCreateInfo.AnisotropicClamp);
samplers[5] = new Sampler(GraphicsDevice, SamplerCreateInfo.AnisotropicWrap);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
var vertexData = new Span<PositionTextureVertex>([
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(4, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(4, 4)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 4)),
]);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
new PositionTextureVertex(new Vector3(-1, -1, 0), new Vector2(0, 0)),
new PositionTextureVertex(new Vector3(1, -1, 0), new Vector2(4, 0)),
new PositionTextureVertex(new Vector3(1, 1, 0), new Vector2(4, 4)),
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 4)),
}
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
0, 1, 2,
0, 2, 3,
}
);
textures[0] = Texture.FromImageFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.png"));
textures[1] = Texture.FromImageBytes(GraphicsDevice, cmdbuf, pngBytes);
textures[2] = Texture.FromImageFile(GraphicsDevice, cmdbuf, TestUtils.GetTexturePath("ravioli.qoi"));
textures[3] = Texture.FromImageBytes(GraphicsDevice, cmdbuf, qoiBytes);
GraphicsDevice.Submit(cmdbuf);
var indexData = new Span<ushort>([
0, 1, 2,
0, 2, 3,
]);
// Create and populate the GPU resources
var resourceUploader = new ResourceUploader(GraphicsDevice);
vertexBuffer = resourceUploader.CreateBuffer(vertexData, BufferUsageFlags.Vertex);
indexBuffer = resourceUploader.CreateBuffer(indexData, BufferUsageFlags.Index);
textures[0] = resourceUploader.CreateTexture2DFromCompressed(TestUtils.GetTexturePath("ravioli.png"));
textures[1] = resourceUploader.CreateTexture2DFromCompressed(pngBytes);
textures[2] = resourceUploader.CreateTexture2DFromCompressed(TestUtils.GetTexturePath("ravioli.qoi"));
textures[3] = resourceUploader.CreateTexture2DFromCompressed(qoiBytes);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta)
@ -147,12 +145,12 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
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], samplers[currentSamplerIndex]));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -7,9 +7,9 @@ namespace MoonWorks.Test
class TriangleVertexBufferGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private GpuBuffer vertexBuffer;
public TriangleVertexBufferGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public TriangleVertexBufferGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));
@ -25,19 +25,19 @@ namespace MoonWorks.Test
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the vertex buffer
vertexBuffer = Buffer.Create<PositionColorVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 3);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionColorVertex[]
{
vertexBuffer = resourceUploader.CreateBuffer(
[
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
);
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta) { }
@ -48,10 +48,10 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -1,4 +1,5 @@
using MoonWorks;
using System;
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
@ -7,11 +8,11 @@ namespace MoonWorks.Test
class VertexSamplerGame : Game
{
private GraphicsPipeline pipeline;
private Buffer vertexBuffer;
private GpuBuffer vertexBuffer;
private Texture texture;
private Sampler sampler;
public VertexSamplerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public VertexSamplerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionSampler.vert"));
@ -28,22 +29,27 @@ namespace MoonWorks.Test
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 3);
texture = Texture.CreateTexture2D(GraphicsDevice, 3, 1, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
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(0.334f, 0)),
new PositionTextureVertex(new Vector3(0, -1, 0), new Vector2(0.667f, 0)),
}
],
BufferUsageFlags.Vertex
);
cmdbuf.SetTextureData(texture, new Color[] { Color.Yellow, Color.Indigo, Color.HotPink });
GraphicsDevice.Submit(cmdbuf);
texture = resourceUploader.CreateTexture2D(
new Span<Color>([Color.Yellow, Color.Indigo, Color.HotPink]),
3,
1
);
resourceUploader.Upload();
resourceUploader.Dispose();
}
protected override void Update(System.TimeSpan delta) { }
@ -54,11 +60,11 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindVertexSamplers(new TextureSamplerBinding(texture, sampler));
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -8,13 +8,13 @@ namespace MoonWorks.Test
{
private GraphicsPipeline pipeline;
private Sampler sampler;
private Buffer vertexBuffer;
private Buffer indexBuffer;
private GpuBuffer vertexBuffer;
private GpuBuffer indexBuffer;
private Video.VideoAV1 video;
private VideoPlayer videoPlayer;
public VideoPlayerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public VideoPlayerGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
@ -34,29 +34,28 @@ namespace MoonWorks.Test
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.LinearClamp);
// Create and populate the GPU resources
vertexBuffer = Buffer.Create<PositionTextureVertex>(GraphicsDevice, BufferUsageFlags.Vertex, 4);
indexBuffer = Buffer.Create<ushort>(GraphicsDevice, BufferUsageFlags.Index, 6);
var resourceUploader = new ResourceUploader(GraphicsDevice);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.SetBufferData(
vertexBuffer,
new PositionTextureVertex[]
{
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
);
cmdbuf.SetBufferData(
indexBuffer,
new ushort[]
{
indexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
0, 2, 3,
}
],
BufferUsageFlags.Index
);
GraphicsDevice.Submit(cmdbuf);
resourceUploader.Upload();
resourceUploader.Dispose();
// Load the video
video = new VideoAV1(GraphicsDevice, TestUtils.GetVideoPath("hello.obu"), 25);
@ -79,12 +78,12 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(videoPlayer.RenderTexture, sampler));
cmdbuf.DrawIndexedPrimitives(0, 0, 2, 0, 0);
cmdbuf.DrawIndexedPrimitives(0, 0, 2);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -20,7 +20,7 @@ namespace MoonWorks.Test
new Res(3840, 2160),
};
public WindowResizingGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public WindowResizingGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.PreferredBackends, 60, true)
{
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));
@ -68,9 +68,9 @@ namespace MoonWorks.Test
Texture? backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.Cycle, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.DrawPrimitives(0, 1, 0, 0);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);