another refresh2 update
parent
178a5ea3cf
commit
e0f4c19dc2
|
@ -1 +1 @@
|
||||||
Subproject commit 2e346d84016fb7b26dbe7c5b6c485109571c30f4
|
Subproject commit 031ad4c04781fe4a0d98a177333ebf7764d2fe91
|
|
@ -1949,7 +1949,8 @@ namespace MoonWorks.Graphics
|
||||||
public void UploadToTexture(
|
public void UploadToTexture(
|
||||||
TransferBuffer transferBuffer,
|
TransferBuffer transferBuffer,
|
||||||
in TextureSlice textureSlice,
|
in TextureSlice textureSlice,
|
||||||
in BufferImageCopy copyParams
|
in BufferImageCopy copyParams,
|
||||||
|
CopyOptions option
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
@ -1963,7 +1964,8 @@ namespace MoonWorks.Graphics
|
||||||
Handle,
|
Handle,
|
||||||
transferBuffer.Handle,
|
transferBuffer.Handle,
|
||||||
textureSlice.ToRefreshTextureSlice(),
|
textureSlice.ToRefreshTextureSlice(),
|
||||||
copyParams.ToRefresh()
|
copyParams.ToRefresh(),
|
||||||
|
(Refresh.CopyOptions) option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1972,12 +1974,14 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void UploadToTexture(
|
public void UploadToTexture(
|
||||||
TransferBuffer transferBuffer,
|
TransferBuffer transferBuffer,
|
||||||
Texture texture
|
Texture texture,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
UploadToTexture(
|
UploadToTexture(
|
||||||
transferBuffer,
|
transferBuffer,
|
||||||
new TextureSlice(texture),
|
new TextureSlice(texture),
|
||||||
new BufferImageCopy(0, 0, 0)
|
new BufferImageCopy(0, 0, 0),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1993,7 +1997,8 @@ namespace MoonWorks.Graphics
|
||||||
public void UploadToBuffer(
|
public void UploadToBuffer(
|
||||||
TransferBuffer transferBuffer,
|
TransferBuffer transferBuffer,
|
||||||
GpuBuffer gpuBuffer,
|
GpuBuffer gpuBuffer,
|
||||||
in BufferCopy copyParams
|
in BufferCopy copyParams,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertNotSubmitted();
|
AssertNotSubmitted();
|
||||||
|
@ -2007,7 +2012,8 @@ namespace MoonWorks.Graphics
|
||||||
Handle,
|
Handle,
|
||||||
transferBuffer.Handle,
|
transferBuffer.Handle,
|
||||||
gpuBuffer.Handle,
|
gpuBuffer.Handle,
|
||||||
copyParams.ToRefresh()
|
copyParams.ToRefresh(),
|
||||||
|
(Refresh.CopyOptions) option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2016,12 +2022,14 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void UploadToBuffer(
|
public void UploadToBuffer(
|
||||||
TransferBuffer transferBuffer,
|
TransferBuffer transferBuffer,
|
||||||
GpuBuffer gpuBuffer
|
GpuBuffer gpuBuffer,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
UploadToBuffer(
|
UploadToBuffer(
|
||||||
transferBuffer,
|
transferBuffer,
|
||||||
gpuBuffer,
|
gpuBuffer,
|
||||||
new BufferCopy(0, 0, transferBuffer.Size)
|
new BufferCopy(0, 0, transferBuffer.Size),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2033,7 +2041,8 @@ namespace MoonWorks.Graphics
|
||||||
GpuBuffer gpuBuffer,
|
GpuBuffer gpuBuffer,
|
||||||
uint sourceStartElement,
|
uint sourceStartElement,
|
||||||
uint destinationStartElement,
|
uint destinationStartElement,
|
||||||
uint numElements
|
uint numElements,
|
||||||
|
CopyOptions option
|
||||||
) where T : unmanaged
|
) where T : unmanaged
|
||||||
{
|
{
|
||||||
var elementSize = Marshal.SizeOf<T>();
|
var elementSize = Marshal.SizeOf<T>();
|
||||||
|
@ -2048,7 +2057,8 @@ namespace MoonWorks.Graphics
|
||||||
srcOffsetInBytes,
|
srcOffsetInBytes,
|
||||||
dstOffsetInBytes,
|
dstOffsetInBytes,
|
||||||
dataLengthInBytes
|
dataLengthInBytes
|
||||||
)
|
),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2062,7 +2072,8 @@ namespace MoonWorks.Graphics
|
||||||
public void DownloadFromTexture(
|
public void DownloadFromTexture(
|
||||||
in TextureSlice textureSlice,
|
in TextureSlice textureSlice,
|
||||||
TransferBuffer transferBuffer,
|
TransferBuffer transferBuffer,
|
||||||
in BufferImageCopy copyParams
|
in BufferImageCopy copyParams,
|
||||||
|
TransferOptions option
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertNotSubmitted();
|
AssertNotSubmitted();
|
||||||
|
@ -2075,7 +2086,8 @@ namespace MoonWorks.Graphics
|
||||||
Handle,
|
Handle,
|
||||||
textureSlice.ToRefreshTextureSlice(),
|
textureSlice.ToRefreshTextureSlice(),
|
||||||
transferBuffer.Handle,
|
transferBuffer.Handle,
|
||||||
copyParams.ToRefresh()
|
copyParams.ToRefresh(),
|
||||||
|
(Refresh.TransferOptions) option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2084,12 +2096,14 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DownloadFromTexture(
|
public void DownloadFromTexture(
|
||||||
Texture texture,
|
Texture texture,
|
||||||
TransferBuffer transferBuffer
|
TransferBuffer transferBuffer,
|
||||||
|
TransferOptions option
|
||||||
) {
|
) {
|
||||||
DownloadFromTexture(
|
DownloadFromTexture(
|
||||||
new TextureSlice(texture),
|
new TextureSlice(texture),
|
||||||
transferBuffer,
|
transferBuffer,
|
||||||
new BufferImageCopy(0, 0, 0)
|
new BufferImageCopy(0, 0, 0),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2103,7 +2117,8 @@ namespace MoonWorks.Graphics
|
||||||
public void DownloadFromBuffer(
|
public void DownloadFromBuffer(
|
||||||
GpuBuffer gpuBuffer,
|
GpuBuffer gpuBuffer,
|
||||||
TransferBuffer transferBuffer,
|
TransferBuffer transferBuffer,
|
||||||
in BufferCopy copyParams
|
in BufferCopy copyParams,
|
||||||
|
TransferOptions option
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertNotSubmitted();
|
AssertNotSubmitted();
|
||||||
|
@ -2116,7 +2131,8 @@ namespace MoonWorks.Graphics
|
||||||
Handle,
|
Handle,
|
||||||
gpuBuffer.Handle,
|
gpuBuffer.Handle,
|
||||||
transferBuffer.Handle,
|
transferBuffer.Handle,
|
||||||
copyParams.ToRefresh()
|
copyParams.ToRefresh(),
|
||||||
|
(Refresh.TransferOptions) option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2129,12 +2145,14 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DownloadFromBuffer(
|
public void DownloadFromBuffer(
|
||||||
GpuBuffer gpuBuffer,
|
GpuBuffer gpuBuffer,
|
||||||
TransferBuffer transferBuffer
|
TransferBuffer transferBuffer,
|
||||||
|
TransferOptions option
|
||||||
) {
|
) {
|
||||||
DownloadFromBuffer(
|
DownloadFromBuffer(
|
||||||
gpuBuffer,
|
gpuBuffer,
|
||||||
transferBuffer,
|
transferBuffer,
|
||||||
new BufferCopy(0, 0, gpuBuffer.Size)
|
new BufferCopy(0, 0, gpuBuffer.Size),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2147,7 +2165,8 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CopyTextureToTexture(
|
public void CopyTextureToTexture(
|
||||||
in TextureSlice source,
|
in TextureSlice source,
|
||||||
in TextureSlice destination
|
in TextureSlice destination,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertNotSubmitted();
|
AssertNotSubmitted();
|
||||||
|
@ -2159,7 +2178,8 @@ namespace MoonWorks.Graphics
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
source.ToRefreshTextureSlice(),
|
source.ToRefreshTextureSlice(),
|
||||||
destination.ToRefreshTextureSlice()
|
destination.ToRefreshTextureSlice(),
|
||||||
|
(Refresh.CopyOptions) option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2169,11 +2189,13 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CopyTextureToTexture(
|
public void CopyTextureToTexture(
|
||||||
Texture source,
|
Texture source,
|
||||||
Texture destination
|
Texture destination,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
CopyTextureToTexture(
|
CopyTextureToTexture(
|
||||||
new TextureSlice(source),
|
new TextureSlice(source),
|
||||||
new TextureSlice(destination)
|
new TextureSlice(destination),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2186,7 +2208,8 @@ namespace MoonWorks.Graphics
|
||||||
public void CopyTextureToBuffer(
|
public void CopyTextureToBuffer(
|
||||||
in TextureSlice textureSlice,
|
in TextureSlice textureSlice,
|
||||||
GpuBuffer buffer,
|
GpuBuffer buffer,
|
||||||
in BufferImageCopy copyParams
|
in BufferImageCopy copyParams,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertNotSubmitted();
|
AssertNotSubmitted();
|
||||||
|
@ -2199,7 +2222,8 @@ namespace MoonWorks.Graphics
|
||||||
Handle,
|
Handle,
|
||||||
textureSlice.ToRefreshTextureSlice(),
|
textureSlice.ToRefreshTextureSlice(),
|
||||||
buffer.Handle,
|
buffer.Handle,
|
||||||
copyParams.ToRefresh()
|
copyParams.ToRefresh(),
|
||||||
|
(Refresh.CopyOptions) option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2208,12 +2232,14 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CopyTextureToBuffer(
|
public void CopyTextureToBuffer(
|
||||||
Texture texture,
|
Texture texture,
|
||||||
GpuBuffer buffer
|
GpuBuffer buffer,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
CopyTextureToBuffer(
|
CopyTextureToBuffer(
|
||||||
new TextureSlice(texture),
|
new TextureSlice(texture),
|
||||||
buffer,
|
buffer,
|
||||||
new BufferImageCopy(0, 0, 0)
|
new BufferImageCopy(0, 0, 0),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2226,7 +2252,8 @@ namespace MoonWorks.Graphics
|
||||||
public void CopyBufferToTexture(
|
public void CopyBufferToTexture(
|
||||||
GpuBuffer gpuBuffer,
|
GpuBuffer gpuBuffer,
|
||||||
in TextureSlice textureSlice,
|
in TextureSlice textureSlice,
|
||||||
in BufferImageCopy copyParams
|
in BufferImageCopy copyParams,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertNotSubmitted();
|
AssertNotSubmitted();
|
||||||
|
@ -2239,7 +2266,8 @@ namespace MoonWorks.Graphics
|
||||||
Handle,
|
Handle,
|
||||||
gpuBuffer.Handle,
|
gpuBuffer.Handle,
|
||||||
textureSlice.ToRefreshTextureSlice(),
|
textureSlice.ToRefreshTextureSlice(),
|
||||||
copyParams.ToRefresh()
|
copyParams.ToRefresh(),
|
||||||
|
(Refresh.CopyOptions) option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2248,12 +2276,14 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CopyBufferToTexture(
|
public void CopyBufferToTexture(
|
||||||
GpuBuffer buffer,
|
GpuBuffer buffer,
|
||||||
Texture texture
|
Texture texture,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
CopyBufferToTexture(
|
CopyBufferToTexture(
|
||||||
buffer,
|
buffer,
|
||||||
new TextureSlice(texture),
|
new TextureSlice(texture),
|
||||||
new BufferImageCopy(0, 0, 0)
|
new BufferImageCopy(0, 0, 0),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2266,7 +2296,8 @@ namespace MoonWorks.Graphics
|
||||||
public void CopyBufferToBuffer(
|
public void CopyBufferToBuffer(
|
||||||
GpuBuffer source,
|
GpuBuffer source,
|
||||||
GpuBuffer destination,
|
GpuBuffer destination,
|
||||||
in BufferCopy copyParams
|
in BufferCopy copyParams,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertNotSubmitted();
|
AssertNotSubmitted();
|
||||||
|
@ -2280,7 +2311,8 @@ namespace MoonWorks.Graphics
|
||||||
Handle,
|
Handle,
|
||||||
source.Handle,
|
source.Handle,
|
||||||
destination.Handle,
|
destination.Handle,
|
||||||
copyParams.ToRefresh()
|
copyParams.ToRefresh(),
|
||||||
|
(Refresh.CopyOptions) option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2289,12 +2321,14 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void CopyBufferToBuffer(
|
public void CopyBufferToBuffer(
|
||||||
GpuBuffer source,
|
GpuBuffer source,
|
||||||
GpuBuffer destination
|
GpuBuffer destination,
|
||||||
|
CopyOptions option
|
||||||
) {
|
) {
|
||||||
CopyBufferToBuffer(
|
CopyBufferToBuffer(
|
||||||
source,
|
source,
|
||||||
destination,
|
destination,
|
||||||
new BufferCopy(0, 0, source.Size)
|
new BufferCopy(0, 0, source.Size),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,14 @@ namespace MoonWorks.Graphics.Font
|
||||||
imagePath,
|
imagePath,
|
||||||
transferBuffer,
|
transferBuffer,
|
||||||
0,
|
0,
|
||||||
SetDataOptions.Overwrite
|
TransferOptions.Overwrite
|
||||||
);
|
);
|
||||||
|
|
||||||
commandBuffer.BeginCopyPass();
|
commandBuffer.BeginCopyPass();
|
||||||
commandBuffer.UploadToTexture(
|
commandBuffer.UploadToTexture(
|
||||||
transferBuffer,
|
transferBuffer,
|
||||||
texture
|
texture,
|
||||||
|
CopyOptions.SafeOverwrite
|
||||||
);
|
);
|
||||||
commandBuffer.EndCopyPass();
|
commandBuffer.EndCopyPass();
|
||||||
|
|
||||||
|
|
|
@ -124,11 +124,11 @@ namespace MoonWorks.Graphics.Font
|
||||||
|
|
||||||
if (vertexDataLengthInBytes > 0 && indexDataLengthInBytes > 0)
|
if (vertexDataLengthInBytes > 0 && indexDataLengthInBytes > 0)
|
||||||
{
|
{
|
||||||
TransferBuffer.SetData(vertexSpan, SetDataOptions.Discard);
|
TransferBuffer.SetData(vertexSpan, TransferOptions.Discard);
|
||||||
TransferBuffer.SetData(indexSpan, (uint) vertexSpan.Length, SetDataOptions.Overwrite);
|
TransferBuffer.SetData(indexSpan, (uint) vertexSpan.Length, TransferOptions.Overwrite);
|
||||||
|
|
||||||
commandBuffer.UploadToBuffer(TransferBuffer, VertexBuffer, new BufferCopy(0, 0, (uint) vertexSpan.Length));
|
commandBuffer.UploadToBuffer(TransferBuffer, VertexBuffer, new BufferCopy(0, 0, (uint) vertexSpan.Length), CopyOptions.SafeDiscard);
|
||||||
commandBuffer.UploadToBuffer(TransferBuffer, IndexBuffer, new BufferCopy((uint) vertexSpan.Length, 0, (uint) indexSpan.Length));
|
commandBuffer.UploadToBuffer(TransferBuffer, IndexBuffer, new BufferCopy((uint) vertexSpan.Length, 0, (uint) indexSpan.Length), CopyOptions.SafeDiscard);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrimitiveCount = vertexCount / 2;
|
PrimitiveCount = vertexCount / 2;
|
||||||
|
|
|
@ -152,7 +152,7 @@ namespace MoonWorks.Graphics
|
||||||
Span<byte> data,
|
Span<byte> data,
|
||||||
TransferBuffer transferBuffer,
|
TransferBuffer transferBuffer,
|
||||||
uint bufferOffsetInBytes,
|
uint bufferOffsetInBytes,
|
||||||
SetDataOptions option
|
TransferOptions option
|
||||||
) {
|
) {
|
||||||
var pixelData = GetPixelDataFromBytes(data, out var w, out var h, out var sizeInBytes);
|
var pixelData = GetPixelDataFromBytes(data, out var w, out var h, out var sizeInBytes);
|
||||||
var length = transferBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
var length = transferBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
||||||
|
@ -167,7 +167,7 @@ namespace MoonWorks.Graphics
|
||||||
Stream stream,
|
Stream stream,
|
||||||
TransferBuffer transferBuffer,
|
TransferBuffer transferBuffer,
|
||||||
uint bufferOffsetInBytes,
|
uint bufferOffsetInBytes,
|
||||||
SetDataOptions option
|
TransferOptions option
|
||||||
) {
|
) {
|
||||||
var pixelData = GetPixelDataFromStream(stream, out var w, out var h, out var sizeInBytes);
|
var pixelData = GetPixelDataFromStream(stream, out var w, out var h, out var sizeInBytes);
|
||||||
var length = transferBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
var length = transferBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
||||||
|
@ -182,7 +182,7 @@ namespace MoonWorks.Graphics
|
||||||
string path,
|
string path,
|
||||||
TransferBuffer transferBuffer,
|
TransferBuffer transferBuffer,
|
||||||
uint bufferOffsetInBytes,
|
uint bufferOffsetInBytes,
|
||||||
SetDataOptions option
|
TransferOptions option
|
||||||
) {
|
) {
|
||||||
var pixelData = GetPixelDataFromFile(path, out var w, out var h, out var sizeInBytes);
|
var pixelData = GetPixelDataFromFile(path, out var w, out var h, out var sizeInBytes);
|
||||||
var length = transferBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
var length = transferBuffer.SetData(new Span<byte>((void*) pixelData, (int) sizeInBytes), bufferOffsetInBytes, option);
|
||||||
|
|
|
@ -297,12 +297,18 @@ namespace MoonWorks.Graphics
|
||||||
IntOpaqueWhite
|
IntOpaqueWhite
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SetDataOptions
|
public enum TransferOptions
|
||||||
{
|
{
|
||||||
Discard,
|
Discard,
|
||||||
Overwrite
|
Overwrite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum CopyOptions
|
||||||
|
{
|
||||||
|
SafeDiscard,
|
||||||
|
SafeOverwrite
|
||||||
|
}
|
||||||
|
|
||||||
public enum Backend
|
public enum Backend
|
||||||
{
|
{
|
||||||
DontCare,
|
DontCare,
|
||||||
|
|
|
@ -21,8 +21,8 @@ namespace MoonWorks.Graphics
|
||||||
uint dataOffset = 0;
|
uint dataOffset = 0;
|
||||||
uint dataSize = 1024;
|
uint dataSize = 1024;
|
||||||
|
|
||||||
List<(GpuBuffer, BufferCopy)> BufferUploads = new List<(GpuBuffer, BufferCopy)>();
|
List<(GpuBuffer, BufferCopy, CopyOptions)> BufferUploads = new List<(GpuBuffer, BufferCopy, CopyOptions)>();
|
||||||
List<(TextureSlice, uint)> TextureUploads = new List<(TextureSlice, uint)>();
|
List<(TextureSlice, uint, CopyOptions)> TextureUploads = new List<(TextureSlice, uint, CopyOptions)>();
|
||||||
|
|
||||||
public ResourceUploader(GraphicsDevice device) : base(device)
|
public ResourceUploader(GraphicsDevice device) : base(device)
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ namespace MoonWorks.Graphics
|
||||||
var lengthInBytes = (uint) (Marshal.SizeOf<T>() * data.Length);
|
var lengthInBytes = (uint) (Marshal.SizeOf<T>() * data.Length);
|
||||||
var gpuBuffer = new GpuBuffer(Device, usageFlags, lengthInBytes);
|
var gpuBuffer = new GpuBuffer(Device, usageFlags, lengthInBytes);
|
||||||
|
|
||||||
SetBufferData(gpuBuffer, 0, data);
|
SetBufferData(gpuBuffer, 0, data, CopyOptions.SafeOverwrite);
|
||||||
|
|
||||||
return gpuBuffer;
|
return gpuBuffer;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ namespace MoonWorks.Graphics
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prepares upload of data into a GpuBuffer.
|
/// Prepares upload of data into a GpuBuffer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetBufferData<T>(GpuBuffer buffer, uint bufferOffsetInElements, Span<T> data) where T : unmanaged
|
public void SetBufferData<T>(GpuBuffer buffer, uint bufferOffsetInElements, Span<T> data, CopyOptions option) where T : unmanaged
|
||||||
{
|
{
|
||||||
uint elementSize = (uint) Marshal.SizeOf<T>();
|
uint elementSize = (uint) Marshal.SizeOf<T>();
|
||||||
uint offsetInBytes = elementSize * bufferOffsetInElements;
|
uint offsetInBytes = elementSize * bufferOffsetInElements;
|
||||||
|
@ -60,7 +60,7 @@ namespace MoonWorks.Graphics
|
||||||
}
|
}
|
||||||
|
|
||||||
var bufferCopyParams = new BufferCopy(resourceOffset, offsetInBytes, lengthInBytes);
|
var bufferCopyParams = new BufferCopy(resourceOffset, offsetInBytes, lengthInBytes);
|
||||||
BufferUploads.Add((buffer, bufferCopyParams));
|
BufferUploads.Add((buffer, bufferCopyParams, option));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Textures
|
// Textures
|
||||||
|
@ -68,7 +68,7 @@ namespace MoonWorks.Graphics
|
||||||
public Texture CreateTexture2D(Span<byte> pixelData, uint width, uint height)
|
public Texture CreateTexture2D(Span<byte> pixelData, uint width, uint height)
|
||||||
{
|
{
|
||||||
var texture = Texture.CreateTexture2D(Device, width, height, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
|
var texture = Texture.CreateTexture2D(Device, width, height, TextureFormat.R8G8B8A8, TextureUsageFlags.Sampler);
|
||||||
SetTextureData(texture, pixelData);
|
SetTextureData(texture, pixelData, CopyOptions.SafeOverwrite);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ namespace MoonWorks.Graphics
|
||||||
Depth = 1
|
Depth = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
SetTextureData(textureSlice, byteSpan);
|
SetTextureData(textureSlice, byteSpan, CopyOptions.SafeOverwrite);
|
||||||
|
|
||||||
NativeMemory.Free(byteBuffer);
|
NativeMemory.Free(byteBuffer);
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ namespace MoonWorks.Graphics
|
||||||
var pixelData = ImageUtils.GetPixelDataFromBytes(compressedImageData, out var _, out var _, out var sizeInBytes);
|
var pixelData = ImageUtils.GetPixelDataFromBytes(compressedImageData, out var _, out var _, out var sizeInBytes);
|
||||||
var pixelSpan = new Span<byte>((void*) pixelData, (int) sizeInBytes);
|
var pixelSpan = new Span<byte>((void*) pixelData, (int) sizeInBytes);
|
||||||
|
|
||||||
SetTextureData(textureSlice, pixelSpan);
|
SetTextureData(textureSlice, pixelSpan, CopyOptions.SafeOverwrite);
|
||||||
|
|
||||||
ImageUtils.FreePixelData(pixelData);
|
ImageUtils.FreePixelData(pixelData);
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ namespace MoonWorks.Graphics
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Prepares upload of pixel data into a TextureSlice.
|
/// Prepares upload of pixel data into a TextureSlice.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetTextureData<T>(TextureSlice textureSlice, Span<T> data) where T : unmanaged
|
public void SetTextureData<T>(TextureSlice textureSlice, Span<T> data, CopyOptions option) where T : unmanaged
|
||||||
{
|
{
|
||||||
var elementSize = Marshal.SizeOf<T>();
|
var elementSize = Marshal.SizeOf<T>();
|
||||||
var dataLengthInBytes = (uint) (elementSize * data.Length);
|
var dataLengthInBytes = (uint) (elementSize * data.Length);
|
||||||
|
@ -214,7 +214,7 @@ namespace MoonWorks.Graphics
|
||||||
resourceOffset = CopyDataAligned(dataPtr, dataLengthInBytes, Texture.TexelSize(textureSlice.Texture.Format));
|
resourceOffset = CopyDataAligned(dataPtr, dataLengthInBytes, Texture.TexelSize(textureSlice.Texture.Format));
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureUploads.Add((textureSlice, resourceOffset));
|
TextureUploads.Add((textureSlice, resourceOffset, option));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload
|
// Upload
|
||||||
|
@ -257,23 +257,24 @@ namespace MoonWorks.Graphics
|
||||||
}
|
}
|
||||||
|
|
||||||
var dataSpan = new Span<byte>(data, (int) dataSize);
|
var dataSpan = new Span<byte>(data, (int) dataSize);
|
||||||
TransferBuffer.SetData(dataSpan, SetDataOptions.Discard);
|
TransferBuffer.SetData(dataSpan, TransferOptions.Discard);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RecordUploadCommands(CommandBuffer commandBuffer)
|
private void RecordUploadCommands(CommandBuffer commandBuffer)
|
||||||
{
|
{
|
||||||
commandBuffer.BeginCopyPass();
|
commandBuffer.BeginCopyPass();
|
||||||
|
|
||||||
foreach (var (gpuBuffer, bufferCopyParams) in BufferUploads)
|
foreach (var (gpuBuffer, bufferCopyParams, option) in BufferUploads)
|
||||||
{
|
{
|
||||||
commandBuffer.UploadToBuffer(
|
commandBuffer.UploadToBuffer(
|
||||||
TransferBuffer,
|
TransferBuffer,
|
||||||
gpuBuffer,
|
gpuBuffer,
|
||||||
bufferCopyParams
|
bufferCopyParams,
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var (textureSlice, offset) in TextureUploads)
|
foreach (var (textureSlice, offset, option) in TextureUploads)
|
||||||
{
|
{
|
||||||
commandBuffer.UploadToTexture(
|
commandBuffer.UploadToTexture(
|
||||||
TransferBuffer,
|
TransferBuffer,
|
||||||
|
@ -282,7 +283,8 @@ namespace MoonWorks.Graphics
|
||||||
offset,
|
offset,
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
)
|
),
|
||||||
|
option
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace MoonWorks.Graphics
|
||||||
public unsafe uint SetData<T>(
|
public unsafe uint SetData<T>(
|
||||||
Span<T> data,
|
Span<T> data,
|
||||||
uint bufferOffsetInBytes,
|
uint bufferOffsetInBytes,
|
||||||
SetDataOptions setDataOption
|
TransferOptions setDataOption
|
||||||
) where T : unmanaged
|
) where T : unmanaged
|
||||||
{
|
{
|
||||||
var elementSize = Marshal.SizeOf<T>();
|
var elementSize = Marshal.SizeOf<T>();
|
||||||
|
@ -73,7 +73,7 @@ namespace MoonWorks.Graphics
|
||||||
|
|
||||||
fixed (T* dataPtr = data)
|
fixed (T* dataPtr = data)
|
||||||
{
|
{
|
||||||
Refresh.Refresh_SetData(
|
Refresh.Refresh_SetTransferData(
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
(nint) dataPtr,
|
(nint) dataPtr,
|
||||||
Handle,
|
Handle,
|
||||||
|
@ -83,7 +83,7 @@ namespace MoonWorks.Graphics
|
||||||
dstOffset = bufferOffsetInBytes,
|
dstOffset = bufferOffsetInBytes,
|
||||||
size = dataLengthInBytes
|
size = dataLengthInBytes
|
||||||
},
|
},
|
||||||
(Refresh.SetDataOptions) setDataOption
|
(Refresh.TransferOptions) setDataOption
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ namespace MoonWorks.Graphics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public unsafe uint SetData<T>(
|
public unsafe uint SetData<T>(
|
||||||
Span<T> data,
|
Span<T> data,
|
||||||
SetDataOptions setDataOption
|
TransferOptions setDataOption
|
||||||
) where T : unmanaged
|
) where T : unmanaged
|
||||||
{
|
{
|
||||||
return SetData(data, 0, setDataOption);
|
return SetData(data, 0, setDataOption);
|
||||||
|
@ -125,7 +125,7 @@ namespace MoonWorks.Graphics
|
||||||
|
|
||||||
fixed (T* dataPtr = data)
|
fixed (T* dataPtr = data)
|
||||||
{
|
{
|
||||||
Refresh.Refresh_GetData(
|
Refresh.Refresh_GetTransferData(
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
(nint) dataPtr,
|
(nint) dataPtr,
|
||||||
|
|
|
@ -243,9 +243,9 @@ namespace MoonWorks.Video
|
||||||
TransferBuffer?.Dispose();
|
TransferBuffer?.Dispose();
|
||||||
TransferBuffer = new TransferBuffer(Device, (uint) (ySpan.Length + uSpan.Length + vSpan.Length));
|
TransferBuffer = new TransferBuffer(Device, (uint) (ySpan.Length + uSpan.Length + vSpan.Length));
|
||||||
}
|
}
|
||||||
TransferBuffer.SetData(ySpan, 0, SetDataOptions.Discard);
|
TransferBuffer.SetData(ySpan, 0, TransferOptions.Discard);
|
||||||
TransferBuffer.SetData(uSpan, (uint) ySpan.Length, SetDataOptions.Overwrite);
|
TransferBuffer.SetData(uSpan, (uint) ySpan.Length, TransferOptions.Overwrite);
|
||||||
TransferBuffer.SetData(vSpan, (uint) (ySpan.Length + uSpan.Length), SetDataOptions.Overwrite);
|
TransferBuffer.SetData(vSpan, (uint) (ySpan.Length + uSpan.Length), TransferOptions.Overwrite);
|
||||||
|
|
||||||
commandBuffer.BeginCopyPass();
|
commandBuffer.BeginCopyPass();
|
||||||
|
|
||||||
|
@ -257,7 +257,8 @@ namespace MoonWorks.Video
|
||||||
BufferOffset = 0,
|
BufferOffset = 0,
|
||||||
BufferStride = CurrentStream.yStride,
|
BufferStride = CurrentStream.yStride,
|
||||||
BufferImageHeight = yTexture.Height
|
BufferImageHeight = yTexture.Height
|
||||||
}
|
},
|
||||||
|
CopyOptions.SafeDiscard
|
||||||
);
|
);
|
||||||
|
|
||||||
commandBuffer.UploadToTexture(
|
commandBuffer.UploadToTexture(
|
||||||
|
@ -267,7 +268,8 @@ namespace MoonWorks.Video
|
||||||
BufferOffset = (uint) ySpan.Length,
|
BufferOffset = (uint) ySpan.Length,
|
||||||
BufferStride = CurrentStream.uvStride,
|
BufferStride = CurrentStream.uvStride,
|
||||||
BufferImageHeight = uTexture.Height
|
BufferImageHeight = uTexture.Height
|
||||||
}
|
},
|
||||||
|
CopyOptions.SafeDiscard
|
||||||
);
|
);
|
||||||
|
|
||||||
commandBuffer.UploadToTexture(
|
commandBuffer.UploadToTexture(
|
||||||
|
@ -278,7 +280,8 @@ namespace MoonWorks.Video
|
||||||
BufferOffset = (uint) (ySpan.Length + uSpan.Length),
|
BufferOffset = (uint) (ySpan.Length + uSpan.Length),
|
||||||
BufferStride = CurrentStream.uvStride,
|
BufferStride = CurrentStream.uvStride,
|
||||||
BufferImageHeight = vTexture.Height
|
BufferImageHeight = vTexture.Height
|
||||||
}
|
},
|
||||||
|
CopyOptions.SafeDiscard
|
||||||
);
|
);
|
||||||
|
|
||||||
commandBuffer.EndCopyPass();
|
commandBuffer.EndCopyPass();
|
||||||
|
|
Loading…
Reference in New Issue