From 934a78005e75653529c320cf90e78fe6536447c2 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Mon, 9 Nov 2020 19:35:04 -0300 Subject: Simplify logic for bindless texture handling (#1667) * Simplify logic for bindless texture handling * Nits --- Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs | 66 +++++----------------- .../Image/TextureBindingsManager.cs | 29 ++-------- 2 files changed, 18 insertions(+), 77 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Image') diff --git a/Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs b/Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs index a328fc2b..be94f310 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureBindingInfo.cs @@ -25,28 +25,14 @@ namespace Ryujinx.Graphics.Gpu.Image public int Binding { get; } /// - /// Shader texture handle. - /// This is an index into the texture constant buffer. - /// - public int Handle { get; } - - /// - /// Indicates if the texture is a bindless texture. - /// - /// - /// For those textures, Handle is ignored. - /// - public bool IsBindless { get; } - - /// - /// Constant buffer slot with the bindless texture handle, for bindless texture. + /// Constant buffer slot with the texture handle. /// public int CbufSlot { get; } /// - /// Constant buffer offset of the bindless texture handle, for bindless texture. + /// Index of the texture handle on the constant buffer at slot . /// - public int CbufOffset { get; } + public int Handle { get; } /// /// Flags from the texture descriptor that indicate how the texture is used. @@ -59,21 +45,17 @@ namespace Ryujinx.Graphics.Gpu.Image /// The shader sampler target type /// Format of the image as declared on the shader /// The shader texture binding point + /// Constant buffer slot where the texture handle is located /// The shader texture handle (read index into the texture constant buffer) /// The texture's usage flags, indicating how it is used in the shader - public TextureBindingInfo(Target target, Format format, int binding, int handle, TextureUsageFlags flags) + public TextureBindingInfo(Target target, Format format, int binding, int cbufSlot, int handle, TextureUsageFlags flags) { - Target = target; - Format = format; - Binding = binding; - Handle = handle; - - IsBindless = false; - - CbufSlot = 0; - CbufOffset = 0; - - Flags = flags; + Target = target; + Format = format; + Binding = binding; + CbufSlot = cbufSlot; + Handle = handle; + Flags = flags; } /// @@ -81,33 +63,11 @@ namespace Ryujinx.Graphics.Gpu.Image /// /// The shader sampler target type /// The shader texture binding point + /// Constant buffer slot where the texture handle is located /// The shader texture handle (read index into the texture constant buffer) /// The texture's usage flags, indicating how it is used in the shader - public TextureBindingInfo(Target target, int binding, int handle, TextureUsageFlags flags) : this(target, (Format)0, binding, handle, flags) + public TextureBindingInfo(Target target, int binding, int cbufSlot, int handle, TextureUsageFlags flags) : this(target, (Format)0, binding, cbufSlot, handle, flags) { } - - /// - /// Constructs the bindless texture binding information structure. - /// - /// The shader sampler target type - /// The shader texture binding point - /// Constant buffer slot where the bindless texture handle is located - /// Constant buffer offset of the bindless texture handle - /// The texture's usage flags, indicating how it is used in the shader - public TextureBindingInfo(Target target, int binding, int cbufSlot, int cbufOffset, TextureUsageFlags flags) - { - Target = target; - Format = 0; - Binding = binding; - Handle = 0; - - IsBindless = true; - - CbufSlot = cbufSlot; - CbufOffset = cbufOffset; - - Flags = flags; - } } } \ No newline at end of file diff --git a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs index bfb6da25..8d44165c 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs @@ -267,30 +267,9 @@ namespace Ryujinx.Graphics.Gpu.Image { TextureBindingInfo bindingInfo = _textureBindings[stageIndex][index]; - int packedId; - - if (bindingInfo.IsBindless) - { - ulong address; - - var bufferManager = _context.Methods.BufferManager; - - if (_isCompute) - { - address = bufferManager.GetComputeUniformBufferAddress(bindingInfo.CbufSlot); - } - else - { - address = bufferManager.GetGraphicsUniformBufferAddress(stageIndex, bindingInfo.CbufSlot); - } - - packedId = _context.PhysicalMemory.Read(address + (ulong)bindingInfo.CbufOffset * 4); - } - else - { - packedId = ReadPackedId(stageIndex, bindingInfo.Handle, _textureBufferIndex); - } + int textureBufferIndex = bindingInfo.CbufSlot < 0 ? _textureBufferIndex : bindingInfo.CbufSlot; + int packedId = ReadPackedId(stageIndex, bindingInfo.Handle, textureBufferIndex); int textureId = UnpackTextureId(packedId); int samplerId; @@ -361,7 +340,9 @@ namespace Ryujinx.Graphics.Gpu.Image { TextureBindingInfo bindingInfo = _imageBindings[stageIndex][index]; - int packedId = ReadPackedId(stageIndex, bindingInfo.Handle, _textureBufferIndex); + int textureBufferIndex = bindingInfo.CbufSlot < 0 ? _textureBufferIndex : bindingInfo.CbufSlot; + + int packedId = ReadPackedId(stageIndex, bindingInfo.Handle, textureBufferIndex); int textureId = UnpackTextureId(packedId); Texture texture = pool.Get(textureId); -- cgit v1.2.3