/// <summary> /// Performs disposal of the host GPU caches with resources mapped on this physical memory. /// This must only be called from the render thread. /// </summary> private void Destroy() { ShaderCache.Dispose(); BufferCache.Dispose(); TextureCache.Dispose(); DecrementReferenceCount(); }
/// <summary> /// Creates a new instance of the physical memory. /// </summary> /// <param name="context">GPU context that the physical memory belongs to</param> /// <param name="cpuMemory">CPU memory manager of the application process</param> public PhysicalMemory(GpuContext context, IVirtualMemoryManagerTracked cpuMemory) { _context = context; _cpuMemory = cpuMemory; ShaderCache = new ShaderCache(context); BufferCache = new BufferCache(context, this); TextureCache = new TextureCache(context, this); if (cpuMemory is IRefCounted rc) { rc.IncrementReferenceCount(); } _referenceCount = 1; }
private void BindBuffers(BufferCache bufferCache, BuffersPerStage[] bindings, bool isStorage) { int rangesFirst = 0; int rangesCount = 0; Span <BufferRange> ranges = _ranges; for (ShaderStage stage = ShaderStage.Vertex; stage <= ShaderStage.Fragment; stage++) { ref var buffers = ref bindings[(int)stage - 1]; for (int index = 0; index < buffers.Count; index++) { ref var bindingInfo = ref buffers.Bindings[index]; BufferBounds bounds = buffers.Buffers[bindingInfo.Slot]; if (bounds.Address != 0) { var isWrite = bounds.Flags.HasFlag(BufferUsageFlags.Write); var range = isStorage ? bufferCache.GetBufferRangeTillEnd(bounds.Address, bounds.Size, isWrite) : bufferCache.GetBufferRange(bounds.Address, bounds.Size); if (rangesCount == 0) { rangesFirst = bindingInfo.Binding; } else if (bindingInfo.Binding != rangesFirst + rangesCount) { SetHostBuffers(ranges, rangesFirst, rangesCount, isStorage); rangesFirst = bindingInfo.Binding; rangesCount = 0; } ranges[rangesCount++] = range; } }