1 // Copyright 2018 The Amber Authors.
2 // Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 #include "src/command.h"
17
18 #include "src/pipeline.h"
19
20 namespace amber {
21
Command(Type type)22 Command::Command(Type type) : command_type_(type) {}
23
24 Command::~Command() = default;
25
AsClear()26 ClearCommand* Command::AsClear() {
27 return static_cast<ClearCommand*>(this);
28 }
29
AsClearColor()30 ClearColorCommand* Command::AsClearColor() {
31 return static_cast<ClearColorCommand*>(this);
32 }
33
AsClearDepth()34 ClearDepthCommand* Command::AsClearDepth() {
35 return static_cast<ClearDepthCommand*>(this);
36 }
37
AsClearStencil()38 ClearStencilCommand* Command::AsClearStencil() {
39 return static_cast<ClearStencilCommand*>(this);
40 }
41
AsCompareBuffer()42 CompareBufferCommand* Command::AsCompareBuffer() {
43 return static_cast<CompareBufferCommand*>(this);
44 }
45
AsCompute()46 ComputeCommand* Command::AsCompute() {
47 return static_cast<ComputeCommand*>(this);
48 }
49
AsRayTracing()50 RayTracingCommand* Command::AsRayTracing() {
51 return static_cast<RayTracingCommand*>(this);
52 }
53
AsCopy()54 CopyCommand* Command::AsCopy() {
55 return static_cast<CopyCommand*>(this);
56 }
57
AsDrawArrays()58 DrawArraysCommand* Command::AsDrawArrays() {
59 return static_cast<DrawArraysCommand*>(this);
60 }
61
AsDrawRect()62 DrawRectCommand* Command::AsDrawRect() {
63 return static_cast<DrawRectCommand*>(this);
64 }
65
AsDrawGrid()66 DrawGridCommand* Command::AsDrawGrid() {
67 return static_cast<DrawGridCommand*>(this);
68 }
69
AsEntryPoint()70 EntryPointCommand* Command::AsEntryPoint() {
71 return static_cast<EntryPointCommand*>(this);
72 }
73
AsPatchParameterVertices()74 PatchParameterVerticesCommand* Command::AsPatchParameterVertices() {
75 return static_cast<PatchParameterVerticesCommand*>(this);
76 }
77
AsProbe()78 ProbeCommand* Command::AsProbe() {
79 return static_cast<ProbeCommand*>(this);
80 }
81
AsBuffer()82 BufferCommand* Command::AsBuffer() {
83 return static_cast<BufferCommand*>(this);
84 }
85
AsProbeSSBO()86 ProbeSSBOCommand* Command::AsProbeSSBO() {
87 return static_cast<ProbeSSBOCommand*>(this);
88 }
89
AsRepeat()90 RepeatCommand* Command::AsRepeat() {
91 return static_cast<RepeatCommand*>(this);
92 }
93
PipelineCommand(Type type,Pipeline * pipeline)94 PipelineCommand::PipelineCommand(Type type, Pipeline* pipeline)
95 : Command(type), pipeline_(pipeline) {}
96
97 PipelineCommand::~PipelineCommand() = default;
98
DrawRectCommand(Pipeline * pipeline,PipelineData data)99 DrawRectCommand::DrawRectCommand(Pipeline* pipeline, PipelineData data)
100 : PipelineCommand(Type::kDrawRect, pipeline), data_(data) {}
101
102 DrawRectCommand::~DrawRectCommand() = default;
103
DrawGridCommand(Pipeline * pipeline,PipelineData data)104 DrawGridCommand::DrawGridCommand(Pipeline* pipeline, PipelineData data)
105 : PipelineCommand(Type::kDrawGrid, pipeline), data_(data) {}
106
107 DrawGridCommand::~DrawGridCommand() = default;
108
DrawArraysCommand(Pipeline * pipeline,PipelineData data)109 DrawArraysCommand::DrawArraysCommand(Pipeline* pipeline, PipelineData data)
110 : PipelineCommand(Type::kDrawArrays, pipeline), data_(data) {}
111
112 DrawArraysCommand::~DrawArraysCommand() = default;
113
CompareBufferCommand(Buffer * buffer_1,Buffer * buffer_2)114 CompareBufferCommand::CompareBufferCommand(Buffer* buffer_1, Buffer* buffer_2)
115 : Command(Type::kCompareBuffer), buffer_1_(buffer_1), buffer_2_(buffer_2) {}
116
117 CompareBufferCommand::~CompareBufferCommand() = default;
118
ComputeCommand(Pipeline * pipeline)119 ComputeCommand::ComputeCommand(Pipeline* pipeline)
120 : PipelineCommand(Type::kCompute, pipeline) {}
121
122 ComputeCommand::~ComputeCommand() = default;
123
Probe(Type type,Buffer * buffer)124 Probe::Probe(Type type, Buffer* buffer) : Command(type), buffer_(buffer) {}
125
126 Probe::~Probe() = default;
127
ProbeCommand(Buffer * buffer)128 ProbeCommand::ProbeCommand(Buffer* buffer) : Probe(Type::kProbe, buffer) {}
129
130 ProbeCommand::~ProbeCommand() = default;
131
ProbeSSBOCommand(Buffer * buffer)132 ProbeSSBOCommand::ProbeSSBOCommand(Buffer* buffer)
133 : Probe(Type::kProbeSSBO, buffer) {}
134
135 ProbeSSBOCommand::~ProbeSSBOCommand() = default;
136
BindableResourceCommand(Type type,Pipeline * pipeline)137 BindableResourceCommand::BindableResourceCommand(Type type, Pipeline* pipeline)
138 : PipelineCommand(type, pipeline) {}
139
140 BindableResourceCommand::~BindableResourceCommand() = default;
141
BufferCommand(BufferType type,Pipeline * pipeline)142 BufferCommand::BufferCommand(BufferType type, Pipeline* pipeline)
143 : BindableResourceCommand(Type::kBuffer, pipeline), buffer_type_(type) {}
144
145 BufferCommand::~BufferCommand() = default;
146
SamplerCommand(Pipeline * pipeline)147 SamplerCommand::SamplerCommand(Pipeline* pipeline)
148 : BindableResourceCommand(Type::kSampler, pipeline) {}
149
150 SamplerCommand::~SamplerCommand() = default;
151
CopyCommand(Buffer * buffer_from,Buffer * buffer_to)152 CopyCommand::CopyCommand(Buffer* buffer_from, Buffer* buffer_to)
153 : Command(Type::kCopy), buffer_from_(buffer_from), buffer_to_(buffer_to) {}
154
155 CopyCommand::~CopyCommand() = default;
156
ClearCommand(Pipeline * pipeline)157 ClearCommand::ClearCommand(Pipeline* pipeline)
158 : PipelineCommand(Type::kClear, pipeline) {}
159
160 ClearCommand::~ClearCommand() = default;
161
ClearColorCommand(Pipeline * pipeline)162 ClearColorCommand::ClearColorCommand(Pipeline* pipeline)
163 : PipelineCommand(Type::kClearColor, pipeline) {}
164
165 ClearColorCommand::~ClearColorCommand() = default;
166
ClearDepthCommand(Pipeline * pipeline)167 ClearDepthCommand::ClearDepthCommand(Pipeline* pipeline)
168 : PipelineCommand(Type::kClearDepth, pipeline) {}
169
170 ClearDepthCommand::~ClearDepthCommand() = default;
171
ClearStencilCommand(Pipeline * pipeline)172 ClearStencilCommand::ClearStencilCommand(Pipeline* pipeline)
173 : PipelineCommand(Type::kClearStencil, pipeline) {}
174
175 ClearStencilCommand::~ClearStencilCommand() = default;
176
PatchParameterVerticesCommand(Pipeline * pipeline)177 PatchParameterVerticesCommand::PatchParameterVerticesCommand(Pipeline* pipeline)
178 : PipelineCommand(Type::kPatchParameterVertices, pipeline) {}
179
180 PatchParameterVerticesCommand::~PatchParameterVerticesCommand() = default;
181
EntryPointCommand(Pipeline * pipeline)182 EntryPointCommand::EntryPointCommand(Pipeline* pipeline)
183 : PipelineCommand(Type::kEntryPoint, pipeline) {}
184
185 EntryPointCommand::~EntryPointCommand() = default;
186
RepeatCommand(uint32_t count)187 RepeatCommand::RepeatCommand(uint32_t count)
188 : Command(Type::kRepeat), count_(count) {}
189
190 RepeatCommand::~RepeatCommand() = default;
191
TLASCommand(Pipeline * pipeline)192 TLASCommand::TLASCommand(Pipeline* pipeline)
193 : BindableResourceCommand(Type::kTLAS, pipeline) {}
194
195 TLASCommand::~TLASCommand() = default;
196
RayTracingCommand(Pipeline * pipeline)197 RayTracingCommand::RayTracingCommand(Pipeline* pipeline)
198 : PipelineCommand(Type::kRayTracing, pipeline) {}
199
200 RayTracingCommand::~RayTracingCommand() = default;
201
202 } // namespace amber
203