Initial support for image stores, support texture sample on compute

This commit is contained in:
gdk 2019-10-17 23:41:18 -03:00 committed by Thog
parent 717ace6f6e
commit 1b7d955195
44 changed files with 1053 additions and 497 deletions

View file

@ -1,3 +1,5 @@
using Ryujinx.Graphics.GAL.Texture;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.State;
using Ryujinx.Graphics.Shader;
using System;
@ -23,10 +25,46 @@ namespace Ryujinx.Graphics.Gpu.Engine
dispatchParams.UnpackBlockSizeY(),
dispatchParams.UnpackBlockSizeZ());
_context.Renderer.ComputePipeline.SetProgram(cs.Interface);
_context.Renderer.Pipeline.BindProgram(cs.Interface);
PoolState samplerPool = _context.State.GetSamplerPoolState();
_textureManager.SetComputeSamplerPool(samplerPool.Address.Pack(), samplerPool.MaximumId);
PoolState texturePool = _context.State.GetTexturePoolState();
_textureManager.SetComputeTexturePool(texturePool.Address.Pack(), texturePool.MaximumId);
_textureManager.SetComputeTextureBufferIndex(_context.State.GetTextureBufferIndex());
ShaderProgramInfo info = cs.Shader.Info;
var textureBindings = new TextureBindingInfo[info.Textures.Count];
for (int index = 0; index < info.Textures.Count; index++)
{
var descriptor = info.Textures[index];
Target target = GetTarget(descriptor.Type);
textureBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
}
_textureManager.SetComputeTextures(textureBindings);
var imageBindings = new TextureBindingInfo[info.Images.Count];
for (int index = 0; index < info.Images.Count; index++)
{
var descriptor = info.Images[index];
Target target = GetTarget(descriptor.Type);
imageBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
}
_textureManager.SetComputeImages(imageBindings);
uint sbEnableMask = 0;
uint ubEnableMask = dispatchParams.UnpackUniformBuffersEnableMask();
@ -73,8 +111,9 @@ namespace Ryujinx.Graphics.Gpu.Engine
_bufferManager.SetComputeUniformBufferEnableMask(ubEnableMask);
_bufferManager.CommitComputeBindings();
_textureManager.CommitComputeBindings();
_context.Renderer.ComputePipeline.Dispatch(
_context.Renderer.Pipeline.Dispatch(
dispatchParams.UnpackGridSizeX(),
dispatchParams.UnpackGridSizeY(),
dispatchParams.UnpackGridSizeZ());

View file

@ -26,7 +26,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
clearColor.Blue,
clearColor.Alpha);
_context.Renderer.GraphicsPipeline.ClearRenderTargetColor(
_context.Renderer.Pipeline.ClearRenderTargetColor(
index,
componentMask,
color);
@ -44,7 +44,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
stencilMask = _context.State.GetStencilTestState().FrontMask;
}
_context.Renderer.GraphicsPipeline.ClearRenderTargetDepthStencil(
_context.Renderer.Pipeline.ClearRenderTargetDepthStencil(
depthValue,
clearDepth,
stencilValue,

View file

@ -61,7 +61,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
int firstVertex = _context.State.GetBaseVertex();
_context.Renderer.GraphicsPipeline.DrawIndexed(
_context.Renderer.Pipeline.DrawIndexed(
_indexCount,
1,
_firstIndex,
@ -72,7 +72,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
VertexBufferDrawState drawState = _context.State.GetVertexBufferDrawState();
_context.Renderer.GraphicsPipeline.Draw(
_context.Renderer.Pipeline.Draw(
drawState.Count,
1,
drawState.First,
@ -84,7 +84,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
PrimitiveType type = (PrimitiveType)(argument & 0xffff);
_context.Renderer.GraphicsPipeline.SetPrimitiveTopology(type.Convert());
_context.Renderer.Pipeline.SetPrimitiveTopology(type.Convert());
PrimitiveType = type;
@ -112,7 +112,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (_instancedIndexed)
{
_context.Renderer.GraphicsPipeline.DrawIndexed(
_context.Renderer.Pipeline.DrawIndexed(
_instancedIndexCount,
_instanceIndex + 1,
_instancedFirstIndex,
@ -121,7 +121,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
else
{
_context.Renderer.GraphicsPipeline.Draw(
_context.Renderer.Pipeline.Draw(
_instancedDrawStateCount,
_instanceIndex + 1,
_instancedDrawStateFirst,

View file

@ -21,6 +21,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
private BufferManager _bufferManager;
private TextureManager _textureManager;
public BufferManager BufferManager => _bufferManager;
public TextureManager TextureManager => _textureManager;
private bool _isAnyVbInstanced;
@ -33,7 +34,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
_shaderCache = new ShaderCache(_context);
_bufferManager = new BufferManager(context);
_textureManager = new TextureManager(context, _bufferManager);
_textureManager = new TextureManager(context);
RegisterCallbacks();
}
@ -61,7 +62,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
_context.State.RegisterUniformBufferBind3Callback(UniformBufferBind3);
_context.State.RegisterUniformBufferBind4Callback(UniformBufferBind4);
_context.State.RegisterCallback(MethodOffset.InvalidateTextures, InvalidateTextures);
_context.State.RegisterCallback(MethodOffset.TextureBarrier, TextureBarrier);
_context.State.RegisterCallback(MethodOffset.InvalidateTextures, InvalidateTextures);
_context.State.RegisterCallback(MethodOffset.TextureBarrierTiled, TextureBarrierTiled);
_context.State.RegisterCallback(MethodOffset.ResetCounter, ResetCounter);
@ -153,18 +157,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
private void CommitBindings()
{
_bufferManager.CommitBindings();
_textureManager.CommitBindings();
}
public void InvalidateRange(ulong address, ulong size)
{
_bufferManager.InvalidateRange(address, size);
_textureManager.InvalidateRange(address, size);
}
public void InvalidateTextureRange(ulong address, ulong size)
{
_textureManager.InvalidateRange(address, size);
_textureManager.CommitGraphicsBindings();
}
private void UpdateRenderTargetGroupState()
@ -272,7 +265,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
private void UpdateDepthTestState()
{
_context.Renderer.GraphicsPipeline.SetDepthTest(new DepthTestDescriptor(
_context.Renderer.Pipeline.SetDepthTest(new DepthTestDescriptor(
_context.State.GetDepthTestEnable().IsTrue(),
_context.State.GetDepthWriteEnable().IsTrue(),
_context.State.GetDepthTestFunc()));
@ -305,7 +298,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
extents.DepthFar);
}
_context.Renderer.GraphicsPipeline.SetViewports(0, viewports);
_context.Renderer.Pipeline.SetViewports(0, viewports);
}
private void UpdateDepthBiasState()
@ -322,7 +315,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
enables |= (polygonOffset.LineEnable.IsTrue() ? PolygonModeMask.Line : 0);
enables |= (polygonOffset.FillEnable.IsTrue() ? PolygonModeMask.Fill : 0);
_context.Renderer.GraphicsPipeline.SetDepthBias(enables, factor, units, clamp);
_context.Renderer.Pipeline.SetDepthBias(enables, factor, units, clamp);
}
private void UpdateStencilTestState()
@ -360,7 +353,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
backMask = test.FrontMask;
}
_context.Renderer.GraphicsPipeline.SetStencilTest(new StencilTestDescriptor(
_context.Renderer.Pipeline.SetStencilTest(new StencilTestDescriptor(
test.Enable.IsTrue(),
test.FrontFunc,
test.FrontSFail,
@ -382,16 +375,16 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
PoolState samplerPool = _context.State.GetSamplerPoolState();
_textureManager.SetSamplerPool(samplerPool.Address.Pack(), samplerPool.MaximumId);
_textureManager.SetGraphicsSamplerPool(samplerPool.Address.Pack(), samplerPool.MaximumId);
}
private void UpdateTexturePoolState()
{
PoolState texturePool = _context.State.GetTexturePoolState();
_textureManager.SetTexturePool(texturePool.Address.Pack(), texturePool.MaximumId);
_textureManager.SetGraphicsTexturePool(texturePool.Address.Pack(), texturePool.MaximumId);
_textureManager.SetTextureBufferIndex(_context.State.GetTextureBufferIndex());
_textureManager.SetGraphicsTextureBufferIndex(_context.State.GetTextureBufferIndex());
}
private void UpdateInputAssemblerGroupState()
@ -439,14 +432,14 @@ namespace Ryujinx.Graphics.Gpu.Engine
format);
}
_context.Renderer.GraphicsPipeline.BindVertexAttribs(vertexAttribs);
_context.Renderer.Pipeline.BindVertexAttribs(vertexAttribs);
}
private void UpdatePrimitiveRestartState()
{
PrimitiveRestartState primitiveRestart = _context.State.Get<PrimitiveRestartState>(MethodOffset.PrimitiveRestartState);
_context.Renderer.GraphicsPipeline.SetPrimitiveRestart(
_context.Renderer.Pipeline.SetPrimitiveRestart(
primitiveRestart.Enable,
primitiveRestart.Index);
}
@ -593,9 +586,9 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
FaceState face = _context.State.GetFaceState();
_context.Renderer.GraphicsPipeline.SetFaceCulling(face.CullEnable.IsTrue(), face.CullFace);
_context.Renderer.Pipeline.SetFaceCulling(face.CullEnable.IsTrue(), face.CullFace);
_context.Renderer.GraphicsPipeline.SetFrontFace(face.FrontFace);
_context.Renderer.Pipeline.SetFrontFace(face.FrontFace);
}
private void UpdateRtColorMask()
@ -616,7 +609,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
componentMasks[index] = componentMask;
}
_context.Renderer.GraphicsPipeline.SetRenderTargetColorMasks(componentMasks);
_context.Renderer.Pipeline.SetRenderTargetColorMasks(componentMasks);
}
private void UpdateBlendState()
@ -638,7 +631,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
blend.AlphaSrcFactor,
blend.AlphaDstFactor);
_context.Renderer.GraphicsPipeline.BindBlendState(index, descriptor);
_context.Renderer.Pipeline.BindBlendState(index, descriptor);
}
}
@ -696,12 +689,25 @@ namespace Ryujinx.Graphics.Gpu.Engine
{
var descriptor = info.Textures[index];
Target target = GetTarget(descriptor.Target);
Target target = GetTarget(descriptor.Type);
textureBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
}
_textureManager.BindTextures(stage, textureBindings);
_textureManager.SetGraphicsTextures(stage, textureBindings);
var imageBindings = new TextureBindingInfo[info.Images.Count];
for (int index = 0; index < info.Images.Count; index++)
{
var descriptor = info.Images[index];
Target target = GetTarget(descriptor.Type);
imageBindings[index] = new TextureBindingInfo(target, descriptor.HandleIndex);
}
_textureManager.SetGraphicsImages(stage, imageBindings);
uint sbEnableMask = 0;
uint ubEnableMask = 0;
@ -734,40 +740,43 @@ namespace Ryujinx.Graphics.Gpu.Engine
_bufferManager.SetGraphicsUniformBufferEnableMask(stage, ubEnableMask);
}
_context.Renderer.GraphicsPipeline.BindProgram(gs.Interface);
_context.Renderer.Pipeline.BindProgram(gs.Interface);
}
private static Target GetTarget(Shader.TextureTarget target)
private static Target GetTarget(SamplerType type)
{
target &= ~Shader.TextureTarget.Shadow;
type &= ~SamplerType.Shadow;
switch (target)
switch (type)
{
case Shader.TextureTarget.Texture1D:
case SamplerType.Texture1D:
return Target.Texture1D;
case Shader.TextureTarget.Texture1D | Shader.TextureTarget.Array:
case SamplerType.TextureBuffer:
return Target.TextureBuffer;
case SamplerType.Texture1D | SamplerType.Array:
return Target.Texture1DArray;
case Shader.TextureTarget.Texture2D:
case SamplerType.Texture2D:
return Target.Texture2D;
case Shader.TextureTarget.Texture2D | Shader.TextureTarget.Array:
case SamplerType.Texture2D | SamplerType.Array:
return Target.Texture2DArray;
case Shader.TextureTarget.Texture2D | Shader.TextureTarget.Multisample:
case SamplerType.Texture2D | SamplerType.Multisample:
return Target.Texture2DMultisample;
case Shader.TextureTarget.Texture2D | Shader.TextureTarget.Multisample | Shader.TextureTarget.Array:
case SamplerType.Texture2D | SamplerType.Multisample | SamplerType.Array:
return Target.Texture2DMultisampleArray;
case Shader.TextureTarget.Texture3D:
case SamplerType.Texture3D:
return Target.Texture3D;
case Shader.TextureTarget.TextureCube:
case SamplerType.TextureCube:
return Target.Cubemap;
case Shader.TextureTarget.TextureCube | Shader.TextureTarget.Array:
case SamplerType.TextureCube | SamplerType.Array:
return Target.CubemapArray;
}
@ -776,9 +785,19 @@ namespace Ryujinx.Graphics.Gpu.Engine
return Target.Texture2D;
}
private void TextureBarrier(int argument)
{
_context.Renderer.Pipeline.TextureBarrier();
}
private void InvalidateTextures(int argument)
{
_textureManager.Flush();
}
private void TextureBarrierTiled(int argument)
{
_context.Renderer.Pipeline.TextureBarrierTiled();
}
}
}

View file

@ -107,7 +107,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
ShaderProgram program;
const TranslationFlags flags =
TranslationFlags.Compute |
TranslationFlags.Compute |
TranslationFlags.DebugMode |
TranslationFlags.Unspecialized;
TranslationConfig translationConfig = new TranslationConfig(0x10000, _dumper.CurrentDumpIndex, flags);

View file

@ -217,8 +217,6 @@ namespace Ryujinx.Graphics.Gpu.Image
ulong rangeSize = (EndAddress - Address + pageMask) & ~pageMask;
_context.Methods.InvalidateRange(rangeAddress, rangeSize);
Span<byte> data = _context.PhysicalMemory.Read(Address, Size);
if (_info.IsLinear)
@ -683,11 +681,6 @@ namespace Ryujinx.Graphics.Gpu.Image
return Address < address + size && address < EndAddress;
}
public void Invalidate()
{
// _hasData = false;
}
public void IncrementReferenceCount()
{
_referenceCount++;

View file

@ -0,0 +1,231 @@
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Shader;
using System;
namespace Ryujinx.Graphics.Gpu.Image
{
class TextureBindingsManager
{
private GpuContext _context;
private bool _isCompute;
private SamplerPool _samplerPool;
private ulong _texturePoolAddress;
private int _texturePoolMaximumId;
private TexturePoolCache _texturePoolCache;
private TextureBindingInfo[][] _textureBindings;
private TextureBindingInfo[][] _imageBindings;
private struct TextureStatePerStage
{
public ITexture Texture;
public ISampler Sampler;
}
private TextureStatePerStage[][] _textureState;
private TextureStatePerStage[][] _imageState;
private int _textureBufferIndex;
private bool _rebind;
public TextureBindingsManager(GpuContext context, bool isCompute)
{
_context = context;
_isCompute = isCompute;
_texturePoolCache = new TexturePoolCache(context);
int stages = isCompute ? 1 : Constants.TotalShaderStages;
_textureBindings = new TextureBindingInfo[stages][];
_imageBindings = new TextureBindingInfo[stages][];
_textureState = new TextureStatePerStage[stages][];
_imageState = new TextureStatePerStage[stages][];
}
public void SetTextures(int stage, TextureBindingInfo[] bindings)
{
_textureBindings[stage] = bindings;
_textureState[stage] = new TextureStatePerStage[bindings.Length];
}
public void SetImages(int stage, TextureBindingInfo[] bindings)
{
_imageBindings[stage] = bindings;
_imageState[stage] = new TextureStatePerStage[bindings.Length];
}
public void SetTextureBufferIndex(int index)
{
_textureBufferIndex = index;
}
public void SetSamplerPool(ulong gpuVa, int maximumId)
{
ulong address = _context.MemoryManager.Translate(gpuVa);
if (_samplerPool != null)
{
if (_samplerPool.Address == address)
{
return;
}
_samplerPool.Dispose();
}
_samplerPool = new SamplerPool(_context, address, maximumId);
}
public void SetTexturePool(ulong gpuVa, int maximumId)
{
ulong address = _context.MemoryManager.Translate(gpuVa);
_texturePoolAddress = address;
_texturePoolMaximumId = maximumId;
}
public void CommitBindings()
{
TexturePool texturePool = _texturePoolCache.FindOrCreate(
_texturePoolAddress,
_texturePoolMaximumId);
if (_isCompute)
{
CommitTextureBindings(texturePool, ShaderStage.Compute, 0);
CommitImageBindings (texturePool, ShaderStage.Compute, 0);
}
else
{
for (ShaderStage stage = ShaderStage.Vertex; stage <= ShaderStage.Fragment; stage++)
{
int stageIndex = (int)stage - 1;
CommitTextureBindings(texturePool, stage, stageIndex);
CommitImageBindings (texturePool, stage, stageIndex);
}
}
_rebind = false;
}
private void CommitTextureBindings(TexturePool pool, ShaderStage stage, int stageIndex)
{
if (_textureBindings[stageIndex] == null)
{
return;
}
for (int index = 0; index < _textureBindings[stageIndex].Length; index++)
{
TextureBindingInfo binding = _textureBindings[stageIndex][index];
int packedId = ReadPackedId(stageIndex, binding.Handle);
int textureId = UnpackTextureId(packedId);
int samplerId = UnpackSamplerId(packedId);
Texture texture = pool.Get(textureId);
ITexture hostTexture = texture?.GetTargetTexture(binding.Target);
if (_textureState[stageIndex][index].Texture != hostTexture || _rebind)
{
_textureState[stageIndex][index].Texture = hostTexture;
_context.Renderer.Pipeline.BindTexture(index, stage, hostTexture);
}
Sampler sampler = _samplerPool.Get(samplerId);
ISampler hostSampler = sampler?.HostSampler;
if (_textureState[stageIndex][index].Sampler != hostSampler || _rebind)
{
_textureState[stageIndex][index].Sampler = hostSampler;
_context.Renderer.Pipeline.BindSampler(index, stage, hostSampler);
}
}
}
private void CommitImageBindings(TexturePool pool, ShaderStage stage, int stageIndex)
{
if (_imageBindings[stageIndex] == null)
{
return;
}
for (int index = 0; index < _imageBindings[stageIndex].Length; index++)
{
TextureBindingInfo binding = _imageBindings[stageIndex][index];
int packedId = ReadPackedId(stageIndex, binding.Handle);
int textureId = UnpackTextureId(packedId);
Texture texture = pool.Get(textureId);
ITexture hostTexture = texture?.GetTargetTexture(binding.Target);
if (_imageState[stageIndex][index].Texture != hostTexture || _rebind)
{
_imageState[stageIndex][index].Texture = hostTexture;
_context.Renderer.Pipeline.BindImage(index, stage, hostTexture);
}
}
}
private int ReadPackedId(int stage, int wordOffset)
{
ulong address;
var bufferManager = _context.Methods.BufferManager;
if (_isCompute)
{
address = bufferManager.GetComputeUniformBufferAddress(_textureBufferIndex);
}
else
{
address = bufferManager.GetGraphicsUniformBufferAddress(stage, _textureBufferIndex);
}
address += (uint)wordOffset * 4;
return BitConverter.ToInt32(_context.PhysicalMemory.Read(address, 4));
}
private static int UnpackTextureId(int packedId)
{
return (packedId >> 0) & 0xfffff;
}
private static int UnpackSamplerId(int packedId)
{
return (packedId >> 20) & 0xfff;
}
public void InvalidatePoolRange(ulong address, ulong size)
{
_samplerPool?.InvalidateRange(address, size);
_texturePoolCache.InvalidateRange(address, size);
}
public void Rebind()
{
_rebind = true;
}
}
}

View file

@ -4,7 +4,6 @@ using Ryujinx.Graphics.GAL.Texture;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Gpu.State;
using Ryujinx.Graphics.Shader;
using Ryujinx.Graphics.Texture;
using System;
@ -12,15 +11,10 @@ namespace Ryujinx.Graphics.Gpu.Image
{
class TextureManager
{
private GpuContext _context;
private BufferManager _bufferManager;
private GpuContext _context;
private SamplerPool _samplerPool;
private ulong _texturePoolAddress;
private int _texturePoolMaximumId;
private TexturePoolCache _texturePoolCache;
private TextureBindingsManager _cpBindingsManager;
private TextureBindingsManager _gpBindingsManager;
private Texture[] _rtColors;
private Texture _rtColor3D;
@ -35,24 +29,12 @@ namespace Ryujinx.Graphics.Gpu.Image
private AutoDeleteCache _cache;
private TextureBindingInfo[][] _bindings;
private struct TextureStatePerStage
public TextureManager(GpuContext context)
{
public ITexture Texture;
public ISampler Sampler;
}
_context = context;
private TextureStatePerStage[][] _textureState;
private int _textureBufferIndex;
public TextureManager(GpuContext context, BufferManager bufferManager)
{
_context = context;
_bufferManager = bufferManager;
_texturePoolCache = new TexturePoolCache(context, this);
_cpBindingsManager = new TextureBindingsManager(context, isCompute: true);
_gpBindingsManager = new TextureBindingsManager(context, isCompute: false);
_rtColors = new Texture[Constants.TotalRenderTargets];
@ -61,47 +43,56 @@ namespace Ryujinx.Graphics.Gpu.Image
_textures = new RangeList<Texture>();
_cache = new AutoDeleteCache();
_bindings = new TextureBindingInfo[Constants.TotalShaderStages][];
_textureState = new TextureStatePerStage[Constants.TotalShaderStages][];
}
public void BindTextures(int stage, TextureBindingInfo[] bindings)
public void SetComputeTextures(TextureBindingInfo[] bindings)
{
_bindings[stage] = bindings;
_textureState[stage] = new TextureStatePerStage[bindings.Length];
_cpBindingsManager.SetTextures(0, bindings);
}
public void SetTextureBufferIndex(int index)
public void SetGraphicsTextures(int stage, TextureBindingInfo[] bindings)
{
_textureBufferIndex = index;
_gpBindingsManager.SetTextures(stage, bindings);
}
public void SetSamplerPool(ulong gpuVa, int maximumId)
public void SetComputeImages(TextureBindingInfo[] bindings)
{
ulong address = _context.MemoryManager.Translate(gpuVa);
if (_samplerPool != null)
{
if (_samplerPool.Address == address)
{
return;
}
_samplerPool.Dispose();
}
_samplerPool = new SamplerPool(_context, address, maximumId);
_cpBindingsManager.SetImages(0, bindings);
}
public void SetTexturePool(ulong gpuVa, int maximumId)
public void SetGraphicsImages(int stage, TextureBindingInfo[] bindings)
{
ulong address = _context.MemoryManager.Translate(gpuVa);
_gpBindingsManager.SetImages(stage, bindings);
}
_texturePoolAddress = address;
_texturePoolMaximumId = maximumId;
public void SetComputeTextureBufferIndex(int index)
{
_cpBindingsManager.SetTextureBufferIndex(index);
}
public void SetGraphicsTextureBufferIndex(int index)
{
_gpBindingsManager.SetTextureBufferIndex(index);
}
public void SetComputeSamplerPool(ulong gpuVa, int maximumId)
{
_cpBindingsManager.SetSamplerPool(gpuVa, maximumId);
}
public void SetGraphicsSamplerPool(ulong gpuVa, int maximumId)
{
_gpBindingsManager.SetSamplerPool(gpuVa, maximumId);
}
public void SetComputeTexturePool(ulong gpuVa, int maximumId)
{
_cpBindingsManager.SetTexturePool(gpuVa, maximumId);
}
public void SetGraphicsTexturePool(ulong gpuVa, int maximumId)
{
_gpBindingsManager.SetTexturePool(gpuVa, maximumId);
}
public void SetRenderTargetColor(int index, Texture color)
@ -121,59 +112,22 @@ namespace Ryujinx.Graphics.Gpu.Image
_rtDepthStencil = depthStencil;
}
public void CommitBindings()
public void CommitComputeBindings()
{
UpdateTextures();
UpdateRenderTargets();
// Evert time we switch between graphics and compute work,
// we must rebind everything.
// Since compute work happens less often, we always do that
// before and after the compute dispatch.
_cpBindingsManager.Rebind();
_cpBindingsManager.CommitBindings();
_gpBindingsManager.Rebind();
}
private void UpdateTextures()
public void CommitGraphicsBindings()
{
TexturePool texturePool = _texturePoolCache.FindOrCreate(
_texturePoolAddress,
_texturePoolMaximumId);
_gpBindingsManager.CommitBindings();
for (ShaderStage stage = ShaderStage.Vertex; stage <= ShaderStage.Fragment; stage++)
{
int stageIndex = (int)stage - 1;
if (_bindings[stageIndex] == null)
{
continue;
}
for (int index = 0; index < _bindings[stageIndex].Length; index++)
{
TextureBindingInfo binding = _bindings[stageIndex][index];
int packedId = ReadPackedId(stageIndex, binding.Handle);
int textureId = (packedId >> 0) & 0xfffff;
int samplerId = (packedId >> 20) & 0xfff;
Texture texture = texturePool.Get(textureId);
ITexture hostTexture = texture?.GetTargetTexture(binding.Target);
if (_textureState[stageIndex][index].Texture != hostTexture)
{
_textureState[stageIndex][index].Texture = hostTexture;
_context.Renderer.GraphicsPipeline.BindTexture(index, stage, hostTexture);
}
Sampler sampler = _samplerPool.Get(samplerId);
ISampler hostSampler = sampler?.HostSampler;
if (_textureState[stageIndex][index].Sampler != hostSampler)
{
_textureState[stageIndex][index].Sampler = hostSampler;
_context.Renderer.GraphicsPipeline.BindSampler(index, stage, hostSampler);
}
}
}
UpdateRenderTargets();
}
private void UpdateRenderTargets()
@ -203,7 +157,7 @@ namespace Ryujinx.Graphics.Gpu.Image
if (anyChanged)
{
_context.Renderer.GraphicsPipeline.SetRenderTargets(_rtHostColors, _rtHostDs);
_context.Renderer.Pipeline.SetRenderTargets(_rtHostColors, _rtHostDs);
}
}
else
@ -217,20 +171,11 @@ namespace Ryujinx.Graphics.Gpu.Image
if (anyChanged)
{
_context.Renderer.GraphicsPipeline.SetRenderTargets(_rtColor3D.HostTexture, _rtHostDs);
_context.Renderer.Pipeline.SetRenderTargets(_rtColor3D.HostTexture, _rtHostDs);
}
}
}
private int ReadPackedId(int stage, int wordOffset)
{
ulong address = _bufferManager.GetGraphicsUniformBufferAddress(stage, _textureBufferIndex);
address += (uint)wordOffset * 4;
return BitConverter.ToInt32(_context.PhysicalMemory.Read(address, 4));
}
public Texture FindOrCreateTexture(CopyTexture copyTexture)
{
ulong address = _context.MemoryManager.Translate(copyTexture.Address.Pack());
@ -645,20 +590,6 @@ namespace Ryujinx.Graphics.Gpu.Image
return ts[0];
}
public void InvalidateRange(ulong address, ulong size)
{
Texture[] overlaps = _textures.FindOverlaps(address, size);
foreach (Texture overlap in overlaps)
{
overlap.Invalidate();
}
_samplerPool?.InvalidateRange(address, size);
_texturePoolCache.InvalidateRange(address, size);
}
public void Flush()
{
foreach (Texture texture in _cache)

View file

@ -9,8 +9,6 @@ namespace Ryujinx.Graphics.Gpu.Image
{
class TexturePool : Pool<Texture>
{
private TextureManager _textureManager;
public LinkedListNode<TexturePool> CacheNode { get; set; }
private struct TextureContainer
@ -20,13 +18,9 @@ namespace Ryujinx.Graphics.Gpu.Image
}
public TexturePool(
GpuContext context,
TextureManager textureManager,
ulong address,
int maximumId) : base(context, address, maximumId)
{
_textureManager = textureManager;
}
GpuContext context,
ulong address,
int maximumId) : base(context, address, maximumId) { }
public override Texture Get(int id)
{
@ -56,7 +50,7 @@ namespace Ryujinx.Graphics.Gpu.Image
return null;
}
texture = _textureManager.FindOrCreateTexture(info, TextureSearchFlags.Sampler);
texture = Context.Methods.TextureManager.FindOrCreateTexture(info, TextureSearchFlags.Sampler);
texture.IncrementReferenceCount();

View file

@ -6,15 +6,13 @@ namespace Ryujinx.Graphics.Gpu.Image
{
private const int MaxCapacity = 4;
private GpuContext _context;
private TextureManager _textureManager;
private GpuContext _context;
private LinkedList<TexturePool> _pools;
public TexturePoolCache(GpuContext context, TextureManager textureManager)
public TexturePoolCache(GpuContext context)
{
_context = context;
_textureManager = textureManager;
_context = context;
_pools = new LinkedList<TexturePool>();
}
@ -42,7 +40,7 @@ namespace Ryujinx.Graphics.Gpu.Image
}
// If not found, create a new one.
pool = new TexturePool(_context, _textureManager, address, maximumId);
pool = new TexturePool(_context, address, maximumId);
pool.CacheNode = _pools.AddLast(pool);

View file

@ -272,7 +272,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
BufferRange buffer = GetBufferRange(bounds.Address, bounds.Size);
_context.Renderer.ComputePipeline.SetStorageBuffer(index, buffer);
_context.Renderer.Pipeline.BindStorageBuffer(index, ShaderStage.Compute, buffer);
}
enableMask = _cpUniformBuffers.EnableMask;
@ -293,7 +293,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
BufferRange buffer = GetBufferRange(bounds.Address, bounds.Size);
_context.Renderer.ComputePipeline.SetUniformBuffer(index, buffer);
_context.Renderer.Pipeline.BindUniformBuffer(index, ShaderStage.Compute, buffer);
if (index == 0)
{
@ -312,6 +312,9 @@ namespace Ryujinx.Graphics.Gpu.Memory
buffer.Buffer.SetData(buffer.Offset, data);
}
}
// Force rebind after doing compute work.
_rebind = true;
}
public void CommitBindings()
@ -324,7 +327,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
{
BufferRange buffer = GetBufferRange(_indexBuffer.Address, _indexBuffer.Size);
_context.Renderer.GraphicsPipeline.BindIndexBuffer(buffer, _indexBuffer.Type);
_context.Renderer.Pipeline.BindIndexBuffer(buffer, _indexBuffer.Type);
}
}
else if (_indexBuffer.Address != 0)
@ -352,7 +355,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
vertexBuffers[index] = new VertexBufferDescriptor(buffer, vb.Stride, vb.Divisor);
}
_context.Renderer.GraphicsPipeline.BindVertexBuffers(vertexBuffers);
_context.Renderer.Pipeline.BindVertexBuffers(vertexBuffers);
}
else
{
@ -445,15 +448,13 @@ namespace Ryujinx.Graphics.Gpu.Memory
{
BufferRange buffer = GetBufferRange(bounds.Address, bounds.Size);
BufferRange[] buffers = new BufferRange[] { buffer };
if (isStorage)
{
_context.Renderer.GraphicsPipeline.BindStorageBuffers(index, stage, buffers);
_context.Renderer.Pipeline.BindStorageBuffer(index, stage, buffer);
}
else
{
_context.Renderer.GraphicsPipeline.BindUniformBuffers(index, stage, buffers);
_context.Renderer.Pipeline.BindUniformBuffer(index, stage, buffer);
}
if (!isStorage && index == 0)

View file

@ -23,8 +23,10 @@ namespace Ryujinx.Graphics.Gpu.State
ClearDepthValue = 0x364,
ClearStencilValue = 0x368,
DepthBiasState = 0x370,
TextureBarrier = 0x378,
StencilBackMasks = 0x3d5,
InvalidateTextures = 0x3dd,
TextureBarrierTiled = 0x3df,
RtDepthStencilState = 0x3f8,
VertexAttribState = 0x458,
RtDepthStencilSize = 0x48a,