mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-08-02 19:37:10 +02:00
Address PR feedback
This commit is contained in:
parent
2024da7688
commit
bc38064351
39 changed files with 285 additions and 228 deletions
|
@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.Gpu
|
|||
public const int TotalCpUniformBuffers = 8;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of compute storage buffers (this is a API limitation).
|
||||
/// Maximum number of compute storage buffers (this is an API limitation).
|
||||
/// </summary>
|
||||
public const int TotalCpStorageBuffers = 16;
|
||||
|
||||
|
@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Gpu
|
|||
public const int TotalGpUniformBuffers = 18;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of graphics storage buffers (this is a API limitation).
|
||||
/// Maximum number of graphics storage buffers (this is an API limitation).
|
||||
/// </summary>
|
||||
public const int TotalGpStorageBuffers = 16;
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace Ryujinx.Graphics.Gpu
|
|||
/// <summary>
|
||||
/// Number of shader stages.
|
||||
/// </summary>
|
||||
public const int TotalShaderStages = 5;
|
||||
public const int ShaderStages = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of vertex buffers.
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace Ryujinx.Graphics.Gpu
|
|||
/// <summary>
|
||||
/// Processes a single command on the FIFO.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>True if the FIFO still has commands to be processed, false otherwise</returns>
|
||||
private bool Step()
|
||||
{
|
||||
if (_dmaGet != _dmaPut)
|
||||
|
|
|
@ -8,6 +8,9 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
{
|
||||
partial class Methods
|
||||
{
|
||||
private const int NsToTicksFractionNumerator = 384;
|
||||
private const int NsToTicksFractionDenominator = 625;
|
||||
|
||||
private ulong _runningCounter;
|
||||
|
||||
/// <summary>
|
||||
|
@ -103,8 +106,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
|
||||
/// <summary>
|
||||
/// Converts a nanoseconds timestamp value to Maxwell time ticks.
|
||||
/// The frequency is approximately 1.63Hz.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The frequency is 614400000 Hz.
|
||||
/// </remarks>
|
||||
/// <param name="nanoseconds">Timestamp in nanoseconds</param>
|
||||
/// <returns>Maxwell ticks</returns>
|
||||
private static ulong ConvertNanosecondsToTicks(ulong nanoseconds)
|
||||
|
@ -112,13 +117,13 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
// We need to divide first to avoid overflows.
|
||||
// We fix up the result later by calculating the difference and adding
|
||||
// that to the result.
|
||||
ulong divided = nanoseconds / 625;
|
||||
ulong divided = nanoseconds / NsToTicksFractionDenominator;
|
||||
|
||||
ulong rounded = divided * 625;
|
||||
ulong rounded = divided * NsToTicksFractionDenominator;
|
||||
|
||||
ulong errorBias = ((nanoseconds - rounded) * 384) / 625;
|
||||
ulong errorBias = (nanoseconds - rounded) * NsToTicksFractionNumerator / NsToTicksFractionDenominator;
|
||||
|
||||
return divided * 384 + errorBias;
|
||||
return divided * NsToTicksFractionNumerator + errorBias;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,7 +48,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
|
||||
ShaderCache = new ShaderCache(_context);
|
||||
|
||||
_currentProgramInfo = new ShaderProgramInfo[Constants.TotalShaderStages];
|
||||
_currentProgramInfo = new ShaderProgramInfo[Constants.ShaderStages];
|
||||
|
||||
BufferManager = new BufferManager(context);
|
||||
TextureManager = new TextureManager(context);
|
||||
|
@ -201,7 +201,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
|
||||
/// <summary>
|
||||
/// Ensures that the bindings are visible to the host GPU.
|
||||
/// This actually performs the binding using the host graphics API.
|
||||
/// Note: this actually performs the binding using the host graphics API.
|
||||
/// </summary>
|
||||
private void CommitBindings()
|
||||
{
|
||||
|
@ -622,7 +622,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
|
||||
/// <summary>
|
||||
/// Updates host render target color masks, based on guest GPU state.
|
||||
/// This defines with color channels are written to each color buffer.
|
||||
/// This defines which color channels are written to each color buffer.
|
||||
/// </summary>
|
||||
/// <param name="state">Current GPU state</param>
|
||||
private void UpdateRtColorMask(GpuState state)
|
||||
|
@ -739,7 +739,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
|
||||
_vsUsesInstanceId = gs.Shaders[0].Program.Info.UsesInstanceId;
|
||||
|
||||
for (int stage = 0; stage < Constants.TotalShaderStages; stage++)
|
||||
for (int stage = 0; stage < Constants.ShaderStages; stage++)
|
||||
{
|
||||
ShaderProgramInfo info = gs.Shaders[stage].Program?.Info;
|
||||
|
||||
|
@ -845,7 +845,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
return Target.CubemapArray;
|
||||
}
|
||||
|
||||
// TODO: Warning.
|
||||
Logger.PrintWarning(LogClass.Gpu, $"Invalid sampler type \"{type}\".");
|
||||
|
||||
return Target.Texture2D;
|
||||
}
|
||||
|
@ -855,8 +855,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
/// This waits until previous texture writes from the GPU to finish, before
|
||||
/// performing new operations with said textures.
|
||||
/// </summary>
|
||||
/// <param name="state">Current GPU state</param>
|
||||
/// <param name="argument">Method call argument</param>
|
||||
/// <param name="state">Current GPU state (unused)</param>
|
||||
/// <param name="argument">Method call argument (unused)</param>
|
||||
private void TextureBarrier(GpuState state, int argument)
|
||||
{
|
||||
_context.Renderer.Pipeline.TextureBarrier();
|
||||
|
@ -865,8 +865,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
/// <summary>
|
||||
/// Invalidates all modified textures on the cache.
|
||||
/// </summary>
|
||||
/// <param name="state">Current GPU state</param>
|
||||
/// <param name="argument">Method call argument</param>
|
||||
/// <param name="state">Current GPU state (unused)</param>
|
||||
/// <param name="argument">Method call argument (unused)</param>
|
||||
private void InvalidateTextures(GpuState state, int argument)
|
||||
{
|
||||
TextureManager.Flush();
|
||||
|
@ -880,8 +880,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
|||
/// and current access has the same access patterns.
|
||||
/// This may be faster than the regular barrier on tile-based rasterizers.
|
||||
/// </summary>
|
||||
/// <param name="state"></param>
|
||||
/// <param name="argument"></param>
|
||||
/// <param name="state">Current GPU state (unused)</param>
|
||||
/// <param name="argument">Method call argument (unused)</param>
|
||||
private void TextureBarrierTiled(GpuState state, int argument)
|
||||
{
|
||||
_context.Renderer.Pipeline.TextureBarrierTiled();
|
||||
|
|
|
@ -24,9 +24,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
/// <summary>
|
||||
/// Adds a new texture to the cache, even if the texture added is already on the cache.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Using this method is only recommended if you know that the texture is not yet on the cache,
|
||||
/// otherwise it would store the same texture more than once.
|
||||
/// </summary>
|
||||
/// </remarks>
|
||||
/// <param name="texture">The texture to be added to the cache</param>
|
||||
public void Add(Texture texture)
|
||||
{
|
||||
|
@ -48,9 +50,12 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
/// <summary>
|
||||
/// Adds a new texture to the cache, or just moves it to the top of the list if the
|
||||
/// texture is already on the cache. Moving the texture to the top of the list prevents
|
||||
/// it from being deleted, as the textures on the bottom of the list are deleted when new ones are added.
|
||||
/// texture is already on the cache.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Moving the texture to the top of the list prevents it from being deleted,
|
||||
/// as the textures on the bottom of the list are deleted when new ones are added.
|
||||
/// </remarks>
|
||||
/// <param name="texture">The texture to be added, or moved to the top</param>
|
||||
public void Lift(Texture texture)
|
||||
{
|
||||
|
|
|
@ -18,13 +18,19 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
public Format Format { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The block width for compressed formats. Must be 1 for non-compressed formats.
|
||||
/// The block width for compressed formats.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Must be 1 for non-compressed formats.
|
||||
/// </remarks>
|
||||
public int BlockWidth { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The block height for compressed formats. Must be 1 for non-compressed formats.
|
||||
/// The block height for compressed formats.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Must be 1 for non-compressed formats.
|
||||
/// </remarks>
|
||||
public int BlockHeight { get; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -17,8 +17,10 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
/// <summary>
|
||||
/// The maximum ID value of resources on the pool (inclusive).
|
||||
/// The maximum amount of resources on the pool is equal to this value plus one.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The maximum amount of resources on the pool is equal to this value plus one.
|
||||
/// </remarks>
|
||||
public int MaximumId { get; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -2,8 +2,10 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
{
|
||||
/// <summary>
|
||||
/// Represents a filter used with texture minification linear filtering.
|
||||
/// This feature is only supported on NVIDIA GPUs.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This feature is only supported on NVIDIA GPUs.
|
||||
/// </remarks>
|
||||
enum ReductionFilter
|
||||
{
|
||||
Average,
|
||||
|
|
|
@ -190,9 +190,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
/// <summary>
|
||||
/// Changes the texture size.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This operation may also change the size of all mipmap levels, including from the parent
|
||||
/// and other possible child textures, to ensure that all sizes are consistent.
|
||||
/// </summary>
|
||||
/// </remarks>
|
||||
/// <param name="width">The new texture width</param>
|
||||
/// <param name="height">The new texture height</param>
|
||||
/// <param name="depthOrLayers">The new texture depth (for 3D textures) or layers (for layered textures)</param>
|
||||
|
|
|
@ -21,8 +21,10 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
/// <summary>
|
||||
/// Indicates if the texture is a bindless texture.
|
||||
/// For those textures, Handle is ignored.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For those textures, Handle is ignored.
|
||||
/// </remarks>
|
||||
public bool IsBindless { get; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
_texturePoolCache = texturePoolCache;
|
||||
_isCompute = isCompute;
|
||||
|
||||
int stages = isCompute ? 1 : Constants.TotalShaderStages;
|
||||
int stages = isCompute ? 1 : Constants.ShaderStages;
|
||||
|
||||
_textureBindings = new TextureBindingInfo[stages][];
|
||||
_imageBindings = new TextureBindingInfo[stages][];
|
||||
|
@ -135,7 +135,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
/// <summary>
|
||||
/// Ensures that the bindings are visible to the host GPU.
|
||||
/// This actually performs the binding using the host graphics API.
|
||||
/// Note: this actually performs the binding using the host graphics API.
|
||||
/// </summary>
|
||||
public void CommitBindings()
|
||||
{
|
||||
|
@ -164,7 +164,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
/// <summary>
|
||||
/// Ensures that the texture bindings are visible to the host GPU.
|
||||
/// This actually performs the binding using the host graphics API.
|
||||
/// Note: this actually performs the binding using the host graphics API.
|
||||
/// </summary>
|
||||
/// <param name="pool">The current texture pool</param>
|
||||
/// <param name="stage">The shader stage using the textures to be bound</param>
|
||||
|
@ -242,7 +242,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
/// <summary>
|
||||
/// Ensures that the image bindings are visible to the host GPU.
|
||||
/// This actually performs the binding using the host graphics API.
|
||||
/// Note: this actually performs the binding using the host graphics API.
|
||||
/// </summary>
|
||||
/// <param name="pool">The current texture pool</param>
|
||||
/// <param name="stage">The shader stage using the textures to be bound</param>
|
||||
|
|
|
@ -753,9 +753,11 @@ namespace Ryujinx.Graphics.Gpu.Image
|
|||
|
||||
/// <summary>
|
||||
/// Removes a texture from the cache.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This only removes the texture from the internal list, not from the auto-deletion cache.
|
||||
/// It may still have live references after the removal.
|
||||
/// </summary>
|
||||
/// </remarks>
|
||||
/// <param name="texture">The texture to be removed</param>
|
||||
public void RemoveTextureFromCache(Texture texture)
|
||||
{
|
||||
|
|
|
@ -388,7 +388,7 @@ namespace Ryujinx.Graphics.Gpu
|
|||
/// <summary>
|
||||
/// Extracts a 32-bits signed integer constant from the current operation code.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>The 32-bits immediate value encoded at the current operation code</returns>
|
||||
private int GetImm()
|
||||
{
|
||||
// Note: The immediate is signed, the sign-extension is intended here.
|
||||
|
|
|
@ -53,9 +53,11 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Gets a sub-range from the buffer.
|
||||
/// This can be used to bind and use sub-ranges of the buffer on the host API.
|
||||
/// </summary>
|
||||
/// <param name="address">Start address of the sub-range, must be greater or equal to the buffer address</param>
|
||||
/// <remarks>
|
||||
/// This can be used to bind and use sub-ranges of the buffer on the host API.
|
||||
/// </remarks>
|
||||
/// <param name="address">Start address of the sub-range, must be greater than or equal to the buffer address</param>
|
||||
/// <param name="size">Size in bytes of the sub-range, must be less than or equal to the buffer size</param>
|
||||
/// <returns>The buffer sub-range</returns>
|
||||
public BufferRange GetRange(ulong address, ulong size)
|
||||
|
@ -78,9 +80,11 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Performs guest to host memory synchronization of the buffer data.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This causes the buffer data to be overwritten if a write was detected from the CPU,
|
||||
/// since the last call to this method.
|
||||
/// </summary>
|
||||
/// </remarks>
|
||||
/// <param name="address">Start address of the range to synchronize</param>
|
||||
/// <param name="size">Size in bytes of the range to synchronize</param>
|
||||
public void SynchronizeMemory(ulong address, ulong size)
|
||||
|
|
|
@ -76,10 +76,10 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
_cpStorageBuffers = new BuffersPerStage(Constants.TotalCpStorageBuffers);
|
||||
_cpUniformBuffers = new BuffersPerStage(Constants.TotalCpUniformBuffers);
|
||||
|
||||
_gpStorageBuffers = new BuffersPerStage[Constants.TotalShaderStages];
|
||||
_gpUniformBuffers = new BuffersPerStage[Constants.TotalShaderStages];
|
||||
_gpStorageBuffers = new BuffersPerStage[Constants.ShaderStages];
|
||||
_gpUniformBuffers = new BuffersPerStage[Constants.ShaderStages];
|
||||
|
||||
for (int index = 0; index < Constants.TotalShaderStages; index++)
|
||||
for (int index = 0; index < Constants.ShaderStages; index++)
|
||||
{
|
||||
_gpStorageBuffers[index] = new BuffersPerStage(Constants.TotalGpStorageBuffers);
|
||||
_gpUniformBuffers[index] = new BuffersPerStage(Constants.TotalGpUniformBuffers);
|
||||
|
@ -387,7 +387,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Ensures that the compute engine bindings are visible to the host GPU.
|
||||
/// This actually performs the binding using the host graphics API.
|
||||
/// Note: this actually performs the binding using the host graphics API.
|
||||
/// </summary>
|
||||
public void CommitComputeBindings()
|
||||
{
|
||||
|
@ -439,7 +439,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Ensures that the graphics engine bindings are visible to the host GPU.
|
||||
/// This actually performs the binding using the host graphics API.
|
||||
/// Note: this actually performs the binding using the host graphics API.
|
||||
/// </summary>
|
||||
public void CommitBindings()
|
||||
{
|
||||
|
@ -543,11 +543,11 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// This binds buffer into the host API, or updates data for already bound buffers.
|
||||
/// This binds buffers into the host API, or updates data for already bound buffers.
|
||||
/// </summary>
|
||||
/// <param name="bindings">Bindings to bind or update</param>
|
||||
/// <param name="bind">True to bind, false to update</param>
|
||||
/// <param name="isStorage">True to bind as storage buffer, false to bind as uniform buffers</param>
|
||||
/// <param name="isStorage">True to bind as storage buffer, false to bind as uniform buffer</param>
|
||||
private void BindOrUpdateBuffers(BuffersPerStage[] bindings, bool bind, bool isStorage = false)
|
||||
{
|
||||
for (ShaderStage stage = ShaderStage.Vertex; stage <= ShaderStage.Fragment; stage++)
|
||||
|
@ -608,8 +608,10 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Copy a buffer data from a given address to another.
|
||||
/// This does a GPU side copy.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This does a GPU side copy.
|
||||
/// </remarks>
|
||||
/// <param name="srcVa">GPU virtual address of the copy source</param>
|
||||
/// <param name="dstVa">GPU virtual address of the copy destination</param>
|
||||
/// <param name="size">Size in bytes of the copy</param>
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
/// Reads a structure from GPU mapped memory.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the structure</typeparam>
|
||||
/// <param name="gpuVa">GPU virtual address where the strcture is located</param>
|
||||
/// <param name="gpuVa">GPU virtual address where the structure is located</param>
|
||||
/// <returns>The structure at the specified memory location</returns>
|
||||
public T Read<T>(ulong gpuVa) where T : struct
|
||||
{
|
||||
|
|
|
@ -39,8 +39,10 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Maps a given range of pages to the specified CPU virtual address.
|
||||
/// All addresses and sizes must be page aligned.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// All addresses and sizes must be page aligned.
|
||||
/// </remarks>
|
||||
/// <param name="pa">CPU virtual address to map into</param>
|
||||
/// <param name="va">GPU virtual address to be mapped</param>
|
||||
/// <param name="size">Size in bytes of the mapping</param>
|
||||
|
@ -59,7 +61,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a given range of pages to a allocated GPU virtual address.
|
||||
/// Maps a given range of pages to an allocated GPU virtual address.
|
||||
/// The memory is automatically allocated by the memory manager.
|
||||
/// </summary>
|
||||
/// <param name="pa">CPU virtual address to map into</param>
|
||||
|
@ -84,7 +86,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps a given range of pages to a allocated GPU virtual address.
|
||||
/// Maps a given range of pages to an allocated GPU virtual address.
|
||||
/// The memory is automatically allocated by the memory manager.
|
||||
/// This also ensures that the mapping is always done in the first 4GB of GPU address space.
|
||||
/// </summary>
|
||||
|
|
|
@ -77,9 +77,11 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Gets the first item on the list overlapping in memory with the specified item.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Despite the name, this has no ordering guarantees of the returned item.
|
||||
/// It only ensures that the item returned overlaps the specified item.
|
||||
/// </summary>
|
||||
/// </remarks>
|
||||
/// <param name="item">Item to check for overlaps</param>
|
||||
/// <returns>The overlapping item, or the default value for the type if none found</returns>
|
||||
public T FindFirstOverlap(T item)
|
||||
|
@ -89,9 +91,11 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Gets the first item on the list overlapping the specified memory range.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Despite the name, this has no ordering guarantees of the returned item.
|
||||
/// It only ensures that the item returned overlaps the specified memory range.
|
||||
/// </summary>
|
||||
/// </remarks>
|
||||
/// <param name="address">Start address of the range</param>
|
||||
/// <param name="size">Size in bytes or the rangee</param>
|
||||
/// <returns>The overlapping item, or the default value for the type if none found</returns>
|
||||
|
@ -157,10 +161,12 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Gets all items overlapping with the specified item in memory.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method only returns correct results if none of the items on the list overlaps with
|
||||
/// each other. If that is not the case, this method should not be used.
|
||||
/// This method is faster than the regular method to find all overlaps.
|
||||
/// </summary>
|
||||
/// </remarks>
|
||||
/// <param name="item">Item to check for overlaps</param>
|
||||
/// <param name="output">Output array where matches will be written. It is automatically resized to fit the results</param>
|
||||
/// <returns>The number of overlapping items found</returns>
|
||||
|
@ -171,10 +177,12 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
|||
|
||||
/// <summary>
|
||||
/// Gets all items on the list overlapping the specified memory range.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method only returns correct results if none of the items on the list overlaps with
|
||||
/// each other. If that is not the case, this method should not be used.
|
||||
/// This method is faster than the regular method to find all overlaps.
|
||||
/// </summary>
|
||||
/// </remarks>
|
||||
/// <param name="address">Start address of the range</param>
|
||||
/// <param name="size">Size in bytes or the rangee</param>
|
||||
/// <param name="output">Output array where matches will be written. It is automatically resized to fit the results</param>
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
/// </summary>
|
||||
public GraphicsShader()
|
||||
{
|
||||
Shaders = new CachedShader[5];
|
||||
Shaders = new CachedShader[Constants.ShaderStages];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Graphics.GAL;
|
||||
using Ryujinx.Graphics.Gpu.Image;
|
||||
using Ryujinx.Graphics.Gpu.State;
|
||||
|
@ -45,8 +46,10 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
|
||||
/// <summary>
|
||||
/// Gets a compute shader from the cache.
|
||||
/// This automatically translates, compiles and adds the code to the cache if not present.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This automatically translates, compiles and adds the code to the cache if not present.
|
||||
/// </remarks>
|
||||
/// <param name="gpuVa">GPU virtual address of the binary shader code</param>
|
||||
/// <param name="sharedMemorySize">Shared memory size of the compute shader</param>
|
||||
/// <param name="localSizeX">Local group size X of the computer shader</param>
|
||||
|
@ -93,8 +96,10 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
/// <summary>
|
||||
/// Gets a graphics shader program from the shader cache.
|
||||
/// This includes all the specified shader stages.
|
||||
/// This automatically translates, compiles and adds the code to the cache if not present.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This automatically translates, compiles and adds the code to the cache if not present.
|
||||
/// </remarks>
|
||||
/// <param name="state">Current GPU state</param>
|
||||
/// <param name="addresses">Addresses of the shaders for each stage</param>
|
||||
/// <returns>Compiled graphics shader code</returns>
|
||||
|
@ -246,28 +251,25 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
return null;
|
||||
}
|
||||
|
||||
QueryInfoCallback queryInfo = (QueryInfoName info, int index) =>
|
||||
int QueryInfo(QueryInfoName info, int index)
|
||||
{
|
||||
switch (info)
|
||||
return info switch
|
||||
{
|
||||
case QueryInfoName.ComputeLocalSizeX:
|
||||
return localSizeX;
|
||||
case QueryInfoName.ComputeLocalSizeY:
|
||||
return localSizeY;
|
||||
case QueryInfoName.ComputeLocalSizeZ:
|
||||
return localSizeZ;
|
||||
case QueryInfoName.ComputeSharedMemorySize:
|
||||
return sharedMemorySize;
|
||||
}
|
||||
QueryInfoName.ComputeLocalSizeX => localSizeX,
|
||||
QueryInfoName.ComputeLocalSizeY => localSizeY,
|
||||
QueryInfoName.ComputeLocalSizeZ => localSizeZ,
|
||||
QueryInfoName.ComputeSharedMemorySize => sharedMemorySize,
|
||||
_ => QueryInfoCommon(info)
|
||||
};
|
||||
}
|
||||
|
||||
return QueryInfoCommon(info);
|
||||
};
|
||||
TranslatorCallbacks callbacks = new TranslatorCallbacks(QueryInfo, PrintLog);
|
||||
|
||||
ShaderProgram program;
|
||||
|
||||
Span<byte> code = _context.MemoryAccessor.Read(gpuVa, MaxProgramSize);
|
||||
|
||||
program = Translator.Translate(code, queryInfo, DefaultFlags | TranslationFlags.Compute);
|
||||
program = Translator.Translate(code, callbacks, DefaultFlags | TranslationFlags.Compute);
|
||||
|
||||
int[] codeCached = MemoryMarshal.Cast<byte, int>(code.Slice(0, program.Size)).ToArray();
|
||||
|
||||
|
@ -284,13 +286,15 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
|
||||
/// <summary>
|
||||
/// Translates the binary Maxwell shader code to something that the host API accepts.
|
||||
/// This will combine the "Vertex A" and "Vertex B" shader stages, if specified, into one shader.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This will combine the "Vertex A" and "Vertex B" shader stages, if specified, into one shader.
|
||||
/// </remarks>
|
||||
/// <param name="state">Current GPU state</param>
|
||||
/// <param name="stage">Shader stage</param>
|
||||
/// <param name="gpuVa">GPU virtual address of the shader code</param>
|
||||
/// <param name="gpuVaA">Optional GPU virtual address of the "Vertex A" shader code</param>
|
||||
/// <returns></returns>
|
||||
/// <returns>Compiled graphics shader code</returns>
|
||||
private CachedShader TranslateGraphicsShader(GpuState state, ShaderStage stage, ulong gpuVa, ulong gpuVaA = 0)
|
||||
{
|
||||
if (gpuVa == 0)
|
||||
|
@ -298,20 +302,18 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
return new CachedShader(null, null);
|
||||
}
|
||||
|
||||
QueryInfoCallback queryInfo = (QueryInfoName info, int index) =>
|
||||
int QueryInfo(QueryInfoName info, int index)
|
||||
{
|
||||
switch (info)
|
||||
return info switch
|
||||
{
|
||||
case QueryInfoName.IsTextureBuffer:
|
||||
return Convert.ToInt32(QueryIsTextureBuffer(state, (int)stage - 1, index));
|
||||
case QueryInfoName.IsTextureRectangle:
|
||||
return Convert.ToInt32(QueryIsTextureRectangle(state, (int)stage - 1, index));
|
||||
case QueryInfoName.PrimitiveTopology:
|
||||
return (int)GetPrimitiveTopology();
|
||||
}
|
||||
QueryInfoName.IsTextureBuffer => Convert.ToInt32(QueryIsTextureBuffer(state, (int)stage - 1, index)),
|
||||
QueryInfoName.IsTextureRectangle => Convert.ToInt32(QueryIsTextureRectangle(state, (int)stage - 1, index)),
|
||||
QueryInfoName.PrimitiveTopology => (int)GetPrimitiveTopology(),
|
||||
_ => QueryInfoCommon(info)
|
||||
};
|
||||
}
|
||||
|
||||
return QueryInfoCommon(info);
|
||||
};
|
||||
TranslatorCallbacks callbacks = new TranslatorCallbacks(QueryInfo, PrintLog);
|
||||
|
||||
ShaderProgram program;
|
||||
|
||||
|
@ -322,7 +324,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
Span<byte> codeA = _context.MemoryAccessor.Read(gpuVaA, MaxProgramSize);
|
||||
Span<byte> codeB = _context.MemoryAccessor.Read(gpuVa, MaxProgramSize);
|
||||
|
||||
program = Translator.Translate(codeA, codeB, queryInfo, DefaultFlags);
|
||||
program = Translator.Translate(codeA, codeB, callbacks, DefaultFlags);
|
||||
|
||||
// TODO: We should also take "codeA" into account.
|
||||
codeCached = MemoryMarshal.Cast<byte, int>(codeB.Slice(0, program.Size)).ToArray();
|
||||
|
@ -342,7 +344,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
{
|
||||
Span<byte> code = _context.MemoryAccessor.Read(gpuVa, MaxProgramSize);
|
||||
|
||||
program = Translator.Translate(code, queryInfo, DefaultFlags);
|
||||
program = Translator.Translate(code, callbacks, DefaultFlags);
|
||||
|
||||
codeCached = MemoryMarshal.Cast<byte, int>(code.Slice(0, program.Size)).ToArray();
|
||||
|
||||
|
@ -483,17 +485,21 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
/// <returns>Requested information</returns>
|
||||
private int QueryInfoCommon(QueryInfoName info)
|
||||
{
|
||||
switch (info)
|
||||
return info switch
|
||||
{
|
||||
case QueryInfoName.MaximumViewportDimensions:
|
||||
return _context.Capabilities.MaximumViewportDimensions;
|
||||
case QueryInfoName.StorageBufferOffsetAlignment:
|
||||
return _context.Capabilities.StorageBufferOffsetAlignment;
|
||||
case QueryInfoName.SupportsNonConstantTextureOffset:
|
||||
return Convert.ToInt32(_context.Capabilities.SupportsNonConstantTextureOffset);
|
||||
}
|
||||
QueryInfoName.StorageBufferOffsetAlignment => _context.Capabilities.StorageBufferOffsetAlignment,
|
||||
QueryInfoName.SupportsNonConstantTextureOffset => Convert.ToInt32(_context.Capabilities.SupportsNonConstantTextureOffset),
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
return 0;
|
||||
/// <summary>
|
||||
/// Prints a warning from the shader code translator.
|
||||
/// </summary>
|
||||
/// <param name="message">Warning message</param>
|
||||
private static void PrintLog(string message)
|
||||
{
|
||||
Logger.PrintWarning(LogClass.Gpu, $"Shader translator: {message}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -187,7 +187,7 @@ namespace Ryujinx.Graphics.Gpu.State
|
|||
/// </summary>
|
||||
/// <param name="m1">First register offset</param>
|
||||
/// <param name="m2">Second register offset</param>
|
||||
/// <param name="m3">Third register offset</param>
|
||||
/// <param name="m3">Third register offset</param>
|
||||
/// <returns>True if any register was modified, false otherwise</returns>
|
||||
public bool QueryModified(MethodOffset m1, MethodOffset m2, MethodOffset m3)
|
||||
{
|
||||
|
@ -207,7 +207,7 @@ namespace Ryujinx.Graphics.Gpu.State
|
|||
/// </summary>
|
||||
/// <param name="m1">First register offset</param>
|
||||
/// <param name="m2">Second register offset</param>
|
||||
/// <param name="m3">Third register offset</param>
|
||||
/// <param name="m3">Third register offset</param>
|
||||
/// <param name="m4">Fourth register offset</param>
|
||||
/// <returns>True if any register was modified, false otherwise</returns>
|
||||
public bool QueryModified(MethodOffset m1, MethodOffset m2, MethodOffset m3, MethodOffset m4)
|
||||
|
@ -230,7 +230,7 @@ namespace Ryujinx.Graphics.Gpu.State
|
|||
/// </summary>
|
||||
/// <param name="m1">First register offset</param>
|
||||
/// <param name="m2">Second register offset</param>
|
||||
/// <param name="m3">Third register offset</param>
|
||||
/// <param name="m3">Third register offset</param>
|
||||
/// <param name="m4">Fourth register offset</param>
|
||||
/// <param name="m5">Fifth register offset</param>
|
||||
/// <returns>True if any register was modified, false otherwise</returns>
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.Gpu.State
|
|||
/// <summary>
|
||||
/// Packs the split address into a 64-bits address value.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>The 64-bits address value</returns>
|
||||
public ulong Pack()
|
||||
{
|
||||
return Low | ((ulong)High << 32);
|
||||
|
|
|
@ -3,6 +3,9 @@ namespace Ryujinx.Graphics.Gpu.State
|
|||
/// <summary>
|
||||
/// GPU method offset.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is indexed in 32 bits word.
|
||||
/// </remarks>
|
||||
enum MethodOffset
|
||||
{
|
||||
I2mParams = 0x60,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue