Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Metal] Support CommandList.CopyBuffer and UpdateBuffer when region i…
…s unaligned. * Metal's blit encoder does not support buffer copies with unaligned regions on macOS. An unaligned region is one where the size or offset is not a multiple of 4 bytes. * When necessary, these copies are now performed with a specialized compute shader, which does a byte-by-byte copy of the data from source to destination. * The compute shader is embedded into Veldrid.dll and lazily loaded at runtime if the unaligned copy code path is used. Validation changes: * An exception is now thrown if you attempt to create a buffer with BufferUsage.UniformBuffer whose size is not a multiple of 16 bytes.
- Loading branch information
Showing
13 changed files
with
250 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file added
BIN
+2.82 KB
src/Veldrid/MTL/EmbeddedShaders/MTL_UnalignedBufferCopy_macOS.metallib
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <metal_stdlib> | ||
using namespace metal; | ||
|
||
// This must be kept in sync with MTLUnalignedBufferCopyInfo.cs | ||
struct CopyInfo | ||
{ | ||
uint32_t SrcOffset; | ||
uint32_t DstOffset; | ||
uint32_t CopySize; | ||
}; | ||
|
||
kernel void copy_bytes( | ||
device uint8_t* src [[ buffer(0) ]], | ||
device uint8_t* dst [[ buffer(1) ]], | ||
constant CopyInfo& info [[ buffer(2) ]]) | ||
{ | ||
for (uint32_t i = 0; i < info.CopySize; i++) | ||
{ | ||
dst[i + info.DstOffset] = src[i + info.SrcOffset]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
xcrun -sdk macosx metal $script_dir/UnalignedBufferCopy.metal -o $script_dir/UnalignedBufferCopy.macos.air | ||
xcrun -sdk macosx metallib $script_dir/UnalignedBufferCopy.macos.air -o $script_dir/MTL_UnalignedBufferCopy_macOS.metallib | ||
|
||
xcrun -sdk iphoneos metal $script_dir/UnalignedBufferCopy.metal -o $script_dir/UnalignedBufferCopy.ios.air | ||
xcrun -sdk iphoneos metallib $script_dir/UnalignedBufferCopy.ios.air -o $script_dir/MTL_UnalignedBufferCopy_iOS.metallib | ||
|
||
rm $script_dir/UnalignedBufferCopy.macos.air | ||
rm $script_dir/UnalignedBufferCopy.ios.air |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Veldrid.MTL | ||
{ | ||
internal struct MTLUnalignedBufferCopyInfo | ||
{ | ||
public uint SourceOffset; | ||
public uint DestinationOffset; | ||
public uint CopySize; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters