2021-06-23 19:51:41 -04:00
|
|
|
|
using Ryujinx.Common;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
using Ryujinx.Graphics.GAL;
|
2021-03-08 16:43:39 -05:00
|
|
|
|
using Ryujinx.Graphics.Gpu.Image;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
using Ryujinx.Graphics.Shader;
|
|
|
|
|
using System;
|
2021-03-08 16:43:39 -05:00
|
|
|
|
using System.Collections.Generic;
|
2020-11-08 06:10:00 -05:00
|
|
|
|
using System.Collections.ObjectModel;
|
2021-08-11 15:33:43 -04:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Memory
|
|
|
|
|
{
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Buffer manager.
|
|
|
|
|
/// </summary>
|
2021-06-29 13:32:02 -04:00
|
|
|
|
class BufferManager
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2021-06-23 19:51:41 -04:00
|
|
|
|
private readonly GpuContext _context;
|
2021-06-29 13:32:02 -04:00
|
|
|
|
private readonly GpuChannel _channel;
|
2019-11-24 19:29:37 -05:00
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
|
private IndexBuffer _indexBuffer;
|
2021-06-23 19:51:41 -04:00
|
|
|
|
private readonly VertexBuffer[] _vertexBuffers;
|
|
|
|
|
private readonly BufferBounds[] _transformFeedbackBuffers;
|
|
|
|
|
private readonly List<BufferTextureBinding> _bufferTextures;
|
2021-08-11 15:33:43 -04:00
|
|
|
|
private readonly BufferRange[] _ranges;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Holds shader stage buffer state and binding information.
|
|
|
|
|
/// </summary>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
private class BuffersPerStage
|
|
|
|
|
{
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Shader buffer binding information.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public BufferDescriptor[] Bindings { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Buffer regions.
|
|
|
|
|
/// </summary>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public BufferBounds[] Buffers { get; }
|
|
|
|
|
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Total amount of buffers used on the shader.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Count { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new instance of the shader stage buffer information.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="count">Maximum amount of buffers that the shader stage can use</param>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public BuffersPerStage(int count)
|
|
|
|
|
{
|
2020-11-08 06:10:00 -05:00
|
|
|
|
Bindings = new BufferDescriptor[count];
|
2019-10-13 02:02:07 -04:00
|
|
|
|
Buffers = new BufferBounds[count];
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the region of a buffer at a given slot.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">Buffer slot</param>
|
|
|
|
|
/// <param name="address">Region virtual address</param>
|
|
|
|
|
/// <param name="size">Region size in bytes</param>
|
2021-01-17 15:08:06 -05:00
|
|
|
|
/// <param name="flags">Buffer usage flags</param>
|
|
|
|
|
public void SetBounds(int index, ulong address, ulong size, BufferUsageFlags flags = BufferUsageFlags.None)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2021-01-17 15:08:06 -05:00
|
|
|
|
Buffers[index] = new BufferBounds(address, size, flags);
|
2020-11-08 06:10:00 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets shader buffer binding information.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="descriptors">Buffer binding information</param>
|
|
|
|
|
public void SetBindings(ReadOnlyCollection<BufferDescriptor> descriptors)
|
|
|
|
|
{
|
|
|
|
|
if (descriptors == null)
|
|
|
|
|
{
|
|
|
|
|
Count = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
descriptors.CopyTo(Bindings, 0);
|
|
|
|
|
Count = descriptors.Count;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 19:51:41 -04:00
|
|
|
|
private readonly BuffersPerStage _cpStorageBuffers;
|
|
|
|
|
private readonly BuffersPerStage _cpUniformBuffers;
|
|
|
|
|
private readonly BuffersPerStage[] _gpStorageBuffers;
|
|
|
|
|
private readonly BuffersPerStage[] _gpUniformBuffers;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
private bool _gpStorageBuffersDirty;
|
|
|
|
|
private bool _gpUniformBuffersDirty;
|
|
|
|
|
|
|
|
|
|
private bool _indexBufferDirty;
|
|
|
|
|
private bool _vertexBuffersDirty;
|
2019-11-23 00:17:22 -05:00
|
|
|
|
private uint _vertexBuffersEnableMask;
|
2020-07-14 23:01:10 -04:00
|
|
|
|
private bool _transformFeedbackBuffersDirty;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
private bool _rebind;
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new instance of the buffer manager.
|
|
|
|
|
/// </summary>
|
2021-06-23 19:51:41 -04:00
|
|
|
|
/// <param name="context">GPU context that the buffer manager belongs to</param>
|
2021-06-29 13:32:02 -04:00
|
|
|
|
/// <param name="channel">GPU channel that the buffer manager belongs to</param>
|
|
|
|
|
public BufferManager(GpuContext context, GpuChannel channel)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
|
|
|
|
_context = context;
|
2021-06-29 13:32:02 -04:00
|
|
|
|
_channel = channel;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
_vertexBuffers = new VertexBuffer[Constants.TotalVertexBuffers];
|
|
|
|
|
|
2020-07-14 23:01:10 -04:00
|
|
|
|
_transformFeedbackBuffers = new BufferBounds[Constants.TotalTransformFeedbackBuffers];
|
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
|
_cpStorageBuffers = new BuffersPerStage(Constants.TotalCpStorageBuffers);
|
|
|
|
|
_cpUniformBuffers = new BuffersPerStage(Constants.TotalCpUniformBuffers);
|
|
|
|
|
|
2020-01-01 10:39:09 -05:00
|
|
|
|
_gpStorageBuffers = new BuffersPerStage[Constants.ShaderStages];
|
|
|
|
|
_gpUniformBuffers = new BuffersPerStage[Constants.ShaderStages];
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2020-01-01 10:39:09 -05:00
|
|
|
|
for (int index = 0; index < Constants.ShaderStages; index++)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
|
|
|
|
_gpStorageBuffers[index] = new BuffersPerStage(Constants.TotalGpStorageBuffers);
|
|
|
|
|
_gpUniformBuffers[index] = new BuffersPerStage(Constants.TotalGpUniformBuffers);
|
|
|
|
|
}
|
2021-03-08 16:43:39 -05:00
|
|
|
|
|
|
|
|
|
_bufferTextures = new List<BufferTextureBinding>();
|
2021-08-11 15:33:43 -04:00
|
|
|
|
|
|
|
|
|
_ranges = new BufferRange[Constants.TotalGpUniformBuffers * Constants.ShaderStages];
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 19:51:41 -04:00
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the memory range with the index buffer data, to be used for subsequent draw calls.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gpuVa">Start GPU virtual address of the index buffer</param>
|
|
|
|
|
/// <param name="size">Size, in bytes, of the index buffer</param>
|
|
|
|
|
/// <param name="type">Type of each index buffer element</param>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public void SetIndexBuffer(ulong gpuVa, ulong size, IndexType type)
|
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
_indexBuffer.Address = address;
|
2021-06-23 19:51:41 -04:00
|
|
|
|
_indexBuffer.Size = size;
|
|
|
|
|
_indexBuffer.Type = type;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
_indexBufferDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 18:41:27 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a new index buffer that overrides the one set on the call to <see cref="CommitGraphicsBindings"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="buffer">Buffer to be used as index buffer</param>
|
|
|
|
|
/// <param name="type">Type of each index buffer element</param>
|
|
|
|
|
public void SetIndexBuffer(BufferRange buffer, IndexType type)
|
|
|
|
|
{
|
|
|
|
|
_context.Renderer.Pipeline.SetIndexBuffer(buffer, type);
|
|
|
|
|
|
|
|
|
|
_indexBufferDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the memory range with vertex buffer data, to be used for subsequent draw calls.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">Index of the vertex buffer (up to 16)</param>
|
|
|
|
|
/// <param name="gpuVa">GPU virtual address of the buffer</param>
|
|
|
|
|
/// <param name="size">Size in bytes of the buffer</param>
|
|
|
|
|
/// <param name="stride">Stride of the buffer, defined as the number of bytes of each vertex</param>
|
|
|
|
|
/// <param name="divisor">Vertex divisor of the buffer, for instanced draws</param>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public void SetVertexBuffer(int index, ulong gpuVa, ulong size, int stride, int divisor)
|
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
_vertexBuffers[index].Address = address;
|
2021-06-23 19:51:41 -04:00
|
|
|
|
_vertexBuffers[index].Size = size;
|
|
|
|
|
_vertexBuffers[index].Stride = stride;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
_vertexBuffers[index].Divisor = divisor;
|
|
|
|
|
|
|
|
|
|
_vertexBuffersDirty = true;
|
2019-11-23 00:17:22 -05:00
|
|
|
|
|
|
|
|
|
if (address != 0)
|
|
|
|
|
{
|
|
|
|
|
_vertexBuffersEnableMask |= 1u << index;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_vertexBuffersEnableMask &= ~(1u << index);
|
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 20:40:50 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a transform feedback buffer on the graphics pipeline.
|
|
|
|
|
/// The output from the vertex transformation stages are written into the feedback buffer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">Index of the transform feedback buffer</param>
|
|
|
|
|
/// <param name="gpuVa">Start GPU virtual address of the buffer</param>
|
|
|
|
|
/// <param name="size">Size in bytes of the transform feedback buffer</param>
|
2020-07-14 23:01:10 -04:00
|
|
|
|
public void SetTransformFeedbackBuffer(int index, ulong gpuVa, ulong size)
|
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size);
|
2020-07-14 23:01:10 -04:00
|
|
|
|
|
2020-11-08 06:10:00 -05:00
|
|
|
|
_transformFeedbackBuffers[index] = new BufferBounds(address, size);
|
2020-07-14 23:01:10 -04:00
|
|
|
|
_transformFeedbackBuffersDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a storage buffer on the compute pipeline.
|
|
|
|
|
/// Storage buffers can be read and written to on shaders.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">Index of the storage buffer</param>
|
|
|
|
|
/// <param name="gpuVa">Start GPU virtual address of the buffer</param>
|
|
|
|
|
/// <param name="size">Size in bytes of the storage buffer</param>
|
2021-01-17 15:08:06 -05:00
|
|
|
|
/// <param name="flags">Buffer usage flags</param>
|
|
|
|
|
public void SetComputeStorageBuffer(int index, ulong gpuVa, ulong size, BufferUsageFlags flags)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-11-30 21:53:09 -05:00
|
|
|
|
size += gpuVa & ((ulong)_context.Capabilities.StorageBufferOffsetAlignment - 1);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-11-30 21:53:09 -05:00
|
|
|
|
gpuVa = BitUtils.AlignDown(gpuVa, _context.Capabilities.StorageBufferOffsetAlignment);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2021-01-17 15:08:06 -05:00
|
|
|
|
_cpStorageBuffers.SetBounds(index, address, size, flags);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a storage buffer on the graphics pipeline.
|
|
|
|
|
/// Storage buffers can be read and written to on shaders.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stage">Index of the shader stage</param>
|
|
|
|
|
/// <param name="index">Index of the storage buffer</param>
|
|
|
|
|
/// <param name="gpuVa">Start GPU virtual address of the buffer</param>
|
|
|
|
|
/// <param name="size">Size in bytes of the storage buffer</param>
|
2021-01-17 15:08:06 -05:00
|
|
|
|
/// <param name="flags">Buffer usage flags</param>
|
|
|
|
|
public void SetGraphicsStorageBuffer(int stage, int index, ulong gpuVa, ulong size, BufferUsageFlags flags)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2019-11-30 21:53:09 -05:00
|
|
|
|
size += gpuVa & ((ulong)_context.Capabilities.StorageBufferOffsetAlignment - 1);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-11-30 21:53:09 -05:00
|
|
|
|
gpuVa = BitUtils.AlignDown(gpuVa, _context.Capabilities.StorageBufferOffsetAlignment);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-10-26 13:50:52 -04:00
|
|
|
|
if (_gpStorageBuffers[stage].Buffers[index].Address != address ||
|
2021-06-23 19:51:41 -04:00
|
|
|
|
_gpStorageBuffers[stage].Buffers[index].Size != size)
|
2019-10-26 13:50:52 -04:00
|
|
|
|
{
|
|
|
|
|
_gpStorageBuffersDirty = true;
|
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2021-01-17 15:08:06 -05:00
|
|
|
|
_gpStorageBuffers[stage].SetBounds(index, address, size, flags);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a uniform buffer on the compute pipeline.
|
|
|
|
|
/// Uniform buffers are read-only from shaders, and have a small capacity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">Index of the uniform buffer</param>
|
|
|
|
|
/// <param name="gpuVa">Start GPU virtual address of the buffer</param>
|
|
|
|
|
/// <param name="size">Size in bytes of the storage buffer</param>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public void SetComputeUniformBuffer(int index, ulong gpuVa, ulong size)
|
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2020-11-08 06:10:00 -05:00
|
|
|
|
_cpUniformBuffers.SetBounds(index, address, size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets a uniform buffer on the graphics pipeline.
|
|
|
|
|
/// Uniform buffers are read-only from shaders, and have a small capacity.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stage">Index of the shader stage</param>
|
|
|
|
|
/// <param name="index">Index of the uniform buffer</param>
|
|
|
|
|
/// <param name="gpuVa">Start GPU virtual address of the buffer</param>
|
|
|
|
|
/// <param name="size">Size in bytes of the storage buffer</param>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public void SetGraphicsUniformBuffer(int stage, int index, ulong gpuVa, ulong size)
|
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
ulong address = _channel.MemoryManager.Physical.BufferCache.TranslateAndCreateBuffer(_channel.MemoryManager, gpuVa, size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2020-11-08 06:10:00 -05:00
|
|
|
|
_gpUniformBuffers[stage].SetBounds(index, address, size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
_gpUniformBuffersDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// Sets the binding points for the storage buffers bound on the compute pipeline.
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// </summary>
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// <param name="descriptors">Buffer descriptors with the binding point values</param>
|
|
|
|
|
public void SetComputeStorageBufferBindings(ReadOnlyCollection<BufferDescriptor> descriptors)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2020-11-08 06:10:00 -05:00
|
|
|
|
_cpStorageBuffers.SetBindings(descriptors);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// Sets the binding points for the storage buffers bound on the graphics pipeline.
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stage">Index of the shader stage</param>
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// <param name="descriptors">Buffer descriptors with the binding point values</param>
|
|
|
|
|
public void SetGraphicsStorageBufferBindings(int stage, ReadOnlyCollection<BufferDescriptor> descriptors)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2020-11-08 06:10:00 -05:00
|
|
|
|
_gpStorageBuffers[stage].SetBindings(descriptors);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
_gpStorageBuffersDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the binding points for the uniform buffers bound on the compute pipeline.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="descriptors">Buffer descriptors with the binding point values</param>
|
|
|
|
|
public void SetComputeUniformBufferBindings(ReadOnlyCollection<BufferDescriptor> descriptors)
|
|
|
|
|
{
|
|
|
|
|
_cpUniformBuffers.SetBindings(descriptors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the enabled uniform buffers mask on the graphics pipeline.
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// Each bit set on the mask indicates that the respective buffer index is enabled.
|
|
|
|
|
/// </summary>
|
2020-11-08 06:10:00 -05:00
|
|
|
|
/// <param name="stage">Index of the shader stage</param>
|
|
|
|
|
/// <param name="descriptors">Buffer descriptors with the binding point values</param>
|
|
|
|
|
public void SetGraphicsUniformBufferBindings(int stage, ReadOnlyCollection<BufferDescriptor> descriptors)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2020-11-08 06:10:00 -05:00
|
|
|
|
_gpUniformBuffers[stage].SetBindings(descriptors);
|
|
|
|
|
_gpUniformBuffersDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 20:40:50 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a bit mask indicating which compute uniform buffers are currently bound.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Mask where each bit set indicates a bound constant buffer</returns>
|
|
|
|
|
public uint GetComputeUniformBufferUseMask()
|
|
|
|
|
{
|
|
|
|
|
uint mask = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < _cpUniformBuffers.Buffers.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (_cpUniformBuffers.Buffers[i].Address != 0)
|
|
|
|
|
{
|
|
|
|
|
mask |= 1u << i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a bit mask indicating which graphics uniform buffers are currently bound.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stage">Index of the shader stage</param>
|
|
|
|
|
/// <returns>Mask where each bit set indicates a bound constant buffer</returns>
|
|
|
|
|
public uint GetGraphicsUniformBufferUseMask(int stage)
|
|
|
|
|
{
|
|
|
|
|
uint mask = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < _gpUniformBuffers[stage].Buffers.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (_gpUniformBuffers[stage].Buffers[i].Address != 0)
|
|
|
|
|
{
|
|
|
|
|
mask |= 1u << i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the address of the compute uniform buffer currently bound at the given index.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index">Index of the uniform buffer binding</param>
|
2020-01-01 18:14:18 -05:00
|
|
|
|
/// <returns>The uniform buffer address, or an undefined value if the buffer is not currently bound</returns>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public ulong GetComputeUniformBufferAddress(int index)
|
|
|
|
|
{
|
|
|
|
|
return _cpUniformBuffers.Buffers[index].Address;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the address of the graphics uniform buffer currently bound at the given index.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stage">Index of the shader stage</param>
|
|
|
|
|
/// <param name="index">Index of the uniform buffer binding</param>
|
2020-01-01 18:14:18 -05:00
|
|
|
|
/// <returns>The uniform buffer address, or an undefined value if the buffer is not currently bound</returns>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public ulong GetGraphicsUniformBufferAddress(int stage, int index)
|
|
|
|
|
{
|
|
|
|
|
return _gpUniformBuffers[stage].Buffers[index].Address;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures that the compute engine bindings are visible to the host GPU.
|
2020-01-01 10:39:09 -05:00
|
|
|
|
/// Note: this actually performs the binding using the host graphics API.
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// </summary>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public void CommitComputeBindings()
|
|
|
|
|
{
|
2021-08-11 15:33:43 -04:00
|
|
|
|
var bufferCache = _channel.MemoryManager.Physical.BufferCache;
|
2019-10-17 22:41:18 -04:00
|
|
|
|
|
2021-08-11 15:33:43 -04:00
|
|
|
|
BindBuffers(bufferCache, _cpStorageBuffers, isStorage: true);
|
|
|
|
|
BindBuffers(bufferCache, _cpUniformBuffers, isStorage: false);
|
2020-11-08 06:10:00 -05:00
|
|
|
|
|
2021-03-08 16:43:39 -05:00
|
|
|
|
CommitBufferTextureBindings();
|
|
|
|
|
|
2019-10-17 22:41:18 -04:00
|
|
|
|
// Force rebind after doing compute work.
|
2021-06-23 19:51:41 -04:00
|
|
|
|
Rebind();
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 16:43:39 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Commit any queued buffer texture bindings.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void CommitBufferTextureBindings()
|
|
|
|
|
{
|
|
|
|
|
if (_bufferTextures.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var binding in _bufferTextures)
|
|
|
|
|
{
|
2021-06-23 19:51:41 -04:00
|
|
|
|
var isStore = binding.BindingInfo.Flags.HasFlag(TextureUsageFlags.ImageStore);
|
2021-06-29 13:32:02 -04:00
|
|
|
|
var range = _channel.MemoryManager.Physical.BufferCache.GetBufferRange(binding.Address, binding.Size, isStore);
|
2021-06-23 19:51:41 -04:00
|
|
|
|
binding.Texture.SetStorage(range);
|
2021-03-08 16:43:39 -05:00
|
|
|
|
|
|
|
|
|
// The texture must be rebound to use the new storage if it was updated.
|
|
|
|
|
|
|
|
|
|
if (binding.IsImage)
|
|
|
|
|
{
|
|
|
|
|
_context.Renderer.Pipeline.SetImage(binding.BindingInfo.Binding, binding.Texture, binding.Format);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_context.Renderer.Pipeline.SetTexture(binding.BindingInfo.Binding, binding.Texture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_bufferTextures.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ensures that the graphics engine bindings are visible to the host GPU.
|
2020-01-01 10:39:09 -05:00
|
|
|
|
/// Note: this actually performs the binding using the host graphics API.
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// </summary>
|
2020-04-25 09:02:18 -04:00
|
|
|
|
public void CommitGraphicsBindings()
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2021-08-11 15:33:43 -04:00
|
|
|
|
var bufferCache = _channel.MemoryManager.Physical.BufferCache;
|
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
|
if (_indexBufferDirty || _rebind)
|
|
|
|
|
{
|
|
|
|
|
_indexBufferDirty = false;
|
|
|
|
|
|
|
|
|
|
if (_indexBuffer.Address != 0)
|
|
|
|
|
{
|
2021-08-11 15:33:43 -04:00
|
|
|
|
BufferRange buffer = bufferCache.GetBufferRange(_indexBuffer.Address, _indexBuffer.Size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-29 12:41:50 -05:00
|
|
|
|
_context.Renderer.Pipeline.SetIndexBuffer(buffer, _indexBuffer.Type);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (_indexBuffer.Address != 0)
|
|
|
|
|
{
|
2021-08-11 15:33:43 -04:00
|
|
|
|
bufferCache.SynchronizeBufferRange(_indexBuffer.Address, _indexBuffer.Size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-23 00:17:22 -05:00
|
|
|
|
uint vbEnableMask = _vertexBuffersEnableMask;
|
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
|
if (_vertexBuffersDirty || _rebind)
|
|
|
|
|
{
|
|
|
|
|
_vertexBuffersDirty = false;
|
|
|
|
|
|
2020-05-23 05:46:09 -04:00
|
|
|
|
Span<VertexBufferDescriptor> vertexBuffers = stackalloc VertexBufferDescriptor[Constants.TotalVertexBuffers];
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-11-23 00:17:22 -05:00
|
|
|
|
for (int index = 0; (vbEnableMask >> index) != 0; index++)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
|
|
|
|
VertexBuffer vb = _vertexBuffers[index];
|
|
|
|
|
|
|
|
|
|
if (vb.Address == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 15:33:43 -04:00
|
|
|
|
BufferRange buffer = bufferCache.GetBufferRange(vb.Address, vb.Size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
vertexBuffers[index] = new VertexBufferDescriptor(buffer, vb.Stride, vb.Divisor);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 12:41:50 -05:00
|
|
|
|
_context.Renderer.Pipeline.SetVertexBuffers(vertexBuffers);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-11-23 00:17:22 -05:00
|
|
|
|
for (int index = 0; (vbEnableMask >> index) != 0; index++)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
|
|
|
|
VertexBuffer vb = _vertexBuffers[index];
|
|
|
|
|
|
|
|
|
|
if (vb.Address == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 15:33:43 -04:00
|
|
|
|
bufferCache.SynchronizeBufferRange(vb.Address, vb.Size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 18:05:06 -04:00
|
|
|
|
if (_transformFeedbackBuffersDirty || _rebind)
|
2020-07-14 23:01:10 -04:00
|
|
|
|
{
|
|
|
|
|
_transformFeedbackBuffersDirty = false;
|
|
|
|
|
|
2020-10-25 16:23:42 -04:00
|
|
|
|
Span<BufferRange> tfbs = stackalloc BufferRange[Constants.TotalTransformFeedbackBuffers];
|
|
|
|
|
|
2020-07-14 23:01:10 -04:00
|
|
|
|
for (int index = 0; index < Constants.TotalTransformFeedbackBuffers; index++)
|
|
|
|
|
{
|
|
|
|
|
BufferBounds tfb = _transformFeedbackBuffers[index];
|
|
|
|
|
|
|
|
|
|
if (tfb.Address == 0)
|
|
|
|
|
{
|
2020-10-25 16:23:42 -04:00
|
|
|
|
tfbs[index] = BufferRange.Empty;
|
2020-07-14 23:01:10 -04:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 13:09:27 -04:00
|
|
|
|
tfbs[index] = bufferCache.GetBufferRange(tfb.Address, tfb.Size, write: true);
|
2020-07-14 23:01:10 -04:00
|
|
|
|
}
|
2020-10-25 16:23:42 -04:00
|
|
|
|
|
|
|
|
|
_context.Renderer.Pipeline.SetTransformFeedbackBuffers(tfbs);
|
2020-07-14 23:01:10 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int index = 0; index < Constants.TotalTransformFeedbackBuffers; index++)
|
|
|
|
|
{
|
|
|
|
|
BufferBounds tfb = _transformFeedbackBuffers[index];
|
|
|
|
|
|
|
|
|
|
if (tfb.Address == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 15:33:43 -04:00
|
|
|
|
bufferCache.SynchronizeBufferRange(tfb.Address, tfb.Size);
|
2020-07-14 23:01:10 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
|
if (_gpStorageBuffersDirty || _rebind)
|
|
|
|
|
{
|
|
|
|
|
_gpStorageBuffersDirty = false;
|
|
|
|
|
|
2021-08-11 15:33:43 -04:00
|
|
|
|
BindBuffers(bufferCache, _gpStorageBuffers, isStorage: true);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UpdateBuffers(_gpStorageBuffers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_gpUniformBuffersDirty || _rebind)
|
|
|
|
|
{
|
|
|
|
|
_gpUniformBuffersDirty = false;
|
|
|
|
|
|
2021-08-11 15:33:43 -04:00
|
|
|
|
BindBuffers(bufferCache, _gpUniformBuffers, isStorage: false);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UpdateBuffers(_gpUniformBuffers);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 16:43:39 -05:00
|
|
|
|
CommitBufferTextureBindings();
|
|
|
|
|
|
2019-10-13 02:02:07 -04:00
|
|
|
|
_rebind = false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bind respective buffer bindings on the host API.
|
|
|
|
|
/// </summary>
|
2021-08-11 15:33:43 -04:00
|
|
|
|
/// <param name="bufferCache">Buffer cache holding the buffers for the specified ranges</param>
|
|
|
|
|
/// <param name="bindings">Buffer memory ranges to bind</param>
|
|
|
|
|
/// <param name="isStorage">True to bind as storage buffer, false to bind as uniform buffer</param>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private void BindBuffers(BufferCache bufferCache, BuffersPerStage[] bindings, bool isStorage)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2021-08-11 15:33:43 -04:00
|
|
|
|
int rangesFirst = 0;
|
|
|
|
|
int rangesCount = 0;
|
2020-11-08 06:10:00 -05:00
|
|
|
|
|
2021-08-11 15:33:43 -04:00
|
|
|
|
Span<BufferRange> ranges = _ranges;
|
2020-11-08 06:10:00 -05:00
|
|
|
|
|
|
|
|
|
for (ShaderStage stage = ShaderStage.Vertex; stage <= ShaderStage.Fragment; stage++)
|
|
|
|
|
{
|
|
|
|
|
ref var buffers = ref bindings[(int)stage - 1];
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < buffers.Count; index++)
|
|
|
|
|
{
|
|
|
|
|
ref var bindingInfo = ref buffers.Bindings[index];
|
|
|
|
|
|
|
|
|
|
BufferBounds bounds = buffers.Buffers[bindingInfo.Slot];
|
|
|
|
|
|
|
|
|
|
if (bounds.Address != 0)
|
|
|
|
|
{
|
2021-06-23 19:51:41 -04:00
|
|
|
|
var isWrite = bounds.Flags.HasFlag(BufferUsageFlags.Write);
|
2021-08-11 15:33:43 -04:00
|
|
|
|
var range = isStorage
|
|
|
|
|
? bufferCache.GetBufferRangeTillEnd(bounds.Address, bounds.Size, isWrite)
|
|
|
|
|
: bufferCache.GetBufferRange(bounds.Address, bounds.Size);
|
|
|
|
|
|
|
|
|
|
if (rangesCount == 0)
|
|
|
|
|
{
|
|
|
|
|
rangesFirst = bindingInfo.Binding;
|
|
|
|
|
}
|
|
|
|
|
else if (bindingInfo.Binding != rangesFirst + rangesCount)
|
|
|
|
|
{
|
|
|
|
|
SetHostBuffers(ranges, rangesFirst, rangesCount, isStorage);
|
|
|
|
|
rangesFirst = bindingInfo.Binding;
|
|
|
|
|
rangesCount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ranges[rangesCount++] = range;
|
2020-11-08 06:10:00 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 15:33:43 -04:00
|
|
|
|
if (rangesCount != 0)
|
|
|
|
|
{
|
|
|
|
|
SetHostBuffers(ranges, rangesFirst, rangesCount, isStorage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bind respective buffer bindings on the host API.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bufferCache">Buffer cache holding the buffers for the specified ranges</param>
|
|
|
|
|
/// <param name="buffers">Buffer memory ranges to bind</param>
|
|
|
|
|
/// <param name="isStorage">True to bind as storage buffer, false to bind as uniform buffer</param>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private void BindBuffers(BufferCache bufferCache, BuffersPerStage buffers, bool isStorage)
|
|
|
|
|
{
|
|
|
|
|
int rangesFirst = 0;
|
|
|
|
|
int rangesCount = 0;
|
|
|
|
|
|
|
|
|
|
Span<BufferRange> ranges = _ranges;
|
|
|
|
|
|
|
|
|
|
for (int index = 0; index < buffers.Count; index++)
|
|
|
|
|
{
|
|
|
|
|
ref var bindingInfo = ref buffers.Bindings[index];
|
|
|
|
|
|
|
|
|
|
BufferBounds bounds = buffers.Buffers[bindingInfo.Slot];
|
|
|
|
|
|
|
|
|
|
if (bounds.Address != 0)
|
|
|
|
|
{
|
|
|
|
|
var isWrite = bounds.Flags.HasFlag(BufferUsageFlags.Write);
|
|
|
|
|
var range = isStorage
|
|
|
|
|
? bufferCache.GetBufferRangeTillEnd(bounds.Address, bounds.Size, isWrite)
|
|
|
|
|
: bufferCache.GetBufferRange(bounds.Address, bounds.Size);
|
|
|
|
|
|
|
|
|
|
if (rangesCount == 0)
|
|
|
|
|
{
|
|
|
|
|
rangesFirst = bindingInfo.Binding;
|
|
|
|
|
}
|
|
|
|
|
else if (bindingInfo.Binding != rangesFirst + rangesCount)
|
|
|
|
|
{
|
|
|
|
|
SetHostBuffers(ranges, rangesFirst, rangesCount, isStorage);
|
|
|
|
|
rangesFirst = bindingInfo.Binding;
|
|
|
|
|
rangesCount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ranges[rangesCount++] = range;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rangesCount != 0)
|
|
|
|
|
{
|
|
|
|
|
SetHostBuffers(ranges, rangesFirst, rangesCount, isStorage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bind respective buffer bindings on the host API.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ranges">Host buffers to bind, with their offsets and sizes</param>
|
|
|
|
|
/// <param name="first">First binding point</param>
|
|
|
|
|
/// <param name="count">Number of bindings</param>
|
|
|
|
|
/// <param name="isStorage">Indicates if the buffers are storage or uniform buffers</param>
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
private void SetHostBuffers(ReadOnlySpan<BufferRange> ranges, int first, int count, bool isStorage)
|
|
|
|
|
{
|
2020-11-08 06:10:00 -05:00
|
|
|
|
if (isStorage)
|
|
|
|
|
{
|
2021-08-11 15:33:43 -04:00
|
|
|
|
_context.Renderer.Pipeline.SetStorageBuffers(first, ranges.Slice(0, count));
|
2020-11-08 06:10:00 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-08-11 15:33:43 -04:00
|
|
|
|
_context.Renderer.Pipeline.SetUniformBuffers(first, ranges.Slice(0, count));
|
2020-11-08 06:10:00 -05:00
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates data for the already bound buffer bindings.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bindings">Bindings to update</param>
|
2019-10-13 02:02:07 -04:00
|
|
|
|
private void UpdateBuffers(BuffersPerStage[] bindings)
|
|
|
|
|
{
|
|
|
|
|
for (ShaderStage stage = ShaderStage.Vertex; stage <= ShaderStage.Fragment; stage++)
|
|
|
|
|
{
|
2020-11-08 06:10:00 -05:00
|
|
|
|
ref var buffers = ref bindings[(int)stage - 1];
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2020-11-08 06:10:00 -05:00
|
|
|
|
for (int index = 0; index < buffers.Count; index++)
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2020-11-08 06:10:00 -05:00
|
|
|
|
ref var binding = ref buffers.Bindings[index];
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2020-11-08 06:10:00 -05:00
|
|
|
|
BufferBounds bounds = buffers.Buffers[binding.Slot];
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
if (bounds.Address == 0)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 13:32:02 -04:00
|
|
|
|
_channel.MemoryManager.Physical.BufferCache.SynchronizeBufferRange(bounds.Address, bounds.Size);
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-25 09:02:18 -04:00
|
|
|
|
/// <summary>
|
2021-03-08 16:43:39 -05:00
|
|
|
|
/// Sets the buffer storage of a buffer texture. This will be bound when the buffer manager commits bindings.
|
2020-04-25 09:02:18 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="texture">Buffer texture</param>
|
|
|
|
|
/// <param name="address">Address of the buffer in memory</param>
|
|
|
|
|
/// <param name="size">Size of the buffer in bytes</param>
|
2021-03-08 16:43:39 -05:00
|
|
|
|
/// <param name="bindingInfo">Binding info for the buffer texture</param>
|
|
|
|
|
/// <param name="format">Format of the buffer texture</param>
|
|
|
|
|
/// <param name="isImage">Whether the binding is for an image or a sampler</param>
|
|
|
|
|
public void SetBufferTextureStorage(ITexture texture, ulong address, ulong size, TextureBindingInfo bindingInfo, Format format, bool isImage)
|
2020-04-25 09:02:18 -04:00
|
|
|
|
{
|
2021-06-29 13:32:02 -04:00
|
|
|
|
_channel.MemoryManager.Physical.BufferCache.CreateBuffer(address, size);
|
2020-04-25 09:02:18 -04:00
|
|
|
|
|
2021-03-08 16:43:39 -05:00
|
|
|
|
_bufferTextures.Add(new BufferTextureBinding(texture, address, size, bindingInfo, format, isImage));
|
2020-04-25 09:02:18 -04:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// <summary>
|
2021-06-23 19:51:41 -04:00
|
|
|
|
/// Force all bound textures and images to be rebound the next time CommitBindings is called.
|
2019-12-30 22:22:58 -05:00
|
|
|
|
/// </summary>
|
2021-06-23 19:51:41 -04:00
|
|
|
|
public void Rebind()
|
2019-10-13 02:02:07 -04:00
|
|
|
|
{
|
2021-06-23 19:51:41 -04:00
|
|
|
|
_rebind = true;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-23 19:51:41 -04:00
|
|
|
|
}
|