-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathEncoder.h
More file actions
131 lines (103 loc) · 4.45 KB
/
Copy pathEncoder.h
File metadata and controls
131 lines (103 loc) · 4.45 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//===- Encoder.h - Offload API Command Encoder Abstraction ----------------===//
//
// 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_ENCODER_H
#define OFFLOADTEST_API_ENCODER_H
#include "API/API.h"
#include "API/Enums.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include <cstddef>
#include <cstdint>
namespace offloadtest {
class Buffer;
class PipelineState;
/// Base class for all command encoders. An encoder records commands into a
/// command buffer. Call endEncoding() when done recording. Barriers are
/// automatically inserted between commands.
class CommandEncoder {
GPUAPI API;
bool Ended = false;
protected:
/// Backend-specific cleanup. Called exactly once, either explicitly via
/// endEncoding() or implicitly from the most-derived destructor.
virtual void endEncodingImpl() = 0;
public:
explicit CommandEncoder(GPUAPI API) : API(API) {}
virtual ~CommandEncoder();
CommandEncoder(const CommandEncoder &) = delete;
CommandEncoder &operator=(const CommandEncoder &) = delete;
GPUAPI getAPI() const { return API; }
bool isEnded() const { return Ended; }
/// Begin a named debug group. Visible in GPU debuggers (PIX, RenderDoc,
/// Xcode). Must be balanced by a corresponding popDebugGroup() call.
virtual void pushDebugGroup(llvm::StringRef Label) {}
/// End the most recently pushed debug group.
virtual void popDebugGroup() {}
/// Insert a point-in-time debug marker.
virtual void insertDebugSignpost(llvm::StringRef Label) {}
/// Finish recording. No further commands may be recorded after this call.
/// Idempotent: safe to call more than once. If not called explicitly, the
/// most-derived destructor invokes it as a safeguard against leaked open
/// encoders.
void endEncoding() {
if (Ended)
return;
endEncodingImpl();
Ended = true;
}
};
/// Encoder for recording compute dispatch commands.
class ComputeEncoder : public CommandEncoder {
public:
using CommandEncoder::CommandEncoder;
/// Dispatch a compute grid. GroupCount specifies how many workgroups to
/// launch in each dimension. The workgroup size is derived from \p PSO
/// (e.g. the shader's numthreads attribute), which is also bound for the
/// dispatch.
virtual llvm::Error dispatch(const PipelineState &PSO, uint32_t GroupCountX,
uint32_t GroupCountY, uint32_t GroupCountZ) = 0;
/// Copy \p Size bytes from \p Src at \p SrcOffset to \p Dst at
/// \p DstOffset.
virtual llvm::Error copyBufferToBuffer(Buffer &Src, size_t SrcOffset,
Buffer &Dst, size_t DstOffset,
size_t Size) = 0;
};
struct Viewport {
float X = 0.0f, Y = 0.0f;
float Width = 0.0f, Height = 0.0f;
float MinDepth = 0.0f, MaxDepth = 1.0f;
};
struct ScissorRect {
int32_t X = 0, Y = 0;
uint32_t Width = 0, Height = 0;
};
class RenderEncoder : public CommandEncoder {
public:
using CommandEncoder::CommandEncoder;
virtual void setViewport(const Viewport &VP) = 0;
virtual void setScissor(const ScissorRect &Rect) = 0;
virtual void setVertexBuffer(uint32_t Slot, Buffer *VB, size_t Offset,
uint32_t Stride) = 0;
/// Override the pipeline's default per-draw shading rate. Backends that do
/// not implement Variable Rate Shading are free to ignore this; tests that
/// depend on it should mark themselves UNSUPPORTED on those backends.
virtual void setShadingRate(ShadingRate Rate) {}
/// Enable the SV_ShadingRate per-primitive input. Backends that do not
/// implement Variable Rate Shading Tier 2 are free to ignore this.
virtual void enablePrimitiveShadingRate() {}
virtual llvm::Error drawInstanced(const PipelineState &PSO,
uint32_t VertexCount,
uint32_t InstanceCount,
uint32_t FirstVertex = 0,
uint32_t FirstInstance = 0) = 0;
virtual llvm::Error dispatchMesh(const PipelineState &PSO,
uint32_t GroupCountX, uint32_t GroupCountY,
uint32_t GroupCountZ) = 0;
};
} // namespace offloadtest
#endif // OFFLOADTEST_API_ENCODER_H