From 9bfc15c92ad0b7fae673fe2370c17260777e891d Mon Sep 17 00:00:00 2001 From: Feralnex Date: Tue, 2 Dec 2025 21:51:33 +0100 Subject: [PATCH 1/3] Changed Vortice.Vulkan package version --- sources/Directory.Packages.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sources/Directory.Packages.props b/sources/Directory.Packages.props index 6e48598205..6354c5c82b 100644 --- a/sources/Directory.Packages.props +++ b/sources/Directory.Packages.props @@ -40,7 +40,7 @@ - + @@ -123,4 +123,4 @@ - \ No newline at end of file + From 0f34bf43e142f2b203778997b086628e68bcbeb2 Mon Sep 17 00:00:00 2001 From: Feralnex Date: Wed, 17 Dec 2025 19:22:47 +0100 Subject: [PATCH 2/3] Updated Vortice.Vulkan package to the latest version 2.1.2 -> 3.0.3 --- samples/Tests/Stride.Samples.Tests.csproj | 2 +- .../Stride.Graphics/Vulkan/Buffer.Vulkan.cs | 25 ++-- .../Vulkan/CommandList.Vulkan.cs | 108 +++++++++--------- .../Vulkan/DescriptorPool.Vulkan.cs | 16 +-- .../Vulkan/DescriptorSet.Vulkan.cs | 60 +++++----- .../Vulkan/DescriptorSetLayout.Vulkan.cs | 8 +- .../Vulkan/GraphicsAdapter.Vulkan.cs | 16 ++- .../Vulkan/GraphicsAdapterFactory.Vulkan.cs | 58 +++++++--- .../Vulkan/GraphicsDevice.Vulkan.cs | 89 +++++++++------ .../Vulkan/GraphicsResource.Vulkan.cs | 4 +- .../Vulkan/PipelineState.Vulkan.cs | 21 ++-- .../Vulkan/QueryPool.Vulkan.cs | 5 +- .../Vulkan/SamplerState.Vulkan.cs | 3 +- .../SwapChainGraphicsPresenter.Vulkan.cs | 66 ++++++----- .../Stride.Graphics/Vulkan/Texture.Vulkan.cs | 37 +++--- 15 files changed, 279 insertions(+), 239 deletions(-) diff --git a/samples/Tests/Stride.Samples.Tests.csproj b/samples/Tests/Stride.Samples.Tests.csproj index 0a208a6585..210146049d 100644 --- a/samples/Tests/Stride.Samples.Tests.csproj +++ b/samples/Tests/Stride.Samples.Tests.csproj @@ -1,4 +1,4 @@ - + diff --git a/sources/engine/Stride.Graphics/Vulkan/Buffer.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/Buffer.Vulkan.cs index 4d7e5b4f8a..0e43a74d2b 100644 --- a/sources/engine/Stride.Graphics/Vulkan/Buffer.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/Buffer.Vulkan.cs @@ -4,7 +4,6 @@ using System; using Stride.Core; using Vortice.Vulkan; -using static Vortice.Vulkan.Vulkan; namespace Stride.Graphics { @@ -153,7 +152,7 @@ public unsafe void Recreate(IntPtr dataPointer) } // Create buffer - GraphicsDevice.CheckResult(vkCreateBuffer(GraphicsDevice.NativeDevice, &createInfo, null, out NativeBuffer)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateBuffer(GraphicsDevice.NativeDevice, &createInfo, null, out NativeBuffer)); // Allocate memory var memoryProperties = VkMemoryPropertyFlags.DeviceLocal; @@ -162,13 +161,13 @@ public unsafe void Recreate(IntPtr dataPointer) memoryProperties = VkMemoryPropertyFlags.HostVisible | VkMemoryPropertyFlags.HostCoherent; } - vkGetBufferMemoryRequirements(GraphicsDevice.NativeDevice, NativeBuffer, out var memoryRequirements); + GraphicsDevice.NativeDeviceApi.vkGetBufferMemoryRequirements(GraphicsDevice.NativeDevice, NativeBuffer, out var memoryRequirements); AllocateMemory(memoryProperties, memoryRequirements); if (NativeMemory != VkDeviceMemory.Null) { - vkBindBufferMemory(GraphicsDevice.NativeDevice, NativeBuffer, NativeMemory, 0); + GraphicsDevice.NativeDeviceApi.vkBindBufferMemory(GraphicsDevice.NativeDevice, NativeBuffer, NativeMemory, 0); } if (SizeInBytes > 0) @@ -176,7 +175,7 @@ public unsafe void Recreate(IntPtr dataPointer) var commandBuffer = GraphicsDevice.NativeCopyCommandPools.Value.GetObject(GraphicsDevice.CopyFence.GetCompletedValue()); var beginInfo = new VkCommandBufferBeginInfo { sType = VkStructureType.CommandBufferBeginInfo, flags = VkCommandBufferUsageFlags.OneTimeSubmit }; - vkBeginCommandBuffer(commandBuffer, &beginInfo); + GraphicsDevice.NativeDeviceApi.vkBeginCommandBuffer(commandBuffer, &beginInfo); // Copy to upload buffer if (dataPointer != IntPtr.Zero) @@ -184,9 +183,9 @@ public unsafe void Recreate(IntPtr dataPointer) if (Usage == GraphicsResourceUsage.Dynamic) { void* uploadMemory; - vkMapMemory(GraphicsDevice.NativeDevice, NativeMemory, 0, (ulong) SizeInBytes, VkMemoryMapFlags.None, &uploadMemory); + GraphicsDevice.NativeDeviceApi.vkMapMemory(GraphicsDevice.NativeDevice, NativeMemory, 0, (ulong) SizeInBytes, VkMemoryMapFlags.None, &uploadMemory); MemoryUtilities.CopyWithAlignmentFallback(uploadMemory, (void*) dataPointer, (uint) SizeInBytes); - vkUnmapMemory(GraphicsDevice.NativeDevice, NativeMemory); + GraphicsDevice.NativeDeviceApi.vkUnmapMemory(GraphicsDevice.NativeDevice, NativeMemory); } else { @@ -197,7 +196,7 @@ public unsafe void Recreate(IntPtr dataPointer) // Barrier var memoryBarrier = new VkBufferMemoryBarrier(uploadResource, VkAccessFlags.HostWrite, VkAccessFlags.TransferRead, (ulong) uploadOffset, (ulong) sizeInBytes); - vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, &memoryBarrier, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, &memoryBarrier, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); // Copy var bufferCopy = new VkBufferCopy @@ -206,20 +205,20 @@ public unsafe void Recreate(IntPtr dataPointer) dstOffset = 0, size = (uint) sizeInBytes }; - vkCmdCopyBuffer(commandBuffer, uploadResource, NativeBuffer, 1, &bufferCopy); + GraphicsDevice.NativeDeviceApi.vkCmdCopyBuffer(commandBuffer, uploadResource, NativeBuffer, 1, &bufferCopy); } } else { - vkCmdFillBuffer(commandBuffer, NativeBuffer, 0, (uint) bufferDescription.SizeInBytes, 0); + GraphicsDevice.NativeDeviceApi.vkCmdFillBuffer(commandBuffer, NativeBuffer, 0, (uint) bufferDescription.SizeInBytes, 0); } // Barrier var bufferMemoryBarrier = new VkBufferMemoryBarrier(NativeBuffer, VkAccessFlags.TransferWrite, NativeAccessMask); - vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Transfer, VkPipelineStageFlags.AllCommands, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, &bufferMemoryBarrier, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Transfer, VkPipelineStageFlags.AllCommands, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, &bufferMemoryBarrier, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); // Close and submit - GraphicsDevice.CheckResult(vkEndCommandBuffer(commandBuffer)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkEndCommandBuffer(commandBuffer)); var copyFenceValue = GraphicsDevice.ExecuteAndWaitCopyQueueGPU(commandBuffer); GraphicsDevice.NativeCopyCommandPools.Value.RecycleObject(GraphicsDevice.CopyFence.NextFenceValue, commandBuffer); @@ -260,7 +259,7 @@ internal unsafe VkBufferView GetShaderResourceView(PixelFormat viewFormat) //view = (Description.BufferFlags & BufferFlags.RawBuffer) != 0 ? VkBufferViewType.Raw : VkBufferViewType.Formatted, }; - GraphicsDevice.CheckResult(vkCreateBufferView(GraphicsDevice.NativeDevice, &createInfo, allocator: null, out var bufferView)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateBufferView(GraphicsDevice.NativeDevice, &createInfo, allocator: null, out var bufferView)); return bufferView; } diff --git a/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs index c55e856261..8f27ae7dec 100644 --- a/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs @@ -81,7 +81,7 @@ public unsafe partial void Reset() sType = VkStructureType.CommandBufferBeginInfo, flags = VkCommandBufferUsageFlags.OneTimeSubmit }; - vkBeginCommandBuffer(currentCommandList.NativeCommandBuffer, &beginInfo); + GraphicsDevice.NativeDeviceApi.vkBeginCommandBuffer(currentCommandList.NativeCommandBuffer, &beginInfo); pipelineDirty = true; viewportDirty = true; @@ -103,7 +103,7 @@ public partial CompiledCommandList Close() CleanupRenderPass(); // Close - GraphicsDevice.CheckResult(vkEndCommandBuffer(currentCommandList.NativeCommandBuffer)); + GraphicsDevice.CheckResult(vGraphicsDevice.NativeDeviceApi.kEndCommandBuffer(currentCommandList.NativeCommandBuffer)); // Staging resources not updated anymore foreach (var stagingResource in currentCommandList.StagingResources) @@ -211,7 +211,7 @@ private unsafe void SetViewportImpl() var viewportCopy = Viewport; if (viewportDirty) { - vkCmdSetViewport(currentCommandList.NativeCommandBuffer, firstViewport: 0, viewportCount: 1, (VkViewport*) &viewportCopy); + GraphicsDevice.NativeDeviceApi.vkCmdSetViewport(currentCommandList.NativeCommandBuffer, firstViewport: 0, viewportCount: 1, (VkViewport*) &viewportCopy); viewportDirty = false; } @@ -222,7 +222,7 @@ private unsafe void SetViewportImpl() // Use manual scissor var scissor = scissors[0]; var nativeScissor = new VkRect2D(scissor.Left, scissor.Top, (uint)scissor.Width, (uint)scissor.Height); - vkCmdSetScissor(currentCommandList.NativeCommandBuffer, firstScissor: 0, scissorCount: 1, &nativeScissor); + GraphicsDevice.NativeDeviceApi.vkCmdSetScissor(currentCommandList.NativeCommandBuffer, firstScissor: 0, scissorCount: 1, &nativeScissor); } } else @@ -230,7 +230,7 @@ private unsafe void SetViewportImpl() // Use viewport // Always update, because either scissor or viewport was dirty and we use viewport size var scissor = new VkRect2D((int) viewportCopy.X, (int) viewportCopy.Y, (uint) viewportCopy.Width, (uint) viewportCopy.Height); - vkCmdSetScissor(currentCommandList.NativeCommandBuffer, firstScissor: 0, scissorCount: 1, &scissor); + GraphicsDevice.NativeDeviceApi.vkCmdSetScissor(currentCommandList.NativeCommandBuffer, firstScissor: 0, scissorCount: 1, &scissor); } scissorsDirty = false; @@ -314,7 +314,7 @@ private unsafe void BindDescriptorSets() }; VkDescriptorSet localDescriptorSet; - vkAllocateDescriptorSets(GraphicsDevice.NativeDevice, &allocateInfo, &localDescriptorSet); + GraphicsDevice.NativeDeviceApi.vkAllocateDescriptorSets(GraphicsDevice.NativeDevice, &allocateInfo, &localDescriptorSet); descriptorSet = localDescriptorSet; #if !STRIDE_GRAPHICS_NO_DESCRIPTOR_COPIES @@ -335,8 +335,8 @@ private unsafe void BindDescriptorSets() }); } - fixed (CopyDescriptorSet* fCopiesItems = copies.Items) - GraphicsDevice.NativeDevice.UpdateDescriptorSets(0, null, (uint) copies.Count, fCopiesItems); + fixed (VkCopyDescriptorSet* fCopiesItems = copies.Items) + GraphicsDevice.NativeDeviceApi.vkUpdateDescriptorSets(GraphicsDevice.NativeDevice, 0, null, (uint) copies.Count, fCopiesItems); #else var bindingCount = activePipeline.DescriptorBindingMapping.Count; var writes = stackalloc VkWriteDescriptorSet[bindingCount]; @@ -408,9 +408,9 @@ private unsafe void BindDescriptorSets() } } - vkUpdateDescriptorSets(GraphicsDevice.NativeDevice, (uint)bindingCount, writes, descriptorCopyCount: 0, descriptorCopies: null); + GraphicsDevice.NativeDeviceApi.vkUpdateDescriptorSets(GraphicsDevice.NativeDevice, (uint)bindingCount, writes, descriptorCopyCount: 0, descriptorCopies: null); #endif - vkCmdBindDescriptorSets(currentCommandList.NativeCommandBuffer, activePipeline.IsCompute ? VkPipelineBindPoint.Compute : VkPipelineBindPoint.Graphics, activePipeline.NativeLayout, firstSet: 0, descriptorSetCount: 1, &localDescriptorSet, dynamicOffsetCount: 0, dynamicOffsets: null); + GraphicsDevice.NativeDeviceApi.vkCmdBindDescriptorSets(currentCommandList.NativeCommandBuffer, activePipeline.IsCompute ? VkPipelineBindPoint.Compute : VkPipelineBindPoint.Graphics, activePipeline.NativeLayout, firstSet: 0, descriptorSetCount: 1, &localDescriptorSet, dynamicOffsetCount: 0, dynamicOffsets: null); } private readonly FastList copies = new(); @@ -420,7 +420,7 @@ public void SetStencilReference(int stencilReference) if (activeStencilReference != stencilReference) { activeStencilReference = (uint) stencilReference; - vkCmdSetStencilReference(currentCommandList.NativeCommandBuffer, VkStencilFaceFlags.FrontAndBack, activeStencilReference.Value); + GraphicsDevice.NativeDeviceApi.vkCmdSetStencilReference(currentCommandList.NativeCommandBuffer, VkStencilFaceFlags.FrontAndBack, activeStencilReference.Value); } } @@ -448,12 +448,12 @@ public unsafe void SetVertexBuffer(int index, Buffer buffer, int offset, int str var bufferCopy = buffer.NativeBuffer; var offsetCopy = (ulong) offset; - vkCmdBindVertexBuffers(currentCommandList.NativeCommandBuffer, (uint) index, bindingCount: 1, &bufferCopy, &offsetCopy); + GraphicsDevice.NativeDeviceApi.vkCmdBindVertexBuffers(currentCommandList.NativeCommandBuffer, (uint) index, bindingCount: 1, &bufferCopy, &offsetCopy); } public void SetIndexBuffer(Buffer buffer, int offset, bool is32bits) { - vkCmdBindIndexBuffer(currentCommandList.NativeCommandBuffer, buffer.NativeBuffer, (ulong) offset, is32bits ? VkIndexType.Uint32 : VkIndexType.Uint16); + GraphicsDevice.NativeDeviceApi.vkCmdBindIndexBuffer(currentCommandList.NativeCommandBuffer, buffer.NativeBuffer, (ulong) offset, is32bits ? VkIndexType.Uint32 : VkIndexType.Uint16); } public unsafe void ResourceBarrierTransition(GraphicsResource resource, GraphicsResourceState newState) @@ -514,7 +514,7 @@ public unsafe void ResourceBarrierTransition(GraphicsResource resource, Graphics CleanupRenderPass(); var memoryBarrier = new VkImageMemoryBarrier(texture.NativeImage, new VkImageSubresourceRange(texture.NativeImageAspect, 0, uint.MaxValue, 0, uint.MaxValue), oldAccessMask, texture.NativeAccessMask, oldLayout, texture.NativeLayout); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, sourceStages, texture.NativePipelineStageMask, VkDependencyFlags.None, 0, null, 0, null, 1, &memoryBarrier); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, sourceStages, texture.NativePipelineStageMask, VkDependencyFlags.None, 0, null, 0, null, 1, &memoryBarrier); } else { @@ -549,7 +549,7 @@ public void Dispatch(int threadCountX, int threadCountY, int threadCountZ) { CleanupRenderPass(); BindDescriptorSets(); - vkCmdDispatch(currentCommandList.NativeCommandBuffer, (uint)threadCountX, (uint)threadCountY, (uint)threadCountZ); + GraphicsDevice.NativeDeviceApi.vkCmdDispatch(currentCommandList.NativeCommandBuffer, (uint)threadCountX, (uint)threadCountY, (uint)threadCountZ); } /// @@ -561,7 +561,7 @@ public void Dispatch(Buffer indirectBuffer, int offsetInBytes) { CleanupRenderPass(); BindDescriptorSets(); - vkCmdDispatchIndirect(currentCommandList.NativeCommandBuffer, indirectBuffer.NativeBuffer, (ulong)offsetInBytes); + GraphicsDevice.NativeDeviceApi.vkCmdDispatchIndirect(currentCommandList.NativeCommandBuffer, indirectBuffer.NativeBuffer, (ulong)offsetInBytes); } /// @@ -573,7 +573,7 @@ public void Draw(int vertexCount, int startVertexLocation = 0) { PrepareDraw(); - vkCmdDraw(currentCommandList.NativeCommandBuffer, (uint) vertexCount, instanceCount: 1, (uint) startVertexLocation, firstInstance: 0); + GraphicsDevice.NativeDeviceApi.vkCmdDraw(currentCommandList.NativeCommandBuffer, (uint) vertexCount, instanceCount: 1, (uint) startVertexLocation, firstInstance: 0); GraphicsDevice.FrameTriangleCount += (uint) vertexCount; GraphicsDevice.FrameDrawCalls++; @@ -602,7 +602,7 @@ public void DrawIndexed(int indexCount, int startIndexLocation = 0, int baseVert { PrepareDraw(); - vkCmdDrawIndexed(currentCommandList.NativeCommandBuffer, (uint) indexCount, instanceCount: 1, (uint) startIndexLocation, baseVertexLocation, firstInstance: 0); + GraphicsDevice.NativeDeviceApi.vkCmdDrawIndexed(currentCommandList.NativeCommandBuffer, (uint) indexCount, instanceCount: 1, (uint) startIndexLocation, baseVertexLocation, firstInstance: 0); GraphicsDevice.FrameDrawCalls++; GraphicsDevice.FrameTriangleCount += (uint) indexCount; @@ -620,7 +620,7 @@ public void DrawIndexedInstanced(int indexCountPerInstance, int instanceCount, i { PrepareDraw(); - vkCmdDrawIndexed(currentCommandList.NativeCommandBuffer, (uint) indexCountPerInstance, (uint) instanceCount, (uint) startIndexLocation, baseVertexLocation, (uint) startInstanceLocation); + GraphicsDevice.NativeDeviceApi.vkCmdDrawIndexed(currentCommandList.NativeCommandBuffer, (uint) indexCountPerInstance, (uint) instanceCount, (uint) startIndexLocation, baseVertexLocation, (uint) startInstanceLocation); //NativeCommandList.DrawIndexedInstanced(indexCountPerInstance, instanceCount, startIndexLocation, baseVertexLocation, startInstanceLocation); GraphicsDevice.FrameDrawCalls++; @@ -656,7 +656,7 @@ public void DrawInstanced(int vertexCountPerInstance, int instanceCount, int sta { PrepareDraw(); - vkCmdDraw(currentCommandList.NativeCommandBuffer, (uint) vertexCountPerInstance, (uint) instanceCount, (uint) startVertexLocation, (uint) startVertexLocation); + GraphicsDevice.NativeDeviceApi.vkCmdDraw(currentCommandList.NativeCommandBuffer, (uint) vertexCountPerInstance, (uint) instanceCount, (uint) startVertexLocation, (uint) startVertexLocation); //NativeCommandList.DrawInstanced(vertexCountPerInstance, instanceCount, startVertexLocation, startInstanceLocation); GraphicsDevice.FrameDrawCalls++; @@ -699,7 +699,7 @@ public unsafe void BeginProfile(Color4 profileColor, string name) sType = VkStructureType.DebugMarkerMarkerInfoEXT, pMarkerName = bytesPointer }; - vkCmdDebugMarkerBeginEXT(currentCommandList.NativeCommandBuffer, &debugMarkerInfo); + GraphicsDevice.NativeDeviceApi.vkCmdDebugMarkerBeginEXT(currentCommandList.NativeCommandBuffer, &debugMarkerInfo); } } } @@ -711,7 +711,7 @@ public void EndProfile() { if (GraphicsDevice.IsProfilingSupported) { - vkCmdDebugMarkerEndEXT(currentCommandList.NativeCommandBuffer); + GraphicsDevice.NativeDeviceApi.vkCmdDebugMarkerEndEXT(currentCommandList.NativeCommandBuffer); } } /// @@ -721,12 +721,12 @@ public void EndProfile() /// The timestamp query. public void WriteTimestamp(QueryPool queryPool, int index) { - vkCmdWriteTimestamp(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.AllCommands, queryPool.NativeQueryPool, (uint) index); + GraphicsDevice.NativeDeviceApi.vkCmdWriteTimestamp(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.AllCommands, queryPool.NativeQueryPool, (uint) index); } public void ResetQueryPool(QueryPool queryPool) { - vkCmdResetQueryPool(currentCommandList.NativeCommandBuffer, queryPool.NativeQueryPool, firstQuery: 0, (uint) queryPool.QueryCount); + GraphicsDevice.NativeDeviceApi.vkCmdResetQueryPool(currentCommandList.NativeCommandBuffer, queryPool.NativeQueryPool, firstQuery: 0, (uint) queryPool.QueryCount); } /// @@ -755,13 +755,13 @@ public unsafe void Clear(Texture depthStencilBuffer, DepthStencilClearOptions op clearRange.aspectMask |= VkImageAspectFlags.Stencil & depthStencilBuffer.NativeImageAspect; var memoryBarrier = new VkImageMemoryBarrier(depthStencilBuffer.NativeImage, barrierRange, depthStencilBuffer.NativeAccessMask, VkAccessFlags.TransferWrite, depthStencilBuffer.NativeLayout, VkImageLayout.TransferDstOptimal); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, depthStencilBuffer.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, depthStencilBuffer.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); var clearValue = new VkClearDepthStencilValue(depth, stencil); - vkCmdClearDepthStencilImage(currentCommandList.NativeCommandBuffer, depthStencilBuffer.NativeImage, VkImageLayout.TransferDstOptimal, &clearValue, rangeCount: 1, &clearRange); + GraphicsDevice.NativeDeviceApi.vkCmdClearDepthStencilImage(currentCommandList.NativeCommandBuffer, depthStencilBuffer.NativeImage, VkImageLayout.TransferDstOptimal, &clearValue, rangeCount: 1, &clearRange); memoryBarrier = new VkImageMemoryBarrier(depthStencilBuffer.NativeImage, barrierRange, VkAccessFlags.TransferWrite, depthStencilBuffer.NativeAccessMask, VkImageLayout.TransferDstOptimal, depthStencilBuffer.NativeLayout); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, depthStencilBuffer.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, depthStencilBuffer.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); depthStencilBuffer.IsInitialized = true; } @@ -781,12 +781,12 @@ public unsafe void Clear(Texture renderTarget, Color4 color) var clearRange = renderTarget.NativeResourceRange; var memoryBarrier = new VkImageMemoryBarrier(renderTarget.NativeImage, clearRange, renderTarget.NativeAccessMask, VkAccessFlags.TransferWrite, renderTarget.NativeLayout, VkImageLayout.TransferDstOptimal); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, renderTarget.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, renderTarget.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); - vkCmdClearColorImage(currentCommandList.NativeCommandBuffer, renderTarget.NativeImage, VkImageLayout.TransferDstOptimal, (VkClearColorValue*) &color, rangeCount: 1, &clearRange); + GraphicsDevice.NativeDeviceApi.vkCmdClearColorImage(currentCommandList.NativeCommandBuffer, renderTarget.NativeImage, VkImageLayout.TransferDstOptimal, (VkClearColorValue*) &color, rangeCount: 1, &clearRange); memoryBarrier = new VkImageMemoryBarrier(renderTarget.NativeImage, clearRange, VkAccessFlags.TransferWrite, renderTarget.NativeAccessMask, VkImageLayout.TransferDstOptimal, renderTarget.NativeLayout); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, renderTarget.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, renderTarget.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); renderTarget.IsInitialized = true; } @@ -906,7 +906,7 @@ public unsafe void Copy(GraphicsResource source, GraphicsResource destination) imageBarriers[imageBarrierCount++] = new VkImageMemoryBarrier(destinationParent.NativeImage, new VkImageSubresourceRange(destinationParent.NativeImageAspect, baseMipLevel: 0, levelCount: uint.MaxValue, baseArrayLayer: 0, layerCount: uint.MaxValue), destinationTexture.NativeAccessMask, VkAccessFlags.TransferWrite, destinationTexture.NativeLayout, VkImageLayout.TransferDstOptimal); } - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, sourceTexture.NativePipelineStageMask | destinationParent.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferBarrierCount, bufferBarriers, imageBarrierCount, imageBarriers); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, sourceTexture.NativePipelineStageMask | destinationParent.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferBarrierCount, bufferBarriers, imageBarrierCount, imageBarriers); // TODO: compute all regions at once in a single call for (var subresource = 0; subresource < sourceTexture.MipLevelCount * sourceTexture.ArraySize; ++subresource) @@ -933,7 +933,7 @@ public unsafe void Copy(GraphicsResource source, GraphicsResource destination) dstOffset = (ulong) destinationOffset, size = (ulong) size, }; - vkCmdCopyBuffer(currentCommandList.NativeCommandBuffer, sourceParent.NativeBuffer, destinationParent.NativeBuffer, regionCount: 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyBuffer(currentCommandList.NativeCommandBuffer, sourceParent.NativeBuffer, destinationParent.NativeBuffer, regionCount: 1, ©); } else { @@ -943,7 +943,7 @@ public unsafe void Copy(GraphicsResource source, GraphicsResource destination) imageExtent = new VkExtent3D(width, height, depth), bufferOffset = (ulong) destinationOffset }; - vkCmdCopyImageToBuffer(currentCommandList.NativeCommandBuffer, sourceParent.NativeImage, VkImageLayout.TransferSrcOptimal, destinationParent.NativeBuffer, regionCount: 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyImageToBuffer(currentCommandList.NativeCommandBuffer, sourceParent.NativeImage, VkImageLayout.TransferSrcOptimal, destinationParent.NativeBuffer, regionCount: 1, ©); } // VkFence for host access @@ -963,7 +963,7 @@ public unsafe void Copy(GraphicsResource source, GraphicsResource destination) imageExtent = new VkExtent3D(width, height, depth), bufferOffset = (ulong) sourceOffset }; - vkCmdCopyBufferToImage(currentCommandList.NativeCommandBuffer, sourceParent.NativeBuffer, destinationParent.NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyBufferToImage(currentCommandList.NativeCommandBuffer, sourceParent.NativeBuffer, destinationParent.NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); } else { @@ -1017,14 +1017,14 @@ public unsafe void Copy(GraphicsResource source, GraphicsResource destination) imageBarrierCount++; } - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, sourceTexture.NativePipelineStageMask | destinationParent.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferBarrierCount, bufferBarriers, imageBarrierCount, imageBarriers); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, sourceTexture.NativePipelineStageMask | destinationParent.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferBarrierCount, bufferBarriers, imageBarrierCount, imageBarriers); } else if (source is Buffer sourceBuffer && destination is Buffer destinationBuffer) { var bufferBarriers = stackalloc VkBufferMemoryBarrier[2]; bufferBarriers[0] = new VkBufferMemoryBarrier(sourceBuffer.NativeBuffer, sourceBuffer.NativeAccessMask, VkAccessFlags.TransferRead); bufferBarriers[1] = new VkBufferMemoryBarrier(destinationBuffer.NativeBuffer, destinationBuffer.NativeAccessMask, VkAccessFlags.TransferWrite); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, sourceBuffer.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 2, bufferBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, sourceBuffer.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 2, bufferBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); var copy = new VkBufferCopy { @@ -1032,11 +1032,11 @@ public unsafe void Copy(GraphicsResource source, GraphicsResource destination) dstOffset = 0, size = (uint) sourceBuffer.SizeInBytes }; - vkCmdCopyBuffer(currentCommandList.NativeCommandBuffer, sourceBuffer.NativeBuffer, destinationBuffer.NativeBuffer, regionCount: 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyBuffer(currentCommandList.NativeCommandBuffer, sourceBuffer.NativeBuffer, destinationBuffer.NativeBuffer, regionCount: 1, ©); bufferBarriers[0] = new VkBufferMemoryBarrier(sourceBuffer.NativeBuffer, VkAccessFlags.TransferRead, sourceBuffer.NativeAccessMask); bufferBarriers[1] = new VkBufferMemoryBarrier(destinationBuffer.NativeBuffer, VkAccessFlags.TransferWrite, destinationBuffer.NativeAccessMask); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, sourceBuffer.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 2, bufferBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, sourceBuffer.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 2, bufferBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); } else { @@ -1089,7 +1089,7 @@ public unsafe void CopyRegion(GraphicsResource source, int sourceSubresource, Re imageBarriers[imageBarrierCount++] = new VkImageMemoryBarrier(destinationParent.NativeImage, new VkImageSubresourceRange(destinationParent.NativeImageAspect, baseMipLevel: 0, levelCount: uint.MaxValue, baseArrayLayer: 0, layerCount: uint.MaxValue), destinationParent.NativeAccessMask, VkAccessFlags.TransferWrite, destinationParent.NativeLayout, VkImageLayout.TransferDstOptimal); } - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, sourceTexture.NativePipelineStageMask | destinationParent.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferBarrierCount, bufferBarriers, imageBarrierCount, imageBarriers); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, sourceTexture.NativePipelineStageMask | destinationParent.NativePipelineStageMask, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferBarrierCount, bufferBarriers, imageBarrierCount, imageBarriers); // Copy if (destinationTexture.Usage == GraphicsResourceUsage.Staging) @@ -1145,7 +1145,7 @@ public unsafe void CopyRegion(GraphicsResource source, int sourceSubresource, Re imageOffset = new VkOffset3D(dstX, dstY, dstZ), imageExtent = new VkExtent3D(region.Right - region.Left, region.Bottom - region.Top, region.Back - region.Front) }; - vkCmdCopyBufferToImage(currentCommandList.NativeCommandBuffer, sourceParent.NativeBuffer, destinationParent.NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyBufferToImage(currentCommandList.NativeCommandBuffer, sourceParent.NativeBuffer, destinationParent.NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); } else { @@ -1157,7 +1157,7 @@ public unsafe void CopyRegion(GraphicsResource source, int sourceSubresource, Re dstOffset = new VkOffset3D(dstX, dstY, dstZ), extent = new VkExtent3D(region.Right - region.Left, region.Bottom - region.Top, region.Back - region.Front) }; - vkCmdCopyImage(currentCommandList.NativeCommandBuffer, sourceParent.NativeImage, VkImageLayout.TransferSrcOptimal, destinationParent.NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyImage(currentCommandList.NativeCommandBuffer, sourceParent.NativeImage, VkImageLayout.TransferSrcOptimal, destinationParent.NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); } } @@ -1195,7 +1195,7 @@ public unsafe void CopyRegion(GraphicsResource source, int sourceSubresource, Re imageBarrierCount++; } - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, sourceTexture.NativePipelineStageMask | destinationParent.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferBarrierCount, bufferBarriers, imageBarrierCount, imageBarriers); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, sourceTexture.NativePipelineStageMask | destinationParent.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferBarrierCount, bufferBarriers, imageBarrierCount, imageBarriers); } else { @@ -1342,7 +1342,7 @@ internal unsafe partial void UpdateSubResource(GraphicsResource resource, int su var subresourceRange = new VkImageSubresourceRange(VkImageAspectFlags.Color, (uint) mipSlice, levelCount: 1, (uint) arraySlice, 1); var memoryBarrier = new VkImageMemoryBarrier(texture.NativeImage, subresourceRange, texture.NativeAccessMask, VkAccessFlags.TransferWrite, texture.NativeLayout, VkImageLayout.TransferDstOptimal); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, texture.NativePipelineStageMask | VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, &uploadBufferMemoryBarrier, imageMemoryBarrierCount: 1, &memoryBarrier); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, texture.NativePipelineStageMask | VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, &uploadBufferMemoryBarrier, imageMemoryBarrierCount: 1, &memoryBarrier); // TODO VULKAN: Handle depth-stencil (NOTE: only supported on graphics queue) // TODO VULKAN: Handle non-packed pitches @@ -1355,10 +1355,10 @@ internal unsafe partial void UpdateSubResource(GraphicsResource resource, int su imageOffset = new VkOffset3D(region.Left, region.Top, region.Front), imageExtent = new VkExtent3D(region.Right - region.Left, region.Bottom - region.Top, region.Back - region.Front) }; - vkCmdCopyBufferToImage(currentCommandList.NativeCommandBuffer, uploadResource, texture.NativeImage, VkImageLayout.TransferDstOptimal, 1, &bufferCopy); + GraphicsDevice.NativeDeviceApi.vkCmdCopyBufferToImage(currentCommandList.NativeCommandBuffer, uploadResource, texture.NativeImage, VkImageLayout.TransferDstOptimal, 1, &bufferCopy); memoryBarrier = new VkImageMemoryBarrier(texture.NativeImage, subresourceRange, VkAccessFlags.TransferWrite, texture.NativeAccessMask, VkImageLayout.TransferDstOptimal, texture.NativeLayout); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, texture.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, texture.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &memoryBarrier); } else { @@ -1375,12 +1375,12 @@ internal unsafe partial void UpdateSubResource(GraphicsResource resource, int su memoryBarriers[0] = uploadBufferMemoryBarrier; memoryBarriers[1] = new VkBufferMemoryBarrier(buffer.NativeBuffer, buffer.NativeAccessMask, VkAccessFlags.TransferWrite, bufferCopy.dstOffset, bufferCopy.size); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, buffer.NativePipelineStageMask | VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 2, memoryBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, buffer.NativePipelineStageMask | VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 2, memoryBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); - vkCmdCopyBuffer(currentCommandList.NativeCommandBuffer, uploadResource, buffer.NativeBuffer, regionCount: 1, &bufferCopy); + GraphicsDevice.NativeDeviceApi.vkCmdCopyBuffer(currentCommandList.NativeCommandBuffer, uploadResource, buffer.NativeBuffer, regionCount: 1, &bufferCopy); var memoryBarrier = new VkBufferMemoryBarrier(buffer.NativeBuffer, VkAccessFlags.TransferWrite, buffer.NativeAccessMask, bufferCopy.dstOffset, bufferCopy.size); - vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, buffer.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, &memoryBarrier, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(currentCommandList.NativeCommandBuffer, VkPipelineStageFlags.Transfer, buffer.NativePipelineStageMask, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, &memoryBarrier, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); } else { @@ -1476,14 +1476,14 @@ resource.UpdatingCommandList is not null } void* mappedMemory; - vkMapMemory(GraphicsDevice.NativeDevice, resource.NativeMemory, (ulong) offsetInBytes, (ulong) lengthInBytes, VkMemoryMapFlags.None, &mappedMemory); + GraphicsDevice.NativeDeviceApi.vkMapMemory(GraphicsDevice.NativeDevice, resource.NativeMemory, (ulong) offsetInBytes, (ulong) lengthInBytes, VkMemoryMapFlags.None, &mappedMemory); return new MappedResource(resource, subResourceIndex, new DataBox((IntPtr) mappedMemory, rowPitch, slicePitch: 0), offsetInBytes, lengthInBytes); } // TODO GRAPHICS REFACTOR what should we do with this? public unsafe partial void UnmapSubResource(MappedResource unmapped) { - vkUnmapMemory(GraphicsDevice.NativeDevice, unmapped.Resource.NativeMemory); + GraphicsDevice.NativeDeviceApi.vkUnmapMemory(GraphicsDevice.NativeDevice, unmapped.Resource.NativeMemory); } /// @@ -1496,7 +1496,7 @@ protected internal override bool OnRecreate() /// protected internal override void OnDestroyed(bool immediately = false) { - GraphicsDevice.CheckResult(vkDeviceWaitIdle(GraphicsDevice.NativeDevice)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkDeviceWaitIdle(GraphicsDevice.NativeDevice)); if (descriptorPool != VkDescriptorPool.Null) { @@ -1550,7 +1550,7 @@ private unsafe void EnsureRenderPass() height = (uint) renderTarget.ViewHeight, layers = 1 // TODO VULKAN: Use correct view depth/array size }; - GraphicsDevice.CheckResult(vkCreateFramebuffer(GraphicsDevice.NativeDevice, &framebufferCreateInfo, null, out activeFramebuffer)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateFramebuffer(GraphicsDevice.NativeDevice, &framebufferCreateInfo, null, out activeFramebuffer)); GraphicsDevice.Collect(activeFramebuffer); framebuffers.Add(framebufferKey, activeFramebuffer); } @@ -1581,7 +1581,7 @@ private unsafe void EnsureRenderPass() framebuffer = activeFramebuffer, renderArea = new VkRect2D(0, 0, (uint)renderTarget.ViewWidth, (uint)renderTarget.ViewHeight) }; - vkCmdBeginRenderPass(currentCommandList.NativeCommandBuffer, &renderPassBegin, VkSubpassContents.Inline); + GraphicsDevice.NativeDeviceApi.vkCmdBeginRenderPass(currentCommandList.NativeCommandBuffer, &renderPassBegin, VkSubpassContents.Inline); previousRenderPass = activeRenderPass = pipelineRenderPass; } @@ -1591,7 +1591,7 @@ private unsafe void CleanupRenderPass() { if (activeRenderPass != VkRenderPass.Null) { - vkCmdEndRenderPass(currentCommandList.NativeCommandBuffer); + GraphicsDevice.NativeDeviceApi.vkCmdEndRenderPass(currentCommandList.NativeCommandBuffer); activeRenderPass = VkRenderPass.Null; viewportDirty = true; diff --git a/sources/engine/Stride.Graphics/Vulkan/DescriptorPool.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/DescriptorPool.Vulkan.cs index ca728b4b25..22f04fd4b9 100644 --- a/sources/engine/Stride.Graphics/Vulkan/DescriptorPool.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/DescriptorPool.Vulkan.cs @@ -16,8 +16,8 @@ public partial class DescriptorPool public void Reset() { - GraphicsDevice.descriptorPools.RecycleObject(GraphicsDevice.NextFenceValue, NativeDescriptorPool); - NativeDescriptorPool = GraphicsDevice.descriptorPools.GetObject(); + GraphicsDevice.DescriptorPools.RecycleObject(GraphicsDevice.NextFenceValue, NativeDescriptorPool); + NativeDescriptorPool = GraphicsDevice.DescriptorPools.GetObject(); allocatedSetCount = 0; for (int i = 0; i < DescriptorSetLayout.DescriptorTypeCount; i++) @@ -52,16 +52,16 @@ internal unsafe VkDescriptorSet AllocateDescriptorSet(DescriptorSetLayout descri // Allocate new descriptor set var nativeLayoutCopy = descriptorSetLayout.NativeLayout; - var allocateInfo = new DescriptorSetAllocateInfo + var allocateInfo = new VkDescriptorSetAllocateInfo { sType = VkStructureType.DescriptorSetAllocateInfo, - DescriptorPool = NativeDescriptorPool, - DescriptorSetCount = 1, - SetLayouts = new IntPtr(&nativeLayoutCopy) + descriptorPool = NativeDescriptorPool, + descriptorSetCount = 1, + pSetLayouts = &nativeLayoutCopy }; VkDescriptorSet descriptorSet; - GraphicsDevice.NativeDevice.AllocateDescriptorSets(ref allocateInfo, &descriptorSet); + GraphicsDevice.NativeDeviceApi.vkAllocateDescriptorSets(GraphicsDevice.NativeDevice, &allocateInfo, &descriptorSet); return descriptorSet; } @@ -83,7 +83,7 @@ protected internal override bool OnRecreate() /// protected internal override void OnDestroyed(bool immediately = false) { - GraphicsDevice.descriptorPools.RecycleObject(GraphicsDevice.NextFenceValue, NativeDescriptorPool); + GraphicsDevice.DescriptorPools.RecycleObject(GraphicsDevice.NextFenceValue, NativeDescriptorPool); base.OnDestroyed(immediately); } diff --git a/sources/engine/Stride.Graphics/Vulkan/DescriptorSet.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/DescriptorSet.Vulkan.cs index fa879b3e0a..df2b1aaaa7 100644 --- a/sources/engine/Stride.Graphics/Vulkan/DescriptorSet.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/DescriptorSet.Vulkan.cs @@ -51,24 +51,24 @@ public void SetValue(int slot, object value) /// The shader resource view. public unsafe void SetShaderResourceView(int slot, GraphicsResource shaderResourceView) { - var write = new WriteDescriptorSet + var write = new VkWriteDescriptorSet { sType = VkStructureType.WriteDescriptorSet, - DescriptorCount = 1, - DestinationSet = NativeDescriptorSet, - DestinationBinding = (uint)slot, - DestinationArrayElement = 0, + descriptorCount = 1, + dstSet = NativeDescriptorSet, + dstBinding = (uint)slot, + dstArrayElement = 0, }; var texture = shaderResourceView as Texture; if (texture != null) { - var imageInfo = new DescriptorImageInfo { VkImageView = texture.NativeImageView, ImageLayout = VkImageLayout.ShaderReadOnlyOptimal }; + var imageInfo = new VkDescriptorImageInfo { imageView = texture.NativeImageView, imageLayout = VkImageLayout.ShaderReadOnlyOptimal }; - write.VkDescriptorType = VkDescriptorType.SampledImage; - write.ImageInfo = new IntPtr(&imageInfo); + write.descriptorType = VkDescriptorType.SampledImage; + write.pImageInfo = &imageInfo; - GraphicsDevice.NativeDevice.UpdateDescriptorSets(1, &write, 0, null); + GraphicsDevice.NativeDeviceApi.vkUpdateDescriptorSets(GraphicsDevice.NativeDevice, 1, &write, 0, null); } else { @@ -77,10 +77,10 @@ public unsafe void SetShaderResourceView(int slot, GraphicsResource shaderResour { var bufferViewCopy = buffer.NativeBufferView; - write.VkDescriptorType = VkDescriptorType.UniformTexelBuffer; - write.TexelBufferView = new IntPtr(&bufferViewCopy); + write.descriptorType = VkDescriptorType.UniformTexelBuffer; + write.pTexelBufferView = &bufferViewCopy; - GraphicsDevice.NativeDevice.UpdateDescriptorSets(1, &write, 0, null); + GraphicsDevice.NativeDeviceApi.vkUpdateDescriptorSets(GraphicsDevice.NativeDevice, 1, &write, 0, null); } else { @@ -96,20 +96,20 @@ public unsafe void SetShaderResourceView(int slot, GraphicsResource shaderResour /// The sampler state. public unsafe void SetSamplerState(int slot, SamplerState samplerState) { - var imageInfo = new DescriptorImageInfo { Sampler = samplerState.NativeSampler }; + var imageInfo = new VkDescriptorImageInfo { sampler = samplerState.NativeSampler }; - var write = new WriteDescriptorSet + var write = new VkWriteDescriptorSet { sType = VkStructureType.WriteDescriptorSet, - DescriptorCount = 1, - DestinationSet = NativeDescriptorSet, - DestinationBinding = (uint)slot, - DestinationArrayElement = 0, - VkDescriptorType = VkDescriptorType.Sampler, - ImageInfo = new IntPtr(&imageInfo), + descriptorCount = 1, + dstSet = NativeDescriptorSet, + dstBinding = (uint)slot, + dstArrayElement = 0, + descriptorType = VkDescriptorType.Sampler, + pImageInfo = &imageInfo, }; - GraphicsDevice.NativeDevice.UpdateDescriptorSets(1, &write, 0, null); + GraphicsDevice.NativeDeviceApi.vkUpdateDescriptorSets(GraphicsDevice.NativeDevice, 1, &write, 0, null); } /// @@ -121,20 +121,20 @@ public unsafe void SetSamplerState(int slot, SamplerState samplerState) /// The constant buffer view size. public unsafe void SetConstantBuffer(int slot, Buffer buffer, int offset, int size) { - var bufferInfo = new DescriptorBufferInfo { Buffer = buffer.NativeBuffer, Offset = (ulong)offset, Range = (ulong)size }; + var bufferInfo = new VkDescriptorBufferInfo { buffer = buffer.NativeBuffer, offset = (ulong)offset, range = (ulong)size }; - var write = new WriteDescriptorSet + var write = new VkWriteDescriptorSet { sType = VkStructureType.WriteDescriptorSet, - DescriptorCount = 1, - DestinationSet = NativeDescriptorSet, - DestinationBinding = (uint)slot, - DestinationArrayElement = 0, - VkDescriptorType = VkDescriptorType.UniformBuffer, - BufferInfo = new IntPtr(&bufferInfo) + descriptorCount = 1, + dstSet = NativeDescriptorSet, + dstBinding = (uint)slot, + dstArrayElement = 0, + descriptorType = VkDescriptorType.UniformBuffer, + pBufferInfo = &bufferInfo }; - GraphicsDevice.NativeDevice.UpdateDescriptorSets(1, &write, 0, null); + GraphicsDevice.NativeDeviceApi.vkUpdateDescriptorSets(GraphicsDevice.NativeDevice, 1, &write, 0, null); } /// diff --git a/sources/engine/Stride.Graphics/Vulkan/DescriptorSetLayout.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/DescriptorSetLayout.Vulkan.cs index 150d492313..5244b085ea 100644 --- a/sources/engine/Stride.Graphics/Vulkan/DescriptorSetLayout.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/DescriptorSetLayout.Vulkan.cs @@ -3,12 +3,8 @@ using System; using System.Collections.Generic; -using Stride.Core; -using Stride.Core.Collections; -using Stride.Shaders; #if STRIDE_GRAPHICS_API_VULKAN using Vortice.Vulkan; -using static Vortice.Vulkan.Vulkan; namespace Stride.Graphics { @@ -44,7 +40,7 @@ protected internal override bool OnRecreate() /// protected internal override unsafe void OnDestroyed(bool immediately = false) { - GraphicsDevice.NativeDevice.DestroyDescriptorSetLayout(NativeLayout); + GraphicsDevice.NativeDeviceApi.vkDestroyDescriptorSetLayout(GraphicsDevice.NativeDevice, NativeLayout); NativeLayout = VkDescriptorSetLayout.Null; base.OnDestroyed(immediately); @@ -104,7 +100,7 @@ internal static unsafe VkDescriptorSetLayout CreateNativeDescriptorSetLayout(Gra bindingCount = (uint)usedBindingCount, pBindings = usedBindingCount > 0 ? fBindings : null, }; - device.CheckResult(vkCreateDescriptorSetLayout(device.NativeDevice, &createInfo, null, out var descriptorSetLayout)); + device.CheckResult(device.NativeDeviceApi.vkCreateDescriptorSetLayout(device.NativeDevice, &createInfo, null, out var descriptorSetLayout)); return descriptorSetLayout; } } diff --git a/sources/engine/Stride.Graphics/Vulkan/GraphicsAdapter.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/GraphicsAdapter.Vulkan.cs index ad576f261c..250f942bb5 100644 --- a/sources/engine/Stride.Graphics/Vulkan/GraphicsAdapter.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/GraphicsAdapter.Vulkan.cs @@ -41,12 +41,11 @@ public partial class GraphicsAdapter /// /// The default factory. /// The adapter ordinal. - internal GraphicsAdapter(VkPhysicalDevice defaultPhysicalDevice, int adapterOrdinal) + internal GraphicsAdapter(VkPhysicalDevice defaultPhysicalDevice, VkPhysicalDeviceProperties properties, int adapterOrdinal) { this.adapterOrdinal = adapterOrdinal; this.defaultPhysicalDevice = defaultPhysicalDevice; - - vkGetPhysicalDeviceProperties(defaultPhysicalDevice, out properties); + this.properties = properties; // TODO VULKAN //var displayProperties = physicalDevice.DisplayProperties; @@ -100,13 +99,20 @@ public bool IsDefaultAdapter } } - internal VkPhysicalDevice GetPhysicalDevice(bool enableValidation) + internal unsafe VkPhysicalDevice GetPhysicalDevice(bool enableValidation) { if (enableValidation) { if (debugPhysicalDevice == VkPhysicalDevice.Null) { - debugPhysicalDevice = vkEnumeratePhysicalDevices(GraphicsAdapterFactory.GetInstance(true).NativeInstance).ToArray()[adapterOrdinal]; + GraphicsAdapterFactoryInstance defaultInstance = GraphicsAdapterFactory.GetInstance(true); + uint physicalDevicesCount = 0; + defaultInstance.NativeInstanceApi.vkEnumeratePhysicalDevices(defaultInstance.NativeInstance, &physicalDevicesCount, null).CheckResult(); + + Span nativePhysicalDevices = stackalloc VkPhysicalDevice[(int)physicalDevicesCount]; + defaultInstance.NativeInstanceApi.vkEnumeratePhysicalDevices(defaultInstance.NativeInstance, nativePhysicalDevices).CheckResult(); + + debugPhysicalDevice = nativePhysicalDevices[adapterOrdinal]; } return debugPhysicalDevice; diff --git a/sources/engine/Stride.Graphics/Vulkan/GraphicsAdapterFactory.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/GraphicsAdapterFactory.Vulkan.cs index ef23965815..83c0132433 100644 --- a/sources/engine/Stride.Graphics/Vulkan/GraphicsAdapterFactory.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/GraphicsAdapterFactory.Vulkan.cs @@ -21,19 +21,28 @@ public static partial class GraphicsAdapterFactory /// /// Initializes all adapters with the specified factory. /// - internal static void InitializeInternal() + internal static unsafe void InitializeInternal() { var result = vkInitialize(); result.CheckResult(); // Create the default instance to enumerate physical devices defaultInstance = new GraphicsAdapterFactoryInstance(false); - var nativePhysicalDevices = vkEnumeratePhysicalDevices(defaultInstance.NativeInstance); + uint physicalDevicesCount = 0; + defaultInstance.NativeInstanceApi.vkEnumeratePhysicalDevices(defaultInstance.NativeInstance, &physicalDevicesCount, null).CheckResult(); + if (physicalDevicesCount == 0) + throw new Exception("Vulkan: Failed to find GPUs with Vulkan support"); + + Span nativePhysicalDevices = stackalloc VkPhysicalDevice[(int)physicalDevicesCount]; + defaultInstance.NativeInstanceApi.vkEnumeratePhysicalDevices(defaultInstance.NativeInstance, nativePhysicalDevices).CheckResult(); + var adapterList = new List(); - for (int i = 0; i < nativePhysicalDevices.Length; i++) + for (int index = 0; index < nativePhysicalDevices.Length; index++) { - var adapter = new GraphicsAdapter(nativePhysicalDevices[i], i); + VkPhysicalDeviceProperties properties; + defaultInstance.NativeInstanceApi.vkGetPhysicalDeviceProperties(nativePhysicalDevices[index], out properties); + var adapter = new GraphicsAdapter(nativePhysicalDevices[index], properties, index); staticCollector.Add(adapter); adapterList.Add(adapter); } @@ -85,6 +94,7 @@ internal class GraphicsAdapterFactoryInstance : IDisposable private VkDebugUtilsMessengerEXT debugReportCallback; internal VkInstance NativeInstance; + internal VkInstanceApi NativeInstanceApi; internal bool HasXlibSurfaceSupport; // We use GraphicsDevice (similar to OpenGL) @@ -107,20 +117,27 @@ public unsafe GraphicsAdapterFactoryInstance(bool enableValidation) if (enableValidation) { - var layers = vkEnumerateInstanceLayerProperties(); + uint count = 0; + var callResult = vkEnumerateInstanceLayerProperties(&count, null); - for (int index = 0; index < layers.Length; index++) + if (callResult == VkResult.Success && count > 0) { - var properties = layers[index]; - var name = new VkUtf8String(properties.layerName); - var indexOfLayerName = validationLayerNames.IndexOf(name); + VkLayerProperties[] layers = new VkLayerProperties[(int)count]; + vkEnumerateInstanceLayerProperties(layers).CheckResult(); - if (indexOfLayerName >= 0) - enabledLayerNames.Add(validationLayerNames[indexOfLayerName]); - } + for (int index = 0; index < count; index++) + { + var properties = layers[index]; + var name = new VkUtf8String(properties.layerName); + var indexOfLayerName = validationLayerNames.IndexOf(name); + + if (indexOfLayerName >= 0) + enabledLayerNames.Add(validationLayerNames[indexOfLayerName]); + } - // Check if validation was really available - enableValidation = enabledLayerNames.Count > 0; + // Check if validation was really available + enableValidation = enabledLayerNames.Count > 0; + } } var supportedExtensionNames = stackalloc VkUtf8String[] @@ -160,8 +177,11 @@ public unsafe GraphicsAdapterFactoryInstance(bool enableValidation) ppEnabledExtensionNames = ppEnabledExtensionNames, }; - vkCreateInstance(&instanceCreateInfo, null, out NativeInstance); - vkLoadInstance(NativeInstance); + VkResult result = vkCreateInstance(&instanceCreateInfo, out NativeInstance); + if (result != VK_SUCCESS) + throw new InvalidOperationException($"Failed to create vulkan instance: {result}"); + + NativeInstanceApi = GetApi(NativeInstance); // Check if validation layer was available (otherwise detected count is 0) if (enableValidation) @@ -174,7 +194,7 @@ public unsafe GraphicsAdapterFactoryInstance(bool enableValidation) pfnUserCallback = &DebugReport }; - vkCreateDebugUtilsMessengerEXT(NativeInstance, &createInfo, null, out debugReportCallback).CheckResult(); + NativeInstanceApi.vkCreateDebugUtilsMessengerEXT(NativeInstance, &createInfo, null, out debugReportCallback).CheckResult(); } } @@ -281,11 +301,11 @@ public unsafe void Dispose() { if (debugReportCallback != VkDebugUtilsMessengerEXT.Null) { - vkDestroyDebugUtilsMessengerEXT(NativeInstance, debugReportCallback, null); + NativeInstanceApi.vkDestroyDebugUtilsMessengerEXT(NativeInstance, debugReportCallback, null); debugReportCallback = VkDebugUtilsMessengerEXT.Null; } - vkDestroyInstance(NativeInstance, null); + NativeInstanceApi.vkDestroyInstance(NativeInstance, null); } } } diff --git a/sources/engine/Stride.Graphics/Vulkan/GraphicsDevice.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/GraphicsDevice.Vulkan.cs index 19915346d3..bc3361be0d 100644 --- a/sources/engine/Stride.Graphics/Vulkan/GraphicsDevice.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/GraphicsDevice.Vulkan.cs @@ -29,6 +29,7 @@ public partial class GraphicsDevice private string rendererName; private VkDevice nativeDevice; + private VkDeviceApi nativeDeviceApi; internal VkQueue NativeCommandQueue; internal object QueueLock = new object(); @@ -71,6 +72,7 @@ public partial class GraphicsDevice internal VkPhysicalDevice NativePhysicalDevice => Adapter.GetPhysicalDevice(IsDebugMode); internal VkInstance NativeInstance => GraphicsAdapterFactory.GetInstance(IsDebugMode).NativeInstance; + internal VkInstanceApi NativeInstanceApi => GraphicsAdapterFactory.GetInstance(IsDebugMode).NativeInstanceApi; internal struct BufferInfo { @@ -151,6 +153,15 @@ internal VkDevice NativeDevice get { return nativeDevice; } } + /// + /// Gets the native device API. + /// + /// The native device API. + internal VkDeviceApi NativeDeviceApi + { + get { return nativeDeviceApi; } + } + /// /// Marks context as active on the current thread. /// @@ -317,7 +328,7 @@ private unsafe partial void InitializePlatformDevice(GraphicsProfile[] graphicsP rendererName = Adapter.Description; - vkGetPhysicalDeviceProperties(NativePhysicalDevice, out var physicalDeviceProperties); + NativeInstanceApi.vkGetPhysicalDeviceProperties(NativePhysicalDevice, out var physicalDeviceProperties); ConstantBufferDataPlacementAlignment = (int)physicalDeviceProperties.limits.minUniformBufferOffsetAlignment; TimestampFrequency = (long)(1.0e9 / physicalDeviceProperties.limits.timestampPeriod); // Resolution in nanoseconds @@ -339,7 +350,9 @@ void SetMaxDescriptorTypeCount(VkDescriptorType type, uint limit) RequestedProfile = graphicsProfiles.First(); - var queueProperties = vkGetPhysicalDeviceQueueFamilyProperties(NativePhysicalDevice); + NativeInstanceApi.vkGetPhysicalDeviceQueueFamilyProperties(NativePhysicalDevice, out uint queueFamilyCount); + Span queueFamilies = stackalloc VkQueueFamilyProperties[(int)queueFamilyCount]; + NativeInstanceApi.vkGetPhysicalDeviceQueueFamilyProperties(NativePhysicalDevice, queueFamilies); //IsProfilingSupported = queueProperties[0].TimestampValidBits > 0; // Command lists are thread-safe and execute deferred @@ -365,7 +378,7 @@ void SetMaxDescriptorTypeCount(VkDescriptorType type, uint limit) depthClamp = true, }; - vkGetPhysicalDeviceFeatures(NativePhysicalDevice, out var deviceFeatures); + NativeInstanceApi.vkGetPhysicalDeviceFeatures(NativePhysicalDevice, out var deviceFeatures); if (deviceFeatures.shaderStorageImageReadWithoutFormat) { @@ -412,11 +425,11 @@ void SetMaxDescriptorTypeCount(VkDescriptorType type, uint limit) pEnabledFeatures = &enabledFeature, }; - CheckResult(vkCreateDevice(NativePhysicalDevice, in deviceCreateInfo, null, out nativeDevice)); + CheckResult(NativeInstanceApi.vkCreateDevice(NativePhysicalDevice, in deviceCreateInfo, null, out nativeDevice)); - vkLoadDevice(nativeDevice); + nativeDeviceApi = GetApi(NativeInstance, NativeDevice); - vkGetDeviceQueue(nativeDevice, 0, 0, out NativeCommandQueue); + NativeDeviceApi.vkGetDeviceQueue(nativeDevice, 0, 0, out NativeCommandQueue); NativeCopyCommandPools = new(() => new CommandBufferPool(this, false), true); @@ -439,7 +452,9 @@ void SetMaxDescriptorTypeCount(VkDescriptorType type, uint limit) private unsafe HashSet GetAvailableExtensionProperties(Span supportedExtensionProperties) { var availableExtensionProperties = new HashSet(); - var extensionProperties = vkEnumerateDeviceExtensionProperties(NativePhysicalDevice); + NativeInstanceApi.vkEnumerateDeviceExtensionProperties(NativePhysicalDevice, out uint propertyCount).CheckResult(); + Span extensionProperties = stackalloc VkExtensionProperties[(int)propertyCount]; + NativeInstanceApi.vkEnumerateDeviceExtensionProperties(NativePhysicalDevice, extensionProperties).CheckResult(); for (int index = 0; index < extensionProperties.Length; index++) { @@ -472,7 +487,7 @@ internal unsafe IntPtr AllocateUploadBuffer(int size, out VkBuffer resource, out { if (nativeUploadBuffer != VkBuffer.Null) { - vkUnmapMemory(NativeDevice, nativeUploadBufferMemory); + NativeDeviceApi.vkUnmapMemory(NativeDevice, nativeUploadBufferMemory); Collect(nativeUploadBuffer); Collect(nativeUploadBufferMemory); } @@ -489,11 +504,11 @@ internal unsafe IntPtr AllocateUploadBuffer(int size, out VkBuffer resource, out flags = VkBufferCreateFlags.None, usage = VkBufferUsageFlags.TransferSrc, }; - CheckResult(vkCreateBuffer(NativeDevice, &bufferCreateInfo, null, out nativeUploadBuffer)); + CheckResult(NativeDeviceApi.vkCreateBuffer(NativeDevice, &bufferCreateInfo, null, out nativeUploadBuffer)); AllocateMemory(VkMemoryPropertyFlags.HostVisible | VkMemoryPropertyFlags.HostCoherent); fixed (IntPtr* nativeUploadBufferStartPtr = &nativeUploadBufferStart) - vkMapMemory(NativeDevice, nativeUploadBufferMemory, 0, (ulong)nativeUploadBufferSize, VkMemoryMapFlags.None, (void**)nativeUploadBufferStartPtr); + NativeDeviceApi.vkMapMemory(NativeDevice, nativeUploadBufferMemory, 0, (ulong)nativeUploadBufferSize, VkMemoryMapFlags.None, (void**)nativeUploadBufferStartPtr); nativeUploadBufferOffset = 0; } @@ -538,7 +553,7 @@ internal unsafe ulong ExecuteAndWaitCopyQueueGPU(VkCommandBuffer commandBuffer) protected unsafe void AllocateMemory(VkMemoryPropertyFlags memoryProperties) { - vkGetBufferMemoryRequirements(nativeDevice, nativeUploadBuffer, out var memoryRequirements); + NativeDeviceApi.vkGetBufferMemoryRequirements(nativeDevice, nativeUploadBuffer, out var memoryRequirements); if (memoryRequirements.size == 0) return; @@ -549,7 +564,7 @@ protected unsafe void AllocateMemory(VkMemoryPropertyFlags memoryProperties) allocationSize = memoryRequirements.size, }; - vkGetPhysicalDeviceMemoryProperties(NativePhysicalDevice, out var physicalDeviceMemoryProperties); + NativeInstanceApi.vkGetPhysicalDeviceMemoryProperties(NativePhysicalDevice, out var physicalDeviceMemoryProperties); var typeBits = memoryRequirements.memoryTypeBits; for (uint i = 0; i < physicalDeviceMemoryProperties.memoryTypeCount; i++) { @@ -566,8 +581,8 @@ protected unsafe void AllocateMemory(VkMemoryPropertyFlags memoryProperties) typeBits >>= 1; } - vkAllocateMemory(NativeDevice, &allocateInfo, null, out nativeUploadBufferMemory); - vkBindBufferMemory(NativeDevice, nativeUploadBuffer, nativeUploadBufferMemory, 0); + NativeDeviceApi.vkAllocateMemory(NativeDevice, &allocateInfo, null, out nativeUploadBufferMemory); + NativeDeviceApi.vkBindBufferMemory(NativeDevice, nativeUploadBuffer, nativeUploadBufferMemory, 0); } /// @@ -597,12 +612,12 @@ private unsafe void ReleaseDevice() EmptyTexture = null; // Wait for all queues to be idle - CheckResult(vkDeviceWaitIdle(nativeDevice)); + CheckResult(NativeDeviceApi.vkDeviceWaitIdle(nativeDevice)); // Mark upload buffer for destruction if (nativeUploadBuffer != VkBuffer.Null) { - vkUnmapMemory(NativeDevice, nativeUploadBufferMemory); + NativeDeviceApi.vkUnmapMemory(NativeDevice, nativeUploadBufferMemory); nativeResourceCollector.Add(FrameFence.LastCompletedFence, nativeUploadBuffer); nativeResourceCollector.Add(FrameFence.LastCompletedFence, nativeUploadBufferMemory); @@ -622,7 +637,7 @@ private unsafe void ReleaseDevice() nativeCopyCommandPool.Dispose(); NativeCopyCommandPools.Dispose(); NativeCopyCommandPools = null; - vkDestroyDevice(nativeDevice, null); + NativeDeviceApi.vkDestroyDevice(nativeDevice, null); } internal void OnDestroyed(bool immediately = false) @@ -680,7 +695,7 @@ internal unsafe ulong ExecuteCommandListInternal(CompiledCommandList commandList pSignalSemaphores = &semaphores[0], }; - CheckResult(vkQueueSubmit(NativeCommandQueue, 1, &submitInfo, VkFence.Null)); + CheckResult(NativeDeviceApi.vkQueueSubmit(NativeCommandQueue, 1, &submitInfo, VkFence.Null)); } // Collect resources @@ -764,7 +779,7 @@ public FenceHelper(GraphicsDevice graphicsDevice) this.graphicsDevice = graphicsDevice; var timelineInfo = new VkSemaphoreTypeCreateInfo { sType = VkStructureType.SemaphoreTypeCreateInfo, semaphoreType = VkSemaphoreType.Timeline }; var createInfo = new VkSemaphoreCreateInfo { sType = VkStructureType.SemaphoreCreateInfo, pNext = &timelineInfo }; - graphicsDevice.CheckResult(vkCreateSemaphore(graphicsDevice.NativeDevice, &createInfo, null, out Semaphore)); + graphicsDevice.CheckResult(NativeDeviceApi.vkCreateSemaphore(graphicsDevice.NativeDevice, &createInfo, null, out Semaphore)); } internal ulong GetCompletedValue() @@ -800,7 +815,7 @@ internal void WaitForFenceCPUInternal(ulong fenceValue) pSemaphores = semaphore, pValues = &fenceValue, }; - vkWaitSemaphores(graphicsDevice.NativeDevice, &waitInfo, ulong.MaxValue); + NativeDeviceApi.vkWaitSemaphores(graphicsDevice.NativeDevice, &waitInfo, ulong.MaxValue); LastCompletedFence = fenceValue; } } @@ -922,7 +937,7 @@ public unsafe CommandBufferPool(GraphicsDevice graphicsDevice, bool threadsafe) flags = VkCommandPoolCreateFlags.ResetCommandBuffer }; - GraphicsDevice.CheckResult(vkCreateCommandPool(graphicsDevice.NativeDevice, &commandPoolCreateInfo, null, out commandPool)); + GraphicsDevice.CheckResult(graphicsDevice.NativeDeviceApi.vkCreateCommandPool(graphicsDevice.NativeDevice, &commandPoolCreateInfo, null, out commandPool)); } protected override unsafe VkCommandBuffer CreateObject() @@ -937,20 +952,20 @@ protected override unsafe VkCommandBuffer CreateObject() }; VkCommandBuffer commandBuffer; - vkAllocateCommandBuffers(GraphicsDevice.NativeDevice, &commandBufferAllocationInfo, &commandBuffer); + GraphicsDevice.NativeDeviceApi.vkAllocateCommandBuffers(GraphicsDevice.NativeDevice, &commandBufferAllocationInfo, &commandBuffer); return commandBuffer; } protected override void ResetObject(VkCommandBuffer obj) { - vkResetCommandBuffer(obj, VkCommandBufferResetFlags.None); + GraphicsDevice.NativeDeviceApi.vkResetCommandBuffer(obj, VkCommandBufferResetFlags.None); } protected override unsafe void Destroy() { base.Destroy(); - vkDestroyCommandPool(GraphicsDevice.NativeDevice, commandPool, null); + GraphicsDevice.NativeDeviceApi.vkDestroyCommandPool(GraphicsDevice.NativeDevice, commandPool, null); } } @@ -976,19 +991,19 @@ protected override unsafe VkDescriptorPool CreateObject() pPoolSizes = fPoolSizes, maxSets = GraphicsDevice.MaxDescriptorSetCount, }; - GraphicsDevice.CheckResult(vkCreateDescriptorPool(GraphicsDevice.NativeDevice, &descriptorPoolCreateInfo, null, out var descriptorPool)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateDescriptorPool(GraphicsDevice.NativeDevice, &descriptorPoolCreateInfo, null, out var descriptorPool)); return descriptorPool; } } protected override void ResetObject(VkDescriptorPool obj) { - vkResetDescriptorPool(GraphicsDevice.NativeDevice, obj, VkDescriptorPoolResetFlags.None); + GraphicsDevice.NativeDeviceApi.vkResetDescriptorPool(GraphicsDevice.NativeDevice, obj, VkDescriptorPoolResetFlags.None); } protected override unsafe void DestroyObject(VkDescriptorPool obj) { - vkDestroyDescriptorPool(GraphicsDevice.NativeDevice, obj, null); + GraphicsDevice.NativeDeviceApi.vkDestroyDescriptorPool(GraphicsDevice.NativeDevice, obj, null); } } @@ -1061,34 +1076,34 @@ public unsafe void Destroy(GraphicsDevice device) switch (type) { case VkDebugReportObjectTypeEXT.Buffer: - vkDestroyBuffer(device.NativeDevice, *(VkBuffer*)&handleCopy, null); + device.NativeDeviceApi.vkDestroyBuffer(device.NativeDevice, *(VkBuffer*)&handleCopy, null); break; case VkDebugReportObjectTypeEXT.BufferView: - vkDestroyBufferView(device.NativeDevice, *(VkBufferView*)&handleCopy, null); + device.NativeDeviceApi.vkDestroyBufferView(device.NativeDevice, *(VkBufferView*)&handleCopy, null); break; case VkDebugReportObjectTypeEXT.Image: - vkDestroyImage(device.NativeDevice, *(VkImage*)&handleCopy, null); + device.NativeDeviceApi.vkDestroyImage(device.NativeDevice, *(VkImage*)&handleCopy, null); break; case VkDebugReportObjectTypeEXT.ImageView: - vkDestroyImageView(device.NativeDevice, *(VkImageView*)&handleCopy, null); + device.NativeDeviceApi.vkDestroyImageView(device.NativeDevice, *(VkImageView*)&handleCopy, null); break; case VkDebugReportObjectTypeEXT.DeviceMemory: - vkFreeMemory(device.NativeDevice, *(VkDeviceMemory*)&handleCopy, null); + device.NativeDeviceApi.vkFreeMemory(device.NativeDevice, *(VkDeviceMemory*)&handleCopy, null); break; case VkDebugReportObjectTypeEXT.Sampler: - vkDestroySampler(device.NativeDevice, *(VkSampler*)&handleCopy, null); + device.NativeDeviceApi.vkDestroySampler(device.NativeDevice, *(VkSampler*)&handleCopy, null); break; case VkDebugReportObjectTypeEXT.Framebuffer: - vkDestroyFramebuffer(device.NativeDevice, *(VkFramebuffer*)&handleCopy, null); + device.NativeDeviceApi.vkDestroyFramebuffer(device.NativeDevice, *(VkFramebuffer*)&handleCopy, null); break; case VkDebugReportObjectTypeEXT.Semaphore: - vkDestroySemaphore(device.NativeDevice, *(VkSemaphore*)&handleCopy, null); + device.NativeDeviceApi.vkDestroySemaphore(device.NativeDevice, *(VkSemaphore*)&handleCopy, null); break; case VkDebugReportObjectTypeEXT.Fence: - vkDestroyFence(device.NativeDevice, *(VkFence*)&handleCopy, null); + device.NativeDeviceApi.vkDestroyFence(device.NativeDevice, *(VkFence*)&handleCopy, null); break; case VkDebugReportObjectTypeEXT.QueryPool: - vkDestroyQueryPool(device.NativeDevice, *(VkQueryPool*)&handleCopy, null); + device.NativeDeviceApi.vkDestroyQueryPool(device.NativeDevice, *(VkQueryPool*)&handleCopy, null); break; } } diff --git a/sources/engine/Stride.Graphics/Vulkan/GraphicsResource.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/GraphicsResource.Vulkan.cs index 00da219214..c48ac5b00b 100644 --- a/sources/engine/Stride.Graphics/Vulkan/GraphicsResource.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/GraphicsResource.Vulkan.cs @@ -73,7 +73,7 @@ protected unsafe void AllocateMemory(VkMemoryPropertyFlags memoryProperties, VkM allocationSize = memoryRequirements.size, }; - vkGetPhysicalDeviceMemoryProperties(GraphicsDevice.NativePhysicalDevice, out var physicalDeviceMemoryProperties); + GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceMemoryProperties(GraphicsDevice.NativePhysicalDevice, out var physicalDeviceMemoryProperties); var typeBits = memoryRequirements.memoryTypeBits; for (uint i = 0; i < physicalDeviceMemoryProperties.memoryTypeCount; i++) { @@ -90,7 +90,7 @@ protected unsafe void AllocateMemory(VkMemoryPropertyFlags memoryProperties, VkM typeBits >>= 1; } - vkAllocateMemory(GraphicsDevice.NativeDevice, &allocateInfo, null, out NativeMemory); + GraphicsDevice.NativeDeviceApi.vkAllocateMemory(GraphicsDevice.NativeDevice, &allocateInfo, null, out NativeMemory); } /// diff --git a/sources/engine/Stride.Graphics/Vulkan/PipelineState.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/PipelineState.Vulkan.cs index 3ecb9fbd5d..dba294121a 100644 --- a/sources/engine/Stride.Graphics/Vulkan/PipelineState.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/PipelineState.Vulkan.cs @@ -6,7 +6,6 @@ using System.IO; using System.Linq; using Vortice.Vulkan; -using static Vortice.Vulkan.Vulkan; using Stride.Shaders; using Stride.Core.Serialization; using Encoding = System.Text.Encoding; @@ -77,7 +76,7 @@ private unsafe void RecreateInner() }; fixed (VkPipeline* nativePipelinePtr = &NativePipeline) - GraphicsDevice.CheckResult(vkCreateComputePipelines(GraphicsDevice.NativeDevice, VkPipelineCache.Null, 1, &createInfo, allocator: null, nativePipelinePtr)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateComputePipelines(GraphicsDevice.NativeDevice, VkPipelineCache.Null, 1, &createInfo, allocator: null, nativePipelinePtr)); } } else @@ -226,14 +225,14 @@ private unsafe void RecreateInner() subpass = 0 }; fixed (VkPipeline* nativePipelinePtr = &NativePipeline) - GraphicsDevice.CheckResult(vkCreateGraphicsPipelines(GraphicsDevice.NativeDevice, VkPipelineCache.Null, createInfoCount: 1, &createInfo, allocator: null, nativePipelinePtr)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateGraphicsPipelines(GraphicsDevice.NativeDevice, VkPipelineCache.Null, createInfoCount: 1, &createInfo, allocator: null, nativePipelinePtr)); } } // Cleanup shader modules foreach (var stage in stages) { - vkDestroyShaderModule(GraphicsDevice.NativeDevice, stage.module, allocator: null); + GraphicsDevice.NativeDeviceApi.vkDestroyShaderModule(GraphicsDevice.NativeDevice, stage.module, allocator: null); } } @@ -325,7 +324,7 @@ private unsafe void CreateRenderPass(PipelineStateDescription pipelineStateDescr subpassCount = 1, pSubpasses = &subpass }; - GraphicsDevice.CheckResult(vkCreateRenderPass(GraphicsDevice.NativeDevice, &renderPassCreateInfo, allocator: null, out NativeRenderPass)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateRenderPass(GraphicsDevice.NativeDevice, &renderPassCreateInfo, allocator: null, out NativeRenderPass)); } } @@ -334,11 +333,11 @@ protected internal override unsafe void OnDestroyed(bool immediately = false) { if (NativePipeline != VkPipeline.Null) { - vkDestroyRenderPass(GraphicsDevice.NativeDevice, NativeRenderPass, allocator: null); - vkDestroyPipeline(GraphicsDevice.NativeDevice, NativePipeline, allocator: null); - vkDestroyPipelineLayout(GraphicsDevice.NativeDevice, NativeLayout, allocator: null); + GraphicsDevice.NativeDeviceApi.vkDestroyRenderPass(GraphicsDevice.NativeDevice, NativeRenderPass, allocator: null); + GraphicsDevice.NativeDeviceApi.vkDestroyPipeline(GraphicsDevice.NativeDevice, NativePipeline, allocator: null); + GraphicsDevice.NativeDeviceApi.vkDestroyPipelineLayout(GraphicsDevice.NativeDevice, NativeLayout, allocator: null); - vkDestroyDescriptorSetLayout(GraphicsDevice.NativeDevice, NativeDescriptorSetLayout, allocator: null); + GraphicsDevice.NativeDeviceApi.vkDestroyDescriptorSetLayout(GraphicsDevice.NativeDevice, NativeDescriptorSetLayout, allocator: null); } base.OnDestroyed(immediately); @@ -432,7 +431,7 @@ private unsafe void CreatePipelineLayout(PipelineStateDescription pipelineStateD setLayoutCount = 1, pSetLayouts = &nativeDescriptorSetLayout }; - GraphicsDevice.CheckResult(vkCreatePipelineLayout(GraphicsDevice.NativeDevice, &pipelineLayoutCreateInfo, allocator: null, out NativeLayout)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreatePipelineLayout(GraphicsDevice.NativeDevice, &pipelineLayoutCreateInfo, allocator: null, out NativeLayout)); } private unsafe VkPipelineShaderStageCreateInfo[] CreateShaderStages(PipelineStateDescription pipelineStateDescription, out Dictionary inputAttributeNames) @@ -461,7 +460,7 @@ private unsafe VkPipelineShaderStageCreateInfo[] CreateShaderStages(PipelineStat stage = VulkanConvertExtensions.Convert(stages[i].Stage), pName = entryPointPointer }; - GraphicsDevice.CheckResult(vkCreateShaderModule(GraphicsDevice.NativeDevice, shaderBytecode.Data, allocator: null, out nativeStages[i].module)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateShaderModule(GraphicsDevice.NativeDevice, shaderBytecode.Data, allocator: null, out nativeStages[i].module)); } } diff --git a/sources/engine/Stride.Graphics/Vulkan/QueryPool.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/QueryPool.Vulkan.cs index 52efdb681a..df28d11f4c 100644 --- a/sources/engine/Stride.Graphics/Vulkan/QueryPool.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/QueryPool.Vulkan.cs @@ -3,7 +3,6 @@ #if STRIDE_GRAPHICS_API_VULKAN using System; using Vortice.Vulkan; -using static Vortice.Vulkan.Vulkan; namespace Stride.Graphics { @@ -16,7 +15,7 @@ public unsafe bool TryGetData(long[] dataArray) fixed (long* dataPointer = &dataArray[0]) { // Read back all results - var result = vkGetQueryPoolResults(GraphicsDevice.NativeDevice, NativeQueryPool, 0, (uint)QueryCount, (uint)QueryCount * 8, dataPointer, 8, VkQueryResultFlags.Bit64); + var result = GraphicsDevice.NativeDeviceApi.vkGetQueryPoolResults(GraphicsDevice.NativeDevice, NativeQueryPool, 0, (uint)QueryCount, (uint)QueryCount * 8, dataPointer, 8, VkQueryResultFlags.Bit64); // Some queries are not ready yet if (result == VkResult.NotReady) @@ -50,7 +49,7 @@ private unsafe partial void Recreate() throw new NotImplementedException(); } - GraphicsDevice.CheckResult(vkCreateQueryPool(GraphicsDevice.NativeDevice, &createInfo, null, out NativeQueryPool)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateQueryPool(GraphicsDevice.NativeDevice, &createInfo, null, out NativeQueryPool)); } /// diff --git a/sources/engine/Stride.Graphics/Vulkan/SamplerState.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/SamplerState.Vulkan.cs index 13b0db6631..726bc4927b 100644 --- a/sources/engine/Stride.Graphics/Vulkan/SamplerState.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/SamplerState.Vulkan.cs @@ -3,7 +3,6 @@ #if STRIDE_GRAPHICS_API_VULKAN using System; using Vortice.Vulkan; -using static Vortice.Vulkan.Vulkan; using Stride.Core.Mathematics; @@ -79,7 +78,7 @@ private unsafe void CreateNativeSampler() ConvertMinFilter(Description.Filter, out createInfo.minFilter, out createInfo.magFilter, out createInfo.mipmapMode, out createInfo.compareEnable, out createInfo.anisotropyEnable); - GraphicsDevice.CheckResult(vkCreateSampler(GraphicsDevice.NativeDevice, &createInfo, null, out NativeSampler)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateSampler(GraphicsDevice.NativeDevice, &createInfo, null, out NativeSampler)); } private static VkSamplerAddressMode ConvertAddressMode(TextureAddressMode addressMode) diff --git a/sources/engine/Stride.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs index 8b14690396..de9c0afb47 100644 --- a/sources/engine/Stride.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs @@ -6,7 +6,6 @@ using System.Linq; using Stride.Core; using Vortice.Vulkan; -using static Vortice.Vulkan.Vulkan; namespace Stride.Graphics { @@ -169,7 +168,7 @@ public override unsafe void Present() pSignalSemaphores = &submitSemaphore, }; - GraphicsDevice.CheckResult(vkQueueSubmit(GraphicsDevice.NativeCommandQueue, 1, &submitInfo, frameFences[currentFrameIndex])); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkQueueSubmit(GraphicsDevice.NativeCommandQueue, 1, &submitInfo, frameFences[currentFrameIndex])); var currentBufferIndexCopy = currentBufferIndex; var swapChainCopy = swapChain; @@ -184,7 +183,7 @@ public override unsafe void Present() }; // Present - var presentResult = vkQueuePresentKHR(GraphicsDevice.NativeCommandQueue, &presentInfo); + var presentResult = GraphicsDevice.NativeDeviceApi.vkQueuePresentKHR(GraphicsDevice.NativeCommandQueue, &presentInfo); if (presentResult == VkResult.ErrorOutOfDateKHR) { // Likely a window resize; wait for WM_SIZE to be processed next frame @@ -198,7 +197,7 @@ public override unsafe void Present() currentFrameIndex = (currentFrameIndex + 1) % kNumberOfFramesInFlight; // Wait for frame fence to be available - GraphicsDevice.CheckResult(vkWaitForFences(GraphicsDevice.NativeDevice, frameFences[currentFrameIndex], VkBool32.True, ulong.MaxValue)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkWaitForFences(GraphicsDevice.NativeDevice, frameFences[currentFrameIndex], VkBool32.True, ulong.MaxValue)); vkResetFences(GraphicsDevice.NativeDevice, frameFences[currentFrameIndex]); AcquireNextImage(true); @@ -207,7 +206,7 @@ public override unsafe void Present() private unsafe void AcquireNextImage(bool recreateIfFails) { // Get next image - var result = vkAcquireNextImageKHR(GraphicsDevice.NativeDevice, swapChain, ulong.MaxValue, acquireSemaphores[currentFrameIndex], VkFence.Null, out currentBufferIndex); + var result = GraphicsDevice.NativeDeviceApi.vkAcquireNextImageKHR(GraphicsDevice.NativeDevice, swapChain, ulong.MaxValue, acquireSemaphores[currentFrameIndex], VkFence.Null, out currentBufferIndex); if (result == VkResult.ErrorOutOfDateKHR) { if (recreateIfFails) @@ -279,7 +278,7 @@ protected internal override unsafe void OnDestroyed(bool immediately = false) { DestroySwapchain(); - vkDestroySurfaceKHR(GraphicsDevice.NativeInstance, surface, null); + GraphicsDevice.NativeInstanceApi.vkDestroySurfaceKHR(GraphicsDevice.NativeInstance, surface, null); surface = VkSurfaceKHR.Null; base.OnDestroyed(immediately); @@ -347,7 +346,7 @@ private unsafe void DestroySwapchain() if (swapChain == VkSwapchainKHR.Null) return; - GraphicsDevice.CheckResult(vkDeviceWaitIdle(GraphicsDevice.NativeDevice)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkDeviceWaitIdle(GraphicsDevice.NativeDevice)); backBuffer.OnDestroyed(true); @@ -359,19 +358,19 @@ private unsafe void DestroySwapchain() foreach (var swapchainImage in swapchainImages) { - vkDestroyImageView(GraphicsDevice.NativeDevice, swapchainImage.NativeColorAttachmentView, null); + GraphicsDevice.NativeDeviceApi.vkDestroyImageView(GraphicsDevice.NativeDevice, swapchainImage.NativeColorAttachmentView, null); } swapchainImages = null; for (int i = 0; i < kNumberOfFramesInFlight; i++) { - vkDestroySemaphore(GraphicsDevice.NativeDevice, acquireSemaphores[i]); - vkDestroyFence(GraphicsDevice.NativeDevice, frameFences[i]); + GraphicsDevice.NativeDeviceApi.vkDestroySemaphore(GraphicsDevice.NativeDevice, acquireSemaphores[i]); + GraphicsDevice.NativeDeviceApi.vkDestroyFence(GraphicsDevice.NativeDevice, frameFences[i]); } acquireSemaphores = null; frameFences = null; - vkDestroySwapchainKHR(GraphicsDevice.NativeDevice, swapChain, null); + GraphicsDevice.NativeDeviceApi.vkDestroySwapchainKHR(GraphicsDevice.NativeDevice, swapChain, null); swapChain = VkSwapchainKHR.Null; } @@ -383,7 +382,7 @@ private unsafe void CreateSwapChain(int width, int height, PixelFormat desiredFo { var nativeFromat = VulkanConvertExtensions.ConvertPixelFormat(format); - vkGetPhysicalDeviceFormatProperties(GraphicsDevice.NativePhysicalDevice, nativeFromat, out var formatProperties); + GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceFormatProperties(GraphicsDevice.NativePhysicalDevice, nativeFromat, out var formatProperties); if ((formatProperties.optimalTilingFeatures & VkFormatFeatureFlags.ColorAttachment) != 0) { @@ -399,22 +398,27 @@ private unsafe void CreateSwapChain(int width, int height, PixelFormat desiredFo // Queue // TODO VULKAN: Queue family is needed when creating the Device, so here we can just do a sanity check? - var queueNodeIndex = vkGetPhysicalDeviceQueueFamilyProperties(GraphicsDevice.NativePhysicalDevice).ToArray(). - Where((properties, index) => (properties.queueFlags & VkQueueFlags.Graphics) != 0 && vkGetPhysicalDeviceSurfaceSupportKHR(GraphicsDevice.NativePhysicalDevice, (uint)index, surface, out var supported) == VkResult.Success && supported). - Select((properties, index) => index).First(); + GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceQueueFamilyProperties(GraphicsDevice.NativePhysicalDevice, out uint queueFamilyCount); + Span queueFamilies = stackalloc VkQueueFamilyProperties[(int)queueFamilyCount]; + GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceQueueFamilyProperties(GraphicsDevice.NativePhysicalDevice, queueFamilies); + var queueNodeIndex = queueFamilies.ToArray() + .Where((properties, index) => (properties.queueFlags & VkQueueFlags.Graphics) != 0 && GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceSurfaceSupportKHR(GraphicsDevice.NativePhysicalDevice, (uint)index, surface, out var supported) == VkResult.Success && supported) + .Select((properties, index) => index).First(); // Surface format var backBufferFormat = VulkanConvertExtensions.ConvertPixelFormat(Description.BackBufferFormat); - var surfaceFormats = vkGetPhysicalDeviceSurfaceFormatsKHR(GraphicsDevice.NativePhysicalDevice, surface).ToArray(); + GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceSurfaceFormatsKHR(GraphicsDevice.NativePhysicalDevice, surface, out uint surfaceFormatCount); + Span surfaceFormats = stackalloc VkSurfaceFormatKHR[(int)surfaceFormatCount]; + GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceSurfaceFormatsKHR(GraphicsDevice.NativePhysicalDevice, surface, surfaceFormats); if ((surfaceFormats.Length != 1 || surfaceFormats[0].format != VkFormat.Undefined) && - !surfaceFormats.Any(x => x.format == backBufferFormat)) + !surfaceFormats.ToArray().Any(x => x.format == backBufferFormat)) { backBufferFormat = surfaceFormats[0].format; } // Create swapchain - vkGetPhysicalDeviceSurfaceCapabilitiesKHR(GraphicsDevice.NativePhysicalDevice, surface, out var surfaceCapabilities); + GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(GraphicsDevice.NativePhysicalDevice, surface, out var surfaceCapabilities); Description.BackBufferWidth = (int)surfaceCapabilities.currentExtent.width; Description.BackBufferHeight = (int)surfaceCapabilities.currentExtent.height; @@ -438,7 +442,9 @@ private unsafe void CreateSwapChain(int width, int height, PixelFormat desiredFo } // Find present mode - var presentModes = vkGetPhysicalDeviceSurfacePresentModesKHR(GraphicsDevice.NativePhysicalDevice, surface); + GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceSurfacePresentModesKHR(GraphicsDevice.NativePhysicalDevice, surface, out uint presentModeCount); + Span presentModes = stackalloc VkPresentModeKHR[(int)presentModeCount]; + GraphicsDevice.NativeInstanceApi.vkGetPhysicalDeviceSurfacePresentModesKHR(GraphicsDevice.NativePhysicalDevice, surface, presentModes); var swapChainPresentMode = VkPresentModeKHR.Fifo; // Always supported foreach (var presentMode in presentModes) { @@ -476,7 +482,7 @@ private unsafe void CreateSwapChain(int width, int height, PixelFormat desiredFo oldSwapchain = swapChain, clipped = true }; - GraphicsDevice.CheckResult(vkCreateSwapchainKHR(GraphicsDevice.NativeDevice, &swapchainCreateInfo, null, out var newSwapChain)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateSwapchainKHR(GraphicsDevice.NativeDevice, &swapchainCreateInfo, null, out var newSwapChain)); DestroySwapchain(); @@ -575,24 +581,26 @@ private unsafe void CreateBackBuffers() var commandBuffer = GraphicsDevice.NativeCopyCommandPools.Value.GetObject(0); var beginInfo = new VkCommandBufferBeginInfo { sType = VkStructureType.CommandBufferBeginInfo }; - vkBeginCommandBuffer(commandBuffer, &beginInfo); + GraphicsDevice.NativeDeviceApi.vkBeginCommandBuffer(commandBuffer, &beginInfo); - var buffers = vkGetSwapchainImagesKHR(GraphicsDevice.NativeDevice, swapChain); + GraphicsDevice.NativeDeviceApi.vkGetSwapchainImagesKHR(GraphicsDevice.NativeDevice, swapChain, out uint swapchainImageCount); + Span buffers = stackalloc VkImage[(int)swapchainImageCount]; + GraphicsDevice.NativeDeviceApi.vkGetSwapchainImagesKHR(GraphicsDevice.NativeDevice, swapChain, buffers); swapchainImages = new SwapChainImageInfo[buffers.Length]; - for (int i = 0; i < buffers.Length; i++) + for (int index = 0; index < buffers.Length; index++) { // Create image views swapchainImages[i].NativeImage = createInfo.image = buffers[i]; - GraphicsDevice.CheckResult(vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, null, out swapchainImages[i].NativeColorAttachmentView)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, null, out swapchainImages[i].NativeColorAttachmentView)); // Transition to default layout - imageMemoryBarrier.image = buffers[i]; - vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.AllCommands, VkPipelineStageFlags.AllCommands, VkDependencyFlags.None, 0, null, 0, null, 1, &imageMemoryBarrier); + imageMemoryBarrier.image = buffers[index]; + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.AllCommands, VkPipelineStageFlags.AllCommands, VkDependencyFlags.None, 0, null, 0, null, 1, &imageMemoryBarrier); } // Close and submit - GraphicsDevice.CheckResult(vkEndCommandBuffer(commandBuffer)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkEndCommandBuffer(commandBuffer)); lock (GraphicsDevice.QueueLock) { @@ -619,10 +627,10 @@ private unsafe void CreateBackBuffers() var fenceCreateInfo = new VkFenceCreateInfo { sType = VkStructureType.FenceCreateInfo }; for (int i = 0; i < kNumberOfFramesInFlight; i++) { - GraphicsDevice.CheckResult(vkCreateSemaphore(GraphicsDevice.NativeDevice, &semaphoreCreateInfo, null, out acquireSemaphores[i])); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateSemaphore(GraphicsDevice.NativeDevice, &semaphoreCreateInfo, null, out acquireSemaphores[i])); // Make all fence except 0 as signaled (so that next Present()=>vkWaitForFences is not blocked when fetching secondary buffers for first time) fenceCreateInfo.flags = i == 0 ? VkFenceCreateFlags.None : VkFenceCreateFlags.Signaled; - GraphicsDevice.CheckResult(vkCreateFence(GraphicsDevice.NativeDevice, &fenceCreateInfo, null, out frameFences[i])); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateFence(GraphicsDevice.NativeDevice, &fenceCreateInfo, null, out frameFences[i])); } // Get next image diff --git a/sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs index 72f5eff385..fdc835757e 100644 --- a/sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/Texture.Vulkan.cs @@ -4,7 +4,6 @@ using System; using Stride.Core; using Vortice.Vulkan; -using static Vortice.Vulkan.Vulkan; namespace Stride.Graphics { @@ -204,16 +203,16 @@ private unsafe void CreateBuffer() }; // Create buffer - GraphicsDevice.CheckResult(vkCreateBuffer(GraphicsDevice.NativeDevice, &createInfo, allocator: null, out NativeBuffer)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateBuffer(GraphicsDevice.NativeDevice, &createInfo, allocator: null, out NativeBuffer)); // Allocate and bind memory - vkGetBufferMemoryRequirements(GraphicsDevice.NativeDevice, NativeBuffer, out var memoryRequirements); + GraphicsDevice.NativeDeviceApi.vkGetBufferMemoryRequirements(GraphicsDevice.NativeDevice, NativeBuffer, out var memoryRequirements); AllocateMemory(VkMemoryPropertyFlags.HostVisible | VkMemoryPropertyFlags.HostCoherent, memoryRequirements); if (NativeMemory != VkDeviceMemory.Null) { - vkBindBufferMemory(GraphicsDevice.NativeDevice, NativeBuffer, NativeMemory, 0); + GraphicsDevice.NativeDeviceApi.vkBindBufferMemory(GraphicsDevice.NativeDevice, NativeBuffer, NativeMemory, 0); } } @@ -269,16 +268,16 @@ private unsafe void CreateImage() // Create native image // TODO: Multisampling, flags, usage, etc. - GraphicsDevice.CheckResult(vkCreateImage(GraphicsDevice.NativeDevice, &createInfo, allocator: null, out NativeImage)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateImage(GraphicsDevice.NativeDevice, &createInfo, allocator: null, out NativeImage)); // Allocate and bind memory - vkGetImageMemoryRequirements(GraphicsDevice.NativeDevice, NativeImage, out var memoryRequirements); + GraphicsDevice.NativeDeviceApi.vkGetImageMemoryRequirements(GraphicsDevice.NativeDevice, NativeImage, out var memoryRequirements); AllocateMemory(memoryProperties, memoryRequirements); if (NativeMemory != VkDeviceMemory.Null) { - vkBindImageMemory(GraphicsDevice.NativeDevice, NativeImage, NativeMemory, 0); + GraphicsDevice.NativeDeviceApi.vkBindImageMemory(GraphicsDevice.NativeDevice, NativeImage, NativeMemory, 0); } } @@ -287,7 +286,7 @@ private unsafe void InitializeData(DataBox[] dataBoxes) var commandBuffer = GraphicsDevice.NativeCopyCommandPools.Value.GetObject(GraphicsDevice.CopyFence.GetCompletedValue()); var beginInfo = new VkCommandBufferBeginInfo { sType = VkStructureType.CommandBufferBeginInfo, flags = VkCommandBufferUsageFlags.OneTimeSubmit }; - vkBeginCommandBuffer(commandBuffer, &beginInfo); + GraphicsDevice.NativeDeviceApi.vkBeginCommandBuffer(commandBuffer, &beginInfo); if (dataBoxes != null && dataBoxes.Length > 0) { @@ -310,13 +309,13 @@ private unsafe void InitializeData(DataBox[] dataBoxes) if (Usage == GraphicsResourceUsage.Staging) { bufferBarriers[1] = new VkBufferMemoryBarrier(NativeBuffer, NativeAccessMask, VkAccessFlags.TransferWrite); - vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 2, bufferBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 2, bufferBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); } else { // Image barrier var initialBarrier = new VkImageMemoryBarrier(NativeImage, new VkImageSubresourceRange(NativeImageAspect, baseMipLevel: 0, levelCount: uint.MaxValue, baseArrayLayer: 0, layerCount: uint.MaxValue), VkAccessFlags.None, VkAccessFlags.TransferWrite, VkImageLayout.Undefined, VkImageLayout.TransferDstOptimal); - vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, bufferBarriers, imageMemoryBarrierCount: 1, &initialBarrier); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Host, VkPipelineStageFlags.Transfer, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, bufferBarriers, imageMemoryBarrierCount: 1, &initialBarrier); } // Copy data boxes to upload buffer @@ -343,7 +342,7 @@ private unsafe void InitializeData(DataBox[] dataBoxes) size = (uint) ComputeSubResourceSize(i) }; - vkCmdCopyBuffer(commandBuffer, uploadResource, NativeBuffer, regionCount: 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyBuffer(commandBuffer, uploadResource, NativeBuffer, regionCount: 1, ©); } else { @@ -359,7 +358,7 @@ private unsafe void InitializeData(DataBox[] dataBoxes) }; // Copy from upload buffer to image - vkCmdCopyBufferToImage(commandBuffer, uploadResource, NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyBufferToImage(commandBuffer, uploadResource, NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); } uploadMemory += slicePitch; @@ -369,7 +368,7 @@ private unsafe void InitializeData(DataBox[] dataBoxes) if (Usage == GraphicsResourceUsage.Staging) { bufferBarriers[0] = new VkBufferMemoryBarrier(NativeBuffer, VkAccessFlags.TransferWrite, NativeAccessMask); - vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Transfer, VkPipelineStageFlags.AllCommands, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, bufferBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Transfer, VkPipelineStageFlags.AllCommands, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 1, bufferBarriers, imageMemoryBarrierCount: 0, imageMemoryBarriers: null); } IsInitialized = true; @@ -382,11 +381,11 @@ private unsafe void InitializeData(DataBox[] dataBoxes) new VkImageSubresourceRange(NativeImageAspect, baseMipLevel: 0, levelCount: uint.MaxValue, baseArrayLayer: 0, layerCount: uint.MaxValue), dataBoxes == null || dataBoxes.Length == 0 ? VkAccessFlags.None : VkAccessFlags.TransferWrite, NativeAccessMask, dataBoxes == null || dataBoxes.Length == 0 ? VkImageLayout.Undefined : VkImageLayout.TransferDstOptimal, NativeLayout); - vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Transfer, VkPipelineStageFlags.AllCommands, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &imageMemoryBarrier); + GraphicsDevice.NativeDeviceApi.vkCmdPipelineBarrier(commandBuffer, VkPipelineStageFlags.Transfer, VkPipelineStageFlags.AllCommands, VkDependencyFlags.None, memoryBarrierCount: 0, memoryBarriers: null, bufferMemoryBarrierCount: 0, bufferMemoryBarriers: null, imageMemoryBarrierCount: 1, &imageMemoryBarrier); } // Close and submit - GraphicsDevice.CheckResult(vkEndCommandBuffer(commandBuffer)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkEndCommandBuffer(commandBuffer)); var copyFenceValue = GraphicsDevice.ExecuteAndWaitCopyQueueGPU(commandBuffer); GraphicsDevice.NativeCopyCommandPools.Value.RecycleObject(GraphicsDevice.CopyFence.NextFenceValue, commandBuffer); @@ -538,7 +537,7 @@ private unsafe VkImageView GetImageView(ViewType viewType, int arrayOrDepthSlice } } - GraphicsDevice.CheckResult(vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, null, out var imageView)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, null, out var imageView)); return imageView; } @@ -581,7 +580,7 @@ private unsafe VkImageView GetColorAttachmentView(ViewType viewType, int arrayOr throw new NotSupportedException("TextureCube dimension is expecting an arraysize > 1"); } - GraphicsDevice.CheckResult(vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, null, out var imageView)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, null, out var imageView)); return imageView; } @@ -616,7 +615,7 @@ private unsafe VkImageView GetDepthStencilView() // createInfo.Flags |= (int)AttachmentViewCreateFlags.AttachmentViewCreateReadOnlyStencilBit; //} - GraphicsDevice.CheckResult(vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, allocator: null, out var imageView)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, allocator: null, out var imageView)); return imageView; } @@ -698,7 +697,7 @@ internal static VkFormat GetFallbackDepthStencilFormat(GraphicsDevice device, Vk foreach (var fallbackFormat in fallbackFormats) { - vkGetPhysicalDeviceFormatProperties(device.NativePhysicalDevice, fallbackFormat, out var formatProperties); + device.NativeInstanceApi.vkGetPhysicalDeviceFormatProperties(device.NativePhysicalDevice, fallbackFormat, out var formatProperties); if ((formatProperties.optimalTilingFeatures & VkFormatFeatureFlags.DepthStencilAttachment) != 0) { From 1f3feb1a4fc1e919951a6d97c9436464211985a3 Mon Sep 17 00:00:00 2001 From: Feralnex Date: Sat, 10 Jan 2026 14:55:12 +0100 Subject: [PATCH 3/3] Missing Vortice.Vulkan API adjustments --- .../Vulkan/CommandList.Vulkan.cs | 10 +++++----- .../Vulkan/GraphicsDevice.Vulkan.cs | 14 +++++++------- .../SwapChainGraphicsPresenter.Vulkan.cs | 18 +++++++++--------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs index 8f27ae7dec..a30f53bf40 100644 --- a/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/CommandList.Vulkan.cs @@ -103,7 +103,7 @@ public partial CompiledCommandList Close() CleanupRenderPass(); // Close - GraphicsDevice.CheckResult(vGraphicsDevice.NativeDeviceApi.kEndCommandBuffer(currentCommandList.NativeCommandBuffer)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkEndCommandBuffer(currentCommandList.NativeCommandBuffer)); // Staging resources not updated anymore foreach (var stagingResource in currentCommandList.StagingResources) @@ -195,7 +195,7 @@ private unsafe void BindPipeline() if (!pipelineDirty) return; - vkCmdBindPipeline(currentCommandList.NativeCommandBuffer, activePipeline.IsCompute ? VkPipelineBindPoint.Compute : VkPipelineBindPoint.Graphics, activePipeline.NativePipeline); + GraphicsDevice.NativeDeviceApi.vkCmdBindPipeline(currentCommandList.NativeCommandBuffer, activePipeline.IsCompute ? VkPipelineBindPoint.Compute : VkPipelineBindPoint.Graphics, activePipeline.NativePipeline); } /// @@ -273,7 +273,7 @@ private unsafe void PrepareDraw() BindPipeline(); BindDescriptorSets(); SetViewportImpl(); - vkCmdSetStencilReference(currentCommandList.NativeCommandBuffer, VkStencilFaceFlags.FrontAndBack, activeStencilReference ?? 0); + GraphicsDevice.NativeDeviceApi.vkCmdSetStencilReference(currentCommandList.NativeCommandBuffer, VkStencilFaceFlags.FrontAndBack, activeStencilReference ?? 0); } private unsafe void BindDescriptorSets() @@ -977,7 +977,7 @@ public unsafe void Copy(GraphicsResource source, GraphicsResource destination) dstSubresource = destinationSubresource, extent = new VkExtent3D(width, height, depth) }; - vkCmdCopyImage(currentCommandList.NativeCommandBuffer, sourceParent.NativeImage, VkImageLayout.TransferSrcOptimal, destinationParent.NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyImage(currentCommandList.NativeCommandBuffer, sourceParent.NativeImage, VkImageLayout.TransferSrcOptimal, destinationParent.NativeImage, VkImageLayout.TransferDstOptimal, regionCount: 1, ©); } } } @@ -1117,7 +1117,7 @@ public unsafe void CopyRegion(GraphicsResource source, int sourceSubresource, Re imageOffset = new VkOffset3D(region.Left, region.Top, region.Front), imageExtent = new VkExtent3D((uint)(region.Right - region.Left), (uint)(region.Bottom - region.Top), (uint)(region.Back - region.Front)) }; - vkCmdCopyImageToBuffer(currentCommandList.NativeCommandBuffer, sourceParent.NativeImage, VkImageLayout.TransferSrcOptimal, destinationParent.NativeBuffer, 1, ©); + GraphicsDevice.NativeDeviceApi.vkCmdCopyImageToBuffer(currentCommandList.NativeCommandBuffer, sourceParent.NativeImage, VkImageLayout.TransferSrcOptimal, destinationParent.NativeBuffer, 1, ©); } //// VkFence for host access diff --git a/sources/engine/Stride.Graphics/Vulkan/GraphicsDevice.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/GraphicsDevice.Vulkan.cs index bc3361be0d..793a26b1f7 100644 --- a/sources/engine/Stride.Graphics/Vulkan/GraphicsDevice.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/GraphicsDevice.Vulkan.cs @@ -213,7 +213,7 @@ public unsafe void End() pSignalSemaphores = &frameSemaphore, }; - CheckResult(vkQueueSubmit(NativeCommandQueue, 1, &submitInfo, VkFence.Null)); + CheckResult(NativeDeviceApi.vkQueueSubmit(NativeCommandQueue, 1, &submitInfo, VkFence.Null)); } } @@ -279,7 +279,7 @@ public unsafe void ExecuteCommandLists(int count, CompiledCommandList[] commandL pSignalSemaphores = &semaphores[0], }; - CheckResult(vkQueueSubmit(NativeCommandQueue, 1, &submitInfo, VkFence.Null)); + CheckResult(NativeDeviceApi.vkQueueSubmit(NativeCommandQueue, 1, &submitInfo, VkFence.Null)); } // Collect resources @@ -545,7 +545,7 @@ internal unsafe ulong ExecuteAndWaitCopyQueueGPU(VkCommandBuffer commandBuffer) pSignalSemaphores = ©Semaphore, }; - CheckResult(vkQueueSubmit(NativeCommandQueue, 1, &submitInfo, VkFence.Null)); + CheckResult(NativeDeviceApi.vkQueueSubmit(NativeCommandQueue, 1, &submitInfo, VkFence.Null)); return nextCopyFenceValue; } @@ -779,13 +779,13 @@ public FenceHelper(GraphicsDevice graphicsDevice) this.graphicsDevice = graphicsDevice; var timelineInfo = new VkSemaphoreTypeCreateInfo { sType = VkStructureType.SemaphoreTypeCreateInfo, semaphoreType = VkSemaphoreType.Timeline }; var createInfo = new VkSemaphoreCreateInfo { sType = VkStructureType.SemaphoreCreateInfo, pNext = &timelineInfo }; - graphicsDevice.CheckResult(NativeDeviceApi.vkCreateSemaphore(graphicsDevice.NativeDevice, &createInfo, null, out Semaphore)); + graphicsDevice.CheckResult(graphicsDevice.NativeDeviceApi.vkCreateSemaphore(graphicsDevice.NativeDevice, &createInfo, null, out Semaphore)); } internal ulong GetCompletedValue() { ulong result = 0; - vkGetSemaphoreCounterValue(graphicsDevice.NativeDevice, Semaphore, &result); + graphicsDevice.NativeDeviceApi.vkGetSemaphoreCounterValue(graphicsDevice.NativeDevice, Semaphore, &result); return result; } @@ -815,7 +815,7 @@ internal void WaitForFenceCPUInternal(ulong fenceValue) pSemaphores = semaphore, pValues = &fenceValue, }; - NativeDeviceApi.vkWaitSemaphores(graphicsDevice.NativeDevice, &waitInfo, ulong.MaxValue); + graphicsDevice.NativeDeviceApi.vkWaitSemaphores(graphicsDevice.NativeDevice, &waitInfo, ulong.MaxValue); LastCompletedFence = fenceValue; } } @@ -823,7 +823,7 @@ internal void WaitForFenceCPUInternal(ulong fenceValue) public void Dispose() { - vkDestroySemaphore(graphicsDevice.NativeDevice, Semaphore); + graphicsDevice.NativeDeviceApi.vkDestroySemaphore(graphicsDevice.NativeDevice, Semaphore); } } } diff --git a/sources/engine/Stride.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs b/sources/engine/Stride.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs index de9c0afb47..57a4121e57 100644 --- a/sources/engine/Stride.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs +++ b/sources/engine/Stride.Graphics/Vulkan/SwapChainGraphicsPresenter.Vulkan.cs @@ -198,7 +198,7 @@ public override unsafe void Present() // Wait for frame fence to be available GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkWaitForFences(GraphicsDevice.NativeDevice, frameFences[currentFrameIndex], VkBool32.True, ulong.MaxValue)); - vkResetFences(GraphicsDevice.NativeDevice, frameFences[currentFrameIndex]); + GraphicsDevice.NativeDeviceApi.vkResetFences(GraphicsDevice.NativeDevice, frameFences[currentFrameIndex]); AcquireNextImage(true); } @@ -254,7 +254,7 @@ private unsafe void AcquireNextImage(bool recreateIfFails) pSignalSemaphores = &commandListFence, }; - GraphicsDevice.CheckResult(vkQueueSubmit(GraphicsDevice.NativeCommandQueue, 1, &submitInfo, VkFence.Null)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkQueueSubmit(GraphicsDevice.NativeCommandQueue, 1, &submitInfo, VkFence.Null)); } } @@ -352,7 +352,7 @@ private unsafe void DestroySwapchain() foreach (var semaphore in submitSemaphores) { - vkDestroySemaphore(GraphicsDevice.NativeDevice, semaphore); + GraphicsDevice.NativeDeviceApi.vkDestroySemaphore(GraphicsDevice.NativeDevice, semaphore); } submitSemaphores = null; @@ -522,7 +522,7 @@ private unsafe void CreateSurface() hinstance = Process.GetCurrentProcess().Handle, hwnd = controlHandle, }; - GraphicsDevice.CheckResult(vkCreateWin32SurfaceKHR(GraphicsDevice.NativeInstance, &surfaceCreateInfo, null, out surface)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeInstanceApi.vkCreateWin32SurfaceKHR(GraphicsDevice.NativeInstance, &surfaceCreateInfo, null, out surface)); } else if (Platform.Type == PlatformType.Android) { @@ -591,8 +591,8 @@ private unsafe void CreateBackBuffers() for (int index = 0; index < buffers.Length; index++) { // Create image views - swapchainImages[i].NativeImage = createInfo.image = buffers[i]; - GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, null, out swapchainImages[i].NativeColorAttachmentView)); + swapchainImages[index].NativeImage = createInfo.image = buffers[index]; + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateImageView(GraphicsDevice.NativeDevice, &createInfo, null, out swapchainImages[index].NativeColorAttachmentView)); // Transition to default layout imageMemoryBarrier.image = buffers[index]; @@ -610,8 +610,8 @@ private unsafe void CreateBackBuffers() commandBufferCount = 1, pCommandBuffers = &commandBuffer, }; - GraphicsDevice.CheckResult(vkQueueSubmit(GraphicsDevice.NativeCommandQueue, 1, &submitInfo, VkFence.Null)); - GraphicsDevice.CheckResult(vkQueueWaitIdle(GraphicsDevice.NativeCommandQueue)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkQueueSubmit(GraphicsDevice.NativeCommandQueue, 1, &submitInfo, VkFence.Null)); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkQueueWaitIdle(GraphicsDevice.NativeCommandQueue)); } GraphicsDevice.NativeCopyCommandPools.Value.RecycleObject(0, commandBuffer); @@ -620,7 +620,7 @@ private unsafe void CreateBackBuffers() submitSemaphores = new VkSemaphore[buffers.Length]; var semaphoreCreateInfo = new VkSemaphoreCreateInfo { sType = VkStructureType.SemaphoreCreateInfo }; for (int i = 0; i < submitSemaphores.Length; ++i) - GraphicsDevice.CheckResult(vkCreateSemaphore(GraphicsDevice.NativeDevice, &semaphoreCreateInfo, null, out submitSemaphores[i])); + GraphicsDevice.CheckResult(GraphicsDevice.NativeDeviceApi.vkCreateSemaphore(GraphicsDevice.NativeDevice, &semaphoreCreateInfo, null, out submitSemaphores[i])); frameFences = new VkFence[kNumberOfFramesInFlight]; acquireSemaphores = new VkSemaphore[kNumberOfFramesInFlight];