forked from llvm/offload-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuffer.h
More file actions
94 lines (76 loc) · 2.51 KB
/
Copy pathBuffer.h
File metadata and controls
94 lines (76 loc) · 2.51 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//===- Buffer.h - Offload API Buffer --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
#ifndef OFFLOADTEST_API_BUFFER_H
#define OFFLOADTEST_API_BUFFER_H
#include "API/API.h"
#include "API/Resources.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Error.h"
namespace offloadtest {
enum class BufferShaderAccessType : uint32_t {
Raw,
Typed,
Structured,
};
union BufferShaderAccessTypeParams {
Format Fmt; // Typed Only
uint32_t StructureStride; // Structured Only
};
enum class BufferUsage : uint32_t {
Storage,
ConstantBuffer,
IndexBuffer,
VertexBuffer,
IndirectArgs,
};
struct BufferCreateDesc {
MemoryLocation Location;
MemoryBacking Backing;
BufferUsage Usage;
BufferShaderAccessType AccessType;
BufferShaderAccessTypeParams AccessTypeParams;
bool HasCounter;
static BufferCreateDesc uploadBuffer() {
return BufferCreateDesc{MemoryLocation::CpuToGpu,
MemoryBacking::Automatic,
BufferUsage::Storage,
BufferShaderAccessType::Raw,
{},
false};
}
static BufferCreateDesc readbackBuffer() {
return BufferCreateDesc{MemoryLocation::GpuToCpu,
MemoryBacking::Automatic,
BufferUsage::Storage,
BufferShaderAccessType::Raw,
{},
false};
}
};
class Buffer {
GPUAPI API;
public:
virtual ~Buffer();
virtual size_t getSizeInBytes() const = 0;
// Maps the buffer's memory for host access. Only valid for CpuToGpu and
// GpuToCpu buffers; returns an error for GpuOnly. Each successful map() must
// be paired with a call to unmap() before the buffer is used on the GPU.
virtual llvm::Expected<void *> map() = 0;
virtual void unmap() = 0;
Buffer(const Buffer &) = delete;
Buffer &operator=(const Buffer &) = delete;
GPUAPI getAPI() const { return API; }
virtual const BufferCreateDesc &getDesc() const = 0;
protected:
explicit Buffer(GPUAPI API) : API(API) {}
};
} // namespace offloadtest
#endif // OFFLOADTEST_API_BUFFER_H