update bindings and WriteOptions API

refresh2
cosmonaut 2024-03-01 15:03:29 -08:00
parent 52f4e361ae
commit 0855bf6e26
35 changed files with 508 additions and 287 deletions

View File

@ -105,18 +105,18 @@ namespace MoonWorks.Test
// This should result in a bright yellow texture!
cmdbuf.BindComputePipeline(fillTextureComputePipeline);
cmdbuf.BindComputeTextures(new TextureLevelBinding(texture, 0));
cmdbuf.BindComputeTextures(new ComputeTextureBinding(texture, WriteOptions.SafeOverwrite));
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.BindComputeBuffers(new ComputeBufferBinding(squaresBuffer, WriteOptions.SafeOverwrite));
cmdbuf.DispatchCompute((uint) squares.Length / 8, 1, 1);
cmdbuf.EndComputePass();
cmdbuf.BeginCopyPass();
cmdbuf.DownloadFromBuffer(squaresBuffer, transferBuffer);
cmdbuf.DownloadFromBuffer(squaresBuffer, transferBuffer, TransferOptions.Overwrite);
cmdbuf.EndCopyPass();
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
@ -136,7 +136,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.SafeDiscard, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(drawPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
cmdbuf.BindVertexBuffers(vertexBuffer);

View File

@ -89,8 +89,8 @@ 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.SafeDiscard, new DepthStencilValue(0, 0), StoreOp.DontCare, StoreOp.DontCare),
new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black)
);
cmdbuf.BindGraphicsPipeline(maskerPipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);

View File

@ -59,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(useWireframeMode ? linePipeline : fillPipeline);
if (useSmallViewport)

View File

@ -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.SafeDiscard, Color.CornflowerBlue));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -29,7 +29,7 @@ namespace MoonWorks.Test
backbuffer = cmdbuf.AcquireSwapchainTexture(MainWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.CornflowerBlue));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.CornflowerBlue));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);
@ -41,7 +41,7 @@ namespace MoonWorks.Test
backbuffer = cmdbuf.AcquireSwapchainTexture(secondaryWindow);
if (backbuffer != null)
{
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Aquamarine));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Aquamarine));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -111,7 +111,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -97,7 +97,7 @@ namespace MoonWorks.Test
cmdbuf.BeginComputePass();
cmdbuf.BindComputePipeline(gradientTextureComputePipeline);
cmdbuf.BindComputeTextures(new TextureLevelBinding(texture, 0));
cmdbuf.BindComputeTextures(new ComputeTextureBinding(texture, 0));
cmdbuf.PushComputeShaderUniforms(gradientUniforms);
cmdbuf.DispatchCompute(gradientUniforms.groupCountX, gradientUniforms.groupCountY, 1);
cmdbuf.EndComputePass();
@ -113,7 +113,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.SafeDiscard, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(drawPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(texture, sampler));
cmdbuf.BindVertexBuffers(vertexBuffer);

View File

@ -88,6 +88,7 @@ namespace MoonWorks.Test
Height = originalTexture.Height,
Depth = originalTexture.Depth,
IsCube = originalTexture.IsCube,
LayerCount = originalTexture.LayerCount,
LevelCount = originalTexture.LevelCount,
SampleCount = originalTexture.SampleCount,
Format = originalTexture.Format,
@ -100,7 +101,8 @@ namespace MoonWorks.Test
cmdbuf.BeginCopyPass();
cmdbuf.CopyTextureToTexture(
originalTexture,
textureCopy
textureCopy,
WriteOptions.SafeOverwrite
);
cmdbuf.EndCopyPass();
@ -111,16 +113,17 @@ namespace MoonWorks.Test
textureSmallCopy = new Texture(GraphicsDevice, textureCreateInfo);
// Render the half-size copy
cmdbuf.Blit(originalTexture, textureSmallCopy, Filter.Linear);
cmdbuf.Blit(originalTexture, textureSmallCopy, Filter.Linear, WriteOptions.SafeOverwrite);
// Copy the texture to a transfer buffer
TransferBuffer compareBuffer = new TransferBuffer(GraphicsDevice, byteCount);
cmdbuf.BeginCopyPass();
cmdbuf.DownloadFromTexture(
new TextureSlice(originalTexture),
originalTexture,
compareBuffer,
new BufferImageCopy(0, 0, 0)
new BufferImageCopy(0, 0, 0),
TransferOptions.Overwrite
);
cmdbuf.EndCopyPass();
@ -156,7 +159,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -19,10 +19,10 @@ namespace MoonWorks.Test
private Sampler depthSampler;
private DepthUniforms depthUniforms;
private GpuBuffer cubeVertexBuffer;
private GpuBuffer skyboxVertexBuffer;
private GpuBuffer blitVertexBuffer;
private GpuBuffer indexBuffer;
private GpuBuffer cubeVertexBuffer;
private GpuBuffer skyboxVertexBuffer;
private GpuBuffer blitVertexBuffer;
private GpuBuffer indexBuffer;
private TransferBuffer screenshotTransferBuffer;
private Texture screenshotTexture;
@ -52,37 +52,39 @@ namespace MoonWorks.Test
}
}
// Upload cubemap layers one at a time to minimize transfer size
unsafe void LoadCubemap(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
{
Texture = skyboxTexture,
MipLevel = 0,
BaseLayer = i,
LayerCount = 1,
X = 0,
Y = 0,
Z = 0,
Width = skyboxTexture.Width,
Height = skyboxTexture.Height,
Depth = 1
};
for (uint i = 0; i < imagePaths.Length; i++)
{
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(
textureSlice,
textureRegion,
imagePaths[i]
);
cubemapUploader.UploadAndWait();
}
}
cubemapUploader.Dispose();
}
}
public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
{
@ -131,27 +133,27 @@ namespace MoonWorks.Test
);
skyboxSampler = new Sampler(GraphicsDevice, new SamplerCreateInfo());
cubeVertexBuffer = GpuBuffer.Create<PositionColorVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
skyboxVertexBuffer = GpuBuffer.Create<PositionVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
indexBuffer = GpuBuffer.Create<uint>(
GraphicsDevice,
BufferUsageFlags.Index,
36
); // Using uint here just to test IndexElementSize=32
cubeVertexBuffer = GpuBuffer.Create<PositionColorVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
skyboxVertexBuffer = GpuBuffer.Create<PositionVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
24
);
indexBuffer = GpuBuffer.Create<uint>(
GraphicsDevice,
BufferUsageFlags.Index,
36
); // Using uint here just to test IndexElementSize=32
blitVertexBuffer = GpuBuffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
blitVertexBuffer = GpuBuffer.Create<PositionTextureVertex>(
GraphicsDevice,
BufferUsageFlags.Vertex,
6
);
screenshotTransferBuffer = new TransferBuffer(GraphicsDevice, MainWindow.Width * MainWindow.Height * 4);
screenshotTexture = Texture.CreateTexture2D(GraphicsDevice, MainWindow.Width, MainWindow.Height, MainWindow.SwapchainFormat, TextureUsageFlags.Sampler);
@ -222,87 +224,87 @@ namespace MoonWorks.Test
{
Logger.LogInfo("Loading...");
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)),
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)),
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)),
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)),
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
]);
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
]);
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)),
]);
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)),
]);
var resourceUploader = new ResourceUploader(GraphicsDevice);
@ -314,15 +316,15 @@ namespace MoonWorks.Test
resourceUploader.Upload();
resourceUploader.Dispose();
LoadCubemap(new string[]
{
TestUtils.GetTexturePath("right.png"),
TestUtils.GetTexturePath("left.png"),
TestUtils.GetTexturePath("top.png"),
TestUtils.GetTexturePath("bottom.png"),
TestUtils.GetTexturePath("front.png"),
TestUtils.GetTexturePath("back.png")
});
LoadCubemap(new string[]
{
TestUtils.GetTexturePath("right.png"),
TestUtils.GetTexturePath("left.png"),
TestUtils.GetTexturePath("top.png"),
TestUtils.GetTexturePath("bottom.png"),
TestUtils.GetTexturePath("front.png"),
TestUtils.GetTexturePath("back.png")
});
finishedLoading = true;
Logger.LogInfo("Finished loading!");
@ -398,7 +400,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.SafeDiscard, clearColor));
cmdbuf.EndRenderPass();
}
else
@ -406,44 +408,44 @@ namespace MoonWorks.Test
if (!depthOnlyEnabled)
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0)),
new ColorAttachmentInfo(swapchainTexture, LoadOp.DontCare)
new DepthStencilAttachmentInfo(depthTexture, WriteOptions.SafeDiscard, new DepthStencilValue(1f, 0)),
new ColorAttachmentInfo(swapchainTexture, WriteOptions.SafeDiscard, LoadOp.DontCare)
);
}
else
{
cmdbuf.BeginRenderPass(
new DepthStencilAttachmentInfo(depthTexture, new DepthStencilValue(1f, 0))
new DepthStencilAttachmentInfo(depthTexture, WriteOptions.SafeDiscard, new DepthStencilValue(1f, 0), StoreOp.Store)
);
}
// Draw cube
cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? cubePipelineDepthOnly : cubePipeline);
cmdbuf.BindVertexBuffers(cubeVertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo);
cmdbuf.PushVertexShaderUniforms(cubeUniforms);
cmdbuf.DrawIndexedPrimitives(0, 0, 12);
// Draw cube
cmdbuf.BindGraphicsPipeline(depthOnlyEnabled ? cubePipelineDepthOnly : cubePipeline);
cmdbuf.BindVertexBuffers(cubeVertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.ThirtyTwo);
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));
cmdbuf.PushVertexShaderUniforms(skyboxUniforms);
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));
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.SafeOverwrite, LoadOp.Load));
cmdbuf.BindGraphicsPipeline(blitPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(depthTexture, depthSampler));
cmdbuf.BindVertexBuffers(blitVertexBuffer);
cmdbuf.PushFragmentShaderUniforms(depthUniforms);
cmdbuf.DrawPrimitives(0, 2);
cmdbuf.BindGraphicsPipeline(blitPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(depthTexture, depthSampler));
cmdbuf.BindVertexBuffers(blitVertexBuffer);
cmdbuf.PushFragmentShaderUniforms(depthUniforms);
cmdbuf.DrawPrimitives(0, 2);
cmdbuf.EndRenderPass();
}
@ -451,7 +453,7 @@ namespace MoonWorks.Test
if (takeScreenshot)
{
cmdbuf.BeginCopyPass();
cmdbuf.CopyTextureToTexture(swapchainTexture, screenshotTexture);
cmdbuf.CopyTextureToTexture(swapchainTexture, screenshotTexture, WriteOptions.SafeOverwrite);
cmdbuf.EndCopyPass();
swapchainCopied = true;
@ -477,7 +479,8 @@ namespace MoonWorks.Test
commandBuffer.BeginCopyPass();
commandBuffer.DownloadFromTexture(
screenshotTexture,
screenshotTransferBuffer
screenshotTransferBuffer,
TransferOptions.Overwrite
);
commandBuffer.EndCopyPass();

View File

@ -91,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.SafeDiscard, Color.Black));
// Need to bind a pipeline before binding vertex buffers
cmdbuf.BindGraphicsPipeline(CW_CullNonePipeline);

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 GpuBuffer cubeVertexBuffer1;
private GpuBuffer cubeVertexBuffer2;
private GpuBuffer cubeIndexBuffer;
private GpuBuffer quadVertexBuffer;
private GpuBuffer quadIndexBuffer;
private float cubeTimer = 0f;
private Quaternion cubeRotation = Quaternion.Identity;
@ -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,30 +84,9 @@ namespace MoonWorks.Test
);
}
// Create the sampler
rtSampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
// Create the buffers
var resourceUploader = new ResourceUploader(GraphicsDevice);
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))
],
BufferUsageFlags.Vertex
);
quadIndexBuffer = resourceUploader.CreateBuffer<ushort>(
[
0, 1, 2,
0, 2, 3,
],
BufferUsageFlags.Index
);
var cubeVertexData = new System.Span<PositionColorVertex>(
[
new PositionColorVertex(new Vector3(-1, -1, -1), new Color(1f, 0f, 0f)),
@ -248,8 +210,8 @@ 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.SafeDiscard, new DepthStencilValue(1, 0)),
new ColorAttachmentInfo(renderTargets[index], WriteOptions.SafeDiscard, Color.Black)
);
cmdbuf.BindGraphicsPipeline(cubePipelines[index]);
@ -267,14 +229,13 @@ namespace MoonWorks.Test
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);
cmdbuf.EndRenderPass();
// Copy the MSAA RT to the backbuffer
cmdbuf.Blit(
renderTargets[index],
backbuffer,
Filter.Nearest,
WriteOptions.SafeOverwrite
);
}
GraphicsDevice.Submit(cmdbuf);
}

View File

@ -61,7 +61,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.SafeDiscard, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(graphicsPipeline);
cmdbuf.BindVertexBuffers(new BufferBinding(vertexBuffer, 0));
cmdbuf.DrawPrimitivesIndirect(drawBuffer, 0, 2, (uint) Marshal.SizeOf<IndirectDrawCommand>());

View File

@ -41,7 +41,7 @@ namespace MoonWorks.Test
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.BeginCopyPass();
cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer);
cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer, TransferOptions.Overwrite);
cmdbuf.EndCopyPass();
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
@ -60,9 +60,9 @@ namespace MoonWorks.Test
// Change the first three vertices and upload
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
transferBuffer.SetData(otherVerts, SetDataOptions.Overwrite);
transferBuffer.SetData(otherVerts, TransferOptions.Overwrite);
cmdbuf.BeginCopyPass();
cmdbuf.UploadToBuffer(transferBuffer, vertexBuffer);
cmdbuf.UploadToBuffer(transferBuffer, vertexBuffer, WriteOptions.SafeOverwrite);
cmdbuf.EndCopyPass();
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
@ -71,7 +71,7 @@ namespace MoonWorks.Test
// Download the data
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.BeginCopyPass();
cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer);
cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer, TransferOptions.Overwrite);
cmdbuf.EndCopyPass();
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
@ -88,14 +88,15 @@ namespace MoonWorks.Test
// Change the last two vertices and upload
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
var lastTwoSpan = otherVerts.Slice(1, 2);
transferBuffer.SetData(lastTwoSpan, SetDataOptions.Overwrite);
transferBuffer.SetData(lastTwoSpan, TransferOptions.Overwrite);
cmdbuf.BeginCopyPass();
cmdbuf.UploadToBuffer<PositionVertex>(
transferBuffer,
vertexBuffer,
0,
(uint)(vertices.Length - 2),
2
2,
WriteOptions.SafeOverwrite
);
cmdbuf.EndCopyPass();
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
@ -104,7 +105,7 @@ namespace MoonWorks.Test
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.BeginCopyPass();
cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer);
cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer, TransferOptions.Overwrite);
cmdbuf.EndCopyPass();
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
@ -127,7 +128,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.SafeDiscard, Color.Black));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -86,7 +86,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -126,12 +126,12 @@ namespace MoonWorks.Test
{
Texture rt = renderTargets[(int) currentSampleCount];
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(rt, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(rt, WriteOptions.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(msaaPipelines[(int) currentSampleCount]);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, LoadOp.DontCare));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, LoadOp.DontCare));
cmdbuf.BindGraphicsPipeline(blitPipeline);
cmdbuf.BindFragmentSamplers(new TextureSamplerBinding(rt, rtSampler));
cmdbuf.BindVertexBuffers(quadVertexBuffer);

View File

@ -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);
}
@ -185,13 +186,14 @@ namespace MoonWorks.Test
Texture rt = renderTargets[rtIndex];
ColorAttachmentInfo rtAttachmentInfo = new ColorAttachmentInfo(
rt,
WriteOptions.SafeDiscard,
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]);
@ -199,7 +201,7 @@ namespace MoonWorks.Test
cmdbuf.EndRenderPass();
}
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(cubemapPipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

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

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

@ -92,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.SafeDiscard, Color.Red));
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[1], Color.Blue));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[1], WriteOptions.SafeDiscard, Color.Blue));
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[2], Color.Green));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[2], WriteOptions.SafeDiscard, Color.Green));
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[3], Color.Yellow));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(textures[3], WriteOptions.SafeDiscard, Color.Yellow));
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, Color.Black));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(backbuffer, WriteOptions.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -1,9 +1,10 @@
using MoonWorks.Graphics;
using System;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
namespace MoonWorks.Test
{
class RenderTexture3DGame : Game
class RenderTexture2DArrayGame : Game
{
private GraphicsPipeline pipeline;
private GpuBuffer vertexBuffer;
@ -29,11 +30,11 @@ namespace MoonWorks.Test
}
}
public RenderTexture3DGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public RenderTexture2DArrayGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 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(
@ -46,7 +47,7 @@ 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
var resourceUploader = new ResourceUploader(GraphicsDevice);
@ -72,7 +73,7 @@ namespace MoonWorks.Test
resourceUploader.Upload();
resourceUploader.Dispose();
rt = Texture.CreateTexture3D(
rt = Texture.CreateTexture2DArray(
GraphicsDevice,
16,
16,
@ -88,11 +89,13 @@ namespace MoonWorks.Test
{
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
};
@ -108,13 +111,14 @@ 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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);
@ -128,7 +132,7 @@ namespace MoonWorks.Test
public static void Main(string[] args)
{
RenderTexture3DGame game = new RenderTexture3DGame();
RenderTexture2DArrayGame game = new RenderTexture2DArrayGame();
game.Run();
}
}

View File

@ -114,11 +114,13 @@ namespace MoonWorks.Test
{
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
};
@ -156,7 +158,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -121,13 +121,16 @@ namespace MoonWorks.Test
{
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.SafeOverwrite
};
cmdbuf.BeginRenderPass(attachmentInfo);
cmdbuf.EndRenderPass();
@ -163,7 +166,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -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.SafeDiscard, Color.Blue));
cmdbuf.BindGraphicsPipeline(fillPipeline);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, LoadOp.Load, StoreOp.Store));
cmdbuf.BeginRenderPass(new ColorAttachmentInfo(swapchain, WriteOptions.SafeOverwrite, LoadOp.Load, StoreOp.Store));
cmdbuf.EndRenderPass();
}
GraphicsDevice.Submit(cmdbuf);

View File

@ -65,17 +65,26 @@ namespace MoonWorks.Test
BufferUsageFlags.Index
);
texture = Texture.CreateTexture3D(GraphicsDevice, 16, 16, 7, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
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
var region = new TextureRegion
{
Texture = texture,
MipLevel = 0,
BaseLayer = 0,
LayerCount = 1,
TextureSlice = new TextureSlice
{
Texture = texture,
MipLevel = 0,
Layer = 0
},
X = 0,
Y = 0,
Z = i,
@ -85,7 +94,7 @@ namespace MoonWorks.Test
};
resourceUploader.SetTextureDataFromCompressed(
slice,
region,
TestUtils.GetTexturePath($"tex3d_{i}.png")
);
}
@ -130,7 +139,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

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(), 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.SafeOverwrite
);
}
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.SafeDiscard, 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

@ -69,12 +69,14 @@ namespace MoonWorks.Test
{
var w = texture.Width >> (int) i;
var h = texture.Height >> (int) i;
var slice = new TextureSlice
var region = new TextureRegion
{
Texture = texture,
MipLevel = i,
BaseLayer = 0,
LayerCount = 1,
TextureSlice = new TextureSlice
{
Texture = texture,
Layer = 0,
MipLevel = i
},
X = 0,
Y = 0,
Z = 0,
@ -84,7 +86,7 @@ namespace MoonWorks.Test
};
resourceUploader.SetTextureDataFromCompressed(
slice,
region,
TestUtils.GetTexturePath($"mip{i}.png")
);
}
@ -114,7 +116,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -86,7 +86,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -145,7 +145,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -48,7 +48,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.DrawPrimitives(0, 1);

View File

@ -1,4 +1,5 @@
using MoonWorks;
using System;
using MoonWorks;
using MoonWorks.Graphics;
using MoonWorks.Math.Float;
@ -28,7 +29,6 @@ namespace MoonWorks.Test
pipeline = new GraphicsPipeline(GraphicsDevice, pipelineCreateInfo);
// Create and populate the GPU resources
texture = Texture.CreateTexture2D(GraphicsDevice, 3, 1, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
sampler = new Sampler(GraphicsDevice, SamplerCreateInfo.PointClamp);
var resourceUploader = new ResourceUploader(GraphicsDevice);
@ -42,9 +42,10 @@ namespace MoonWorks.Test
BufferUsageFlags.Vertex
);
resourceUploader.SetTextureData(
texture,
[Color.Yellow, Color.Indigo, Color.HotPink]
texture = resourceUploader.CreateTexture2D(
new Span<Color>([Color.Yellow, Color.Indigo, Color.HotPink]),
3,
1
);
resourceUploader.Upload();
@ -59,7 +60,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindVertexSamplers(new TextureSamplerBinding(texture, sampler));

View File

@ -78,7 +78,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.SafeDiscard, Color.CornflowerBlue));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.BindVertexBuffers(vertexBuffer);
cmdbuf.BindIndexBuffer(indexBuffer, IndexElementSize.Sixteen);

View File

@ -68,7 +68,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.SafeDiscard, Color.Black));
cmdbuf.BindGraphicsPipeline(pipeline);
cmdbuf.DrawPrimitives(0, 1);
cmdbuf.EndRenderPass();