1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
using OpenTK.Graphics.OpenGL;
using System;
namespace Ryujinx.Graphics.Gal.OpenGL
{
class OglConstBuffer : IGalConstBuffer
{
private const long MaxConstBufferCacheSize = 64 * 1024 * 1024;
private OglCachedResource<OglStreamBuffer> _cache;
public OglConstBuffer()
{
_cache = new OglCachedResource<OglStreamBuffer>(DeleteBuffer, MaxConstBufferCacheSize);
}
public void LockCache()
{
_cache.Lock();
}
public void UnlockCache()
{
_cache.Unlock();
}
public void Create(long key, long size)
{
OglStreamBuffer buffer = new OglStreamBuffer(BufferTarget.UniformBuffer, size);
_cache.AddOrUpdate(key, buffer, size);
}
public bool IsCached(long key, long size)
{
return _cache.TryGetSize(key, out long cachedSize) && cachedSize == size;
}
public void SetData(long key, long size, IntPtr hostAddress)
{
if (_cache.TryGetValue(key, out OglStreamBuffer buffer))
{
buffer.SetData(size, hostAddress);
}
}
public void SetData(long key, byte[] data)
{
if (_cache.TryGetValue(key, out OglStreamBuffer buffer))
{
buffer.SetData(data);
}
}
public bool TryGetUbo(long key, out int uboHandle)
{
if (_cache.TryGetValue(key, out OglStreamBuffer buffer))
{
uboHandle = buffer.Handle;
return true;
}
uboHandle = 0;
return false;
}
private static void DeleteBuffer(OglStreamBuffer buffer)
{
buffer.Dispose();
}
}
}
|