diff --git a/src/XenoAtom.Graphics.Tests/BufferTests.cs b/src/XenoAtom.Graphics.Tests/BufferTests.cs index c3ae6fd..e2becc7 100644 --- a/src/XenoAtom.Graphics.Tests/BufferTests.cs +++ b/src/XenoAtom.Graphics.Tests/BufferTests.cs @@ -7,7 +7,7 @@ namespace XenoAtom.Graphics.Tests { - public abstract class BufferTestBase : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class BufferTestBase : GraphicsDeviceTestBase { protected BufferTestBase(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { @@ -19,7 +19,7 @@ public void CreateBuffer_Succeeds() uint expectedSize = 64; BufferUsage expectedUsage = BufferUsage.Dynamic | BufferUsage.UniformBuffer; - DeviceBuffer buffer = RF.CreateBuffer(new BufferDescription(expectedSize, expectedUsage)); + DeviceBuffer buffer = GD.CreateBuffer(new BufferDescription(expectedSize, expectedUsage)); Assert.Equal(expectedUsage, buffer.Usage); Assert.Equal(expectedSize, buffer.SizeInBytes); @@ -127,7 +127,7 @@ public void CopyBuffer_Succeeds() DeviceBuffer dst = CreateBuffer(1024, BufferUsage.Staging); - CommandList copyCL = RF.CreateCommandList(); + CommandList copyCL = GD.CreateCommandList(); copyCL.Begin(); copyCL.CopyBuffer(src, 0, dst, 0, src.SizeInBytes); copyCL.End(); @@ -154,10 +154,10 @@ public void CopyBuffer_Chain_Succeeds() for (int chainLength = 2; chainLength <= 10; chainLength += 4) { DeviceBuffer[] dsts = Enumerable.Range(0, chainLength) - .Select(i => RF.CreateBuffer(new BufferDescription(1024, BufferUsage.UniformBuffer))) + .Select(i => GD.CreateBuffer(new BufferDescription(1024, BufferUsage.UniformBuffer))) .ToArray(); - CommandList copyCL = RF.CreateCommandList(); + CommandList copyCL = GD.CreateCommandList(); copyCL.Begin(); copyCL.CopyBuffer(src, 0, dsts[0], 0, src.SizeInBytes); for (int i = 0; i < chainLength - 1; i++) @@ -193,7 +193,7 @@ public void MapThenUpdate_Fails() return; // TODO } - DeviceBuffer buffer = RF.CreateBuffer(new BufferDescription(1024, BufferUsage.Staging)); + DeviceBuffer buffer = GD.CreateBuffer(new BufferDescription(1024, BufferUsage.Staging)); MappedResourceView view = GD.Map(buffer, MapMode.ReadWrite); int[] data = Enumerable.Range(0, 256).Select(i => 2 * i).ToArray(); Assert.Throws(() => GD.UpdateBuffer(buffer, 0, data)); @@ -202,7 +202,7 @@ public void MapThenUpdate_Fails() [Fact] public void Map_MultipleTimes_Succeeds() { - DeviceBuffer buffer = RF.CreateBuffer(new BufferDescription(1024, BufferUsage.Staging)); + DeviceBuffer buffer = GD.CreateBuffer(new BufferDescription(1024, BufferUsage.Staging)); MappedResource map = GD.Map(buffer, MapMode.ReadWrite); IntPtr dataPtr = map.Data; map = GD.Map(buffer, MapMode.ReadWrite); @@ -227,7 +227,7 @@ public void Map_DifferentMode_Fails() return; // TODO } - DeviceBuffer buffer = RF.CreateBuffer(new BufferDescription(1024, BufferUsage.Staging)); + DeviceBuffer buffer = GD.CreateBuffer(new BufferDescription(1024, BufferUsage.Staging)); MappedResource map = GD.Map(buffer, MapMode.Read); Assert.Throws(() => GD.Map(buffer, MapMode.Write)); } @@ -235,15 +235,15 @@ public void Map_DifferentMode_Fails() [Fact] public unsafe void UnusualSize() { - DeviceBuffer src = RF.CreateBuffer( + DeviceBuffer src = GD.CreateBuffer( new BufferDescription(208, BufferUsage.UniformBuffer)); - DeviceBuffer dst = RF.CreateBuffer( + DeviceBuffer dst = GD.CreateBuffer( new BufferDescription(208, BufferUsage.Staging)); byte[] data = Enumerable.Range(0, 208).Select(i => (byte)(i * 150)).ToArray(); GD.UpdateBuffer(src, 0, data); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyBuffer(src, 0, dst, 0, src.SizeInBytes); cl.End(); @@ -259,21 +259,21 @@ public unsafe void UnusualSize() [Fact] public void Update_Dynamic_NonZeroOffset() { - DeviceBuffer dynamic = RF.CreateBuffer( + DeviceBuffer dynamic = GD.CreateBuffer( new BufferDescription(1024, BufferUsage.Dynamic | BufferUsage.UniformBuffer)); byte[] initialData = Enumerable.Range(0, 1024).Select(i => (byte)i).ToArray(); GD.UpdateBuffer(dynamic, 0, initialData); byte[] replacementData = Enumerable.Repeat((byte)255, 512).ToArray(); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.UpdateBuffer(dynamic, 512, replacementData); cl.End(); GD.SubmitCommands(cl); GD.WaitForIdle(); - DeviceBuffer dst = RF.CreateBuffer( + DeviceBuffer dst = GD.CreateBuffer( new BufferDescription(1024, BufferUsage.Staging)); cl.Begin(); @@ -297,7 +297,7 @@ public void Update_Dynamic_NonZeroOffset() [Fact] public void Dynamic_MapRead_Fails() { - DeviceBuffer dynamic = RF.CreateBuffer( + DeviceBuffer dynamic = GD.CreateBuffer( new BufferDescription(1024, BufferUsage.Dynamic | BufferUsage.UniformBuffer)); Assert.Throws(() => GD.Map(dynamic, MapMode.Read)); Assert.Throws(() => GD.Map(dynamic, MapMode.ReadWrite)); @@ -306,11 +306,11 @@ public void Dynamic_MapRead_Fails() [Fact] public void CommandList_Update_Staging() { - DeviceBuffer staging = RF.CreateBuffer( + DeviceBuffer staging = GD.CreateBuffer( new BufferDescription(1024, BufferUsage.Staging)); byte[] data = Enumerable.Range(0, 1024).Select(i => (byte)i).ToArray(); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.UpdateBuffer(staging, 0, data); cl.End(); @@ -356,7 +356,7 @@ public void Copy_UnalignedRegion( byte[] data = Enumerable.Range(0, (int)srcBufferSize).Select(i => (byte)i).ToArray(); GD.UpdateBuffer(src, 0, data); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyBuffer(src, srcCopyOffset, dst, dstCopyOffset, copySize); cl.End(); @@ -384,7 +384,7 @@ public void CommandList_UpdateNonStaging_Unaligned(BufferUsage usage, uint buffe { DeviceBuffer buffer = CreateBuffer(bufferSize, usage); byte[] data = Enumerable.Range(0, (int)dataSize).Select(i => (byte)i).ToArray(); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.UpdateBuffer(buffer, offset, data); cl.End(); @@ -429,7 +429,7 @@ public void UpdateUniform_Offset_GraphicsDevice(BufferUsage usage) public void UpdateUniform_Offset_CommandList(BufferUsage usage) { DeviceBuffer buffer = CreateBuffer(128, usage); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); Matrix4x4 mat1 = new Matrix4x4(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1); cl.UpdateBuffer(buffer, 0, ref mat1); @@ -476,7 +476,7 @@ public void CreateBuffer_UsageFlagsCoverage(BufferUsage usage) description.StructureByteStride = 16; } - DeviceBuffer buffer = RF.CreateBuffer(description); + DeviceBuffer buffer = GD.CreateBuffer(description); GD.UpdateBuffer(buffer, 0, new Vector4[4]); GD.WaitForIdle(); } @@ -504,7 +504,7 @@ public unsafe void CopyBuffer_ZeroSize(BufferUsage usage) GD.UpdateBuffer(src, 0, initialDataSrc); GD.UpdateBuffer(dst, 0, initialDataDst); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyBuffer(src, 0, dst, 0, 0); cl.End(); @@ -547,7 +547,7 @@ public unsafe void UpdateBuffer_ZeroSize(BufferUsage usage, bool useCommandListU if (useCommandListUpdate) { - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); fixed (byte* dataPtr = otherData) { @@ -579,12 +579,12 @@ public unsafe void UpdateBuffer_ZeroSize(BufferUsage usage, bool useCommandListU private DeviceBuffer CreateBuffer(uint size, BufferUsage usage) { - return RF.CreateBuffer(new BufferDescription(size, usage)); + return GD.CreateBuffer(new BufferDescription(size, usage)); } } [Trait("Backend", "Vulkan")] - public class VulkanBufferTests : BufferTestBase + public class VulkanBufferTests : BufferTestBase { public VulkanBufferTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Tests/ComputeTests.cs b/src/XenoAtom.Graphics.Tests/ComputeTests.cs index ed7443a..3f4fa8c 100644 --- a/src/XenoAtom.Graphics.Tests/ComputeTests.cs +++ b/src/XenoAtom.Graphics.Tests/ComputeTests.cs @@ -27,7 +27,7 @@ public FillValueStruct(float fillValue) } - public abstract class ComputeTests : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class ComputeTests : GraphicsDeviceTestBase { protected ComputeTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { @@ -39,20 +39,20 @@ public void ComputeShader3dTexture() const float FillValue = 42.42f; const uint OutputTextureSize = 32; - using Shader computeShader = TestShaders.LoadCompute(RF, "ComputeShader3dTexture"); - using ResourceLayout computeLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + using Shader computeShader = TestShaders.LoadCompute(GD, "ComputeShader3dTexture"); + using ResourceLayout computeLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("TextureToFill", ResourceKind.TextureReadWrite, ShaderStages.Compute), new ResourceLayoutElementDescription("FillValueBuffer", ResourceKind.UniformBuffer, ShaderStages.Compute))); - using Pipeline computePipeline = RF.CreateComputePipeline(new ComputePipelineDescription( + using Pipeline computePipeline = GD.CreateComputePipeline(new ComputePipelineDescription( computeShader, computeLayout, 16, 16, 1)); - using DeviceBuffer fillValueBuffer = RF.CreateBuffer(new BufferDescription((uint)Marshal.SizeOf(), BufferUsage.UniformBuffer)); + using DeviceBuffer fillValueBuffer = GD.CreateBuffer(new BufferDescription((uint)Marshal.SizeOf(), BufferUsage.UniformBuffer)); // Create our output texture. - using Texture computeTargetTexture = RF.CreateTexture(TextureDescription.Texture3D( + using Texture computeTargetTexture = GD.CreateTexture(TextureDescription.Texture3D( OutputTextureSize, OutputTextureSize, OutputTextureSize, @@ -60,14 +60,14 @@ public void ComputeShader3dTexture() PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled | TextureUsage.Storage)); - using TextureView computeTargetTextureView = RF.CreateTextureView(computeTargetTexture); + using TextureView computeTargetTextureView = GD.CreateTextureView(computeTargetTexture); - using ResourceSet computeResourceSet = RF.CreateResourceSet(new ResourceSetDescription( + using ResourceSet computeResourceSet = GD.CreateResourceSet(new ResourceSetDescription( computeLayout, computeTargetTextureView, fillValueBuffer)); - using CommandList cl = RF.CreateCommandList(); + using CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.UpdateBuffer(fillValueBuffer, 0, new FillValueStruct(FillValue)); @@ -100,12 +100,12 @@ private int CountTexelsNotFilledAtDepth(GraphicsDevice device, Textur where TexelType : unmanaged { // We need to create a staging texture and copy into it. - using Texture staging = RF.CreateTexture(new(texture.Width, texture.Height, depth: 1, + using Texture staging = GD.CreateTexture(new(texture.Width, texture.Height, depth: 1, texture.MipLevels, texture.ArrayLayers, texture.Format, TextureUsage.Staging, texture.Type, texture.SampleCount)); - using CommandList cl = RF.CreateCommandList(); + using CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture(texture, @@ -161,16 +161,16 @@ public void BasicCompute() { Skip.IfNot(GD.Features.ComputeShader); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Params", ResourceKind.UniformBuffer, ShaderStages.Compute), new ResourceLayoutElementDescription("Source", ResourceKind.StructuredBufferReadWrite, ShaderStages.Compute), new ResourceLayoutElementDescription("Destination", ResourceKind.StructuredBufferReadWrite, ShaderStages.Compute))); uint width = 1024; uint height = 1024; - DeviceBuffer paramsBuffer = RF.CreateBuffer(new BufferDescription((uint)Unsafe.SizeOf(), BufferUsage.UniformBuffer)); - DeviceBuffer sourceBuffer = RF.CreateBuffer(new BufferDescription(width * height * 4, BufferUsage.StructuredBufferReadWrite, 4, true)); - DeviceBuffer destinationBuffer = RF.CreateBuffer(new BufferDescription(width * height * 4, BufferUsage.StructuredBufferReadWrite, 4, true)); + DeviceBuffer paramsBuffer = GD.CreateBuffer(new BufferDescription((uint)Unsafe.SizeOf(), BufferUsage.UniformBuffer)); + DeviceBuffer sourceBuffer = GD.CreateBuffer(new BufferDescription(width * height * 4, BufferUsage.StructuredBufferReadWrite, 4, true)); + DeviceBuffer destinationBuffer = GD.CreateBuffer(new BufferDescription(width * height * 4, BufferUsage.StructuredBufferReadWrite, 4, true)); GD.UpdateBuffer(paramsBuffer, 0, new BasicComputeTestParams { Width = width, Height = height }); @@ -183,14 +183,14 @@ public void BasicCompute() } GD.UpdateBuffer(sourceBuffer, 0, sourceData); - ResourceSet rs = RF.CreateResourceSet(new ResourceSetDescription(layout, paramsBuffer, sourceBuffer, destinationBuffer)); + ResourceSet rs = GD.CreateResourceSet(new ResourceSetDescription(layout, paramsBuffer, sourceBuffer, destinationBuffer)); - Pipeline pipeline = RF.CreateComputePipeline(new ComputePipelineDescription( - TestShaders.LoadCompute(RF, "BasicComputeTest"), + Pipeline pipeline = GD.CreateComputePipeline(new ComputePipelineDescription( + TestShaders.LoadCompute(GD, "BasicComputeTest"), layout, 16, 16, 1)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetPipeline(pipeline); cl.SetComputeResourceSet(0, rs); @@ -230,7 +230,7 @@ public void ComputeCubemapGeneration() 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled | TextureUsage.Storage | TextureUsage.Cubemap); - Texture computeOutput = RF.CreateTexture(texDesc); + Texture computeOutput = GD.CreateTexture(texDesc); Vector4[] faceColors = new Vector4[] { new Vector4(0 * 42), @@ -241,16 +241,16 @@ public void ComputeCubemapGeneration() new Vector4(5 * 42) }; - ResourceLayout computeLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout computeLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("ComputeOutput", ResourceKind.TextureReadWrite, ShaderStages.Compute))); - ResourceSet computeSet = RF.CreateResourceSet(new ResourceSetDescription(computeLayout, computeOutput)); + ResourceSet computeSet = GD.CreateResourceSet(new ResourceSetDescription(computeLayout, computeOutput)); - Pipeline computePipeline = RF.CreateComputePipeline(new ComputePipelineDescription( - TestShaders.LoadCompute(RF, "ComputeCubemapGenerator"), + Pipeline computePipeline = GD.CreateComputePipeline(new ComputePipelineDescription( + TestShaders.LoadCompute(GD, "ComputeCubemapGenerator"), computeLayout, 32, 32, 1)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetPipeline(computePipeline); cl.SetComputeResourceSet(0, computeSet); @@ -296,9 +296,9 @@ public void ComputeCubemapBindSingleTextureMipLevelOutput() 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled | TextureUsage.Storage | TextureUsage.Cubemap); - Texture computeOutput = RF.CreateTexture(texDesc); + Texture computeOutput = GD.CreateTexture(texDesc); - TextureView computeOutputMipLevel = RF.CreateTextureView(new TextureViewDescription(computeOutput, BoundMipLevel, 1, 0, 1)); + TextureView computeOutputMipLevel = GD.CreateTextureView(new TextureViewDescription(computeOutput, BoundMipLevel, 1, 0, 1)); Vector4[] faceColors = new Vector4[] { new Vector4(0 * 42), @@ -309,12 +309,12 @@ public void ComputeCubemapBindSingleTextureMipLevelOutput() new Vector4(5 * 42) }; - ResourceLayout computeLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout computeLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("ComputeOutput", ResourceKind.TextureReadWrite, ShaderStages.Compute))); - ResourceSet computeSet = RF.CreateResourceSet(new ResourceSetDescription(computeLayout, computeOutputMipLevel)); + ResourceSet computeSet = GD.CreateResourceSet(new ResourceSetDescription(computeLayout, computeOutputMipLevel)); - Pipeline computePipeline = RF.CreateComputePipeline(new ComputePipelineDescription( - TestShaders.LoadCompute(RF, "ComputeCubemapGenerator"), + Pipeline computePipeline = GD.CreateComputePipeline(new ComputePipelineDescription( + TestShaders.LoadCompute(GD, "ComputeCubemapGenerator"), computeLayout, 32, 32, 1)); @@ -338,7 +338,7 @@ public void ComputeCubemapBindSingleTextureMipLevelOutput() } } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetPipeline(computePipeline); cl.SetComputeResourceSet(0, computeSet); @@ -382,9 +382,9 @@ public void FillBuffer_WithOffsets(uint srcSetMultiple, uint srcBindingMultiple, uint totalSrcAlignment = GD.StructuredBufferMinOffsetAlignment * (srcSetMultiple + srcBindingMultiple); uint totalDstAlignment = GD.StructuredBufferMinOffsetAlignment * (dstSetMultiple + dstBindingMultiple); - DeviceBuffer copySrc = RF.CreateBuffer( + DeviceBuffer copySrc = GD.CreateBuffer( new BufferDescription(totalSrcAlignment + dataSize, BufferUsage.StructuredBufferReadOnly, sizeof(uint), true)); - DeviceBuffer copyDst = RF.CreateBuffer( + DeviceBuffer copyDst = GD.CreateBuffer( new BufferDescription(totalDstAlignment + dataSize, BufferUsage.StructuredBufferReadWrite, sizeof(uint), true)); ResourceLayout[] layouts; @@ -397,7 +397,7 @@ public void FillBuffer_WithOffsets(uint srcSetMultiple, uint srcBindingMultiple, { layouts = new[] { - RF.CreateResourceLayout(new ResourceLayoutDescription( + GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription( "CopySrc", ResourceKind.StructuredBufferReadOnly, @@ -411,20 +411,20 @@ public void FillBuffer_WithOffsets(uint srcSetMultiple, uint srcBindingMultiple, }; sets = new[] { - RF.CreateResourceSet(new ResourceSetDescription(layouts[0], srcRange, dstRange)) + GD.CreateResourceSet(new ResourceSetDescription(layouts[0], srcRange, dstRange)) }; } else { layouts = new[] { - RF.CreateResourceLayout(new ResourceLayoutDescription( + GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription( "CopySrc", ResourceKind.StructuredBufferReadOnly, ShaderStages.Compute, ResourceLayoutElementOptions.DynamicBinding))), - RF.CreateResourceLayout(new ResourceLayoutDescription( + GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription( "CopyDst", ResourceKind.StructuredBufferReadWrite, @@ -433,20 +433,20 @@ public void FillBuffer_WithOffsets(uint srcSetMultiple, uint srcBindingMultiple, }; sets = new[] { - RF.CreateResourceSet(new ResourceSetDescription(layouts[0], srcRange)), - RF.CreateResourceSet(new ResourceSetDescription(layouts[1], dstRange)), + GD.CreateResourceSet(new ResourceSetDescription(layouts[0], srcRange)), + GD.CreateResourceSet(new ResourceSetDescription(layouts[1], dstRange)), }; } - Pipeline pipeline = RF.CreateComputePipeline(new ComputePipelineDescription( - TestShaders.LoadCompute(RF, combinedLayout ? "FillBuffer" : "FillBuffer_SeparateLayout"), + Pipeline pipeline = GD.CreateComputePipeline(new ComputePipelineDescription( + TestShaders.LoadCompute(GD, combinedLayout ? "FillBuffer" : "FillBuffer_SeparateLayout"), layouts, 1, 1, 1)); uint[] srcData = Enumerable.Range(0, (int)copySrc.SizeInBytes / sizeof(uint)).Select(i => (uint)i).ToArray(); GD.UpdateBuffer(copySrc, 0, srcData); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetPipeline(pipeline); if (combinedLayout) @@ -501,7 +501,7 @@ public static IEnumerable FillBuffer_WithOffsetsData() } [Trait("Backend", "Vulkan")] - public class VulkanComputeTests : ComputeTests + public class VulkanComputeTests : ComputeTests { public VulkanComputeTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Tests/DisposalTests.cs b/src/XenoAtom.Graphics.Tests/DisposalTests.cs index 40e665f..703e3d9 100644 --- a/src/XenoAtom.Graphics.Tests/DisposalTests.cs +++ b/src/XenoAtom.Graphics.Tests/DisposalTests.cs @@ -3,7 +3,7 @@ namespace XenoAtom.Graphics.Tests { - public abstract class DisposalTestBase : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class DisposalTestBase : GraphicsDeviceTestBase { protected DisposalTestBase(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { @@ -12,7 +12,7 @@ protected DisposalTestBase(ITestOutputHelper textOutputHelper) : base(textOutput [Fact] public void Dispose_Buffer() { - DeviceBuffer b = RF.CreateBuffer(new BufferDescription(256, BufferUsage.VertexBuffer)); + DeviceBuffer b = GD.CreateBuffer(new BufferDescription(256, BufferUsage.VertexBuffer)); b.Dispose(); Assert.True(b.IsDisposed); } @@ -20,8 +20,8 @@ public void Dispose_Buffer() [Fact] public void Dispose_Texture() { - Texture t = RF.CreateTexture(TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled)); - TextureView tv = RF.CreateTextureView(t); + Texture t = GD.CreateTexture(TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled)); + TextureView tv = GD.CreateTextureView(t); GD.WaitForIdle(); // Required currently by Vulkan backend. tv.Dispose(); Assert.True(tv.IsDisposed); @@ -33,8 +33,8 @@ public void Dispose_Texture() [Fact] public void Dispose_Framebuffer() { - Texture t = RF.CreateTexture(TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Framebuffer fb = RF.CreateFramebuffer(new FramebufferDescription(null, t)); + Texture t = GD.CreateTexture(TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); + Framebuffer fb = GD.CreateFramebuffer(new FramebufferDescription(null, t)); GD.WaitForIdle(); // Required currently by Vulkan backend. fb.Dispose(); Assert.True(fb.IsDisposed); @@ -46,7 +46,7 @@ public void Dispose_Framebuffer() [Fact] public void Dispose_CommandList() { - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Dispose(); Assert.True(cl.IsDisposed); } @@ -54,7 +54,7 @@ public void Dispose_CommandList() [Fact] public void Dispose_Sampler() { - Sampler s = RF.CreateSampler(SamplerDescription.Point); + Sampler s = GD.CreateSampler(SamplerDescription.Point); s.Dispose(); Assert.True(s.IsDisposed); } @@ -62,7 +62,7 @@ public void Dispose_Sampler() [Fact] public void Dispose_Pipeline() { - Shader[] shaders = TestShaders.LoadVertexFragment(RF, "UIntVertexAttribs"); + Shader[] shaders = TestShaders.LoadVertexFragment(GD, "UIntVertexAttribs"); ShaderSetDescription shaderSet = new ShaderSetDescription( new VertexLayoutDescription[] { @@ -72,7 +72,7 @@ public void Dispose_Pipeline() }, shaders); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("Ortho", ResourceKind.UniformBuffer, ShaderStages.Vertex))); @@ -84,7 +84,7 @@ public void Dispose_Pipeline() shaderSet, layout, new OutputDescription(null, new OutputAttachmentDescription(PixelFormat.R32_G32_B32_A32_Float))); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); pipeline.Dispose(); Assert.True(pipeline.IsDisposed); Assert.False(shaders[0].IsDisposed); @@ -103,14 +103,14 @@ public void Dispose_Pipeline() [Fact] public void Dispose_ResourceSet() { - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("Ortho", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - DeviceBuffer ub0 = RF.CreateBuffer(new BufferDescription(256, BufferUsage.UniformBuffer)); - DeviceBuffer ub1 = RF.CreateBuffer(new BufferDescription(256, BufferUsage.UniformBuffer)); + DeviceBuffer ub0 = GD.CreateBuffer(new BufferDescription(256, BufferUsage.UniformBuffer)); + DeviceBuffer ub1 = GD.CreateBuffer(new BufferDescription(256, BufferUsage.UniformBuffer)); - ResourceSet rs = RF.CreateResourceSet(new ResourceSetDescription(layout, ub0, ub1)); + ResourceSet rs = GD.CreateResourceSet(new ResourceSetDescription(layout, ub0, ub1)); rs.Dispose(); Assert.True(rs.IsDisposed); Assert.False(ub0.IsDisposed); @@ -128,7 +128,7 @@ public void Dispose_ResourceSet() } [Trait("Backend", "Vulkan")] - public class VulkanDisposalTests : DisposalTestBase + public class VulkanDisposalTests : DisposalTestBase { public VulkanDisposalTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Tests/FramebufferTests.cs b/src/XenoAtom.Graphics.Tests/FramebufferTests.cs index 48407cd..389cd84 100644 --- a/src/XenoAtom.Graphics.Tests/FramebufferTests.cs +++ b/src/XenoAtom.Graphics.Tests/FramebufferTests.cs @@ -4,7 +4,7 @@ namespace XenoAtom.Graphics.Tests { - public abstract class FramebufferTests : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class FramebufferTests : GraphicsDeviceTestBase { protected FramebufferTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { @@ -13,11 +13,11 @@ protected FramebufferTests(ITestOutputHelper textOutputHelper) : base(textOutput [Fact] public void NoDepthTarget_ClearAllColors_Succeeds() { - Texture colorTarget = RF.CreateTexture( + Texture colorTarget = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Framebuffer fb = RF.CreateFramebuffer(new FramebufferDescription(null, colorTarget)); + Framebuffer fb = GD.CreateFramebuffer(new FramebufferDescription(null, colorTarget)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(fb); cl.ClearColorTarget(0, RgbaFloat.Red); @@ -25,7 +25,7 @@ public void NoDepthTarget_ClearAllColors_Succeeds() GD.SubmitCommands(cl); GD.WaitForIdle(); - Texture staging = RF.CreateTexture( + Texture staging = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); cl.Begin(); @@ -48,11 +48,11 @@ public void NoDepthTarget_ClearAllColors_Succeeds() [Fact] public void NoDepthTarget_ClearDepth_Fails() { - Texture colorTarget = RF.CreateTexture( + Texture colorTarget = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Framebuffer fb = RF.CreateFramebuffer(new FramebufferDescription(null, colorTarget)); + Framebuffer fb = GD.CreateFramebuffer(new FramebufferDescription(null, colorTarget)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(fb); Assert.Throws(() => cl.ClearDepthStencil(1f)); @@ -61,11 +61,11 @@ public void NoDepthTarget_ClearDepth_Fails() [Fact] public void NoColorTarget_ClearColor_Fails() { - Texture depthTarget = RF.CreateTexture( + Texture depthTarget = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 1, 1, PixelFormat.R16_UNorm, TextureUsage.DepthStencil)); - Framebuffer fb = RF.CreateFramebuffer(new FramebufferDescription(depthTarget)); + Framebuffer fb = GD.CreateFramebuffer(new FramebufferDescription(depthTarget)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(fb); Assert.Throws(() => cl.ClearColorTarget(0, RgbaFloat.Red)); @@ -76,11 +76,11 @@ public void ClearColorTarget_OutOfRange_Fails() { TextureDescription desc = TextureDescription.Texture2D( 1024, 1024, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget); - Texture colorTarget0 = RF.CreateTexture(desc); - Texture colorTarget1 = RF.CreateTexture(desc); - Framebuffer fb = RF.CreateFramebuffer(new FramebufferDescription(null, colorTarget0, colorTarget1)); + Texture colorTarget0 = GD.CreateTexture(desc); + Texture colorTarget1 = GD.CreateTexture(desc); + Framebuffer fb = GD.CreateFramebuffer(new FramebufferDescription(null, colorTarget0, colorTarget1)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(fb); cl.ClearColorTarget(0, RgbaFloat.Red); @@ -92,17 +92,17 @@ public void ClearColorTarget_OutOfRange_Fails() [Fact] public void NonZeroMipLevel_ClearColor_Succeeds() { - Texture testTex = RF.CreateTexture( + Texture testTex = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 11, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); Framebuffer[] framebuffers = new Framebuffer[11]; for (uint level = 0; level < 11; level++) { - framebuffers[level] = RF.CreateFramebuffer( + framebuffers[level] = GD.CreateFramebuffer( new FramebufferDescription(null, new[] { new FramebufferAttachmentDescription(testTex, 0, level) })); } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); for (uint level = 0; level < 11; level++) { @@ -113,7 +113,7 @@ public void NonZeroMipLevel_ClearColor_Succeeds() GD.SubmitCommands(cl); GD.WaitForIdle(); - Texture readback = RF.CreateTexture( + Texture readback = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 11, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); cl.Begin(); cl.CopyTexture(testTex, readback); @@ -139,7 +139,7 @@ public void NonZeroMipLevel_ClearColor_Succeeds() } } - public abstract class SwapchainFramebufferTests : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class SwapchainFramebufferTests : GraphicsDeviceTestBase { protected SwapchainFramebufferTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { @@ -148,7 +148,7 @@ protected SwapchainFramebufferTests(ITestOutputHelper textOutputHelper) : base(t //[Fact] //public void ClearSwapchainFramebuffer_Succeeds() //{ - // CommandList cl = RF.CreateCommandList(); + // CommandList cl = GD.CreateCommandList(); // cl.Begin(); // cl.SetFramebuffer(GD.SwapchainFramebuffer); // cl.ClearColorTarget(0, RgbaFloat.Red); @@ -158,7 +158,7 @@ protected SwapchainFramebufferTests(ITestOutputHelper textOutputHelper) : base(t } [Trait("Backend", "Vulkan")] - public class VulkanFramebufferTests : FramebufferTests + public class VulkanFramebufferTests : FramebufferTests { public VulkanFramebufferTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Tests/PipelineTests.cs b/src/XenoAtom.Graphics.Tests/PipelineTests.cs index 562946c..9413ef1 100644 --- a/src/XenoAtom.Graphics.Tests/PipelineTests.cs +++ b/src/XenoAtom.Graphics.Tests/PipelineTests.cs @@ -8,13 +8,13 @@ namespace XenoAtom.Graphics.Tests { - public abstract class PipelineTests : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class PipelineTests : GraphicsDeviceTestBase { [Fact] public void CreatePipelines_DifferentInstanceStepRate_Succeeds() { - Texture colorTex = RF.CreateTexture(TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.RenderTarget)); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, colorTex)); + Texture colorTex = GD.CreateTexture(TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.RenderTarget)); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, colorTex)); ShaderSetDescription shaderSet = new ShaderSetDescription( new VertexLayoutDescription[] @@ -25,9 +25,9 @@ public void CreatePipelines_DifferentInstanceStepRate_Succeeds() new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("Color_UInt", VertexElementSemantic.TextureCoordinate, VertexElementFormat.UInt4)) }, - TestShaders.LoadVertexFragment(RF, "UIntVertexAttribs")); + TestShaders.LoadVertexFragment(GD, "UIntVertexAttribs")); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("Ortho", ResourceKind.UniformBuffer, ShaderStages.Vertex))); @@ -40,14 +40,14 @@ public void CreatePipelines_DifferentInstanceStepRate_Succeeds() layout, framebuffer.OutputDescription); - Pipeline pipeline1 = RF.CreateGraphicsPipeline(gpd); - Pipeline pipeline2 = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline1 = GD.CreateGraphicsPipeline(gpd); + Pipeline pipeline2 = GD.CreateGraphicsPipeline(gpd); gpd.ShaderSet.VertexLayouts[0].InstanceStepRate = 4; - Pipeline pipeline3 = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline3 = GD.CreateGraphicsPipeline(gpd); gpd.ShaderSet.VertexLayouts[0].InstanceStepRate = 5; - Pipeline pipeline4 = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline4 = GD.CreateGraphicsPipeline(gpd); } protected PipelineTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) @@ -56,7 +56,7 @@ protected PipelineTests(ITestOutputHelper textOutputHelper) : base(textOutputHel } [Trait("Backend", "Vulkan")] - public class VulkanPipelineTests : PipelineTests + public class VulkanPipelineTests : PipelineTests { public VulkanPipelineTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Tests/RenderTests.cs b/src/XenoAtom.Graphics.Tests/RenderTests.cs index d73c94e..579fc5c 100644 --- a/src/XenoAtom.Graphics.Tests/RenderTests.cs +++ b/src/XenoAtom.Graphics.Tests/RenderTests.cs @@ -41,20 +41,20 @@ public struct TestVertex public Vector4 D_V4; } - public abstract class RenderTests : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class RenderTests : GraphicsDeviceTestBase { [Fact] public void Points_WithUIntColor() { - Texture target = RF.CreateTexture(TextureDescription.Texture2D( + Texture target = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Texture staging = RF.CreateTexture(TextureDescription.Texture2D( + Texture staging = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, target)); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, target)); - DeviceBuffer infoBuffer = RF.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); - DeviceBuffer orthoBuffer = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer infoBuffer = GD.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); + DeviceBuffer orthoBuffer = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); Matrix4x4 orthoMatrix = Matrix4x4.CreateOrthographicOffCenter( 0, framebuffer.Width, @@ -71,13 +71,13 @@ public void Points_WithUIntColor() new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("Color_UInt", VertexElementSemantic.TextureCoordinate, VertexElementFormat.UInt4)) }, - TestShaders.LoadVertexFragment(RF, "UIntVertexAttribs")); + TestShaders.LoadVertexFragment(GD, "UIntVertexAttribs")); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("Ortho", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -88,7 +88,7 @@ public void Points_WithUIntColor() layout, framebuffer.OutputDescription); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); uint colorNormalizationFactor = 2500; @@ -136,12 +136,12 @@ public void Points_WithUIntColor() }, }; - DeviceBuffer vb = RF.CreateBuffer( + DeviceBuffer vb = GD.CreateBuffer( new BufferDescription((uint)(Unsafe.SizeOf() * vertices.Length), BufferUsage.VertexBuffer)); GD.UpdateBuffer(vb, 0, vertices); GD.UpdateBuffer(infoBuffer, 0, new UIntVertexAttribsInfo { ColorNormalizationFactor = colorNormalizationFactor }); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -181,14 +181,14 @@ public void Points_WithUIntColor() [Fact] public void Points_WithUShortNormColor() { - Texture target = RF.CreateTexture(TextureDescription.Texture2D( + Texture target = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Texture staging = RF.CreateTexture(TextureDescription.Texture2D( + Texture staging = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, target)); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, target)); - DeviceBuffer orthoBuffer = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer orthoBuffer = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); Matrix4x4 orthoMatrix = Matrix4x4.CreateOrthographicOffCenter( 0, framebuffer.Width, @@ -205,12 +205,12 @@ public void Points_WithUShortNormColor() new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("Color", VertexElementSemantic.TextureCoordinate, VertexElementFormat.UShort4_Norm)) }, - TestShaders.LoadVertexFragment(RF, "U16NormVertexAttribs")); + TestShaders.LoadVertexFragment(GD, "U16NormVertexAttribs")); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Ortho", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, orthoBuffer)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, orthoBuffer)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -221,7 +221,7 @@ public void Points_WithUShortNormColor() layout, framebuffer.OutputDescription); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); VertexCPU_UShortNorm[] vertices = new VertexCPU_UShortNorm[] { @@ -255,11 +255,11 @@ public void Points_WithUShortNormColor() }, }; - DeviceBuffer vb = RF.CreateBuffer( + DeviceBuffer vb = GD.CreateBuffer( new BufferDescription((uint)(Unsafe.SizeOf() * vertices.Length), BufferUsage.VertexBuffer)); GD.UpdateBuffer(vb, 0, vertices); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -323,15 +323,15 @@ private ushort UShortNorm(float normalizedValue) [Fact] public void Points_WithUShortColor() { - Texture target = RF.CreateTexture(TextureDescription.Texture2D( + Texture target = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Texture staging = RF.CreateTexture(TextureDescription.Texture2D( + Texture staging = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, target)); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, target)); - DeviceBuffer infoBuffer = RF.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); - DeviceBuffer orthoBuffer = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer infoBuffer = GD.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); + DeviceBuffer orthoBuffer = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); Matrix4x4 orthoMatrix = Matrix4x4.CreateOrthographicOffCenter( 0, framebuffer.Width, @@ -348,13 +348,13 @@ public void Points_WithUShortColor() new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("Color_UInt", VertexElementSemantic.TextureCoordinate, VertexElementFormat.UShort4)) }, - TestShaders.LoadVertexFragment(RF, "U16VertexAttribs")); + TestShaders.LoadVertexFragment(GD, "U16VertexAttribs")); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("Ortho", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -365,7 +365,7 @@ public void Points_WithUShortColor() layout, framebuffer.OutputDescription); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); uint colorNormalizationFactor = 2500; @@ -401,12 +401,12 @@ public void Points_WithUShortColor() }, }; - DeviceBuffer vb = RF.CreateBuffer( + DeviceBuffer vb = GD.CreateBuffer( new BufferDescription((uint)(Unsafe.SizeOf() * vertices.Length), BufferUsage.VertexBuffer)); GD.UpdateBuffer(vb, 0, vertices); GD.UpdateBuffer(infoBuffer, 0, new UIntVertexAttribsInfo { ColorNormalizationFactor = colorNormalizationFactor }); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -446,15 +446,15 @@ public void Points_WithUShortColor() [Fact] public void Points_WithFloat16Color() { - Texture target = RF.CreateTexture(TextureDescription.Texture2D( + Texture target = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Texture staging = RF.CreateTexture(TextureDescription.Texture2D( + Texture staging = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, target)); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, target)); - DeviceBuffer infoBuffer = RF.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); - DeviceBuffer orthoBuffer = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer infoBuffer = GD.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); + DeviceBuffer orthoBuffer = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); Matrix4x4 orthoMatrix = Matrix4x4.CreateOrthographicOffCenter( 0, framebuffer.Width, @@ -471,13 +471,13 @@ public void Points_WithFloat16Color() new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("Color_Half", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Half4)) }, - TestShaders.LoadVertexFragment(RF, "F16VertexAttribs")); + TestShaders.LoadVertexFragment(GD, "F16VertexAttribs")); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("OrthoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -488,7 +488,7 @@ public void Points_WithFloat16Color() layout, framebuffer.OutputDescription); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); uint colorNormalizationFactor = 2500; @@ -555,12 +555,12 @@ public void Points_WithFloat16Color() 1), }; - DeviceBuffer vb = RF.CreateBuffer( + DeviceBuffer vb = GD.CreateBuffer( new BufferDescription((uint)(Unsafe.SizeOf() * vertices.Length), BufferUsage.VertexBuffer)); GD.UpdateBuffer(vb, 0, vertices); GD.UpdateBuffer(infoBuffer, 0, new UIntVertexAttribsInfo { ColorNormalizationFactor = colorNormalizationFactor }); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -603,14 +603,14 @@ public unsafe void Points_WithTexture_UpdateUnrelated(bool useTextureView) // at a time after a ResourceSet containing a texture has been bound. The OpenGL // backend was caching texture state improperly, resulting in wrong textures being sampled. - Texture target = RF.CreateTexture(TextureDescription.Texture2D( + Texture target = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Texture staging = RF.CreateTexture(TextureDescription.Texture2D( + Texture staging = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, target)); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, target)); - DeviceBuffer orthoBuffer = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer orthoBuffer = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); Matrix4x4 orthoMatrix = Matrix4x4.CreateOrthographicOffCenter( 0, framebuffer.Width, @@ -620,13 +620,13 @@ public unsafe void Points_WithTexture_UpdateUnrelated(bool useTextureView) 1); GD.UpdateBuffer(orthoBuffer, 0, ref orthoMatrix); - Texture sampledTexture = RF.CreateTexture( + Texture sampledTexture = GD.CreateTexture( TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled)); RgbaFloat white = RgbaFloat.White; GD.UpdateTexture(sampledTexture, (IntPtr)(&white), (uint)Unsafe.SizeOf(), 0, 0, 0, 1, 1, 1, 0, 0); - Texture shouldntBeSampledTexture = RF.CreateTexture( + Texture shouldntBeSampledTexture = GD.CreateTexture( TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled)); ShaderSetDescription shaderSet = new ShaderSetDescription( @@ -635,9 +635,9 @@ public unsafe void Points_WithTexture_UpdateUnrelated(bool useTextureView) new VertexLayoutDescription( new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2)) }, - TestShaders.LoadVertexFragment(RF, "TexturedPoints")); + TestShaders.LoadVertexFragment(GD, "TexturedPoints")); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Ortho", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("Tex", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("Smp", ResourceKind.Sampler, ShaderStages.Fragment))); @@ -645,12 +645,12 @@ public unsafe void Points_WithTexture_UpdateUnrelated(bool useTextureView) ResourceSet set; if (useTextureView) { - TextureView view = RF.CreateTextureView(sampledTexture); - set = RF.CreateResourceSet(new ResourceSetDescription(layout, orthoBuffer, view, GD.PointSampler)); + TextureView view = GD.CreateTextureView(sampledTexture); + set = GD.CreateResourceSet(new ResourceSetDescription(layout, orthoBuffer, view, GD.PointSampler)); } else { - set = RF.CreateResourceSet(new ResourceSetDescription(layout, orthoBuffer, sampledTexture, GD.PointSampler)); + set = GD.CreateResourceSet(new ResourceSetDescription(layout, orthoBuffer, sampledTexture, GD.PointSampler)); } GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( @@ -662,7 +662,7 @@ public unsafe void Points_WithTexture_UpdateUnrelated(bool useTextureView) layout, framebuffer.OutputDescription); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); Vector2[] vertices = new Vector2[] { @@ -672,11 +672,11 @@ public unsafe void Points_WithTexture_UpdateUnrelated(bool useTextureView) new Vector2(3.5f, 25.5f), }; - DeviceBuffer vb = RF.CreateBuffer( + DeviceBuffer vb = GD.CreateBuffer( new BufferDescription((uint)(Unsafe.SizeOf() * vertices.Length), BufferUsage.VertexBuffer)); GD.UpdateBuffer(vb, 0, vertices); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); for (int i = 0; i < 2; i++) { @@ -734,42 +734,42 @@ public void ComputeGeneratedVertices() uint width = 512; uint height = 512; - Texture output = RF.CreateTexture( + Texture output = GD.CreateTexture( TextureDescription.Texture2D(width, height, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, output)); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, output)); uint vertexSize = (uint)Unsafe.SizeOf(); - DeviceBuffer buffer = RF.CreateBuffer(new BufferDescription( + DeviceBuffer buffer = GD.CreateBuffer(new BufferDescription( vertexSize * 4, BufferUsage.StructuredBufferReadWrite, vertexSize, true)); - ResourceLayout computeLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout computeLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("OutputVertices", ResourceKind.StructuredBufferReadWrite, ShaderStages.Compute))); - ResourceSet computeSet = RF.CreateResourceSet(new ResourceSetDescription(computeLayout, buffer)); + ResourceSet computeSet = GD.CreateResourceSet(new ResourceSetDescription(computeLayout, buffer)); - Pipeline computePipeline = RF.CreateComputePipeline(new ComputePipelineDescription( - TestShaders.LoadCompute(RF, "ComputeColoredQuadGenerator"), + Pipeline computePipeline = GD.CreateComputePipeline(new ComputePipelineDescription( + TestShaders.LoadCompute(GD, "ComputeColoredQuadGenerator"), computeLayout, 1, 1, 1)); - ResourceLayout graphicsLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout graphicsLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InputVertices", ResourceKind.StructuredBufferReadOnly, ShaderStages.Vertex))); - ResourceSet graphicsSet = RF.CreateResourceSet(new ResourceSetDescription(graphicsLayout, buffer)); + ResourceSet graphicsSet = GD.CreateResourceSet(new ResourceSetDescription(graphicsLayout, buffer)); - Pipeline graphicsPipeline = RF.CreateGraphicsPipeline(new GraphicsPipelineDescription( + Pipeline graphicsPipeline = GD.CreateGraphicsPipeline(new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, DepthStencilStateDescription.Disabled, RasterizerStateDescription.Default, PrimitiveTopology.TriangleStrip, new ShaderSetDescription( Array.Empty(), - TestShaders.LoadVertexFragment(RF, "ColoredQuadRenderer")), + TestShaders.LoadVertexFragment(GD, "ColoredQuadRenderer")), graphicsLayout, framebuffer.OutputDescription)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetPipeline(computePipeline); cl.SetComputeResourceSet(0, computeSet); @@ -806,37 +806,37 @@ public void ComputeGeneratedTexture() 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled | TextureUsage.Storage); - Texture computeOutput = RF.CreateTexture(texDesc); + Texture computeOutput = GD.CreateTexture(texDesc); texDesc.Usage = TextureUsage.RenderTarget; - Texture finalOutput = RF.CreateTexture(texDesc); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, finalOutput)); + Texture finalOutput = GD.CreateTexture(texDesc); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, finalOutput)); - ResourceLayout computeLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout computeLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("ComputeOutput", ResourceKind.TextureReadWrite, ShaderStages.Compute))); - ResourceSet computeSet = RF.CreateResourceSet(new ResourceSetDescription(computeLayout, computeOutput)); + ResourceSet computeSet = GD.CreateResourceSet(new ResourceSetDescription(computeLayout, computeOutput)); - Pipeline computePipeline = RF.CreateComputePipeline(new ComputePipelineDescription( - TestShaders.LoadCompute(RF, "ComputeTextureGenerator"), + Pipeline computePipeline = GD.CreateComputePipeline(new ComputePipelineDescription( + TestShaders.LoadCompute(GD, "ComputeTextureGenerator"), computeLayout, 4, 1, 1)); - ResourceLayout graphicsLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout graphicsLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Input", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("InputSampler", ResourceKind.Sampler, ShaderStages.Fragment))); - ResourceSet graphicsSet = RF.CreateResourceSet(new ResourceSetDescription(graphicsLayout, computeOutput, GD.PointSampler)); + ResourceSet graphicsSet = GD.CreateResourceSet(new ResourceSetDescription(graphicsLayout, computeOutput, GD.PointSampler)); - Pipeline graphicsPipeline = RF.CreateGraphicsPipeline(new GraphicsPipelineDescription( + Pipeline graphicsPipeline = GD.CreateGraphicsPipeline(new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, DepthStencilStateDescription.Disabled, RasterizerStateDescription.CullNone, PrimitiveTopology.TriangleStrip, new ShaderSetDescription( Array.Empty(), - TestShaders.LoadVertexFragment(RF, "FullScreenBlit")), + TestShaders.LoadVertexFragment(GD, "FullScreenBlit")), graphicsLayout, framebuffer.OutputDescription)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetPipeline(computePipeline); cl.SetComputeResourceSet(0, computeSet); @@ -874,18 +874,18 @@ public void ComputeBindTextureWithArrayLayersAsWriteable(uint ArrayLayers) ArrayLayers, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled | TextureUsage.Storage); - Texture computeOutput = RF.CreateTexture(texDesc); + Texture computeOutput = GD.CreateTexture(texDesc); - ResourceLayout computeLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout computeLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("ComputeOutput", ResourceKind.TextureReadWrite, ShaderStages.Compute))); - ResourceSet computeSet = RF.CreateResourceSet(new ResourceSetDescription(computeLayout, computeOutput)); + ResourceSet computeSet = GD.CreateResourceSet(new ResourceSetDescription(computeLayout, computeOutput)); - Pipeline computePipeline = RF.CreateComputePipeline(new ComputePipelineDescription( - TestShaders.LoadCompute(RF, "ComputeImage2DArrayGenerator"), + Pipeline computePipeline = GD.CreateComputePipeline(new ComputePipelineDescription( + TestShaders.LoadCompute(GD, "ComputeImage2DArrayGenerator"), computeLayout, 32, 32, 1)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetPipeline(computePipeline); cl.SetComputeResourceSet(0, computeSet); @@ -928,30 +928,30 @@ public void SampleTexture1D(bool arrayTexture) { if (!GD.Features.Texture1D) { return; } - Texture target = RF.CreateTexture(TextureDescription.Texture2D( + Texture target = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Texture staging = RF.CreateTexture(TextureDescription.Texture2D( + Texture staging = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, target)); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, target)); string SetName = arrayTexture ? "FullScreenTriSampleTextureArray" : "FullScreenTriSampleTexture"; ShaderSetDescription shaderSet = new ShaderSetDescription( Array.Empty(), - TestShaders.LoadVertexFragment(RF, SetName)); + TestShaders.LoadVertexFragment(GD, SetName)); uint layers = arrayTexture ? 10u : 1u; - Texture tex1D = RF.CreateTexture( + Texture tex1D = GD.CreateTexture( TextureDescription.Texture1D(128, 1, layers, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled)); RgbaFloat[] colors = new RgbaFloat[tex1D.Width]; for (int i = 0; i < colors.Length; i++) { colors[i] = RgbaFloat.Pink; } GD.UpdateTexture(tex1D, colors, 0, 0, 0, tex1D.Width, 1, 1, 0, 0); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Tex", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("Smp", ResourceKind.Sampler, ShaderStages.Fragment))); - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, tex1D, GD.PointSampler)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, tex1D, GD.PointSampler)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -962,9 +962,9 @@ public void SampleTexture1D(bool arrayTexture) layout, framebuffer.OutputDescription); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -990,27 +990,27 @@ public void SampleTexture1D(bool arrayTexture) [Fact] public void BindTextureAcrossMultipleDrawCalls() { - using Texture target1 = RF.CreateTexture(TextureDescription.Texture2D( + using Texture target1 = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - using Texture target2 = RF.CreateTexture(TextureDescription.Texture2D( + using Texture target2 = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget | TextureUsage.Sampled)); - using TextureView textureView = RF.CreateTextureView(target2); + using TextureView textureView = GD.CreateTextureView(target2); - using Texture staging1 = RF.CreateTexture(TextureDescription.Texture2D( + using Texture staging1 = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); - using Texture staging2 = RF.CreateTexture(TextureDescription.Texture2D( + using Texture staging2 = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); - using Texture staging3 = RF.CreateTexture(TextureDescription.Texture2D( + using Texture staging3 = GD.CreateTexture(TextureDescription.Texture2D( 50, 50, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); - using Framebuffer framebuffer1 = RF.CreateFramebuffer(new FramebufferDescription(null, target1)); - using Framebuffer framebuffer2 = RF.CreateFramebuffer(new FramebufferDescription(null, target2)); + using Framebuffer framebuffer1 = GD.CreateFramebuffer(new FramebufferDescription(null, target1)); + using Framebuffer framebuffer2 = GD.CreateFramebuffer(new FramebufferDescription(null, target2)); // This shader doesn't really matter, just as long as it is different to the first // and third render pass and also doesn't use any texture bindings ShaderSetDescription textureShaderSet = new ShaderSetDescription( Array.Empty(), - TestShaders.LoadVertexFragment(RF, "FullScreenTriSampleTexture2D")); + TestShaders.LoadVertexFragment(GD, "FullScreenTriSampleTexture2D")); ShaderSetDescription quadShaderSet = new ShaderSetDescription( new VertexLayoutDescription[] { @@ -1021,9 +1021,9 @@ public void BindTextureAcrossMultipleDrawCalls() new VertexElementDescription("D_V4", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float4) ) }, - TestShaders.LoadVertexFragment(RF, "VertexLayoutTestShader")); + TestShaders.LoadVertexFragment(GD, "VertexLayoutTestShader")); - using DeviceBuffer vertexBuffer = RF.CreateBuffer(new BufferDescription( + using DeviceBuffer vertexBuffer = GD.CreateBuffer(new BufferDescription( (uint)Unsafe.SizeOf() * 3, BufferUsage.VertexBuffer)); GD.UpdateBuffer(vertexBuffer, 0, new[] { @@ -1037,13 +1037,13 @@ public void BindTextureAcrossMultipleDrawCalls() for (int i = 0; i < colors.Length; i++) { colors[i] = RgbaFloat.Pink; } GD.UpdateTexture(target2, colors, 0, 0, 0, target2.Width, target2.Height, 1, 0, 0); - using ResourceLayout textureLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + using ResourceLayout textureLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Tex", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("Smp", ResourceKind.Sampler, ShaderStages.Fragment))); - using ResourceSet textureSet = RF.CreateResourceSet(new ResourceSetDescription(textureLayout, textureView, GD.PointSampler)); + using ResourceSet textureSet = GD.CreateResourceSet(new ResourceSetDescription(textureLayout, textureView, GD.PointSampler)); - using Pipeline texturePipeline = RF.CreateGraphicsPipeline(new GraphicsPipelineDescription( + using Pipeline texturePipeline = GD.CreateGraphicsPipeline(new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, DepthStencilStateDescription.Disabled, RasterizerStateDescription.CullNone, @@ -1051,7 +1051,7 @@ public void BindTextureAcrossMultipleDrawCalls() textureShaderSet, textureLayout, framebuffer1.OutputDescription)); - using Pipeline quadPipeline = RF.CreateGraphicsPipeline(new GraphicsPipelineDescription( + using Pipeline quadPipeline = GD.CreateGraphicsPipeline(new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, DepthStencilStateDescription.Disabled, RasterizerStateDescription.CullNone, @@ -1060,7 +1060,7 @@ public void BindTextureAcrossMultipleDrawCalls() Array.Empty(), framebuffer2.OutputDescription)); - using CommandList cl = RF.CreateCommandList(); + using CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer1); @@ -1114,9 +1114,9 @@ public void BindTextureAcrossMultipleDrawCalls() [InlineData(32, 31)] public void FramebufferArrayLayer(uint layerCount, uint targetLayer) { - Texture target = RF.CreateTexture(TextureDescription.Texture2D( + Texture target = GD.CreateTexture(TextureDescription.Texture2D( 16, 16, 1, layerCount, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Framebuffer framebuffer = RF.CreateFramebuffer( + Framebuffer framebuffer = GD.CreateFramebuffer( new FramebufferDescription( null, new[] { new FramebufferAttachmentDescription(target, targetLayer) })); @@ -1124,19 +1124,19 @@ public void FramebufferArrayLayer(uint layerCount, uint targetLayer) string setName = "FullScreenTriSampleTexture2D"; ShaderSetDescription shaderSet = new ShaderSetDescription( Array.Empty(), - TestShaders.LoadVertexFragment(RF, setName)); + TestShaders.LoadVertexFragment(GD, setName)); - Texture tex2D = RF.CreateTexture( + Texture tex2D = GD.CreateTexture( TextureDescription.Texture2D(128, 128, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled)); RgbaFloat[] colors = new RgbaFloat[tex2D.Width * tex2D.Height]; for (int i = 0; i < colors.Length; i++) { colors[i] = RgbaFloat.Pink; } GD.UpdateTexture(tex2D, colors, 0, 0, 0, tex2D.Width, 1, 1, 0, 0); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Tex", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("Smp", ResourceKind.Sampler, ShaderStages.Fragment))); - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, tex2D, GD.PointSampler)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, tex2D, GD.PointSampler)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -1147,9 +1147,9 @@ public void FramebufferArrayLayer(uint layerCount, uint targetLayer) layout, framebuffer.OutputDescription); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -1181,12 +1181,12 @@ public void FramebufferArrayLayer(uint layerCount, uint targetLayer) [InlineData(4, 2, 5)] public void RenderToCubemapFace(uint layerCount, uint targetLayer, uint targetFace) { - Texture target = RF.CreateTexture(TextureDescription.Texture2D( + Texture target = GD.CreateTexture(TextureDescription.Texture2D( 16, 16, 1, layerCount, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget | TextureUsage.Cubemap)); - Framebuffer framebuffer = RF.CreateFramebuffer( + Framebuffer framebuffer = GD.CreateFramebuffer( new FramebufferDescription( null, new[] { new FramebufferAttachmentDescription(target, (targetLayer * 6) + targetFace) })); @@ -1194,19 +1194,19 @@ public void RenderToCubemapFace(uint layerCount, uint targetLayer, uint targetFa string setName = "FullScreenTriSampleTexture2D"; ShaderSetDescription shaderSet = new ShaderSetDescription( Array.Empty(), - TestShaders.LoadVertexFragment(RF, setName)); + TestShaders.LoadVertexFragment(GD, setName)); - Texture tex2D = RF.CreateTexture( + Texture tex2D = GD.CreateTexture( TextureDescription.Texture2D(128, 128, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled)); RgbaFloat[] colors = new RgbaFloat[tex2D.Width * tex2D.Height]; for (int i = 0; i < colors.Length; i++) { colors[i] = RgbaFloat.Pink; } GD.UpdateTexture(tex2D, colors, 0, 0, 0, tex2D.Width, 1, 1, 0, 0); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("Tex", ResourceKind.TextureReadOnly, ShaderStages.Fragment), new ResourceLayoutElementDescription("Smp", ResourceKind.Sampler, ShaderStages.Fragment))); - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, tex2D, GD.PointSampler)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, tex2D, GD.PointSampler)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -1217,9 +1217,9 @@ public void RenderToCubemapFace(uint layerCount, uint targetLayer, uint targetFa layout, framebuffer.OutputDescription); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -1245,21 +1245,21 @@ public void RenderToCubemapFace(uint layerCount, uint targetLayer, uint targetFa [Fact] public void WriteFragmentDepth() { - Texture depthTarget = RF.CreateTexture( + Texture depthTarget = GD.CreateTexture( TextureDescription.Texture2D(64, 64, 1, 1, PixelFormat.R32_Float, TextureUsage.DepthStencil | TextureUsage.Sampled)); - Framebuffer framebuffer = RF.CreateFramebuffer(new FramebufferDescription(depthTarget)); + Framebuffer framebuffer = GD.CreateFramebuffer(new FramebufferDescription(depthTarget)); string setName = "FullScreenWriteDepth"; ShaderSetDescription shaderSet = new ShaderSetDescription( Array.Empty(), - TestShaders.LoadVertexFragment(RF, setName)); + TestShaders.LoadVertexFragment(GD, setName)); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("FramebufferInfo", ResourceKind.UniformBuffer, ShaderStages.Fragment))); - DeviceBuffer ub = RF.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); + DeviceBuffer ub = GD.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); GD.UpdateBuffer(ub, 0, new Vector4(depthTarget.Width, depthTarget.Height, 0, 0)); - ResourceSet rs = RF.CreateResourceSet(new ResourceSetDescription(layout, ub)); + ResourceSet rs = GD.CreateResourceSet(new ResourceSetDescription(layout, ub)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -1270,9 +1270,9 @@ public void WriteFragmentDepth() layout, framebuffer.OutputDescription); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -1308,9 +1308,9 @@ public void UseBlendFactor() { const uint width = 512; const uint height = 512; - using var output = RF.CreateTexture( + using var output = GD.CreateTexture( TextureDescription.Texture2D(width, height, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - using var framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, output)); + using var framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, output)); var yMod = GD.IsClipSpaceYInverted ? -1.0f : 1.0f; var vertices = new[] @@ -1321,16 +1321,16 @@ public void UseBlendFactor() new ColoredVertex { Position = new Vector2(1, -1 * yMod), Color = Vector4.One } }; uint vertexSize = (uint)Unsafe.SizeOf(); - using var buffer = RF.CreateBuffer(new BufferDescription( + using var buffer = GD.CreateBuffer(new BufferDescription( vertexSize * (uint)vertices.Length, BufferUsage.StructuredBufferReadOnly, vertexSize, true)); GD.UpdateBuffer(buffer, 0, vertices); - using var graphicsLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + using var graphicsLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InputVertices", ResourceKind.StructuredBufferReadOnly, ShaderStages.Vertex))); - using var graphicsSet = RF.CreateResourceSet(new ResourceSetDescription(graphicsLayout, buffer)); + using var graphicsSet = GD.CreateResourceSet(new ResourceSetDescription(graphicsLayout, buffer)); var blendDesc = new BlendStateDescription { @@ -1356,12 +1356,12 @@ public void UseBlendFactor() PrimitiveTopology.TriangleStrip, new ShaderSetDescription( Array.Empty(), - TestShaders.LoadVertexFragment(RF, "ColoredQuadRenderer")), + TestShaders.LoadVertexFragment(GD, "ColoredQuadRenderer")), graphicsLayout, framebuffer.OutputDescription); - using (var pipeline1 = RF.CreateGraphicsPipeline(pipelineDesc)) - using (var cl = RF.CreateCommandList()) + using (var pipeline1 = GD.CreateGraphicsPipeline(pipelineDesc)) + using (var cl = GD.CreateCommandList()) { cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -1390,8 +1390,8 @@ public void UseBlendFactor() blendDesc.AttachmentStates[0].DestinationAlphaFactor = BlendFactor.InverseBlendFactor; pipelineDesc.BlendState = blendDesc; - using (var pipeline2 = RF.CreateGraphicsPipeline(pipelineDesc)) - using (var cl = RF.CreateCommandList()) + using (var pipeline2 = GD.CreateGraphicsPipeline(pipelineDesc)) + using (var cl = GD.CreateCommandList()) { cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -1418,9 +1418,9 @@ public void UseBlendFactor() [Fact] public void UseColorWriteMask() { - Texture output = RF.CreateTexture( + Texture output = GD.CreateTexture( TextureDescription.Texture2D(64, 64, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - using var framebuffer = RF.CreateFramebuffer(new FramebufferDescription(null, output)); + using var framebuffer = GD.CreateFramebuffer(new FramebufferDescription(null, output)); var yMod = GD.IsClipSpaceYInverted ? -1.0f : 1.0f; var vertices = new[] @@ -1431,16 +1431,16 @@ public void UseColorWriteMask() new ColoredVertex { Position = new Vector2(1, -1 * yMod), Color = Vector4.One } }; uint vertexSize = (uint)Unsafe.SizeOf(); - using var buffer = RF.CreateBuffer(new BufferDescription( + using var buffer = GD.CreateBuffer(new BufferDescription( vertexSize * (uint)vertices.Length, BufferUsage.StructuredBufferReadOnly, vertexSize, true)); GD.UpdateBuffer(buffer, 0, vertices); - using var graphicsLayout = RF.CreateResourceLayout(new ResourceLayoutDescription( + using var graphicsLayout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InputVertices", ResourceKind.StructuredBufferReadOnly, ShaderStages.Vertex))); - using var graphicsSet = RF.CreateResourceSet(new ResourceSetDescription(graphicsLayout, buffer)); + using var graphicsSet = GD.CreateResourceSet(new ResourceSetDescription(graphicsLayout, buffer)); var blendDesc = new BlendStateDescription { @@ -1466,12 +1466,12 @@ public void UseColorWriteMask() PrimitiveTopology.TriangleStrip, new ShaderSetDescription( Array.Empty(), - TestShaders.LoadVertexFragment(RF, "ColoredQuadRenderer")), + TestShaders.LoadVertexFragment(GD, "ColoredQuadRenderer")), graphicsLayout, framebuffer.OutputDescription); - using (var pipeline1 = RF.CreateGraphicsPipeline(pipelineDesc)) - using (var cl = RF.CreateCommandList()) + using (var pipeline1 = GD.CreateGraphicsPipeline(pipelineDesc)) + using (var cl = GD.CreateCommandList()) { cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -1501,8 +1501,8 @@ public void UseColorWriteMask() blendDesc.AttachmentStates[0].ColorWriteMask = mask; pipelineDesc.BlendState = blendDesc; - using (var maskedPipeline = RF.CreateGraphicsPipeline(pipelineDesc)) - using (var cl = RF.CreateCommandList()) + using (var maskedPipeline = GD.CreateGraphicsPipeline(pipelineDesc)) + using (var cl = GD.CreateCommandList()) { cl.Begin(); cl.SetFramebuffer(framebuffer); @@ -1537,7 +1537,7 @@ protected RenderTests(ITestOutputHelper textOutputHelper) : base(textOutputHelpe } [Trait("Backend", "Vulkan")] - public class VulkanRenderTests : RenderTests + public class VulkanRenderTests : RenderTests { public VulkanRenderTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Tests/ResourceFactoryExtensions.cs b/src/XenoAtom.Graphics.Tests/ResourceFactoryExtensions.cs index 59cb877..3abdfa9 100644 --- a/src/XenoAtom.Graphics.Tests/ResourceFactoryExtensions.cs +++ b/src/XenoAtom.Graphics.Tests/ResourceFactoryExtensions.cs @@ -16,7 +16,7 @@ public static class ResourceFactoryExtensions /// Creates a vertex and fragment shader pair from the given pair containing SPIR-V /// bytecode or GLSL source code. /// - /// The used to compile the translated shader code. + /// The used to compile the translated shader code. /// The vertex shader's description. /// should contain SPIR-V bytecode or Vulkan-style GLSL source code which can be compiled to SPIR-V. /// The fragment shader's description. @@ -24,18 +24,18 @@ public static class ResourceFactoryExtensions /// can be compiled to SPIR-V. /// A two-element array, containing the vertex shader (element 0) and the fragment shader (element 1). public static Shader[] CreateFromSpirv( - this ResourceFactory factory, + this GraphicsDevice device, ShaderDescription vertexShaderDescription, ShaderDescription fragmentShaderDescription) { - return CreateFromSpirv(factory, vertexShaderDescription, fragmentShaderDescription, new CrossCompileOptions()); + return CreateFromSpirv(device, vertexShaderDescription, fragmentShaderDescription, new CrossCompileOptions()); } /// /// Creates a vertex and fragment shader pair from the given pair containing SPIR-V /// bytecode or GLSL source code. /// - /// The used to compile the translated shader code. + /// The used to compile the translated shader code. /// The vertex shader's description. /// should contain SPIR-V bytecode or Vulkan-style GLSL source code which can be compiled to SPIR-V. /// The fragment shader's description. @@ -45,19 +45,19 @@ public static Shader[] CreateFromSpirv( /// shaders from SPIR-V to the target language. /// A two-element array, containing the vertex shader (element 0) and the fragment shader (element 1). public static Shader[] CreateFromSpirv( - this ResourceFactory factory, + this GraphicsDevice device, ShaderDescription vertexShaderDescription, ShaderDescription fragmentShaderDescription, CrossCompileOptions options) { - GraphicsBackend backend = factory.BackendType; + GraphicsBackend backend = device.BackendType; vertexShaderDescription.ShaderBytes = EnsureSpirv(vertexShaderDescription); fragmentShaderDescription.ShaderBytes = EnsureSpirv(fragmentShaderDescription); return new Shader[] { - factory.CreateShader(vertexShaderDescription), - factory.CreateShader(fragmentShaderDescription) + device.CreateShader(vertexShaderDescription), + device.CreateShader(fragmentShaderDescription) }; } @@ -65,23 +65,23 @@ public static Shader[] CreateFromSpirv( /// Creates a compute shader from the given containing SPIR-V bytecode or GLSL source /// code. /// - /// The used to compile the translated shader code. + /// The used to compile the translated shader code. /// The compute shader's description. /// should contain SPIR-V bytecode or Vulkan-style GLSL source code which /// can be compiled to SPIR-V. /// The compiled compute . public static Shader CreateFromSpirv( - this ResourceFactory factory, + this GraphicsDevice device, ShaderDescription computeShaderDescription) { - return CreateFromSpirv(factory, computeShaderDescription, new CrossCompileOptions()); + return CreateFromSpirv(device, computeShaderDescription, new CrossCompileOptions()); } /// /// Creates a compute shader from the given containing SPIR-V bytecode or GLSL source /// code. /// - /// The used to compile the translated shader code. + /// The used to compile the translated shader code. /// The compute shader's description. /// should contain SPIR-V bytecode or Vulkan-style GLSL source code which /// can be compiled to SPIR-V. @@ -89,13 +89,13 @@ public static Shader CreateFromSpirv( /// shaders from SPIR-V to the target language. /// The compiled compute . public static Shader CreateFromSpirv( - this ResourceFactory factory, + this GraphicsDevice device, ShaderDescription computeShaderDescription, CrossCompileOptions options) { - GraphicsBackend backend = factory.BackendType; + GraphicsBackend backend = device.BackendType; computeShaderDescription.ShaderBytes = EnsureSpirv(computeShaderDescription); - return factory.CreateShader(computeShaderDescription); + return device.CreateShader(computeShaderDescription); } private static unsafe byte[] EnsureSpirv(ShaderDescription description) diff --git a/src/XenoAtom.Graphics.Tests/ResourceSetTests.cs b/src/XenoAtom.Graphics.Tests/ResourceSetTests.cs index 72c902c..6c2c85b 100644 --- a/src/XenoAtom.Graphics.Tests/ResourceSetTests.cs +++ b/src/XenoAtom.Graphics.Tests/ResourceSetTests.cs @@ -4,19 +4,19 @@ namespace XenoAtom.Graphics.Tests { - public abstract class ResourceSetTests : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class ResourceSetTests : GraphicsDeviceTestBase { [Fact] public void ResourceSet_BufferInsteadOfTextureView_Fails() { - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("TV0", ResourceKind.TextureReadOnly, ShaderStages.Vertex))); - DeviceBuffer ub = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer ub = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); Assert.Throws(() => { - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, ub)); }); } @@ -24,80 +24,80 @@ public void ResourceSet_BufferInsteadOfTextureView_Fails() [Fact] public void ResourceSet_IncorrectTextureUsage_Fails() { - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("TV0", ResourceKind.TextureReadWrite, ShaderStages.Vertex))); - Texture t = RF.CreateTexture(TextureDescription.Texture2D(64, 64, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled)); - TextureView tv = RF.CreateTextureView(t); + Texture t = GD.CreateTexture(TextureDescription.Texture2D(64, 64, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled)); + TextureView tv = GD.CreateTextureView(t); Assert.Throws(() => { - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, tv)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, tv)); }); } [Fact] public void ResourceSet_IncorrectBufferUsage_Fails() { - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("RWB0", ResourceKind.StructuredBufferReadWrite, ShaderStages.Vertex))); - DeviceBuffer readOnlyBuffer = RF.CreateBuffer(new BufferDescription(1024, BufferUsage.UniformBuffer)); + DeviceBuffer readOnlyBuffer = GD.CreateBuffer(new BufferDescription(1024, BufferUsage.UniformBuffer)); Assert.Throws(() => { - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, readOnlyBuffer)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, readOnlyBuffer)); }); } [Fact] public void ResourceSet_TooFewOrTooManyElements_Fails() { - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("UB0", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("UB1", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("UB2", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - DeviceBuffer ub = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer ub = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); Assert.Throws(() => { - RF.CreateResourceSet(new ResourceSetDescription(layout, ub)); + GD.CreateResourceSet(new ResourceSetDescription(layout, ub)); }); Assert.Throws(() => { - RF.CreateResourceSet(new ResourceSetDescription(layout, ub, ub)); + GD.CreateResourceSet(new ResourceSetDescription(layout, ub, ub)); }); Assert.Throws(() => { - RF.CreateResourceSet(new ResourceSetDescription(layout, ub, ub, ub, ub)); + GD.CreateResourceSet(new ResourceSetDescription(layout, ub, ub, ub, ub)); }); Assert.Throws(() => { - RF.CreateResourceSet(new ResourceSetDescription(layout, ub, ub, ub, ub, ub)); + GD.CreateResourceSet(new ResourceSetDescription(layout, ub, ub, ub, ub, ub)); }); } [Fact] public void ResourceSet_InvalidUniformOffset_Fails() { - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("UB0", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - DeviceBuffer buffer = RF.CreateBuffer(new BufferDescription(1024, BufferUsage.UniformBuffer)); + DeviceBuffer buffer = GD.CreateBuffer(new BufferDescription(1024, BufferUsage.UniformBuffer)); Assert.Throws(() => { - RF.CreateResourceSet(new ResourceSetDescription(layout, + GD.CreateResourceSet(new ResourceSetDescription(layout, new DeviceBufferRange(buffer, GD.UniformBufferMinOffsetAlignment - 1, 256))); }); Assert.Throws(() => { - RF.CreateResourceSet(new ResourceSetDescription(layout, + GD.CreateResourceSet(new ResourceSetDescription(layout, new DeviceBufferRange(buffer, GD.UniformBufferMinOffsetAlignment + 1, 256))); }); } @@ -105,14 +105,14 @@ public void ResourceSet_InvalidUniformOffset_Fails() [Fact] public void ResourceSet_NoPipelineBound_Fails() { - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("UB0", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - DeviceBuffer ub = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer ub = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); - ResourceSet rs = RF.CreateResourceSet(new ResourceSetDescription(layout, ub)); + ResourceSet rs = GD.CreateResourceSet(new ResourceSetDescription(layout, ub)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); Assert.Throws(() => cl.SetGraphicsResourceSet(0, rs)); cl.End(); @@ -121,8 +121,8 @@ public void ResourceSet_NoPipelineBound_Fails() [Fact] public void ResourceSet_InvalidSlot_Fails() { - DeviceBuffer infoBuffer = RF.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); - DeviceBuffer orthoBuffer = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer infoBuffer = GD.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); + DeviceBuffer orthoBuffer = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); ShaderSetDescription shaderSet = new ShaderSetDescription( new VertexLayoutDescription[] @@ -131,13 +131,13 @@ public void ResourceSet_InvalidSlot_Fails() new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("Color_UInt", VertexElementSemantic.TextureCoordinate, VertexElementFormat.UInt4)) }, - TestShaders.LoadVertexFragment(RF, "UIntVertexAttribs")); + TestShaders.LoadVertexFragment(GD, "UIntVertexAttribs")); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("Ortho", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -148,9 +148,9 @@ public void ResourceSet_InvalidSlot_Fails() layout, new OutputDescription(null, new OutputAttachmentDescription(PixelFormat.B8_G8_R8_A8_UNorm))); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetPipeline(pipeline); Assert.Throws(() => cl.SetGraphicsResourceSet(1, set)); @@ -162,8 +162,8 @@ public void ResourceSet_InvalidSlot_Fails() [Fact] public void ResourceSet_IncompatibleSet_Fails() { - DeviceBuffer infoBuffer = RF.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); - DeviceBuffer orthoBuffer = RF.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); + DeviceBuffer infoBuffer = GD.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); + DeviceBuffer orthoBuffer = GD.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); ShaderSetDescription shaderSet = new ShaderSetDescription( new VertexLayoutDescription[] @@ -172,25 +172,25 @@ public void ResourceSet_IncompatibleSet_Fails() new VertexElementDescription("Position", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2), new VertexElementDescription("Color_UInt", VertexElementSemantic.TextureCoordinate, VertexElementFormat.UInt4)) }, - TestShaders.LoadVertexFragment(RF, "UIntVertexAttribs")); + TestShaders.LoadVertexFragment(GD, "UIntVertexAttribs")); - ResourceLayout layout = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("Ortho", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - ResourceLayout layout2 = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout2 = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex), new ResourceLayoutElementDescription("Tex", ResourceKind.TextureReadOnly, ShaderStages.Fragment))); - ResourceLayout layout3 = RF.CreateResourceLayout(new ResourceLayoutDescription( + ResourceLayout layout3 = GD.CreateResourceLayout(new ResourceLayoutDescription( new ResourceLayoutElementDescription("InfoBuffer", ResourceKind.UniformBuffer, ShaderStages.Vertex))); - Texture tex = RF.CreateTexture(TextureDescription.Texture2D(16, 16, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled)); - TextureView texView = RF.CreateTextureView(tex); + Texture tex = GD.CreateTexture(TextureDescription.Texture2D(16, 16, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Sampled)); + TextureView texView = GD.CreateTextureView(tex); - ResourceSet set = RF.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); - ResourceSet set2 = RF.CreateResourceSet(new ResourceSetDescription(layout2, infoBuffer, texView)); - ResourceSet set3 = RF.CreateResourceSet(new ResourceSetDescription(layout3, infoBuffer)); + ResourceSet set = GD.CreateResourceSet(new ResourceSetDescription(layout, infoBuffer, orthoBuffer)); + ResourceSet set2 = GD.CreateResourceSet(new ResourceSetDescription(layout2, infoBuffer, texView)); + ResourceSet set3 = GD.CreateResourceSet(new ResourceSetDescription(layout3, infoBuffer)); GraphicsPipelineDescription gpd = new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, @@ -201,9 +201,9 @@ public void ResourceSet_IncompatibleSet_Fails() layout, new OutputDescription(null, new OutputAttachmentDescription(PixelFormat.B8_G8_R8_A8_UNorm))); - Pipeline pipeline = RF.CreateGraphicsPipeline(gpd); + Pipeline pipeline = GD.CreateGraphicsPipeline(gpd); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetPipeline(pipeline); cl.SetGraphicsResourceSet(0, set); @@ -218,7 +218,7 @@ protected ResourceSetTests(ITestOutputHelper textOutputHelper) : base(textOutput } [Trait("Backend", "Vulkan")] - public class VulkanResourceSetTests : ResourceSetTests + public class VulkanResourceSetTests : ResourceSetTests { public VulkanResourceSetTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Tests/SwapchainTests.cs b/src/XenoAtom.Graphics.Tests/SwapchainTests.cs index 34ca60f..8aa0091 100644 --- a/src/XenoAtom.Graphics.Tests/SwapchainTests.cs +++ b/src/XenoAtom.Graphics.Tests/SwapchainTests.cs @@ -3,7 +3,7 @@ namespace XenoAtom.Graphics.Tests { - public abstract class SwapchainTests : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class SwapchainTests : GraphicsDeviceTestBase { /* [Theory] @@ -18,7 +18,7 @@ public void Ctor_SetsProperties(PixelFormat? depthFormat, bool syncToVerticalBla //Sdl2Window window = new Sdl2Window("SwapchainTestWindow", 0, 0, 100, 100, SDL_WindowFlags.Hidden, false); //SwapchainSource source = VeldridStartup.GetSwapchainSource(window); //SwapchainDescription swapchainDesc = new SwapchainDescription(source, 100, 100, depthFormat, syncToVerticalBlank); - //Swapchain swapchain = RF.CreateSwapchain(ref swapchainDesc); + //Swapchain swapchain = GD.CreateSwapchain(ref swapchainDesc); //if (depthFormat == null) //{ @@ -40,7 +40,7 @@ protected SwapchainTests(ITestOutputHelper textOutputHelper) : base(textOutputHe } } - public abstract class MainSwapchainTests : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class MainSwapchainTests : GraphicsDeviceTestBase { protected MainSwapchainTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { @@ -73,7 +73,7 @@ protected MainSwapchainTests(ITestOutputHelper textOutputHelper) : base(textOutp } [Trait("Backend", "Vulkan")] - public class VulkanSwapchainTests : SwapchainTests + public class VulkanSwapchainTests : SwapchainTests { public VulkanSwapchainTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Tests/TestShaders.cs b/src/XenoAtom.Graphics.Tests/TestShaders.cs index 7814ccc..d03b180 100644 --- a/src/XenoAtom.Graphics.Tests/TestShaders.cs +++ b/src/XenoAtom.Graphics.Tests/TestShaders.cs @@ -1,13 +1,13 @@ -using System; +using System; using System.IO; namespace XenoAtom.Graphics.Tests { internal static class TestShaders { - public static Shader[] LoadVertexFragment(ResourceFactory factory, string setName) + public static Shader[] LoadVertexFragment(GraphicsDevice device, string setName) { - return factory.CreateFromSpirv( + return device.CreateFromSpirv( new ShaderDescription(ShaderStages.Vertex, File.ReadAllBytes(GetPath(setName, ShaderStages.Vertex)), "main"u8), new ShaderDescription(ShaderStages.Fragment, File.ReadAllBytes(GetPath(setName, ShaderStages.Fragment)), "main"u8), new CrossCompileOptions(false, false, new SpecializationConstant[] @@ -16,9 +16,9 @@ public static Shader[] LoadVertexFragment(ResourceFactory factory, string setNam })); } - public static Shader LoadCompute(ResourceFactory factory, string setName) + public static Shader LoadCompute(GraphicsDevice device, string setName) { - return factory.CreateFromSpirv( + return device.CreateFromSpirv( new ShaderDescription(ShaderStages.Compute, File.ReadAllBytes(GetPath(setName, ShaderStages.Compute)), "main"u8), new CrossCompileOptions(false, false, new SpecializationConstant[] { diff --git a/src/XenoAtom.Graphics.Tests/TestUtils.cs b/src/XenoAtom.Graphics.Tests/TestUtils.cs index fd0d1fb..4ac3f37 100644 --- a/src/XenoAtom.Graphics.Tests/TestUtils.cs +++ b/src/XenoAtom.Graphics.Tests/TestUtils.cs @@ -10,7 +10,7 @@ namespace XenoAtom.Graphics.Tests { public static class TestUtils { - public static GraphicsDevice CreateVulkanDevice(DebugLogDelegate log) + public static GraphicsDevice CreateVulkanDevice(DebugLogDelegate log, Action resourcesCreated) { var manager = GraphicsManager.Create(new GraphicsManagerOptions(true) { @@ -21,25 +21,27 @@ public static GraphicsDevice CreateVulkanDevice(DebugLogDelegate log) var adapter = manager.Adapters[0]; - return adapter.CreateDevice(); + return adapter.CreateDevice(new GraphicsDeviceOptions() + { + OnResourceCreated = resourcesCreated + }); } } - public abstract class GraphicsDeviceTestBase : IDisposable where T : GraphicsDeviceCreator + public abstract class GraphicsDeviceTestBase : IDisposable { private readonly ITestOutputHelper _textOutputHelper; private readonly GraphicsDevice _gd; - private readonly DisposeCollectorResourceFactory _factory; + private readonly DisposeCollector _disposeCollector; private bool _hasWarningOrErrorLogs; public GraphicsDevice GD => _gd; - public ResourceFactory RF => _factory; public GraphicsDeviceTestBase(ITestOutputHelper textOutputHelper) { _textOutputHelper = textOutputHelper; - Activator.CreateInstance().CreateGraphicsDevice(out _gd, DebugLogImpl); - _factory = new DisposeCollectorResourceFactory(_gd.ResourceFactory); + _disposeCollector = new DisposeCollector(); + _gd = TestUtils.CreateVulkanDevice(DebugLogImpl, o => _disposeCollector.Add(o)); } @@ -63,8 +65,8 @@ protected DeviceBuffer GetReadback(DeviceBuffer buffer) } else { - readback = RF.CreateBuffer(new BufferDescription(buffer.SizeInBytes, BufferUsage.Staging)); - CommandList cl = RF.CreateCommandList(); + readback = GD.CreateBuffer(new BufferDescription(buffer.SizeInBytes, BufferUsage.Staging)); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyBuffer(buffer, 0, readback, 0, buffer.SizeInBytes); cl.End(); @@ -93,8 +95,8 @@ protected Texture GetReadback(Texture texture) texture.MipLevels, layers, texture.Format, TextureUsage.Staging, texture.Type); - Texture readback = RF.CreateTexture(desc); - CommandList cl = RF.CreateCommandList(); + Texture readback = GD.CreateTexture(desc); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture(texture, readback); cl.End(); @@ -107,7 +109,7 @@ protected Texture GetReadback(Texture texture) public void Dispose() { GD.WaitForIdle(); - _factory.DisposeCollector.DisposeAll(); + _disposeCollector.DisposeAll(); GD.Dispose(); var manager = GD.Adapter.Manager; @@ -116,17 +118,4 @@ public void Dispose() Assert.False(_hasWarningOrErrorLogs); } } - - public interface GraphicsDeviceCreator - { - void CreateGraphicsDevice(out GraphicsDevice gd, DebugLogDelegate log); - } - - public class VulkanDeviceCreator : GraphicsDeviceCreator - { - public void CreateGraphicsDevice(out GraphicsDevice gd, DebugLogDelegate log) - { - gd = TestUtils.CreateVulkanDevice(log); - } - } } diff --git a/src/XenoAtom.Graphics.Tests/TextureTests.cs b/src/XenoAtom.Graphics.Tests/TextureTests.cs index 0348635..45255e3 100644 --- a/src/XenoAtom.Graphics.Tests/TextureTests.cs +++ b/src/XenoAtom.Graphics.Tests/TextureTests.cs @@ -7,12 +7,12 @@ namespace XenoAtom.Graphics.Tests { - public abstract class TextureTestBase : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class TextureTestBase : GraphicsDeviceTestBase { [Fact] public void Map_Succeeds() { - Texture texture = RF.CreateTexture( + Texture texture = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.Staging)); MappedResource map = GD.Map(texture, MapMode.ReadWrite, 0); @@ -22,7 +22,7 @@ public void Map_Succeeds() [Fact] public void Map_Succeeds_R32_G32_B32_A32_UInt() { - Texture texture = RF.CreateTexture( + Texture texture = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 1, 1, PixelFormat.R32_G32_B32_A32_UInt, TextureUsage.Staging)); MappedResource map = GD.Map(texture, MapMode.ReadWrite, 0); @@ -34,7 +34,7 @@ public void Map_Succeeds_R32_G32_B32_A32_UInt() [InlineData(true)] public unsafe void Update_ThenMapRead_Succeeds_R32Float(bool useArrayOverload) { - Texture texture = RF.CreateTexture( + Texture texture = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 1, 1, PixelFormat.R32_Float, TextureUsage.Staging)); float[] data = Enumerable.Range(0, 1024 * 1024).Select(i => (float)i).ToArray(); @@ -69,7 +69,7 @@ public unsafe void Update_ThenMapRead_Succeeds_R32Float(bool useArrayOverload) [InlineData(true)] public unsafe void Update_ThenMapRead_SingleMip_Succeeds_R16UNorm(bool useArrayOverload) { - Texture texture = RF.CreateTexture( + Texture texture = GD.CreateTexture( TextureDescription.Texture2D(1024, 1024, 3, 1, PixelFormat.R16_UNorm, TextureUsage.Staging)); ushort[] data = Enumerable.Range(0, 256 * 256).Select(i => (ushort)i).ToArray(); @@ -105,8 +105,8 @@ public unsafe void Update_ThenCopySingleMip_Succeeds_R16UNorm() { TextureDescription desc = TextureDescription.Texture2D( 1024, 1024, 3, 1, PixelFormat.R16_UNorm, TextureUsage.Staging); - Texture src = RF.CreateTexture(desc); - Texture dst = RF.CreateTexture(desc); + Texture src = GD.CreateTexture(desc); + Texture dst = GD.CreateTexture(desc); ushort[] data = Enumerable.Range(0, 256 * 256).Select(i => (ushort)i).ToArray(); @@ -115,7 +115,7 @@ public unsafe void Update_ThenCopySingleMip_Succeeds_R16UNorm() GD.UpdateTexture(src, (IntPtr)dataPtr, 256 * 256 * sizeof(ushort), 0, 0, 0, 256, 256, 1, 2, 0); } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture(src, dst, 2, 0); cl.End(); @@ -146,7 +146,7 @@ public void CreateTextureViewFromTextureWithArrayLayers() TextureDescription texDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, ArrayLayers, PixelFormat.R8_UNorm, TextureUsage.Storage | TextureUsage.Sampled); - Texture tex = RF.CreateTexture(texDesc); + Texture tex = GD.CreateTexture(texDesc); for (uint mip = 0; mip < MipLevels; mip++) { @@ -158,7 +158,7 @@ public void CreateTextureViewFromTextureWithArrayLayers() } } - var textureView = RF.CreateTextureView(tex); + var textureView = GD.CreateTextureView(tex); Assert.NotNull(textureView); } @@ -170,7 +170,7 @@ public void CubeMap_UpdateAndRead() TextureDescription texDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, 1, PixelFormat.R8_UNorm, TextureUsage.Cubemap); - Texture tex = RF.CreateTexture(texDesc); + Texture tex = GD.CreateTexture(texDesc); for (uint mip = 0; mip < MipLevels; mip++) { @@ -214,7 +214,7 @@ public void CubeMap_CreateViewWithSingleMipLevel() TextureDescription texDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, 1, PixelFormat.R8_UNorm, TextureUsage.Cubemap | TextureUsage.Sampled); - Texture tex = RF.CreateTexture(texDesc); + Texture tex = GD.CreateTexture(texDesc); for (uint mip = 0; mip < MipLevels; mip++) { @@ -226,7 +226,7 @@ public void CubeMap_CreateViewWithSingleMipLevel() } } - var view = RF.CreateTextureView(new TextureViewDescription(tex, 0, 1, 0, 1)); + var view = GD.CreateTextureView(new TextureViewDescription(tex, 0, 1, 0, 1)); Assert.NotNull(view); } @@ -240,8 +240,8 @@ public unsafe void CubeMap_Copy_OneMip() TexSize, TexSize, MipLevels, 1, PixelFormat.R8_UNorm, TextureUsage.Cubemap); TextureDescription dstDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, 6, PixelFormat.R8_UNorm, TextureUsage.Staging); - Texture src = RF.CreateTexture(srcDesc); - Texture dst = RF.CreateTexture(dstDesc); + Texture src = GD.CreateTexture(srcDesc); + Texture dst = GD.CreateTexture(dstDesc); for (uint face = 0; face < 6; face++) { @@ -249,7 +249,7 @@ public unsafe void CubeMap_Copy_OneMip() GD.UpdateTexture(src, data, 0, 0, 0, TexSize, TexSize, 1, 0, face); } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture(src, dst); cl.End(); @@ -288,8 +288,8 @@ public unsafe void CubeMap_Copy_FromNonCubeMapWith6ArrayLayers() TexSize, TexSize, MipLevels, 6, PixelFormat.R8_UNorm, TextureUsage.Staging); TextureDescription dstDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, 1, PixelFormat.R8_UNorm, TextureUsage.Sampled | TextureUsage.Cubemap); - Texture src = RF.CreateTexture(srcDesc); - Texture dst = RF.CreateTexture(dstDesc); + Texture src = GD.CreateTexture(srcDesc); + Texture dst = GD.CreateTexture(dstDesc); for (uint face = 0; face < 6; face++) { @@ -297,7 +297,7 @@ public unsafe void CubeMap_Copy_FromNonCubeMapWith6ArrayLayers() GD.UpdateTexture(src, data, 0, 0, 0, TexSize, TexSize, 1, 0, face); } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); for (uint face = 0; face < 6; face++) cl.CopyTexture(src, dst, 0, face); @@ -340,8 +340,8 @@ public void CubeMap_Copy_MultipleMip_CopySingleMipFaces() TexSize, TexSize, MipLevels, 1, PixelFormat.R8_UNorm, TextureUsage.Cubemap); TextureDescription dstDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, 6, PixelFormat.R8_UNorm, TextureUsage.Staging); - Texture src = RF.CreateTexture(srcDesc); - Texture dst = RF.CreateTexture(dstDesc); + Texture src = GD.CreateTexture(srcDesc); + Texture dst = GD.CreateTexture(dstDesc); for (uint mip = 0; mip < MipLevels; mip++) { @@ -353,7 +353,7 @@ public void CubeMap_Copy_MultipleMip_CopySingleMipFaces() } } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); for (uint face = 0; face < 6; face++) cl.CopyTexture(src, dst, CopiedMip, face); @@ -389,8 +389,8 @@ public void CubeMap_Copy_MultipleMip_AllAtOnce() TexSize, TexSize, MipLevels, 1, PixelFormat.R8_UNorm, TextureUsage.Cubemap); TextureDescription dstDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, 6, PixelFormat.R8_UNorm, TextureUsage.Staging); - Texture src = RF.CreateTexture(srcDesc); - Texture dst = RF.CreateTexture(dstDesc); + Texture src = GD.CreateTexture(srcDesc); + Texture dst = GD.CreateTexture(dstDesc); for (uint mip = 0; mip < MipLevels; mip++) { @@ -402,7 +402,7 @@ public void CubeMap_Copy_MultipleMip_AllAtOnce() } } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture(src, dst); cl.End(); @@ -442,8 +442,8 @@ public void CubeMap_Copy_MultipleMip_SpecificArrayLayer() TexSize, TexSize, MipLevels, 1, PixelFormat.R8_UNorm, TextureUsage.Cubemap); TextureDescription dstDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, CopiedArrayLayer + 1, PixelFormat.R8_UNorm, TextureUsage.Staging); - Texture src = RF.CreateTexture(srcDesc); - Texture dst = RF.CreateTexture(dstDesc); + Texture src = GD.CreateTexture(srcDesc); + Texture dst = GD.CreateTexture(dstDesc); for (uint mip = 0; mip < MipLevels; mip++) { @@ -455,7 +455,7 @@ public void CubeMap_Copy_MultipleMip_SpecificArrayLayer() } } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); for (uint mip = 0; mip < MipLevels; mip++) cl.CopyTexture(src, dst, mip, CopiedArrayLayer); @@ -495,7 +495,7 @@ public void CubeMap_GenerateMipmaps(uint TexSize, uint MipLevels) { TextureDescription texDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, 1, PixelFormat.R8_UNorm, TextureUsage.Cubemap | TextureUsage.GenerateMipmaps); - Texture tex = RF.CreateTexture(texDesc); + Texture tex = GD.CreateTexture(texDesc); for (uint face = 0; face < 6; face++) { @@ -522,7 +522,7 @@ public void CubeMap_GenerateMipmaps(uint TexSize, uint MipLevels) GD.Unmap(readback, subresource); } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.GenerateMipmaps(tex); cl.End(); @@ -565,7 +565,7 @@ public void ArrayLayers_StagingWriteAndRead_SmallTextures(uint TexSize) TextureDescription texDesc = TextureDescription.Texture2D( TexSize, TexSize, 1, ArrayLayers, PixelFormat.R8_UNorm, TextureUsage.Staging); - Texture tex = RF.CreateTexture(texDesc); + Texture tex = GD.CreateTexture(texDesc); for (uint layer = 0; layer < ArrayLayers; layer++) { @@ -596,7 +596,7 @@ public void ArrayLayers_StagingWriteAndRead() TextureDescription texDesc = TextureDescription.Texture2D( TexSize, TexSize, 1, ArrayLayers, PixelFormat.R8_UNorm, TextureUsage.Staging); - Texture tex = RF.CreateTexture(texDesc); + Texture tex = GD.CreateTexture(texDesc); for (uint layer = 0; layer < ArrayLayers; layer++) { @@ -628,9 +628,9 @@ public void ArrayLayers_WriteAndCopyAndRead() TextureDescription texDesc = TextureDescription.Texture2D( TexSize, TexSize, MipLevels, ArrayLayers, PixelFormat.R8_UNorm, TextureUsage.Sampled); - Texture tex = RF.CreateTexture(texDesc); + Texture tex = GD.CreateTexture(texDesc); texDesc.Usage = TextureUsage.Staging; - Texture readback = RF.CreateTexture(texDesc); + Texture readback = GD.CreateTexture(texDesc); for (uint mip = 0; mip < MipLevels; mip++) { @@ -642,7 +642,7 @@ public void ArrayLayers_WriteAndCopyAndRead() } } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture(tex, readback); cl.End(); @@ -703,9 +703,9 @@ public unsafe void Copy_Compressed_Texture(PixelFormat format, uint blockSizeInB return; } - Texture copySrc = RF.CreateTexture(TextureDescription.Texture2D( + Texture copySrc = GD.CreateTexture(TextureDescription.Texture2D( 64, 64, 1, 1, format, TextureUsage.Staging)); - Texture copyDst = RF.CreateTexture(TextureDescription.Texture2D( + Texture copyDst = GD.CreateTexture(TextureDescription.Texture2D( copyWidth, copyHeight, 1, 1, format, TextureUsage.Staging)); const int numPixelsInBlockSide = 4; @@ -723,7 +723,7 @@ public unsafe void Copy_Compressed_Texture(PixelFormat format, uint blockSizeInB GD.UpdateTexture(copySrc, (IntPtr)dataPtr, totalDataSize, srcX, srcY, 0, copyWidth, copyHeight, 1, 0, 0); } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture( copySrc, srcX, srcY, 0, 0, 0, @@ -761,9 +761,9 @@ public unsafe void Copy_Compressed_Array(bool separateLayerCopies) format, TextureUsage.Sampled); - Texture copySrc = RF.CreateTexture(texDesc); + Texture copySrc = GD.CreateTexture(texDesc); texDesc.Usage = TextureUsage.Staging; - Texture copyDst = RF.CreateTexture(texDesc); + Texture copyDst = GD.CreateTexture(texDesc); for (uint layer = 0; layer < copySrc.ArrayLayers; layer++) { @@ -777,7 +777,7 @@ public unsafe void Copy_Compressed_Array(bool separateLayerCopies) 0, layer); } - CommandList copyCL = RF.CreateCommandList(); + CommandList copyCL = GD.CreateCommandList(); copyCL.Begin(); if (separateLayerCopies) { @@ -791,7 +791,7 @@ public unsafe void Copy_Compressed_Array(bool separateLayerCopies) copyCL.CopyTexture(copySrc, 0, 0, 0, 0, 0, copyDst, 0, 0, 0, 0, 0, 16, 16, 1, copySrc.ArrayLayers); } copyCL.End(); - Fence fence = RF.CreateFence(false); + Fence fence = GD.CreateFence(false); GD.SubmitCommands(copyCL, fence); GD.WaitForFence(fence); @@ -820,7 +820,7 @@ public unsafe void Copy_Compressed_Array(bool separateLayerCopies) [Fact] public unsafe void Update_ThenMapRead_3D() { - Texture tex3D = RF.CreateTexture(TextureDescription.Texture3D( + Texture tex3D = GD.CreateTexture(TextureDescription.Texture3D( 10, 10, 10, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); RgbaByte[] data = new RgbaByte[tex3D.Width * tex3D.Height * tex3D.Depth]; @@ -853,7 +853,7 @@ public unsafe void Update_ThenMapRead_3D() [Fact] public unsafe void MapWrite_ThenMapRead_3D() { - Texture tex3D = RF.CreateTexture(TextureDescription.Texture3D( + Texture tex3D = GD.CreateTexture(TextureDescription.Texture3D( 10, 10, 10, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); MappedResourceView writeView = GD.Map(tex3D, MapMode.Write); @@ -880,7 +880,7 @@ public unsafe void Update_ThenMapRead_1D() { if (!GD.Features.Texture1D) { return; } - Texture tex1D = RF.CreateTexture( + Texture tex1D = GD.CreateTexture( TextureDescription.Texture1D(100, 1, 1, PixelFormat.R16_UNorm, TextureUsage.Staging)); ushort[] data = Enumerable.Range(0, (int)tex1D.Width).Select(i => (ushort)(i * 2)).ToArray(); fixed (ushort* dataPtr = &data[0]) @@ -901,7 +901,7 @@ public unsafe void MapWrite_ThenMapRead_1D() { if (!GD.Features.Texture1D) { return; } - Texture tex1D = RF.CreateTexture( + Texture tex1D = GD.CreateTexture( TextureDescription.Texture1D(100, 1, 1, PixelFormat.R16_UNorm, TextureUsage.Staging)); MappedResourceView writeView = GD.Map(tex1D, MapMode.Write); @@ -923,15 +923,15 @@ public unsafe void MapWrite_ThenMapRead_1D() [Fact] public unsafe void Copy_DepthStencil() { - Texture depthTarget = RF.CreateTexture( + Texture depthTarget = GD.CreateTexture( TextureDescription.Texture2D(64, 64, 1, 1, PixelFormat.D32_Float_S8_UInt, TextureUsage.DepthStencil)); - Texture depthTarget1 = RF.CreateTexture( + Texture depthTarget1 = GD.CreateTexture( TextureDescription.Texture2D(64, 64, 1, 1, PixelFormat.D32_Float_S8_UInt, TextureUsage.DepthStencil)); - Framebuffer fb = RF.CreateFramebuffer(new FramebufferDescription(depthTarget)); + Framebuffer fb = GD.CreateFramebuffer(new FramebufferDescription(depthTarget)); { - using CommandList cl = RF.CreateCommandList(); + using CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.SetFramebuffer(fb); cl.ClearDepthStencil(0.5f, 12); @@ -939,11 +939,11 @@ public unsafe void Copy_DepthStencil() GD.SubmitCommands(cl); } - Texture copySrcFromDepth = RF.CreateTexture(TextureDescription.Texture2D( + Texture copySrcFromDepth = GD.CreateTexture(TextureDescription.Texture2D( 64, 64, 1, 1, PixelFormat.R32_Float, TextureUsage.Staging)); { - using CommandList cl = RF.CreateCommandList(); + using CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture(depthTarget, 0, 0, 0, 0, 0, depthTarget1, 0, 0, 0, 0, 0, 64, 64, 1, 1); cl.CopyTexture(depthTarget1, 0, 0, 0, 0, 0, copySrcFromDepth, 0, 0, 0, 0, 0, 64, 64, 1, 1); @@ -968,9 +968,9 @@ public unsafe void Copy_1DTo2D() { if (!GD.Features.Texture1D) { return; } - Texture tex1D = RF.CreateTexture( + Texture tex1D = GD.CreateTexture( TextureDescription.Texture1D(100, 1, 1, PixelFormat.R16_UNorm, TextureUsage.Staging)); - Texture tex2D = RF.CreateTexture( + Texture tex2D = GD.CreateTexture( TextureDescription.Texture2D(100, 10, 1, 1, PixelFormat.R16_UNorm, TextureUsage.Staging)); MappedResourceView writeView = GD.Map(tex1D, MapMode.Write); @@ -980,7 +980,7 @@ public unsafe void Copy_1DTo2D() } GD.Unmap(tex1D); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture( tex1D, 0, 0, 0, 0, 0, @@ -1004,7 +1004,7 @@ public void Update_MultipleMips_1D() { if (!GD.Features.Texture1D) { return; } - Texture tex1D = RF.CreateTexture(TextureDescription.Texture1D( + Texture tex1D = GD.CreateTexture(TextureDescription.Texture1D( 100, 5, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); for (uint level = 0; level < tex1D.MipLevels; level++) @@ -1033,9 +1033,9 @@ public void Copy_DifferentMip_1DTo2D() { if (!GD.Features.Texture1D) { return; } - Texture tex1D = RF.CreateTexture( + Texture tex1D = GD.CreateTexture( TextureDescription.Texture1D(200, 2, 1, PixelFormat.R16_UNorm, TextureUsage.Staging)); - Texture tex2D = RF.CreateTexture( + Texture tex2D = GD.CreateTexture( TextureDescription.Texture2D(100, 10, 1, 1, PixelFormat.R16_UNorm, TextureUsage.Staging)); MappedResourceView writeView = GD.Map(tex1D, MapMode.Write, 1); @@ -1045,7 +1045,7 @@ public void Copy_DifferentMip_1DTo2D() } GD.Unmap(tex1D, 1); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture( tex1D, 0, 0, 0, 1, 0, @@ -1071,10 +1071,10 @@ public void Copy_DifferentMip_1DTo2D() [Theory] public void Copy_WithOffsets_2D(TextureUsage srcUsage, TextureUsage dstUsage) { - Texture src = RF.CreateTexture(TextureDescription.Texture2D( + Texture src = GD.CreateTexture(TextureDescription.Texture2D( 100, 100, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, srcUsage)); - Texture dst = RF.CreateTexture(TextureDescription.Texture2D( + Texture dst = GD.CreateTexture(TextureDescription.Texture2D( 100, 100, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, dstUsage)); RgbaByte[] srcData = new RgbaByte[src.Height * src.Width]; @@ -1086,7 +1086,7 @@ public void Copy_WithOffsets_2D(TextureUsage srcUsage, TextureUsage dstUsage) GD.UpdateTexture(src, srcData, 0, 0, 0, src.Width, src.Height, 1, 0, 0); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture( src, @@ -1111,9 +1111,9 @@ public void Copy_WithOffsets_2D(TextureUsage srcUsage, TextureUsage dstUsage) [Fact] public void Copy_ArrayToNonArray() { - Texture src = RF.CreateTexture(TextureDescription.Texture2D( + Texture src = GD.CreateTexture(TextureDescription.Texture2D( 10, 10, 1, 10, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); - Texture dst = RF.CreateTexture(TextureDescription.Texture2D( + Texture dst = GD.CreateTexture(TextureDescription.Texture2D( 10, 10, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); MappedResourceView writeView = GD.Map(src, MapMode.Write, 5); @@ -1124,7 +1124,7 @@ public void Copy_ArrayToNonArray() } GD.Unmap(src, 5); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture( src, 0, 0, 0, 0, 5, @@ -1146,7 +1146,7 @@ public void Copy_ArrayToNonArray() [Fact] public void Map_ThenRead_MultipleArrayLayers() { - Texture src = RF.CreateTexture(TextureDescription.Texture2D( + Texture src = GD.CreateTexture(TextureDescription.Texture2D( 10, 10, 1, 10, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); for (uint layer = 0; layer < src.ArrayLayers; layer++) @@ -1175,7 +1175,7 @@ public void Map_ThenRead_MultipleArrayLayers() [Fact] public unsafe void Update_WithOffset_2D() { - Texture tex2D = RF.CreateTexture(TextureDescription.Texture2D( + Texture tex2D = GD.CreateTexture(TextureDescription.Texture2D( 100, 100, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); RgbaByte[] data = new RgbaByte[50 * 30]; @@ -1205,7 +1205,7 @@ public unsafe void Update_WithOffset_2D() [Fact] public unsafe void Update_NonMultipleOfFourWithCompressedTexture_2D() { - Texture tex2D = RF.CreateTexture(TextureDescription.Texture2D( + Texture tex2D = GD.CreateTexture(TextureDescription.Texture2D( 2, 2, 1, 1, PixelFormat.BC1_Rgb_UNorm, TextureUsage.Staging)); byte[] data = new byte[16]; @@ -1223,7 +1223,7 @@ public unsafe void Update_NonMultipleOfFourWithCompressedTexture_2D() [Fact] public unsafe void Map_NonZeroMip_3D() { - Texture tex3D = RF.CreateTexture(TextureDescription.Texture3D( + Texture tex3D = GD.CreateTexture(TextureDescription.Texture3D( 40, 40, 40, 3, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); MappedResourceView writeView = GD.Map(tex3D, MapMode.Write, 2); @@ -1248,7 +1248,7 @@ public unsafe void Map_NonZeroMip_3D() [Fact] public unsafe void Update_NonStaging_3D() { - Texture tex3D = RF.CreateTexture(TextureDescription.Texture3D( + Texture tex3D = GD.CreateTexture(TextureDescription.Texture3D( 16, 16, 16, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled)); RgbaByte[] data = new RgbaByte[16 * 16 * 16]; for (int z = 0; z < 16; z++) @@ -1267,10 +1267,10 @@ public unsafe void Update_NonStaging_3D() 0, 0); } - Texture staging = RF.CreateTexture(TextureDescription.Texture3D( + Texture staging = GD.CreateTexture(TextureDescription.Texture3D( 16, 16, 16, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Staging)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture(tex3D, staging); cl.End(); @@ -1290,7 +1290,7 @@ public unsafe void Update_NonStaging_3D() [Fact] public unsafe void Copy_NonSquareTexture() { - Texture src = RF.CreateTexture( + Texture src = GD.CreateTexture( TextureDescription.Texture2D(512, 128, 1, 1, PixelFormat.R8_UNorm, TextureUsage.Staging)); byte[] data = Enumerable.Repeat((byte)255, (int)(src.Width * src.Height)).ToArray(); fixed (byte* dataPtr = data) @@ -1301,7 +1301,7 @@ public unsafe void Copy_NonSquareTexture() 0, 0); } - Texture dst = RF.CreateTexture( + Texture dst = GD.CreateTexture( TextureDescription.Texture2D(512, 128, 1, 1, PixelFormat.R8_UNorm, TextureUsage.Staging)); byte[] data2 = Enumerable.Repeat((byte)100, (int)(dst.Width * dst.Height)).ToArray(); fixed (byte* dataPtr2 = data2) @@ -1312,7 +1312,7 @@ public unsafe void Copy_NonSquareTexture() 0, 0); } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture(src, dst); cl.End(); @@ -1348,7 +1348,7 @@ public unsafe void FormatCoverage_CopyThenRead( return; } - Texture srcTex = RF.CreateTexture(new TextureDescription( + Texture srcTex = GD.CreateTexture(new TextureDescription( srcWidth, srcHeight, srcDepth, srcMipLevels, srcArrayLayers, format, TextureUsage.Staging, srcType)); @@ -1376,11 +1376,11 @@ public unsafe void FormatCoverage_CopyThenRead( 0, 0, 0, srcWidth, srcHeight, srcDepth, 0, 0); } - Texture dstTex = RF.CreateTexture(new TextureDescription( + Texture dstTex = GD.CreateTexture(new TextureDescription( dstWidth, dstHeight, dstDepth, dstMipLevels, dstArrayLayers, format, TextureUsage.Staging, dstType)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture( @@ -1443,10 +1443,10 @@ public unsafe void GenerateMipmaps(TextureUsage usage) 1024, 1024, 11, 1, PixelFormat.R32_G32_B32_A32_Float, usage); - Texture tex = RF.CreateTexture(texDesc); + Texture tex = GD.CreateTexture(texDesc); texDesc.Usage = TextureUsage.Staging; - Texture readback = RF.CreateTexture(texDesc); + Texture readback = GD.CreateTexture(texDesc); RgbaFloat[] pixelData = Enumerable.Repeat(RgbaFloat.Red, 1024 * 1024).ToArray(); fixed (RgbaFloat* pixelDataPtr = pixelData) @@ -1454,7 +1454,7 @@ public unsafe void GenerateMipmaps(TextureUsage usage) GD.UpdateTexture(tex, (IntPtr)pixelDataPtr, 1024 * 1024 * 16, 0, 0, 0, 1024, 1024, 1, 0, 0); } - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.GenerateMipmaps(tex); cl.CopyTexture(tex, readback); @@ -1475,10 +1475,10 @@ public unsafe void GenerateMipmaps(TextureUsage usage) [Fact] public void CopyTexture_SmallCompressed() { - Texture src = RF.CreateTexture(TextureDescription.Texture2D(16, 16, 4, 1, PixelFormat.BC3_UNorm, TextureUsage.Staging)); - Texture dst = RF.CreateTexture(TextureDescription.Texture2D(16, 16, 4, 1, PixelFormat.BC3_UNorm, TextureUsage.Sampled)); + Texture src = GD.CreateTexture(TextureDescription.Texture2D(16, 16, 4, 1, PixelFormat.BC3_UNorm, TextureUsage.Staging)); + Texture dst = GD.CreateTexture(TextureDescription.Texture2D(16, 16, 4, 1, PixelFormat.BC3_UNorm, TextureUsage.Sampled)); - CommandList cl = RF.CreateCommandList(); + CommandList cl = GD.CreateCommandList(); cl.Begin(); cl.CopyTexture( src, 0, 0, 0, 3, 0, @@ -1506,7 +1506,7 @@ public void CopyTexture_SmallCompressed() [InlineData(PixelFormat.BC7_UNorm_SRgb)] public void CreateSmallTexture(PixelFormat format) { - Texture tex = RF.CreateTexture(TextureDescription.Texture2D(1, 1, 1, 1, format, TextureUsage.Sampled)); + Texture tex = GD.CreateTexture(TextureDescription.Texture2D(1, 1, 1, 1, format, TextureUsage.Sampled)); Assert.Equal(1u, tex.Width); Assert.Equal(1u, tex.Height); } @@ -1588,7 +1588,7 @@ protected TextureTestBase(ITestOutputHelper textOutputHelper) : base(textOutputH } [Trait("Backend", "Vulkan")] - public class VulkanTextureTests : TextureTestBase + public class VulkanTextureTests : TextureTestBase { public VulkanTextureTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Tests/VertexLayoutTests.cs b/src/XenoAtom.Graphics.Tests/VertexLayoutTests.cs index 5426875..eb07dfb 100644 --- a/src/XenoAtom.Graphics.Tests/VertexLayoutTests.cs +++ b/src/XenoAtom.Graphics.Tests/VertexLayoutTests.cs @@ -5,7 +5,7 @@ namespace XenoAtom.Graphics.Tests { - public abstract class VertexLayoutTests : GraphicsDeviceTestBase where T : GraphicsDeviceCreator + public abstract class VertexLayoutTests : GraphicsDeviceTestBase { [Theory] [InlineData(0, 0, 0, 0, -1, true)] @@ -19,9 +19,9 @@ public abstract class VertexLayoutTests : GraphicsDeviceTestBase where T : [InlineData(0, 12, 28, 35, -1, false)] public void ExplicitOffsets(uint firstOffset, uint secondOffset, uint thirdOffset, uint fourthOffset, int stride, bool succeeds) { - Texture outTex = RF.CreateTexture( + Texture outTex = GD.CreateTexture( TextureDescription.Texture2D(1, 1, 1, 1, PixelFormat.R32_G32_B32_A32_Float, TextureUsage.RenderTarget)); - Framebuffer fb = RF.CreateFramebuffer(new FramebufferDescription(null, outTex)); + Framebuffer fb = GD.CreateFramebuffer(new FramebufferDescription(null, outTex)); VertexLayoutDescription vertexLayoutDesc = new VertexLayoutDescription( new VertexElementDescription("A_V3", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float3, firstOffset), @@ -39,11 +39,11 @@ public void ExplicitOffsets(uint firstOffset, uint secondOffset, uint thirdOffse { vertexLayoutDesc }, - TestShaders.LoadVertexFragment(RF, "VertexLayoutTestShader")); + TestShaders.LoadVertexFragment(GD, "VertexLayoutTestShader")); try { - RF.CreateGraphicsPipeline(new GraphicsPipelineDescription( + GD.CreateGraphicsPipeline(new GraphicsPipelineDescription( BlendStateDescription.SingleOverrideBlend, DepthStencilStateDescription.Disabled, RasterizerStateDescription.Default, @@ -61,7 +61,7 @@ protected VertexLayoutTests(ITestOutputHelper textOutputHelper) : base(textOutpu } [Trait("Backend", "Vulkan")] - public class VulkanVertexLayoutTests : VertexLayoutTests + public class VulkanVertexLayoutTests : VertexLayoutTests { public VulkanVertexLayoutTests(ITestOutputHelper textOutputHelper) : base(textOutputHelper) { diff --git a/src/XenoAtom.Graphics.Utilities/DisposeCollectorResourceFactory.cs b/src/XenoAtom.Graphics.Utilities/DisposeCollectorResourceFactory.cs deleted file mode 100644 index 0ef67ea..0000000 --- a/src/XenoAtom.Graphics.Utilities/DisposeCollectorResourceFactory.cs +++ /dev/null @@ -1,120 +0,0 @@ -namespace XenoAtom.Graphics.Utilities -{ - public class DisposeCollectorResourceFactory : ResourceFactory - { - public ResourceFactory Factory { get; } - public DisposeCollector DisposeCollector { get; } - - public DisposeCollectorResourceFactory(ResourceFactory factory) - : this(factory, new DisposeCollector()) - { - } - - public DisposeCollectorResourceFactory(ResourceFactory factory, DisposeCollector disposeCollector) - : base(factory.Features) - { - Factory = factory; - DisposeCollector = disposeCollector; - } - - public override GraphicsBackend BackendType => Factory.BackendType; - - public override CommandList CreateCommandList(in CommandListDescription description) - { - CommandList cl = Factory.CreateCommandList(description); - DisposeCollector.Add(cl); - return cl; - } - - public override Framebuffer CreateFramebuffer(in FramebufferDescription description) - { - Framebuffer fb = Factory.CreateFramebuffer(description); - DisposeCollector.Add(fb); - return fb; - } - - protected override DeviceBuffer CreateBufferCore(in BufferDescription description) - { - DeviceBuffer buffer = Factory.CreateBuffer(description); - DisposeCollector.Add(buffer); - return buffer; - } - - protected override Pipeline CreateGraphicsPipelineCore(in GraphicsPipelineDescription description) - { - Pipeline pipeline = Factory.CreateGraphicsPipeline(description); - DisposeCollector.Add(pipeline); - return pipeline; - } - - public override Pipeline CreateComputePipeline(in ComputePipelineDescription description) - { - Pipeline pipeline = Factory.CreateComputePipeline(description); - DisposeCollector.Add(pipeline); - return pipeline; - } - - public override ResourceLayout CreateResourceLayout(in ResourceLayoutDescription description) - { - ResourceLayout layout = Factory.CreateResourceLayout(description); - DisposeCollector.Add(layout); - return layout; - } - - public override ResourceSet CreateResourceSet(in ResourceSetDescription description) - { - ResourceSet rs = Factory.CreateResourceSet(description); - DisposeCollector.Add(rs); - return rs; - } - - protected override Sampler CreateSamplerCore(in SamplerDescription description) - { - Sampler sampler = Factory.CreateSampler(description); - DisposeCollector.Add(sampler); - return sampler; - } - - protected override Shader CreateShaderCore(in ShaderDescription description) - { - Shader shader = Factory.CreateShader(description); - DisposeCollector.Add(shader); - return shader; - } - - protected override Texture CreateTextureCore(in TextureDescription description) - { - Texture tex = Factory.CreateTexture(description); - DisposeCollector.Add(tex); - return tex; - } - - protected override TextureView CreateTextureViewCore(in TextureViewDescription description) - { - TextureView texView = Factory.CreateTextureView(description); - DisposeCollector.Add(texView); - return texView; - } - - public override Fence CreateFence(bool signaled) - { - Fence f = Factory.CreateFence(signaled); - DisposeCollector.Add(f); - return f; - } - - public override Swapchain CreateSwapchain(in SwapchainDescription description) - { - Swapchain sc = Factory.CreateSwapchain(description); - DisposeCollector.Add(sc); - return sc; - } - - public override Texture CreateTexture(ulong nativeTexture, in TextureDescription description) - { - Texture tex = Factory.CreateTexture(nativeTexture, description); - DisposeCollector.Add(tex); - return tex; - } - } -} diff --git a/src/XenoAtom.Graphics.Utilities/MeshData.cs b/src/XenoAtom.Graphics.Utilities/MeshData.cs index 9cd9c84..817e292 100644 --- a/src/XenoAtom.Graphics.Utilities/MeshData.cs +++ b/src/XenoAtom.Graphics.Utilities/MeshData.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Numerics; namespace XenoAtom.Graphics.Utilities @@ -12,16 +12,19 @@ public interface MeshData /// /// Constructs a from this . /// - /// The to use for device resource creation. + /// + /// /// - DeviceBuffer CreateVertexBuffer(ResourceFactory factory, CommandList cl); + DeviceBuffer CreateVertexBuffer(GraphicsDevice device, CommandList cl); /// /// Constructs a from this . /// - /// The to use for device resource creation. + /// + /// + /// /// - DeviceBuffer CreateIndexBuffer(ResourceFactory factory, CommandList cl, out int indexCount); + DeviceBuffer CreateIndexBuffer(GraphicsDevice device, CommandList cl, out int indexCount); /// /// Gets a centered which completely encapsulates the vertices of this mesh. diff --git a/src/XenoAtom.Graphics.Utilities/ObjParser.cs b/src/XenoAtom.Graphics.Utilities/ObjParser.cs index 20c2309..db18152 100644 --- a/src/XenoAtom.Graphics.Utilities/ObjParser.cs +++ b/src/XenoAtom.Graphics.Utilities/ObjParser.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -591,17 +591,17 @@ public ConstructedMeshInfo(VertexPositionNormalTexture[] vertices, ushort[] indi MaterialName = materialName; } - public DeviceBuffer CreateVertexBuffer(ResourceFactory factory, CommandList cl) + public DeviceBuffer CreateVertexBuffer(GraphicsDevice device, CommandList cl) { - DeviceBuffer vb = factory.CreateBuffer( + DeviceBuffer vb = device.CreateBuffer( new BufferDescription((uint)(Vertices.Length * VertexPositionNormalTexture.SizeInBytes), BufferUsage.VertexBuffer)); cl.UpdateBuffer(vb, 0, Vertices); return vb; } - public DeviceBuffer CreateIndexBuffer(ResourceFactory factory, CommandList cl, out int indexCount) + public DeviceBuffer CreateIndexBuffer(GraphicsDevice device, CommandList cl, out int indexCount) { - DeviceBuffer ib = factory.CreateBuffer(new BufferDescription((uint)(Indices.Length * sizeof(int)), BufferUsage.IndexBuffer)); + DeviceBuffer ib = device.CreateBuffer(new BufferDescription((uint)(Indices.Length * sizeof(int)), BufferUsage.IndexBuffer)); cl.UpdateBuffer(ib, 0, Indices); indexCount = Indices.Length; return ib; diff --git a/src/XenoAtom.Graphics.Utilities/SimpleMeshDataProvider.cs b/src/XenoAtom.Graphics.Utilities/SimpleMeshDataProvider.cs index e71e331..579877b 100644 --- a/src/XenoAtom.Graphics.Utilities/SimpleMeshDataProvider.cs +++ b/src/XenoAtom.Graphics.Utilities/SimpleMeshDataProvider.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Numerics; @@ -16,9 +16,9 @@ public SimpleMeshDataProvider(VertexPositionNormalTexture[] vertices, ushort[] i Indices = indices; } - public DeviceBuffer CreateVertexBuffer(ResourceFactory factory, CommandList cl) + public DeviceBuffer CreateVertexBuffer(GraphicsDevice device, CommandList cl) { - DeviceBuffer vb = factory.CreateBuffer( + DeviceBuffer vb = device.CreateBuffer( new BufferDescription( (uint)(Vertices.Length * VertexPositionNormalTexture.SizeInBytes), BufferUsage.VertexBuffer)); @@ -26,9 +26,9 @@ public DeviceBuffer CreateVertexBuffer(ResourceFactory factory, CommandList cl) return vb; } - public DeviceBuffer CreateIndexBuffer(ResourceFactory factory, CommandList cl, out int indexCount) + public DeviceBuffer CreateIndexBuffer(GraphicsDevice device, CommandList cl, out int indexCount) { - DeviceBuffer ib = factory.CreateBuffer(new BufferDescription((uint)(Indices.Length * sizeof(ushort)), BufferUsage.IndexBuffer)); + DeviceBuffer ib = device.CreateBuffer(new BufferDescription((uint)(Indices.Length * sizeof(ushort)), BufferUsage.IndexBuffer)); cl.UpdateBuffer(ib, 0, Indices); indexCount = Indices.Length; return ib; diff --git a/src/XenoAtom.Graphics/ResourceFactory.cs b/src/XenoAtom.Graphics/GraphicsDevice.ResourceFactory.cs similarity index 96% rename from src/XenoAtom.Graphics/ResourceFactory.cs rename to src/XenoAtom.Graphics/GraphicsDevice.ResourceFactory.cs index 5a73a83..d184286 100644 --- a/src/XenoAtom.Graphics/ResourceFactory.cs +++ b/src/XenoAtom.Graphics/GraphicsDevice.ResourceFactory.cs @@ -5,25 +5,8 @@ namespace XenoAtom.Graphics /// /// A device object responsible for the creation of graphics resources. /// - public abstract class ResourceFactory + partial class GraphicsDevice { - /// - /// - protected ResourceFactory(GraphicsDeviceFeatures features) - { - Features = features; - } - - /// - /// Gets the of this instance. - /// - public abstract GraphicsBackend BackendType { get; } - - /// - /// Gets the this instance was created with. - /// - public GraphicsDeviceFeatures Features { get; } - /// /// Creates a new object. /// diff --git a/src/XenoAtom.Graphics/GraphicsDevice.cs b/src/XenoAtom.Graphics/GraphicsDevice.cs index 077953c..cb3e4e9 100644 --- a/src/XenoAtom.Graphics/GraphicsDevice.cs +++ b/src/XenoAtom.Graphics/GraphicsDevice.cs @@ -10,7 +10,7 @@ namespace XenoAtom.Graphics /// /// Represents an abstract graphics device, capable of creating device resources and executing commands. /// - public abstract class GraphicsDevice : GraphicsObject + public abstract partial class GraphicsDevice : GraphicsObject { private readonly object _deferredDisposalLock = new(); private readonly List _disposables = new(); @@ -49,12 +49,6 @@ internal GraphicsDevice(GraphicsAdapter adapter) /// public abstract bool IsClipSpaceYInverted { get; } - /// - /// Gets the controlled by this instance. - /// - public abstract ResourceFactory ResourceFactory { get; } - - /// /// Gets a which enumerates the optional features supported by this instance. /// diff --git a/src/XenoAtom.Graphics/GraphicsDeviceOptions.cs b/src/XenoAtom.Graphics/GraphicsDeviceOptions.cs index 9a79845..76de7db 100644 --- a/src/XenoAtom.Graphics/GraphicsDeviceOptions.cs +++ b/src/XenoAtom.Graphics/GraphicsDeviceOptions.cs @@ -44,6 +44,11 @@ public struct GraphicsDeviceOptions /// public bool SwapchainSrgbFormat; + /// + /// A callback that receive objects that have been created. This can be used to track the lifetime of objects created by . + /// + public Action? OnResourceCreated; + /// /// Gets or sets Vulkan device specific options. /// diff --git a/src/XenoAtom.Graphics/Texture.cs b/src/XenoAtom.Graphics/Texture.cs index 64828ef..f1a0a93 100644 --- a/src/XenoAtom.Graphics/Texture.cs +++ b/src/XenoAtom.Graphics/Texture.cs @@ -80,7 +80,7 @@ internal TextureView GetFullTextureView(GraphicsDevice gd) private protected virtual TextureView CreateFullTextureView(GraphicsDevice gd) { - return gd.ResourceFactory.CreateTextureView(this); + return gd.CreateTextureView(this); } internal void DisposeTextureView() diff --git a/src/XenoAtom.Graphics/Vk/VkCommandList.cs b/src/XenoAtom.Graphics/Vk/VkCommandList.cs index 8d2674f..5506c5b 100644 --- a/src/XenoAtom.Graphics/Vk/VkCommandList.cs +++ b/src/XenoAtom.Graphics/Vk/VkCommandList.cs @@ -1302,7 +1302,7 @@ private VkBuffer GetStagingBuffer(uint size) } if (ret == null) { - ret = (VkBuffer)_gd.ResourceFactory.CreateBuffer(new BufferDescription(size, BufferUsage.Staging)); + ret = (VkBuffer)_gd.CreateBuffer(new BufferDescription(size, BufferUsage.Staging)); ret.Name = $"Staging Buffer (CommandList {Name})"; } diff --git a/src/XenoAtom.Graphics/Vk/VkGraphicsDevice.ResourceFactory.cs b/src/XenoAtom.Graphics/Vk/VkGraphicsDevice.ResourceFactory.cs new file mode 100644 index 0000000..df39774 --- /dev/null +++ b/src/XenoAtom.Graphics/Vk/VkGraphicsDevice.ResourceFactory.cs @@ -0,0 +1,68 @@ +using static XenoAtom.Interop.vulkan; + +namespace XenoAtom.Graphics.Vk +{ + partial class VkGraphicsDevice + { + public override CommandList CreateCommandList(in CommandListDescription description) + => LogResourceCreated(new VkCommandList(this, description)); + + public override Framebuffer CreateFramebuffer(in FramebufferDescription description) + => LogResourceCreated(new VkFramebuffer(this, description, false)); + + protected override Pipeline CreateGraphicsPipelineCore(in GraphicsPipelineDescription description) + => LogResourceCreated(new VkPipeline(this, description)); + + public override Pipeline CreateComputePipeline(in ComputePipelineDescription description) + => LogResourceCreated(new VkPipeline(this, description)); + + public override ResourceLayout CreateResourceLayout(in ResourceLayoutDescription description) + => LogResourceCreated(new VkResourceLayout(this, description)); + + public override ResourceSet CreateResourceSet(in ResourceSetDescription description) + { + ValidationHelpers.ValidateResourceSet(this, description); + return LogResourceCreated(new VkResourceSet(this, description)); + } + + protected override Sampler CreateSamplerCore(in SamplerDescription description) + => LogResourceCreated(new VkSampler(this, description)); + + protected override Shader CreateShaderCore(in ShaderDescription description) + => LogResourceCreated(new VkShader(this, description)); + + protected override Texture CreateTextureCore(in TextureDescription description) + => LogResourceCreated(new VkTexture(this, description)); + + public override Texture CreateTexture(ulong nativeTexture, in TextureDescription description) + => LogResourceCreated( + new VkTexture( + this, + description.Width, description.Height, + description.MipLevels, description.ArrayLayers, + VkFormats.VdToVkPixelFormat(description.Format, (description.Usage & TextureUsage.DepthStencil) != 0), + description.Usage, + description.SampleCount, + new VkImage(new((nint)nativeTexture))) + ); + + + protected override TextureView CreateTextureViewCore(in TextureViewDescription description) + => LogResourceCreated(new VkTextureView(this, description)); + + protected override DeviceBuffer CreateBufferCore(in BufferDescription description) + => LogResourceCreated(new VkBuffer(this, description.SizeInBytes, description.Usage)); + + public override Fence CreateFence(bool signaled) + => LogResourceCreated(new VkFence(this, signaled)); + + public override Swapchain CreateSwapchain(in SwapchainDescription description) + => LogResourceCreated(new VkSwapchain(this, description)); + + private TResource LogResourceCreated(TResource resource) where TResource : GraphicsObject + { + _onResourceCreated?.Invoke(resource); + return resource; + } + } +} diff --git a/src/XenoAtom.Graphics/Vk/VkGraphicsDevice.cs b/src/XenoAtom.Graphics/Vk/VkGraphicsDevice.cs index b83f264..5194741 100644 --- a/src/XenoAtom.Graphics/Vk/VkGraphicsDevice.cs +++ b/src/XenoAtom.Graphics/Vk/VkGraphicsDevice.cs @@ -10,7 +10,7 @@ namespace XenoAtom.Graphics.Vk { - internal sealed unsafe class VkGraphicsDevice : GraphicsDevice + internal sealed unsafe partial class VkGraphicsDevice : GraphicsDevice { private readonly VkPhysicalDevice _physicalDevice; private readonly VkInstance _instance; @@ -21,6 +21,7 @@ internal sealed unsafe class VkGraphicsDevice : GraphicsDevice private readonly VkCommandPool _graphicsCommandPool; private readonly object _graphicsCommandPoolLock = new object(); private readonly VkQueue _graphicsQueue; + private readonly Action? _onResourceCreated; public readonly object GraphicsQueueLock = new object(); @@ -115,6 +116,7 @@ public VkGraphicsDevice(VkGraphicsAdapter adapter, GraphicsDeviceOptions options _instance = Manager.Instance; _isDebugActivated = Manager.IsDebugActivated; _vkSetDebugUtilsObjectNameEXT = Manager._vkSetDebugUtilsObjectNameEXT; + _onResourceCreated = options.OnResourceCreated; // --------------------------------------------------------------- // Get QueueFamilyIndices @@ -279,8 +281,6 @@ public VkGraphicsDevice(VkGraphicsAdapter adapter, GraphicsDeviceOptions options bufferRangeBinding: true, shaderFloat64: physicalDeviceFeatures.shaderFloat64); - ResourceFactory = new VkResourceFactory(this); - _descriptorPoolManager = new VkDescriptorPoolManager(this); CreateGraphicsCommandPool(out _graphicsCommandPool); for (int i = 0; i < SharedCommandPoolCount; i++) @@ -290,16 +290,14 @@ public VkGraphicsDevice(VkGraphicsAdapter adapter, GraphicsDeviceOptions options _vulkanInfo = new BackendInfoVulkan(this); - PointSampler = ResourceFactory.CreateSampler(SamplerDescription.Point); - LinearSampler = ResourceFactory.CreateSampler(SamplerDescription.Linear); + PointSampler = CreateSampler(SamplerDescription.Point); + LinearSampler = CreateSampler(SamplerDescription.Linear); if (Features.SamplerAnisotropy) { - AnisotropicSampler4x = ResourceFactory.CreateSampler(SamplerDescription.Aniso4x); + AnisotropicSampler4x = CreateSampler(SamplerDescription.Aniso4x); } } - public override ResourceFactory ResourceFactory { get; } - private protected override void SubmitCommandsCore(CommandList cl, Fence? fence) { SubmitCommandList(cl, 0, null, 0, null, fence); @@ -890,7 +888,7 @@ private VkTexture GetFreeStagingTexture(uint width, uint height, uint depth, Pix uint texWidth = Math.Max(256, width); uint texHeight = Math.Max(256, height); - VkTexture newTex = (VkTexture)ResourceFactory.CreateTexture(TextureDescription.Texture3D( + VkTexture newTex = (VkTexture)CreateTexture(TextureDescription.Texture3D( texWidth, texHeight, depth, 1, format, TextureUsage.Staging)); newTex.SetStagingDimensions(width, height, depth, format); @@ -913,7 +911,7 @@ private VkBuffer GetFreeStagingBuffer(uint size) } uint newBufferSize = Math.Max(MinStagingBufferSize, size); - VkBuffer newBuffer = (VkBuffer)ResourceFactory.CreateBuffer( + VkBuffer newBuffer = (VkBuffer)CreateBuffer( new BufferDescription(newBufferSize, BufferUsage.Staging)); return newBuffer; } diff --git a/src/XenoAtom.Graphics/Vk/VkResourceFactory.cs b/src/XenoAtom.Graphics/Vk/VkResourceFactory.cs deleted file mode 100644 index ef4d2ee..0000000 --- a/src/XenoAtom.Graphics/Vk/VkResourceFactory.cs +++ /dev/null @@ -1,97 +0,0 @@ -using static XenoAtom.Interop.vulkan; - -namespace XenoAtom.Graphics.Vk -{ - internal class VkResourceFactory : ResourceFactory - { - private readonly VkGraphicsDevice _gd; - private readonly VkDevice _device; - - public VkResourceFactory(VkGraphicsDevice vkGraphicsDevice) - : base (vkGraphicsDevice.Features) - { - _gd = vkGraphicsDevice; - _device = vkGraphicsDevice.Device; - } - - public override GraphicsBackend BackendType => GraphicsBackend.Vulkan; - - public override CommandList CreateCommandList(in CommandListDescription description) - { - return new VkCommandList(_gd, description); - } - - public override Framebuffer CreateFramebuffer(in FramebufferDescription description) - { - return new VkFramebuffer(_gd, description, false); - } - - protected override Pipeline CreateGraphicsPipelineCore(in GraphicsPipelineDescription description) - { - return new VkPipeline(_gd, description); - } - - public override Pipeline CreateComputePipeline(in ComputePipelineDescription description) - { - return new VkPipeline(_gd, description); - } - - public override ResourceLayout CreateResourceLayout(in ResourceLayoutDescription description) - { - return new VkResourceLayout(_gd, description); - } - - public override ResourceSet CreateResourceSet(in ResourceSetDescription description) - { - ValidationHelpers.ValidateResourceSet(_gd, description); - return new VkResourceSet(_gd, description); - } - - protected override Sampler CreateSamplerCore(in SamplerDescription description) - { - return new VkSampler(_gd, description); - } - - protected override Shader CreateShaderCore(in ShaderDescription description) - { - return new VkShader(_gd, description); - } - - protected override Texture CreateTextureCore(in TextureDescription description) - { - return new VkTexture(_gd, description); - } - - public override Texture CreateTexture(ulong nativeTexture, in TextureDescription description) - { - return new VkTexture( - _gd, - description.Width, description.Height, - description.MipLevels, description.ArrayLayers, - VkFormats.VdToVkPixelFormat(description.Format, (description.Usage & TextureUsage.DepthStencil) != 0), - description.Usage, - description.SampleCount, - new VkImage(new((nint)nativeTexture))); - } - - protected override TextureView CreateTextureViewCore(in TextureViewDescription description) - { - return new VkTextureView(_gd, description); - } - - protected override DeviceBuffer CreateBufferCore(in BufferDescription description) - { - return new VkBuffer(_gd, description.SizeInBytes, description.Usage); - } - - public override Fence CreateFence(bool signaled) - { - return new VkFence(_gd, signaled); - } - - public override Swapchain CreateSwapchain(in SwapchainDescription description) - { - return new VkSwapchain(_gd, description); - } - } -} diff --git a/src/XenoAtom.Graphics/Vk/VkSwapchainFramebuffer.cs b/src/XenoAtom.Graphics/Vk/VkSwapchainFramebuffer.cs index 24b6918..52cd011 100644 --- a/src/XenoAtom.Graphics/Vk/VkSwapchainFramebuffer.cs +++ b/src/XenoAtom.Graphics/Vk/VkSwapchainFramebuffer.cs @@ -122,7 +122,7 @@ private void CreateDepthTexture() if (_depthFormat.HasValue) { _depthAttachment?.Target.Dispose(); - VkTexture depthTexture = (VkTexture)_gd.ResourceFactory.CreateTexture(TextureDescription.Texture2D( + VkTexture depthTexture = (VkTexture)_gd.CreateTexture(TextureDescription.Texture2D( Math.Max(1, _scExtent.width), Math.Max(1, _scExtent.height), 1,