start converting tests to be D3D11-compatibility

refresh2
cosmonaut 2024-03-06 00:15:44 -08:00
parent beacd05925
commit 5159442540
38 changed files with 84 additions and 85 deletions

View File

@ -11,7 +11,7 @@ namespace MoonWorks.Test
private Sampler sampler;
private GpuBuffer vertexBuffer;
public BasicComputeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public BasicComputeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 60, true)
{
// Create the compute pipeline that writes texture data
ShaderModule fillTextureComputeShaderModule = new ShaderModule(
@ -115,15 +115,12 @@ namespace MoonWorks.Test
cmdbuf.EndComputePass();
cmdbuf.BeginCopyPass();
cmdbuf.DownloadFromBuffer(squaresBuffer, transferBuffer, TransferOptions.Overwrite);
cmdbuf.EndCopyPass();
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Print the squares!
GraphicsDevice.DownloadFromBuffer(squaresBuffer, transferBuffer, TransferOptions.Overwrite);
transferBuffer.GetData<uint>(squares, 0);
Logger.LogInfo("Squares of the first " + squares.Length + " integers: " + string.Join(", ", squares));
}

View File

@ -11,7 +11,7 @@ namespace MoonWorks.Test
private GpuBuffer vertexBuffer;
private Texture depthStencilTexture;
public BasicStencilGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public BasicStencilGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));

View File

@ -14,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.DefaultBackend, 60, true)
{
Logger.LogInfo("Press Left to toggle wireframe mode\nPress Down to toggle small viewport\nPress Right to toggle scissor rect");

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.DefaultBackend, 60, true) { }
protected override void Update(System.TimeSpan delta) { }

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.DefaultBackend, 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);
}

View File

@ -21,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.DefaultBackend, 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between textures");
Logger.LogInfo("Setting texture to: " + textureNames[0]);

View File

@ -23,7 +23,7 @@ namespace MoonWorks.Test
}
}
public ComputeUniformsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public ComputeUniformsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 60, true)
{
// Create the compute pipeline that writes texture data
ShaderModule gradientTextureComputeShaderModule = new ShaderModule(

View File

@ -14,7 +14,7 @@ namespace MoonWorks.Test
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.DefaultBackend, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));
@ -115,22 +115,19 @@ namespace MoonWorks.Test
// Render the half-size copy
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(
originalTexture,
compareBuffer,
new BufferImageCopy(0, 0, 0),
TransferOptions.Overwrite
);
cmdbuf.EndCopyPass();
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Copy the texture to a transfer buffer
TransferBuffer compareBuffer = new TransferBuffer(GraphicsDevice, byteCount);
GraphicsDevice.DownloadFromTexture(
textureCopy,
compareBuffer,
TransferOptions.Overwrite
);
// Compare the original bytes to the copied bytes.
var copiedBytes = NativeMemory.Alloc(byteCount);
var copiedSpan = new System.Span<byte>(copiedBytes, (int) byteCount);
@ -140,12 +137,12 @@ namespace MoonWorks.Test
if (System.MemoryExtensions.SequenceEqual(originalSpan, copiedSpan))
{
Logger.LogError("SUCCESS! Original texture bytes and the bytes from CopyTextureToBuffer match!");
Logger.LogError("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);

View File

@ -26,6 +26,7 @@ namespace MoonWorks.Test
private TransferBuffer screenshotTransferBuffer;
private Texture screenshotTexture;
private Fence? screenshotFence;
private Texture skyboxTexture;
private Sampler skyboxSampler;
@ -38,6 +39,7 @@ namespace MoonWorks.Test
private Vector3 camPos = new Vector3(0, 1.5f, 4f);
private bool takeScreenshot;
private bool screenshotInProgress;
private bool swapchainCopied; // don't want to take screenshot if the swapchain was invalid
struct DepthUniforms
@ -86,7 +88,7 @@ namespace MoonWorks.Test
cubemapUploader.Dispose();
}
public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public CubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 60, true)
{
ShaderModule cubeVertShaderModule = new ShaderModule(
GraphicsDevice,
@ -360,7 +362,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;
}
@ -461,32 +463,31 @@ namespace MoonWorks.Test
}
}
GraphicsDevice.Submit(cmdbuf);
if (takeScreenshot && swapchainCopied)
{
screenshotFence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
Task.Run(TakeScreenshot);
takeScreenshot = false;
swapchainCopied = false;
}
else
{
GraphicsDevice.Submit(cmdbuf);
}
}
private unsafe void TakeScreenshot()
{
var commandBuffer = GraphicsDevice.AcquireCommandBuffer();
screenshotInProgress = true;
commandBuffer.BeginCopyPass();
commandBuffer.DownloadFromTexture(
GraphicsDevice.WaitForFences(screenshotFence);
GraphicsDevice.DownloadFromTexture(
screenshotTexture,
screenshotTransferBuffer,
TransferOptions.Overwrite
);
commandBuffer.EndCopyPass();
var fence = GraphicsDevice.SubmitAndAcquireFence(commandBuffer);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
ImageUtils.SavePNG(
Path.Combine(System.AppContext.BaseDirectory, "screenshot.png"),
@ -496,6 +497,11 @@ namespace MoonWorks.Test
(int) screenshotTexture.Height,
screenshotTexture.Format == TextureFormat.B8G8R8A8
);
GraphicsDevice.ReleaseFence(screenshotFence);
screenshotFence = null;
screenshotInProgress = false;
}
public static void Main(string[] args)

View File

@ -17,7 +17,7 @@ namespace MoonWorks.Test
private bool useClockwiseWinding;
public CullFaceGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public CullFaceGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 60, true)
{
Logger.LogInfo("Press Down to toggle the winding order of the triangles (default is counter-clockwise)");

View File

@ -21,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.DefaultBackend, 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between sample counts");
Logger.LogInfo("Setting sample count to: " + currentSampleCount);

View File

@ -10,7 +10,7 @@ namespace MoonWorks.Test
private GpuBuffer vertexBuffer;
private GpuBuffer drawBuffer;
public DrawIndirectGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public DrawIndirectGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("PositionColor.vert"));

View File

@ -6,7 +6,7 @@ namespace MoonWorks.Test
{
class GetBufferDataGame : Game
{
public GetBufferDataGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public GetBufferDataGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 60, true)
{
var vertices = new System.Span<PositionVertex>(
[
@ -33,24 +33,19 @@ namespace MoonWorks.Test
var vertexBuffer = resourceUploader.CreateBuffer(vertices, BufferUsageFlags.Vertex);
resourceUploader.Upload();
// Wait for the vertices to finish copying...
resourceUploader.UploadAndWait();
resourceUploader.Dispose();
var transferBuffer = new TransferBuffer(GraphicsDevice, vertexBuffer.Size);
CommandBuffer cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.BeginCopyPass();
cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer, TransferOptions.Overwrite);
cmdbuf.EndCopyPass();
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
// Wait for the vertices to finish copying...
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Read back and print out the vertex values
GraphicsDevice.DownloadFromBuffer(
vertexBuffer,
transferBuffer,
TransferOptions.Overwrite
);
PositionVertex[] readbackVertices = new PositionVertex[vertices.Length];
transferBuffer.GetData<PositionVertex>(readbackVertices);
for (int i = 0; i < readbackVertices.Length; i += 1)
@ -59,23 +54,22 @@ namespace MoonWorks.Test
}
// Change the first three vertices and upload
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
transferBuffer.SetData(otherVerts, TransferOptions.Overwrite);
var cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.BeginCopyPass();
cmdbuf.UploadToBuffer(transferBuffer, vertexBuffer, WriteOptions.SafeOverwrite);
cmdbuf.EndCopyPass();
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
var fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
// Download the data
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.BeginCopyPass();
cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer, TransferOptions.Overwrite);
cmdbuf.EndCopyPass();
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
GraphicsDevice.DownloadFromBuffer(
vertexBuffer,
transferBuffer,
TransferOptions.Overwrite
);
// Read the updated buffer
transferBuffer.GetData<PositionVertex>(readbackVertices);
@ -103,13 +97,11 @@ namespace MoonWorks.Test
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
cmdbuf = GraphicsDevice.AcquireCommandBuffer();
cmdbuf.BeginCopyPass();
cmdbuf.DownloadFromBuffer(vertexBuffer, transferBuffer, TransferOptions.Overwrite);
cmdbuf.EndCopyPass();
fence = GraphicsDevice.SubmitAndAcquireFence(cmdbuf);
GraphicsDevice.WaitForFences(fence);
GraphicsDevice.ReleaseFence(fence);
GraphicsDevice.DownloadFromBuffer(
vertexBuffer,
transferBuffer,
TransferOptions.Overwrite
);
// Read the updated buffer
transferBuffer.GetData<PositionVertex>(readbackVertices);

View File

@ -13,7 +13,7 @@ namespace MoonWorks.Test
private bool useVertexOffset;
private bool useIndexOffset;
public InstancingAndOffsetsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public InstancingAndOffsetsGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 60, true)
{
Logger.LogInfo("Press Left to toggle vertex offset\nPress Right to toggle index offset");

View File

@ -16,7 +16,7 @@ namespace MoonWorks.Test
private SampleCount currentSampleCount = SampleCount.Four;
public MSAAGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public MSAAGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 60, true)
{
Logger.LogInfo("Press Left and Right to cycle between sample counts");
Logger.LogInfo("Setting sample count to: " + currentSampleCount);

View File

@ -20,7 +20,7 @@ namespace MoonWorks.Test
private SampleCount currentSampleCount = SampleCount.Four;
public MSAACubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), 60, true)
public MSAACubeGame() : base(TestUtils.GetStandardWindowCreateInfo(), TestUtils.GetStandardFrameLimiterSettings(), TestUtils.DefaultBackend, 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");

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,8 @@ namespace MoonWorks.Test
{
public static class TestUtils
{
public static Backend DefaultBackend = Backend.D3D11; // change this to test different backends
public static WindowCreateInfo GetStandardWindowCreateInfo()
{
return new WindowCreateInfo(

View File

@ -12,7 +12,7 @@ namespace MoonWorks.Test
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.DefaultBackend, 60, true)
{
// Load the shaders
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("TexturedQuad.vert"));

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.DefaultBackend, 60, true)
{
ShaderModule vertShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("RawTriangle.vert"));
ShaderModule fragShaderModule = new ShaderModule(GraphicsDevice, TestUtils.GetShaderPath("SolidColor.frag"));