From e58b540c4e2a8df460e0e357e3f341842dd59a71 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 31 Dec 2019 00:22:58 -0300 Subject: Add XML documentation to Ryujinx.Graphics.Gpu.Memory --- Ryujinx.Graphics.Gpu/Memory/BufferManager.cs | 156 +++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) (limited to 'Ryujinx.Graphics.Gpu/Memory/BufferManager.cs') diff --git a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs index d02146b4..1d27bc7e 100644 --- a/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs +++ b/Ryujinx.Graphics.Gpu/Memory/BufferManager.cs @@ -6,6 +6,9 @@ using System; namespace Ryujinx.Graphics.Gpu.Memory { + /// + /// Buffer manager. + /// class BufferManager { private const int OverlapsBufferInitialCapacity = 10; @@ -56,6 +59,10 @@ namespace Ryujinx.Graphics.Gpu.Memory private bool _rebind; + /// + /// Creates a new instance of the buffer manager. + /// + /// The GPU context that the buffer manager belongs to public BufferManager(GpuContext context) { _context = context; @@ -79,6 +86,12 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Sets the memory range with the index buffer data, to be used for subsequent draw calls. + /// + /// Start GPU virtual address of the index buffer + /// Size, in bytes, of the index buffer + /// Type of each index buffer element public void SetIndexBuffer(ulong gpuVa, ulong size, IndexType type) { ulong address = TranslateAndCreateBuffer(gpuVa, size); @@ -90,6 +103,14 @@ namespace Ryujinx.Graphics.Gpu.Memory _indexBufferDirty = true; } + /// + /// Sets the memory range with vertex buffer data, to be used for subsequent draw calls. + /// + /// Index of the vertex buffer (up to 16) + /// GPU virtual address of the buffer + /// Size in bytes of the buffer + /// Stride of the buffer, defined as the number of bytes of each vertex + /// Vertex divisor of the buffer, for instanced draws public void SetVertexBuffer(int index, ulong gpuVa, ulong size, int stride, int divisor) { ulong address = TranslateAndCreateBuffer(gpuVa, size); @@ -111,6 +132,13 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Sets a storage buffer on the compute pipeline. + /// Storage buffers can be read and written to on shaders. + /// + /// Index of the storage buffer + /// Start GPU virtual address of the buffer + /// Size in bytes of the storage buffer public void SetComputeStorageBuffer(int index, ulong gpuVa, ulong size) { size += gpuVa & ((ulong)_context.Capabilities.StorageBufferOffsetAlignment - 1); @@ -122,6 +150,14 @@ namespace Ryujinx.Graphics.Gpu.Memory _cpStorageBuffers.Bind(index, address, size); } + /// + /// Sets a storage buffer on the graphics pipeline. + /// Storage buffers can be read and written to on shaders. + /// + /// Index of the shader stage + /// Index of the storage buffer + /// Start GPU virtual address of the buffer + /// Size in bytes of the storage buffer public void SetGraphicsStorageBuffer(int stage, int index, ulong gpuVa, ulong size) { size += gpuVa & ((ulong)_context.Capabilities.StorageBufferOffsetAlignment - 1); @@ -139,6 +175,13 @@ namespace Ryujinx.Graphics.Gpu.Memory _gpStorageBuffers[stage].Bind(index, address, size); } + /// + /// Sets a uniform buffer on the compute pipeline. + /// Uniform buffers are read-only from shaders, and have a small capacity. + /// + /// Index of the uniform buffer + /// Start GPU virtual address of the buffer + /// Size in bytes of the storage buffer public void SetComputeUniformBuffer(int index, ulong gpuVa, ulong size) { ulong address = TranslateAndCreateBuffer(gpuVa, size); @@ -146,6 +189,14 @@ namespace Ryujinx.Graphics.Gpu.Memory _cpUniformBuffers.Bind(index, address, size); } + /// + /// Sets a uniform buffer on the graphics pipeline. + /// Uniform buffers are read-only from shaders, and have a small capacity. + /// + /// Index of the shader stage + /// Index of the uniform buffer + /// Start GPU virtual address of the buffer + /// Size in bytes of the storage buffer public void SetGraphicsUniformBuffer(int stage, int index, ulong gpuVa, ulong size) { ulong address = TranslateAndCreateBuffer(gpuVa, size); @@ -155,11 +206,22 @@ namespace Ryujinx.Graphics.Gpu.Memory _gpUniformBuffersDirty = true; } + /// + /// Sets the enabled storage buffers mask on the compute pipeline. + /// Each bit set on the mask indicates that the respective buffer index is enabled. + /// + /// Buffer enable mask public void SetComputeStorageBufferEnableMask(uint mask) { _cpStorageBuffers.EnableMask = mask; } + /// + /// Sets the enabled storage buffers mask on the graphics pipeline. + /// Each bit set on the mask indicates that the respective buffer index is enabled. + /// + /// Index of the shader stage + /// Buffer enable mask public void SetGraphicsStorageBufferEnableMask(int stage, uint mask) { _gpStorageBuffers[stage].EnableMask = mask; @@ -167,11 +229,22 @@ namespace Ryujinx.Graphics.Gpu.Memory _gpStorageBuffersDirty = true; } + /// + /// Sets the enabled uniform buffers mask on the compute pipeline. + /// Each bit set on the mask indicates that the respective buffer index is enabled. + /// + /// Buffer enable mask public void SetComputeUniformBufferEnableMask(uint mask) { _cpUniformBuffers.EnableMask = mask; } + /// + /// Sets the enabled uniform buffers mask on the graphics pipeline. + /// Each bit set on the mask indicates that the respective buffer index is enabled. + /// + /// Index of the shader stage + /// Buffer enable mask public void SetGraphicsUniformBufferEnableMask(int stage, uint mask) { _gpUniformBuffers[stage].EnableMask = mask; @@ -179,6 +252,13 @@ namespace Ryujinx.Graphics.Gpu.Memory _gpUniformBuffersDirty = true; } + /// + /// Performs address translation of the GPU virtual address, and creates a + /// new buffer, if needed, for the specified range. + /// + /// Start GPU virtual address of the buffer + /// Size in bytes of the buffer + /// CPU virtual address of the buffer, after address translation private ulong TranslateAndCreateBuffer(ulong gpuVa, ulong size) { if (gpuVa == 0) @@ -210,6 +290,13 @@ namespace Ryujinx.Graphics.Gpu.Memory return address; } + /// + /// Creates a new buffer for the specified range, if needed. + /// If a buffer where this range can be fully contained already exists, + /// then the creation of a new buffer is not necessary. + /// + /// Address of the buffer in guest memory + /// Size in bytes of the buffer private void CreateBuffer(ulong address, ulong size) { int overlapsCount = _buffers.FindOverlapsNonOverlapping(address, size, ref _bufferOverlaps); @@ -266,6 +353,9 @@ namespace Ryujinx.Graphics.Gpu.Memory ShrinkOverlapsBufferIfNeeded(); } + /// + /// Resizes the temporary buffer used for range list intersection results, if it has grown too much. + /// private void ShrinkOverlapsBufferIfNeeded() { if (_bufferOverlaps.Length > OverlapsBufferMaxCapacity) @@ -274,16 +364,31 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Gets the address of the compute uniform buffer currently bound at the given index. + /// + /// Index of the uniform buffer binding + /// The uniform buffer address, or a undefined value if the buffer is not currently bound public ulong GetComputeUniformBufferAddress(int index) { return _cpUniformBuffers.Buffers[index].Address; } + /// + /// Gets the address of the graphics uniform buffer currently bound at the given index. + /// + /// Index of the shader stage + /// Index of the uniform buffer binding + /// The uniform buffer address, or a undefined value if the buffer is not currently bound public ulong GetGraphicsUniformBufferAddress(int stage, int index) { return _gpUniformBuffers[stage].Buffers[index].Address; } + /// + /// Ensures that the compute engine bindings are visible to the host GPU. + /// This actually performs the binding using the host graphics API. + /// public void CommitComputeBindings() { uint enableMask = _cpStorageBuffers.EnableMask; @@ -332,6 +437,10 @@ namespace Ryujinx.Graphics.Gpu.Memory _rebind = true; } + /// + /// Ensures that the graphics engine bindings are visible to the host GPU. + /// This actually performs the binding using the host graphics API. + /// public void CommitBindings() { if (_indexBufferDirty || _rebind) @@ -414,16 +523,31 @@ namespace Ryujinx.Graphics.Gpu.Memory _rebind = false; } + /// + /// Bind respective buffer bindings on the host API. + /// + /// Bindings to bind + /// True to bind as storage buffer, false to bind as uniform buffers private void BindBuffers(BuffersPerStage[] bindings, bool isStorage) { BindOrUpdateBuffers(bindings, bind: true, isStorage); } + /// + /// Updates data for the already bound buffer bindings. + /// + /// Bindings to update private void UpdateBuffers(BuffersPerStage[] bindings) { BindOrUpdateBuffers(bindings, bind: false); } + /// + /// This binds buffer into the host API, or updates data for already bound buffers. + /// + /// Bindings to bind or update + /// True to bind, false to update + /// True to bind as storage buffer, false to bind as uniform buffers private void BindOrUpdateBuffers(BuffersPerStage[] bindings, bool bind, bool isStorage = false) { for (ShaderStage stage = ShaderStage.Vertex; stage <= ShaderStage.Fragment; stage++) @@ -461,6 +585,13 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Binds a buffer on the host API. + /// + /// Index to bind the buffer into + /// Shader stage to bind the buffer into + /// Buffer address and size + /// True to bind as storage buffer, false to bind as uniform buffer private void BindBuffer(int index, ShaderStage stage, BufferBounds bounds, bool isStorage) { BufferRange buffer = GetBufferRange(bounds.Address, bounds.Size); @@ -475,6 +606,13 @@ namespace Ryujinx.Graphics.Gpu.Memory } } + /// + /// Copy a buffer data from a given address to another. + /// This does a GPU side copy. + /// + /// GPU virtual address of the copy source + /// GPU virtual address of the copy destination + /// Size in bytes of the copy public void CopyBuffer(GpuVa srcVa, GpuVa dstVa, ulong size) { ulong srcAddress = TranslateAndCreateBuffer(srcVa.Pack(), size); @@ -495,11 +633,24 @@ namespace Ryujinx.Graphics.Gpu.Memory dstBuffer.Flush(dstAddress, size); } + /// + /// Gets a buffer sub-range for a given memory range. + /// + /// Start address of the memory range + /// Size in bytes of the memory range + /// The buffer sub-range for the given range private BufferRange GetBufferRange(ulong address, ulong size) { return GetBuffer(address, size).GetRange(address, size); } + /// + /// Gets a buffer for a given memory range. + /// A buffer overlapping with the specified range is assumed to already exist on the cache. + /// + /// Start address of the memory range + /// Size in bytes of the memory range + /// The buffer where the range is fully contained private Buffer GetBuffer(ulong address, ulong size) { Buffer buffer; @@ -518,6 +669,11 @@ namespace Ryujinx.Graphics.Gpu.Memory return buffer; } + /// + /// Performs guest to host memory synchronization of a given memory range. + /// + /// Start address of the memory range + /// Size in bytes of the memory range private void SynchronizeBufferRange(ulong address, ulong size) { if (size != 0) -- cgit v1.2.3