update CubeGame to use resourceInitializer
parent
91aecfd13c
commit
d8f402646a
|
@ -24,9 +24,7 @@ namespace MoonWorks.Test
|
||||||
private GpuBuffer blitVertexBuffer;
|
private GpuBuffer blitVertexBuffer;
|
||||||
private GpuBuffer indexBuffer;
|
private GpuBuffer indexBuffer;
|
||||||
|
|
||||||
private CpuBuffer transferBuffer;
|
private TransferBuffer screenshotTransferBuffer;
|
||||||
private CpuBuffer cubemapTransferBuffer;
|
|
||||||
private CpuBuffer screenshotTransferBuffer;
|
|
||||||
private Texture screenshotTexture;
|
private Texture screenshotTexture;
|
||||||
|
|
||||||
private Texture skyboxTexture;
|
private Texture skyboxTexture;
|
||||||
|
@ -56,6 +54,8 @@ namespace MoonWorks.Test
|
||||||
|
|
||||||
unsafe void LoadCubemap(string[] imagePaths)
|
unsafe void LoadCubemap(string[] imagePaths)
|
||||||
{
|
{
|
||||||
|
var cubemapTransferBuffer = new TransferBuffer(GraphicsDevice, skyboxTexture.Width * skyboxTexture.Height * 4);
|
||||||
|
|
||||||
/* Upload cubemap layers one at a time to minimize transfer size */
|
/* Upload cubemap layers one at a time to minimize transfer size */
|
||||||
for (uint i = 0; i < imagePaths.Length; i++)
|
for (uint i = 0; i < imagePaths.Length; i++)
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ namespace MoonWorks.Test
|
||||||
Depth = 1
|
Depth = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
ImageUtils.DecodeIntoCpuBuffer(imagePaths[i], cubemapTransferBuffer, 0, SetDataOptions.Overwrite);
|
ImageUtils.DecodeIntoTransferBuffer(imagePaths[i], cubemapTransferBuffer, 0, SetDataOptions.Overwrite);
|
||||||
|
|
||||||
commandBuffer.BeginCopyPass();
|
commandBuffer.BeginCopyPass();
|
||||||
commandBuffer.UploadToTexture(cubemapTransferBuffer, textureSlice, new BufferImageCopy(0, 0, 0));
|
commandBuffer.UploadToTexture(cubemapTransferBuffer, textureSlice, new BufferImageCopy(0, 0, 0));
|
||||||
|
@ -85,6 +85,8 @@ namespace MoonWorks.Test
|
||||||
GraphicsDevice.WaitForFences(fence);
|
GraphicsDevice.WaitForFences(fence);
|
||||||
GraphicsDevice.ReleaseFence(fence);
|
GraphicsDevice.ReleaseFence(fence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cubemapTransferBuffer.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
|
||||||
|
@ -156,10 +158,8 @@ namespace MoonWorks.Test
|
||||||
6
|
6
|
||||||
);
|
);
|
||||||
|
|
||||||
transferBuffer = new CpuBuffer(GraphicsDevice, 32768);
|
screenshotTransferBuffer = new TransferBuffer(GraphicsDevice, MainWindow.Width * MainWindow.Height * 4);
|
||||||
cubemapTransferBuffer = new CpuBuffer(GraphicsDevice, 2048 * 2048 * 4);
|
screenshotTexture = Texture.CreateTexture2D(GraphicsDevice, MainWindow.Width, MainWindow.Height, MainWindow.SwapchainFormat, TextureUsageFlags.Sampler);
|
||||||
screenshotTransferBuffer = new CpuBuffer(GraphicsDevice, MainWindow.Width * MainWindow.Height * 4);
|
|
||||||
screenshotTexture = Texture.CreateTexture2D(GraphicsDevice, MainWindow.Width, MainWindow.Height, MainWindow.SwapchainFormat, 0);
|
|
||||||
|
|
||||||
Task loadingTask = Task.Run(() => UploadGPUAssets());
|
Task loadingTask = Task.Run(() => UploadGPUAssets());
|
||||||
|
|
||||||
|
@ -309,60 +309,15 @@ namespace MoonWorks.Test
|
||||||
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
|
new PositionTextureVertex(new Vector3(-1, 1, 0), new Vector2(0, 1)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
|
var resourceInitializer = new ResourceInitializer(GraphicsDevice);
|
||||||
|
|
||||||
cmdbuf.BeginCopyPass();
|
cubeVertexBuffer = resourceInitializer.CreateBuffer(cubeVertexData, BufferUsageFlags.Vertex);
|
||||||
|
skyboxVertexBuffer = resourceInitializer.CreateBuffer(skyboxVertexData, BufferUsageFlags.Vertex);
|
||||||
|
indexBuffer = resourceInitializer.CreateBuffer(indexData, BufferUsageFlags.Index);
|
||||||
|
blitVertexBuffer = resourceInitializer.CreateBuffer(blitVertexData, BufferUsageFlags.Vertex);
|
||||||
|
|
||||||
uint offset = 0;
|
resourceInitializer.Upload();
|
||||||
uint length = transferBuffer.SetData(cubeVertexData, SetDataOptions.Overwrite);
|
resourceInitializer.Dispose();
|
||||||
cmdbuf.UploadToBuffer(
|
|
||||||
transferBuffer,
|
|
||||||
cubeVertexBuffer,
|
|
||||||
new BufferCopy(
|
|
||||||
offset,
|
|
||||||
0,
|
|
||||||
length
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
offset += length;
|
|
||||||
length = transferBuffer.SetData(skyboxVertexData, offset, SetDataOptions.Overwrite);
|
|
||||||
cmdbuf.UploadToBuffer(
|
|
||||||
transferBuffer,
|
|
||||||
skyboxVertexBuffer,
|
|
||||||
new BufferCopy(
|
|
||||||
offset,
|
|
||||||
0,
|
|
||||||
length
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
offset += length;
|
|
||||||
length = transferBuffer.SetData(indexData, offset, SetDataOptions.Overwrite);
|
|
||||||
cmdbuf.UploadToBuffer(
|
|
||||||
transferBuffer,
|
|
||||||
indexBuffer,
|
|
||||||
new BufferCopy(
|
|
||||||
offset,
|
|
||||||
0,
|
|
||||||
length
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
offset += length;
|
|
||||||
length = transferBuffer.SetData(blitVertexData, offset, SetDataOptions.Overwrite);
|
|
||||||
cmdbuf.UploadToBuffer(
|
|
||||||
transferBuffer,
|
|
||||||
blitVertexBuffer,
|
|
||||||
new BufferCopy(
|
|
||||||
offset,
|
|
||||||
0,
|
|
||||||
length
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
cmdbuf.EndCopyPass();
|
|
||||||
GraphicsDevice.Submit(cmdbuf);
|
|
||||||
|
|
||||||
LoadCubemap(new string[]
|
LoadCubemap(new string[]
|
||||||
{
|
{
|
||||||
|
@ -374,9 +329,6 @@ namespace MoonWorks.Test
|
||||||
TestUtils.GetTexturePath("back.png")
|
TestUtils.GetTexturePath("back.png")
|
||||||
});
|
});
|
||||||
|
|
||||||
cubemapTransferBuffer.Dispose();
|
|
||||||
transferBuffer.Dispose();
|
|
||||||
|
|
||||||
finishedLoading = true;
|
finishedLoading = true;
|
||||||
Logger.LogInfo("Finished loading!");
|
Logger.LogInfo("Finished loading!");
|
||||||
Logger.LogInfo("Press Left to toggle Depth-Only Mode");
|
Logger.LogInfo("Press Left to toggle Depth-Only Mode");
|
||||||
|
|
Loading…
Reference in New Issue