diff options
author | gdkchan <gab.dark.100@gmail.com> | 2024-09-19 14:38:30 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-19 14:38:30 -0300 |
commit | 24ee8c39f1fd8ae2dc2d92cda1cdb41e8af45f0a (patch) | |
tree | 5cdbf2df0e5ca731ae7368c79f70e734da6d8c62 | |
parent | 73f985d27ca0c85f053e8b9494ba83a6c4d3afbf (diff) |
Add support for sampler sRGB disable (#7312)1.1.1396
-rw-r--r-- | src/Ryujinx.Graphics.Gpu/Image/Sampler.cs | 7 | ||||
-rw-r--r-- | src/Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs | 9 | ||||
-rw-r--r-- | src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs | 10 | ||||
-rw-r--r-- | src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs | 28 |
4 files changed, 48 insertions, 6 deletions
diff --git a/src/Ryujinx.Graphics.Gpu/Image/Sampler.cs b/src/Ryujinx.Graphics.Gpu/Image/Sampler.cs index d6a3d975b..b007c1591 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/Sampler.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/Sampler.cs | |||
@@ -14,6 +14,11 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
14 | public bool IsDisposed { get; private set; } | 14 | public bool IsDisposed { get; private set; } |
15 | 15 | ||
16 | /// <summary> | 16 | /// <summary> |
17 | /// True if the sampler has sRGB conversion enabled, false otherwise. | ||
18 | /// </summary> | ||
19 | public bool IsSrgb { get; } | ||
20 | |||
21 | /// <summary> | ||
17 | /// Host sampler object. | 22 | /// Host sampler object. |
18 | /// </summary> | 23 | /// </summary> |
19 | private readonly ISampler _hostSampler; | 24 | private readonly ISampler _hostSampler; |
@@ -30,6 +35,8 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
30 | /// <param name="descriptor">The Maxwell sampler descriptor</param> | 35 | /// <param name="descriptor">The Maxwell sampler descriptor</param> |
31 | public Sampler(GpuContext context, SamplerDescriptor descriptor) | 36 | public Sampler(GpuContext context, SamplerDescriptor descriptor) |
32 | { | 37 | { |
38 | IsSrgb = descriptor.UnpackSrgb(); | ||
39 | |||
33 | MinFilter minFilter = descriptor.UnpackMinFilter(); | 40 | MinFilter minFilter = descriptor.UnpackMinFilter(); |
34 | MagFilter magFilter = descriptor.UnpackMagFilter(); | 41 | MagFilter magFilter = descriptor.UnpackMagFilter(); |
35 | 42 | ||
diff --git a/src/Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs b/src/Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs index e04c31dfa..836a3260c 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/SamplerDescriptor.cs | |||
@@ -114,6 +114,15 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
114 | } | 114 | } |
115 | 115 | ||
116 | /// <summary> | 116 | /// <summary> |
117 | /// Unpacks the sampler sRGB format flag. | ||
118 | /// </summary> | ||
119 | /// <returns>True if the has sampler is sRGB conversion enabled, false otherwise</returns> | ||
120 | public readonly bool UnpackSrgb() | ||
121 | { | ||
122 | return (Word0 & (1 << 13)) != 0; | ||
123 | } | ||
124 | |||
125 | /// <summary> | ||
117 | /// Unpacks and converts the maximum anisotropy value used for texture anisotropic filtering. | 126 | /// Unpacks and converts the maximum anisotropy value used for texture anisotropic filtering. |
118 | /// </summary> | 127 | /// </summary> |
119 | /// <returns>The maximum anisotropy</returns> | 128 | /// <returns>The maximum anisotropy</returns> |
diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs index ad018f159..f96ddfb1b 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs | |||
@@ -187,7 +187,9 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
187 | { | 187 | { |
188 | (TexturePool texturePool, SamplerPool samplerPool) = GetPools(); | 188 | (TexturePool texturePool, SamplerPool samplerPool) = GetPools(); |
189 | 189 | ||
190 | return (texturePool.Get(textureId), samplerPool.Get(samplerId)); | 190 | Sampler sampler = samplerPool?.Get(samplerId); |
191 | |||
192 | return (texturePool.Get(textureId, sampler?.IsSrgb ?? true), sampler); | ||
191 | } | 193 | } |
192 | 194 | ||
193 | /// <summary> | 195 | /// <summary> |
@@ -508,11 +510,11 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
508 | state.TextureHandle = textureId; | 510 | state.TextureHandle = textureId; |
509 | state.SamplerHandle = samplerId; | 511 | state.SamplerHandle = samplerId; |
510 | 512 | ||
511 | ref readonly TextureDescriptor descriptor = ref texturePool.GetForBinding(textureId, out Texture texture); | 513 | Sampler sampler = samplerPool?.Get(samplerId); |
512 | 514 | ||
513 | specStateMatches &= specState.MatchesTexture(stage, index, descriptor); | 515 | ref readonly TextureDescriptor descriptor = ref texturePool.GetForBinding(textureId, sampler?.IsSrgb ?? true, out Texture texture); |
514 | 516 | ||
515 | Sampler sampler = samplerPool?.Get(samplerId); | 517 | specStateMatches &= specState.MatchesTexture(stage, index, descriptor); |
516 | 518 | ||
517 | ITexture hostTexture = texture?.GetTargetTexture(bindingInfo.Target); | 519 | ITexture hostTexture = texture?.GetTargetTexture(bindingInfo.Target); |
518 | ISampler hostSampler = sampler?.GetHostSampler(texture); | 520 | ISampler hostSampler = sampler?.GetHostSampler(texture); |
diff --git a/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs b/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs index 5f43c1824..be7cb0b89 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs | |||
@@ -228,6 +228,17 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
228 | /// <returns>The texture with the given ID</returns> | 228 | /// <returns>The texture with the given ID</returns> |
229 | public override Texture Get(int id) | 229 | public override Texture Get(int id) |
230 | { | 230 | { |
231 | return Get(id, srgbSampler: true); | ||
232 | } | ||
233 | |||
234 | /// <summary> | ||
235 | /// Gets the texture with the given ID. | ||
236 | /// </summary> | ||
237 | /// <param name="id">ID of the texture. This is effectively a zero-based index</param> | ||
238 | /// <param name="srgbSampler">Whether the texture is being accessed with a sampler that has sRGB conversion enabled</param> | ||
239 | /// <returns>The texture with the given ID</returns> | ||
240 | public Texture Get(int id, bool srgbSampler) | ||
241 | { | ||
231 | if ((uint)id >= Items.Length) | 242 | if ((uint)id >= Items.Length) |
232 | { | 243 | { |
233 | return null; | 244 | return null; |
@@ -240,7 +251,7 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
240 | SynchronizeMemory(); | 251 | SynchronizeMemory(); |
241 | } | 252 | } |
242 | 253 | ||
243 | GetInternal(id, out Texture texture); | 254 | GetForBinding(id, srgbSampler, out Texture texture); |
244 | 255 | ||
245 | return texture; | 256 | return texture; |
246 | } | 257 | } |
@@ -252,9 +263,10 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
252 | /// This method assumes that the pool has been manually synchronized before doing binding. | 263 | /// This method assumes that the pool has been manually synchronized before doing binding. |
253 | /// </remarks> | 264 | /// </remarks> |
254 | /// <param name="id">ID of the texture. This is effectively a zero-based index</param> | 265 | /// <param name="id">ID of the texture. This is effectively a zero-based index</param> |
266 | /// <param name="srgbSampler">Whether the texture is being accessed with a sampler that has sRGB conversion enabled</param> | ||
255 | /// <param name="texture">The texture with the given ID</param> | 267 | /// <param name="texture">The texture with the given ID</param> |
256 | /// <returns>The texture descriptor with the given ID</returns> | 268 | /// <returns>The texture descriptor with the given ID</returns> |
257 | public ref readonly TextureDescriptor GetForBinding(int id, out Texture texture) | 269 | public ref readonly TextureDescriptor GetForBinding(int id, bool srgbSampler, out Texture texture) |
258 | { | 270 | { |
259 | if ((uint)id >= Items.Length) | 271 | if ((uint)id >= Items.Length) |
260 | { | 272 | { |
@@ -264,6 +276,18 @@ namespace Ryujinx.Graphics.Gpu.Image | |||
264 | 276 | ||
265 | // When getting for binding, assume the pool has already been synchronized. | 277 | // When getting for binding, assume the pool has already been synchronized. |
266 | 278 | ||
279 | if (!srgbSampler) | ||
280 | { | ||
281 | // If the sampler does not have the sRGB bit enabled, then the texture can't use a sRGB format. | ||
282 | ref readonly TextureDescriptor tempDescriptor = ref GetDescriptorRef(id); | ||
283 | |||
284 | if (tempDescriptor.UnpackSrgb() && FormatTable.TryGetTextureFormat(tempDescriptor.UnpackFormat(), isSrgb: false, out FormatInfo formatInfo)) | ||
285 | { | ||
286 | // Get a view of the texture with the right format. | ||
287 | return ref GetForBinding(id, formatInfo, out texture); | ||
288 | } | ||
289 | } | ||
290 | |||
267 | return ref GetInternal(id, out texture); | 291 | return ref GetInternal(id, out texture); |
268 | } | 292 | } |
269 | 293 | ||