forked from Mirror/Ryujinx
Address PR feedback
This commit is contained in:
parent
40ef18d759
commit
92703af555
39 changed files with 285 additions and 228 deletions
|
@ -5,20 +5,17 @@ namespace Ryujinx.Graphics.GAL
|
|||
public bool SupportsAstcCompression { get; }
|
||||
public bool SupportsNonConstantTextureOffset { get; }
|
||||
|
||||
public int MaximumViewportDimensions { get; }
|
||||
public int MaximumComputeSharedMemorySize { get; }
|
||||
public int StorageBufferOffsetAlignment { get; }
|
||||
|
||||
public Capabilities(
|
||||
bool supportsAstcCompression,
|
||||
bool supportsNonConstantTextureOffset,
|
||||
int maximumViewportDimensions,
|
||||
int maximumComputeSharedMemorySize,
|
||||
int storageBufferOffsetAlignment)
|
||||
{
|
||||
SupportsAstcCompression = supportsAstcCompression;
|
||||
SupportsNonConstantTextureOffset = supportsNonConstantTextureOffset;
|
||||
MaximumViewportDimensions = maximumViewportDimensions;
|
||||
MaximumComputeSharedMemorySize = maximumComputeSharedMemorySize;
|
||||
StorageBufferOffsetAlignment = storageBufferOffsetAlignment;
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
{
|
||||
private static Lazy<bool> _supportsAstcCompression = new Lazy<bool>(() => HasExtension("GL_KHR_texture_compression_astc_ldr"));
|
||||
|
||||
private static Lazy<int> _maximumViewportDimensions = new Lazy<int>(() => GetLimit(All.MaxViewportDims));
|
||||
private static Lazy<int> _maximumComputeSharedMemorySize = new Lazy<int>(() => GetLimit(All.MaxComputeSharedMemorySize));
|
||||
private static Lazy<int> _storageBufferOffsetAlignment = new Lazy<int>(() => GetLimit(All.ShaderStorageBufferOffsetAlignment));
|
||||
|
||||
|
@ -16,7 +15,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
public static bool SupportsAstcCompression => _supportsAstcCompression.Value;
|
||||
public static bool SupportsNonConstantTextureOffset => _isNvidiaDriver.Value;
|
||||
|
||||
public static int MaximumViewportDimensions => _maximumViewportDimensions.Value;
|
||||
public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value;
|
||||
public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value;
|
||||
|
||||
|
|
|
@ -64,7 +64,6 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
return new Capabilities(
|
||||
HwCapabilities.SupportsAstcCompression,
|
||||
HwCapabilities.SupportsNonConstantTextureOffset,
|
||||
HwCapabilities.MaximumViewportDimensions,
|
||||
HwCapabilities.MaximumComputeSharedMemorySize,
|
||||
HwCapabilities.StorageBufferOffsetAlignment);
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
|
||||
GL.TexParameter(target, TextureParameterName.TextureMaxLevel, maxLevel);
|
||||
|
||||
// TODO: This requires ARB_stencil_texturing, we should uncomment and test this.
|
||||
// GL.TexParameter(target, TextureParameterName.DepthStencilTextureMode, (int)_info.DepthStencilMode.Convert());
|
||||
}
|
||||
|
||||
|
@ -118,7 +119,11 @@ namespace Ryujinx.Graphics.OpenGL
|
|||
}
|
||||
else
|
||||
{
|
||||
// TODO: Improve
|
||||
// TODO: Most graphics APIs doesn't support creating a texture view from a compressed format
|
||||
// with a non-compressed format (or vice-versa), however NVN seems to support it.
|
||||
// So we emulate that here with a texture copy (see the first CopyTo overload).
|
||||
// However right now it only does a single copy right after the view is created,
|
||||
// so it doesn't work for all cases.
|
||||
TextureView emulatedView = (TextureView)_renderer.CreateTexture(info);
|
||||
|
||||
emulatedView._emulatedViewParent = this;
|
||||
|
|
|
@ -91,10 +91,5 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
|
||||
return indentation;
|
||||
}
|
||||
|
||||
public string GetTabString()
|
||||
{
|
||||
return Tab;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -86,6 +86,10 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
{
|
||||
context.Barrier();
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Config.PrintLog($"Invalid barrier mode: {op.Mode}.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void Ipa(EmitterContext context)
|
||||
|
@ -101,8 +105,6 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
|
||||
Operand srcA = Attribute(op.AttributeOffset, iq);
|
||||
|
||||
Operand srcB = GetSrcB(context);
|
||||
|
||||
Operand res = context.FPSaturate(srcA, op.Saturate);
|
||||
|
||||
context.Copy(GetDest(context), res);
|
||||
|
@ -128,7 +130,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
|
||||
if (op.Size > IntegerSize.B64)
|
||||
{
|
||||
// TODO: Warning.
|
||||
context.Config.PrintLog($"Invalid LDC size: {op.Size}.");
|
||||
}
|
||||
|
||||
bool isSmallInt = op.Size < IntegerSize.B32;
|
||||
|
@ -156,7 +158,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
|
||||
if (isSmallInt)
|
||||
{
|
||||
value = ExtractSmallInt(context, op.Size, wordOffset, value);
|
||||
value = ExtractSmallInt(context, op.Size, bitOffset, value);
|
||||
}
|
||||
|
||||
context.Copy(Register(rd), value);
|
||||
|
@ -261,7 +263,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
}
|
||||
else
|
||||
{
|
||||
// Not supported or invalid.
|
||||
context.Config.PrintLog($"Invalid reduction type: {type}.");
|
||||
}
|
||||
break;
|
||||
case AtomicOp.BitwiseAnd:
|
||||
|
@ -271,7 +273,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
}
|
||||
else
|
||||
{
|
||||
// Not supported or invalid.
|
||||
context.Config.PrintLog($"Invalid reduction type: {type}.");
|
||||
}
|
||||
break;
|
||||
case AtomicOp.BitwiseExclusiveOr:
|
||||
|
@ -281,7 +283,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
}
|
||||
else
|
||||
{
|
||||
// Not supported or invalid.
|
||||
context.Config.PrintLog($"Invalid reduction type: {type}.");
|
||||
}
|
||||
break;
|
||||
case AtomicOp.BitwiseOr:
|
||||
|
@ -291,7 +293,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
}
|
||||
else
|
||||
{
|
||||
// Not supported or invalid.
|
||||
context.Config.PrintLog($"Invalid reduction type: {type}.");
|
||||
}
|
||||
break;
|
||||
case AtomicOp.Maximum:
|
||||
|
@ -305,7 +307,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
}
|
||||
else
|
||||
{
|
||||
// Not supported or invalid.
|
||||
context.Config.PrintLog($"Invalid reduction type: {type}.");
|
||||
}
|
||||
break;
|
||||
case AtomicOp.Minimum:
|
||||
|
@ -319,7 +321,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
}
|
||||
else
|
||||
{
|
||||
// Not supported or invalid.
|
||||
context.Config.PrintLog($"Invalid reduction type: {type}.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -333,7 +335,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
|
||||
if (op.Size > IntegerSize.B128)
|
||||
{
|
||||
// TODO: Warning.
|
||||
context.Config.PrintLog($"Invalid load size: {op.Size}.");
|
||||
}
|
||||
|
||||
bool isSmallInt = op.Size < IntegerSize.B32;
|
||||
|
@ -419,7 +421,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
|
||||
if (op.Size > IntegerSize.B128)
|
||||
{
|
||||
// TODO: Warning.
|
||||
context.Config.PrintLog($"Invalid store size: {op.Size}.");
|
||||
}
|
||||
|
||||
bool isSmallInt = op.Size < IntegerSize.B32;
|
||||
|
|
|
@ -11,8 +11,6 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
{
|
||||
public static void Mov(EmitterContext context)
|
||||
{
|
||||
OpCodeAlu op = (OpCodeAlu)context.CurrOp;
|
||||
|
||||
context.Copy(GetDest(context), GetSrcB(context));
|
||||
}
|
||||
|
||||
|
@ -33,7 +31,8 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
|
||||
if (isCC)
|
||||
{
|
||||
// TODO.
|
||||
// TODO: Support Register to condition code flags copy.
|
||||
context.Config.PrintLog("R2P.CC not implemented.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
|
||||
if (type == SamplerType.None)
|
||||
{
|
||||
// TODO: Error, encoding is invalid.
|
||||
context.Config.PrintLog("Invalid image store sampler type.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
}
|
||||
else
|
||||
{
|
||||
// TODO.
|
||||
context.Config.PrintLog("Unsized image store not supported.");
|
||||
}
|
||||
|
||||
Operand[] sources = sourcesList.ToArray();
|
||||
|
@ -180,7 +180,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
|
||||
if (type == SamplerType.None)
|
||||
{
|
||||
// TODO: Error, encoding is invalid.
|
||||
context.Config.PrintLog("Invalid texture sampler type.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -210,40 +210,40 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
{
|
||||
switch (texsOp.Target)
|
||||
{
|
||||
case Decoders.TextureTarget.Texture1DLodZero:
|
||||
case TextureTarget.Texture1DLodZero:
|
||||
sourcesList.Add(Ra());
|
||||
break;
|
||||
|
||||
case Decoders.TextureTarget.Texture2D:
|
||||
case TextureTarget.Texture2D:
|
||||
sourcesList.Add(Ra());
|
||||
sourcesList.Add(Rb());
|
||||
break;
|
||||
|
||||
case Decoders.TextureTarget.Texture2DLodZero:
|
||||
case TextureTarget.Texture2DLodZero:
|
||||
sourcesList.Add(Ra());
|
||||
sourcesList.Add(Rb());
|
||||
sourcesList.Add(ConstF(0));
|
||||
break;
|
||||
|
||||
case Decoders.TextureTarget.Texture2DLodLevel:
|
||||
case Decoders.TextureTarget.Texture2DDepthCompare:
|
||||
case Decoders.TextureTarget.Texture3D:
|
||||
case Decoders.TextureTarget.TextureCube:
|
||||
case TextureTarget.Texture2DLodLevel:
|
||||
case TextureTarget.Texture2DDepthCompare:
|
||||
case TextureTarget.Texture3D:
|
||||
case TextureTarget.TextureCube:
|
||||
sourcesList.Add(Ra());
|
||||
sourcesList.Add(Ra());
|
||||
sourcesList.Add(Rb());
|
||||
break;
|
||||
|
||||
case Decoders.TextureTarget.Texture2DLodZeroDepthCompare:
|
||||
case Decoders.TextureTarget.Texture3DLodZero:
|
||||
case TextureTarget.Texture2DLodZeroDepthCompare:
|
||||
case TextureTarget.Texture3DLodZero:
|
||||
sourcesList.Add(Ra());
|
||||
sourcesList.Add(Ra());
|
||||
sourcesList.Add(Rb());
|
||||
sourcesList.Add(ConstF(0));
|
||||
break;
|
||||
|
||||
case Decoders.TextureTarget.Texture2DLodLevelDepthCompare:
|
||||
case Decoders.TextureTarget.TextureCubeLodLevel:
|
||||
case TextureTarget.Texture2DLodLevelDepthCompare:
|
||||
case TextureTarget.TextureCubeLodLevel:
|
||||
sourcesList.Add(Ra());
|
||||
sourcesList.Add(Ra());
|
||||
sourcesList.Add(Rb());
|
||||
|
@ -258,7 +258,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
|
||||
if (type == SamplerType.None)
|
||||
{
|
||||
// TODO: Error, encoding is invalid.
|
||||
context.Config.PrintLog("Invalid texel fetch sampler type.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -743,7 +743,6 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
OpCodeTexture op = (OpCodeTexture)context.CurrOp;
|
||||
|
||||
bool isBindless = (flags & TextureFlags.Bindless) != 0;
|
||||
bool intCoords = (flags & TextureFlags.IntCoords) != 0;
|
||||
|
||||
if (op.Rd.IsRZ)
|
||||
{
|
||||
|
@ -920,36 +919,36 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
throw new ArgumentException($"Invalid texture dimensions \"{dimensions}\".");
|
||||
}
|
||||
|
||||
private static SamplerType ConvertSamplerType(Decoders.TextureTarget type)
|
||||
private static SamplerType ConvertSamplerType(TextureTarget type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Decoders.TextureTarget.Texture1DLodZero:
|
||||
case TextureTarget.Texture1DLodZero:
|
||||
return SamplerType.Texture1D;
|
||||
|
||||
case Decoders.TextureTarget.Texture2D:
|
||||
case Decoders.TextureTarget.Texture2DLodZero:
|
||||
case Decoders.TextureTarget.Texture2DLodLevel:
|
||||
case TextureTarget.Texture2D:
|
||||
case TextureTarget.Texture2DLodZero:
|
||||
case TextureTarget.Texture2DLodLevel:
|
||||
return SamplerType.Texture2D;
|
||||
|
||||
case Decoders.TextureTarget.Texture2DDepthCompare:
|
||||
case Decoders.TextureTarget.Texture2DLodLevelDepthCompare:
|
||||
case Decoders.TextureTarget.Texture2DLodZeroDepthCompare:
|
||||
case TextureTarget.Texture2DDepthCompare:
|
||||
case TextureTarget.Texture2DLodLevelDepthCompare:
|
||||
case TextureTarget.Texture2DLodZeroDepthCompare:
|
||||
return SamplerType.Texture2D | SamplerType.Shadow;
|
||||
|
||||
case Decoders.TextureTarget.Texture2DArray:
|
||||
case Decoders.TextureTarget.Texture2DArrayLodZero:
|
||||
case TextureTarget.Texture2DArray:
|
||||
case TextureTarget.Texture2DArrayLodZero:
|
||||
return SamplerType.Texture2D | SamplerType.Array;
|
||||
|
||||
case Decoders.TextureTarget.Texture2DArrayLodZeroDepthCompare:
|
||||
case TextureTarget.Texture2DArrayLodZeroDepthCompare:
|
||||
return SamplerType.Texture2D | SamplerType.Array | SamplerType.Shadow;
|
||||
|
||||
case Decoders.TextureTarget.Texture3D:
|
||||
case Decoders.TextureTarget.Texture3DLodZero:
|
||||
case TextureTarget.Texture3D:
|
||||
case TextureTarget.Texture3DLodZero:
|
||||
return SamplerType.Texture3D;
|
||||
|
||||
case Decoders.TextureTarget.TextureCube:
|
||||
case Decoders.TextureTarget.TextureCubeLodLevel:
|
||||
case TextureTarget.TextureCube:
|
||||
case TextureTarget.TextureCubeLodLevel:
|
||||
return SamplerType.TextureCube;
|
||||
}
|
||||
|
||||
|
@ -987,22 +986,22 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
{
|
||||
switch (type)
|
||||
{
|
||||
case Decoders.TextureTarget.Texture1DLodZero:
|
||||
case Decoders.TextureTarget.Texture2DLodZero:
|
||||
case Decoders.TextureTarget.Texture2DLodLevel:
|
||||
case Decoders.TextureTarget.Texture2DLodLevelDepthCompare:
|
||||
case Decoders.TextureTarget.Texture2DLodZeroDepthCompare:
|
||||
case Decoders.TextureTarget.Texture2DArrayLodZero:
|
||||
case Decoders.TextureTarget.Texture2DArrayLodZeroDepthCompare:
|
||||
case Decoders.TextureTarget.Texture3DLodZero:
|
||||
case Decoders.TextureTarget.TextureCubeLodLevel:
|
||||
case TextureTarget.Texture1DLodZero:
|
||||
case TextureTarget.Texture2DLodZero:
|
||||
case TextureTarget.Texture2DLodLevel:
|
||||
case TextureTarget.Texture2DLodLevelDepthCompare:
|
||||
case TextureTarget.Texture2DLodZeroDepthCompare:
|
||||
case TextureTarget.Texture2DArrayLodZero:
|
||||
case TextureTarget.Texture2DArrayLodZeroDepthCompare:
|
||||
case TextureTarget.Texture3DLodZero:
|
||||
case TextureTarget.TextureCubeLodLevel:
|
||||
return TextureFlags.LodLevel;
|
||||
|
||||
case Decoders.TextureTarget.Texture2D:
|
||||
case Decoders.TextureTarget.Texture2DDepthCompare:
|
||||
case Decoders.TextureTarget.Texture2DArray:
|
||||
case Decoders.TextureTarget.Texture3D:
|
||||
case Decoders.TextureTarget.TextureCube:
|
||||
case TextureTarget.Texture2D:
|
||||
case TextureTarget.Texture2DDepthCompare:
|
||||
case TextureTarget.Texture2DArray:
|
||||
case TextureTarget.Texture3D:
|
||||
case TextureTarget.TextureCube:
|
||||
return TextureFlags.None;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
|||
}
|
||||
else
|
||||
{
|
||||
// Invalid.
|
||||
context.Config.PrintLog($"Invalid vote operation: {op.VoteOp}.");
|
||||
}
|
||||
|
||||
if (!op.Rd.IsRZ)
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
namespace Ryujinx.Graphics.Shader
|
||||
{
|
||||
public delegate int QueryInfoCallback(QueryInfoName info, int index);
|
||||
}
|
|
@ -8,7 +8,6 @@ namespace Ryujinx.Graphics.Shader
|
|||
ComputeSharedMemorySize,
|
||||
IsTextureBuffer,
|
||||
IsTextureRectangle,
|
||||
MaximumViewportDimensions,
|
||||
PrimitiveTopology,
|
||||
StorageBufferOffsetAlignment,
|
||||
SupportsNonConstantTextureOffset
|
||||
|
|
|
@ -13,6 +13,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
|
||||
private ShaderConfig _config;
|
||||
|
||||
public ShaderConfig Config => _config;
|
||||
|
||||
private List<Operation> _operations;
|
||||
|
||||
private Dictionary<ulong, Operand> _labels;
|
||||
|
|
|
@ -16,9 +16,9 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
|
||||
public TranslationFlags Flags { get; }
|
||||
|
||||
private QueryInfoCallback _queryInfoCallback;
|
||||
private TranslatorCallbacks _callbacks;
|
||||
|
||||
public ShaderConfig(TranslationFlags flags, QueryInfoCallback queryInfoCallback)
|
||||
public ShaderConfig(TranslationFlags flags, TranslatorCallbacks callbacks)
|
||||
{
|
||||
Stage = ShaderStage.Compute;
|
||||
OutputTopology = OutputTopology.PointList;
|
||||
|
@ -27,10 +27,10 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
OmapSampleMask = false;
|
||||
OmapDepth = false;
|
||||
Flags = flags;
|
||||
_queryInfoCallback = queryInfoCallback;
|
||||
_callbacks = callbacks;
|
||||
}
|
||||
|
||||
public ShaderConfig(ShaderHeader header, TranslationFlags flags, QueryInfoCallback queryInfoCallback)
|
||||
public ShaderConfig(ShaderHeader header, TranslationFlags flags, TranslatorCallbacks callbacks)
|
||||
{
|
||||
Stage = header.Stage;
|
||||
OutputTopology = header.OutputTopology;
|
||||
|
@ -39,7 +39,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
OmapSampleMask = header.OmapSampleMask;
|
||||
OmapDepth = header.OmapDepth;
|
||||
Flags = flags;
|
||||
_queryInfoCallback = queryInfoCallback;
|
||||
_callbacks = callbacks;
|
||||
}
|
||||
|
||||
public int GetDepthRegister()
|
||||
|
@ -68,9 +68,9 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
|
||||
public int QueryInfo(QueryInfoName info, int index = 0)
|
||||
{
|
||||
if (_queryInfoCallback != null)
|
||||
if (_callbacks.QueryInfo != null)
|
||||
{
|
||||
return _queryInfoCallback(info, index);
|
||||
return _callbacks.QueryInfo(info, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -86,8 +86,6 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
return Convert.ToInt32(false);
|
||||
case QueryInfoName.IsTextureRectangle:
|
||||
return Convert.ToInt32(false);
|
||||
case QueryInfoName.MaximumViewportDimensions:
|
||||
return 0x8000;
|
||||
case QueryInfoName.PrimitiveTopology:
|
||||
return (int)InputTopology.Points;
|
||||
case QueryInfoName.StorageBufferOffsetAlignment:
|
||||
|
@ -99,5 +97,10 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void PrintLog(string message)
|
||||
{
|
||||
_callbacks.PrintLog?.Invoke(message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -40,21 +40,17 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
return code.Slice(0, headerSize + (int)endAddress);
|
||||
}
|
||||
|
||||
public static ShaderProgram Translate(Span<byte> code, QueryInfoCallback queryInfoCallback, TranslationFlags flags)
|
||||
public static ShaderProgram Translate(Span<byte> code, TranslatorCallbacks callbacks, TranslationFlags flags)
|
||||
{
|
||||
bool compute = (flags & TranslationFlags.Compute) != 0;
|
||||
|
||||
Operation[] ops = DecodeShader(code, queryInfoCallback, flags, out ShaderConfig config, out int size);
|
||||
Operation[] ops = DecodeShader(code, callbacks, flags, out ShaderConfig config, out int size);
|
||||
|
||||
return Translate(ops, config, size);
|
||||
}
|
||||
|
||||
public static ShaderProgram Translate(Span<byte> vpACode, Span<byte> vpBCode, QueryInfoCallback queryInfoCallback, TranslationFlags flags)
|
||||
public static ShaderProgram Translate(Span<byte> vpACode, Span<byte> vpBCode, TranslatorCallbacks callbacks, TranslationFlags flags)
|
||||
{
|
||||
bool debugMode = (flags & TranslationFlags.DebugMode) != 0;
|
||||
|
||||
Operation[] vpAOps = DecodeShader(vpACode, queryInfoCallback, flags, out _, out _);
|
||||
Operation[] vpBOps = DecodeShader(vpBCode, queryInfoCallback, flags, out ShaderConfig config, out int sizeB);
|
||||
Operation[] vpAOps = DecodeShader(vpACode, callbacks, flags, out _, out _);
|
||||
Operation[] vpBOps = DecodeShader(vpBCode, callbacks, flags, out ShaderConfig config, out int sizeB);
|
||||
|
||||
return Translate(Combine(vpAOps, vpBOps), config, sizeB);
|
||||
}
|
||||
|
@ -95,7 +91,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
|
||||
private static Operation[] DecodeShader(
|
||||
Span<byte> code,
|
||||
QueryInfoCallback queryInfoCallback,
|
||||
TranslatorCallbacks callbacks,
|
||||
TranslationFlags flags,
|
||||
out ShaderConfig config,
|
||||
out int size)
|
||||
|
@ -104,24 +100,24 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
|
||||
if ((flags & TranslationFlags.Compute) != 0)
|
||||
{
|
||||
config = new ShaderConfig(flags, queryInfoCallback);
|
||||
config = new ShaderConfig(flags, callbacks);
|
||||
|
||||
cfg = Decoder.Decode(code, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
config = new ShaderConfig(new ShaderHeader(code), flags, queryInfoCallback);
|
||||
config = new ShaderConfig(new ShaderHeader(code), flags, callbacks);
|
||||
|
||||
cfg = Decoder.Decode(code, HeaderSize);
|
||||
}
|
||||
|
||||
if (cfg == null)
|
||||
{
|
||||
// TODO: Error.
|
||||
config.PrintLog("Invalid branch detected, failed to build CFG.");
|
||||
|
||||
size = 0;
|
||||
|
||||
return new Operation[0];
|
||||
return Array.Empty<Operation>();
|
||||
}
|
||||
|
||||
EmitterContext context = new EmitterContext(config);
|
||||
|
@ -156,6 +152,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
else
|
||||
{
|
||||
instName = "???";
|
||||
|
||||
config.PrintLog($"Invalid instruction at 0x{op.Address:X6} (0x{op.RawOpCode:X16}).");
|
||||
}
|
||||
|
||||
string dbgComment = $"0x{op.Address:X6}: 0x{op.RawOpCode:X16} {instName}";
|
||||
|
@ -210,10 +208,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
|
||||
context.CurrOp = op;
|
||||
|
||||
if (op.Emitter != null)
|
||||
{
|
||||
op.Emitter(context);
|
||||
}
|
||||
op.Emitter?.Invoke(context);
|
||||
|
||||
if (predSkipLbl != null)
|
||||
{
|
||||
|
|
17
Ryujinx.Graphics.Shader/Translation/TranslatorCallbacks.cs
Normal file
17
Ryujinx.Graphics.Shader/Translation/TranslatorCallbacks.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.Translation
|
||||
{
|
||||
public struct TranslatorCallbacks
|
||||
{
|
||||
internal Func<QueryInfoName, int, int> QueryInfo { get; }
|
||||
|
||||
internal Action<string> PrintLog { get; }
|
||||
|
||||
public TranslatorCallbacks(Func<QueryInfoName, int, int> queryInfoCallback, Action<string> printLogCallback)
|
||||
{
|
||||
QueryInfo = queryInfoCallback;
|
||||
PrintLog = printLogCallback;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -405,14 +405,14 @@ namespace Ryujinx.Ui
|
|||
/// <returns>An <see cref="IAalOutput"/> supported by this machine</returns>
|
||||
private static IAalOutput InitializeAudioEngine()
|
||||
{
|
||||
/*if (SoundIoAudioOut.IsSupported)
|
||||
{
|
||||
return new SoundIoAudioOut();
|
||||
}
|
||||
else*/ if (OpenALAudioOut.IsSupported)
|
||||
if (OpenALAudioOut.IsSupported)
|
||||
{
|
||||
return new OpenALAudioOut();
|
||||
}
|
||||
else if (SoundIoAudioOut.IsSupported)
|
||||
{
|
||||
return new SoundIoAudioOut();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new DummyAudioOut();
|
||||
|
|
Loading…
Reference in a new issue