Do not require texture and sampler pools being initialized (#2476)

This commit is contained in:
gdkchan 2021-07-14 14:27:22 -03:00 committed by GitHub
parent 9d688e37d6
commit 96a070a9a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,4 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.Types;
using Ryujinx.Graphics.Shader;
@ -118,20 +119,25 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="maximumId">Maximum ID of the pool (total count minus one)</param>
/// <param name="samplerIndex">Type of the sampler pool indexing used for bound samplers</param>
public void SetSamplerPool(ulong gpuVa, int maximumId, SamplerIndex samplerIndex)
{
if (gpuVa != 0)
{
ulong address = _channel.MemoryManager.Translate(gpuVa);
if (_samplerPool != null)
{
if (_samplerPool.Address == address && _samplerPool.MaximumId >= maximumId)
if (_samplerPool != null && _samplerPool.Address == address && _samplerPool.MaximumId >= maximumId)
{
return;
}
_samplerPool.Dispose();
_samplerPool?.Dispose();
_samplerPool = new SamplerPool(_context, _channel.MemoryManager.Physical, address, maximumId);
}
else
{
_samplerPool?.Dispose();
_samplerPool = null;
}
_samplerPool = new SamplerPool(_context, _channel.MemoryManager.Physical, address, maximumId);
_samplerIndex = samplerIndex;
}
@ -141,12 +147,20 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="gpuVa">Start GPU virtual address of the pool</param>
/// <param name="maximumId">Maximum ID of the pool (total count minus one)</param>
public void SetTexturePool(ulong gpuVa, int maximumId)
{
if (gpuVa != 0)
{
ulong address = _channel.MemoryManager.Translate(gpuVa);
_texturePoolAddress = address;
_texturePoolMaximumId = maximumId;
}
else
{
_texturePoolAddress = 0;
_texturePoolMaximumId = 0;
}
}
/// <summary>
/// Updates the texture scale for a given texture or image.
@ -227,10 +241,11 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </summary>
public void CommitBindings()
{
TexturePool texturePool = _texturePoolCache.FindOrCreate(
_channel,
_texturePoolAddress,
_texturePoolMaximumId);
ulong texturePoolAddress = _texturePoolAddress;
TexturePool texturePool = texturePoolAddress != 0
? _texturePoolCache.FindOrCreate(_channel, texturePoolAddress, _texturePoolMaximumId)
: null;
if (_isCompute)
{
@ -264,11 +279,25 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="stageIndex">The stage number of the specified shader stage</param>
private void CommitTextureBindings(TexturePool pool, ShaderStage stage, int stageIndex)
{
if (_textureBindings[stageIndex] == null)
if (_textureBindings[stageIndex] == null || _textureBindings[stageIndex].Length == 0)
{
return;
}
var samplerPool = _samplerPool;
if (pool == null)
{
Logger.Error?.Print(LogClass.Gpu, $"Shader stage \"{stage}\" uses textures, but texture pool was not set.");
return;
}
if (samplerPool == null)
{
Logger.Error?.Print(LogClass.Gpu, $"Shader stage \"{stage}\" uses textures, but sampler pool was not set.");
return;
}
for (int index = 0; index < _textureBindings[stageIndex].Length; index++)
{
TextureBindingInfo bindingInfo = _textureBindings[stageIndex][index];
@ -324,7 +353,7 @@ namespace Ryujinx.Graphics.Gpu.Image
_channel.BufferManager.SetBufferTextureStorage(hostTexture, texture.Range.GetSubRange(0).Address, texture.Size, bindingInfo, bindingInfo.Format, false);
}
Sampler sampler = _samplerPool.Get(samplerId);
Sampler sampler = samplerPool.Get(samplerId);
ISampler hostSampler = sampler?.HostSampler;
@ -351,6 +380,12 @@ namespace Ryujinx.Graphics.Gpu.Image
return;
}
if (pool == null && _imageBindings[stageIndex].Length != 0)
{
Logger.Error?.Print(LogClass.Gpu, $"Shader stage \"{stage}\" uses images, but texture pool was not set.");
return;
}
// Scales for images appear after the texture ones.
int baseScaleIndex = _textureBindings[stageIndex]?.Length ?? 0;