File: command_buffer_pool_allocator.h

package info (click to toggle)
intel-compute-runtime 26.05.37020.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,596 kB
  • sloc: cpp: 976,037; lisp: 2,096; sh: 704; makefile: 162
file content (64 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download
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
/*
 * Copyright (C) 2026 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/helpers/constants.h"
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/utilities/buffer_pool_allocator.h"
#include "shared/source/utilities/stackvec.h"

#include <mutex>

namespace NEO {
class GraphicsAllocation;
class Device;

class CommandBufferPool : public AbstractBuffersPool<CommandBufferPool, GraphicsAllocation> {
    using BaseType = AbstractBuffersPool<CommandBufferPool, GraphicsAllocation>;

  public:
    CommandBufferPool(Device *device, size_t storageSize);

    CommandBufferPool(const CommandBufferPool &) = delete;
    CommandBufferPool &operator=(const CommandBufferPool &) = delete;

    CommandBufferPool(CommandBufferPool &&pool) noexcept;
    CommandBufferPool &operator=(CommandBufferPool &&other) = delete;

    ~CommandBufferPool() override;

    GraphicsAllocation *allocateCommandBuffer(size_t requestedSize) const;
    const StackVec<GraphicsAllocation *, 1> &getAllocationsVector();

  private:
    Device *device;
    StackVec<GraphicsAllocation *, 1> stackVec;
    std::unique_ptr<std::mutex> mtx;
};

class CommandBufferPoolAllocator : public AbstractBuffersAllocator<CommandBufferPool, GraphicsAllocation> {
  public:
    explicit CommandBufferPoolAllocator(Device *device);

    GraphicsAllocation *allocateCommandBuffer(size_t size);
    void freeCommandBuffer(GraphicsAllocation *allocation);

  private:
    GraphicsAllocation *tryAllocate(size_t size);
    size_t alignToPoolSize(size_t size) const;

    Device *device;
    size_t defaultPoolSize = MemoryConstants::pageSize2M * 4;
    size_t poolAlignment = MemoryConstants::pageSize2M;
    size_t maxRequestedSize = MemoryConstants::pageSize2M;
    std::mutex allocatorMtx;
};

static_assert(NEO::NonCopyable<CommandBufferPool>);

} // namespace NEO