Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Commands.h
Go to the documentation of this file.
1 // Copyright (c) 2018 the Talvos developers. All rights reserved.
2 //
3 // This file is distributed under a three-clause BSD license. For full license
4 // terms please see the LICENSE file distributed with this source code.
5 
8 
9 #ifndef TALVOS_COMMANDS_H
10 #define TALVOS_COMMANDS_H
11 
12 #include <memory>
13 #include <vector>
14 
15 #include "vulkan/vulkan_core.h"
16 
17 #include "talvos/Dim3.h"
18 #include "talvos/PipelineContext.h"
19 
20 namespace talvos
21 {
22 
23 class Device;
24 class ComputePipeline;
25 class GraphicsPipeline;
26 class Image;
27 class Object;
28 class RenderPassInstance;
29 
31 class Command
32 {
33 public:
35  enum Type
36  {
55  };
56 
58  Type getType() const { return Ty; }
59 
61  void run(Device &Dev) const;
62 
63 protected:
65  Command(Type Ty) : Ty(Ty){};
66 
67  Type Ty;
68 
70  virtual void runImpl(Device &Dev) const = 0;
71 };
72 
75 {
76 public:
78  BeginRenderPassCommand(std::shared_ptr<RenderPassInstance> RPI)
79  : Command(BEGIN_RENDER_PASS), RPI(RPI)
80  {}
81 
82 protected:
84  virtual void runImpl(Device &Dev) const override;
85 
86 private:
88  std::shared_ptr<RenderPassInstance> RPI;
89 };
90 
92 class BlitImageCommand : public Command
93 {
94 public:
97  const std::vector<VkImageBlit> &Regions, VkFilter Filter)
98  : Command(BLIT_IMAGE), SrcImage(SrcImage), DstImage(DstImage),
99  Regions(Regions), Filter(Filter)
100  {}
101 
102 protected:
104  virtual void runImpl(Device &Dev) const override;
105 
106 private:
108  const Image &SrcImage;
109 
111  const Image &DstImage;
112 
114  std::vector<VkImageBlit> Regions;
115 
117  VkFilter Filter;
118 };
119 
122 {
123 public:
126  const std::vector<VkClearAttachment> &ClearAttachments,
127  const std::vector<VkClearRect> &ClearRects)
128  : Command(CLEAR_ATTACHMENT), RPI(RPI), ClearAttachments(ClearAttachments),
129  ClearRects(ClearRects)
130  {}
131 
132 protected:
134  virtual void runImpl(Device &Dev) const override;
135 
136 private:
139 
141  std::vector<VkClearAttachment> ClearAttachments;
142 
144  std::vector<VkClearRect> ClearRects;
145 };
146 
149 {
150 public:
152  ClearColorImageCommand(const Image &DstImage, VkClearColorValue Color,
153  const std::vector<VkImageSubresourceRange> &Ranges)
154  : Command(CLEAR_COLOR_IMAGE), DstImage(DstImage), Color(Color),
155  Ranges(Ranges)
156  {}
157 
158 protected:
160  virtual void runImpl(Device &Dev) const override;
161 
162 private:
164  const Image &DstImage;
165 
167  VkClearColorValue Color;
168 
170  std::vector<VkImageSubresourceRange> Ranges;
171 };
172 
175 {
176 public:
178  CopyBufferCommand(uint64_t SrcAddr, uint64_t DstAddr,
179  const std::vector<VkBufferCopy> &Regions)
180  : Command(COPY_BUFFER), SrcAddr(SrcAddr), DstAddr(DstAddr),
181  Regions(Regions)
182  {}
183 
184 protected:
186  virtual void runImpl(Device &Dev) const override;
187 
188 private:
190  uint64_t SrcAddr;
191 
193  uint64_t DstAddr;
194 
196  std::vector<VkBufferCopy> Regions;
197 };
198 
201 {
202 public:
205  const std::vector<VkBufferImageCopy> &Regions)
206  : Command(COPY_BUFFER_TO_IMAGE), SrcAddr(SrcAddr), DstImage(DstImage),
207  Regions(Regions)
208  {}
209 
210 protected:
212  virtual void runImpl(Device &Dev) const override;
213 
214 private:
216  uint64_t SrcAddr;
217 
219  const Image &DstImage;
220 
222  std::vector<VkBufferImageCopy> Regions;
223 };
224 
226 class CopyImageCommand : public Command
227 {
228 public:
231  const std::vector<VkImageCopy> &Regions)
232  : Command(COPY_IMAGE), SrcImage(SrcImage), DstImage(DstImage),
233  Regions(Regions)
234  {}
235 
236 protected:
238  virtual void runImpl(Device &Dev) const override;
239 
240 private:
242  const Image &SrcImage;
243 
245  const Image &DstImage;
246 
248  std::vector<VkImageCopy> Regions;
249 };
250 
253 {
254 public:
257  const std::vector<VkBufferImageCopy> &Regions)
258  : Command(COPY_IMAGE_TO_BUFFER), SrcImage(SrcImage), DstAddr(DstAddr),
259  Regions(Regions)
260  {}
261 
262 protected:
264  virtual void runImpl(Device &Dev) const override;
265 
266 private:
268  const Image &SrcImage;
269 
271  uint64_t DstAddr;
272 
274  std::vector<VkBufferImageCopy> Regions;
275 };
276 
278 class DispatchCommand : public Command
279 {
280 public:
287  : Command(DISPATCH), PC(PC), BaseGroup(BaseGroup), NumGroups(NumGroups)
288  {}
289 
291  Dim3 getBaseGroup() const { return BaseGroup; }
292 
294  Dim3 getNumGroups() const { return NumGroups; }
295 
297  const PipelineContext &getPipelineContext() const { return PC; }
298 
299 protected:
301  virtual void runImpl(Device &Dev) const override;
302 
303 private:
305 
308 };
309 
311 class DrawCommandBase : public Command
312 {
313 public:
323  const std::shared_ptr<RenderPassInstance> RPI,
324  uint32_t NumVertices, uint32_t VertexOffset,
325  uint32_t NumInstances, uint32_t InstanceOffset)
326  : Command(Ty), PC(PC), RPI(RPI), NumVertices(NumVertices),
327  VertexOffset(VertexOffset), NumInstances(NumInstances),
328  InstanceOffset(InstanceOffset)
329  {}
330 
332  uint32_t getInstanceOffset() const { return InstanceOffset; }
333 
335  uint32_t getNumInstances() const { return NumInstances; }
336 
338  uint32_t getNumVertices() const { return NumVertices; }
339 
341  const PipelineContext &getPipelineContext() const { return PC; }
342 
344  const RenderPassInstance &getRenderPassInstance() const { return *RPI; }
345 
347  uint32_t getVertexOffset() const { return VertexOffset; }
348 
350  void setRenderPassInstance(const std::shared_ptr<RenderPassInstance> RPI)
351  {
352  this->RPI = RPI;
353  }
354 
355 protected:
357  virtual void runImpl(Device &Dev) const override = 0;
358 
359 private:
361 
362  std::shared_ptr<RenderPassInstance> RPI;
363 
364  uint32_t NumVertices;
365  uint32_t VertexOffset;
366  uint32_t NumInstances;
367  uint32_t InstanceOffset;
368 };
369 
372 {
373 public:
383  const std::shared_ptr<RenderPassInstance> RPI,
384  uint32_t NumVertices, uint32_t VertexOffset,
385  uint32_t NumInstances, uint32_t InstanceOffset)
386  : DrawCommandBase(DRAW, PC, RPI, NumVertices, VertexOffset, NumInstances,
387  InstanceOffset){};
388 
389 protected:
391  virtual void runImpl(Device &Dev) const override;
392 };
393 
396 {
397 public:
410  const std::shared_ptr<RenderPassInstance> RPI,
411  uint32_t NumVertices, uint32_t IndexOffset,
412  uint32_t VertexOffset, uint32_t NumInstances,
413  uint32_t InstanceOffset, uint64_t IndexBaseAddress,
414  VkIndexType IndexType)
415  : DrawCommandBase(DRAW_INDEXED, PC, RPI, NumVertices, VertexOffset,
416  NumInstances, InstanceOffset),
417  IndexOffset(IndexOffset), IndexBaseAddress(IndexBaseAddress),
418  IndexType(IndexType){};
419 
421  uint64_t getIndexBaseAddress() const { return IndexBaseAddress; }
422 
424  uint32_t getIndexOffset() const { return IndexOffset; }
425 
427  VkIndexType getIndexType() const { return IndexType; }
428 
429 protected:
431  virtual void runImpl(Device &Dev) const override;
432 
433 private:
434  uint32_t IndexOffset;
435  uint64_t IndexBaseAddress;
436  VkIndexType IndexType;
437 };
438 
441 {
442 public:
444  EndRenderPassCommand(std::shared_ptr<RenderPassInstance> RPI)
445  : Command(END_RENDER_PASS), RPI(RPI)
446  {}
447 
448 protected:
450  virtual void runImpl(Device &Dev) const override;
451 
452 private:
454  std::shared_ptr<RenderPassInstance> RPI;
455 };
456 
459 {
460 public:
462  FillBufferCommand(uint64_t Base, uint64_t NumBytes, uint32_t Data)
463  : Command(FILL_BUFFER), Base(Base), NumBytes(NumBytes), Data(Data)
464  {}
465 
466 protected:
468  virtual void runImpl(Device &Dev) const override;
469 
470 private:
472  uint64_t Base;
473 
475  uint64_t NumBytes;
476 
478  uint32_t Data;
479 };
480 
483 {
484 public:
486  NextSubpassCommand(std::shared_ptr<RenderPassInstance> RPI)
487  : Command(NEXT_SUBPASS), RPI(RPI)
488  {}
489 
490 protected:
492  virtual void runImpl(Device &Dev) const override;
493 
494 private:
496  std::shared_ptr<RenderPassInstance> RPI;
497 };
498 
501 {
502 public:
504  ResetEventCommand(volatile bool *Event) : Command(RESET_EVENT), Event(Event)
505  {}
506 
507 protected:
509  virtual void runImpl(Device &Dev) const override;
510 
511 private:
513  volatile bool *Event;
514 };
515 
517 class SetEventCommand : public Command
518 {
519 public:
521  SetEventCommand(volatile bool *Event) : Command(SET_EVENT), Event(Event) {}
522 
523 protected:
525  virtual void runImpl(Device &Dev) const override;
526 
527 private:
529  volatile bool *Event;
530 };
531 
534 {
535 public:
537  UpdateBufferCommand(uint64_t Base, uint64_t NumBytes, const void *Data);
538 
540 
541 protected:
543  virtual void runImpl(Device &Dev) const override;
544 
545 private:
547  uint64_t Base;
548 
550  uint64_t NumBytes;
551 
553  uint8_t *Data;
554 };
555 
558 {
559 public:
561  WaitEventsCommand(std::vector<volatile bool *> Events)
562  : Command(WAIT_EVENTS), Events(Events)
563  {}
564 
565 protected:
567  virtual void runImpl(Device &Dev) const override;
568 
569 private:
571  std::vector<volatile bool *> Events;
572 };
573 
574 } // namespace talvos
575 
576 #endif
void run(Device &Dev) const
Run this command on Dev.
Definition: Commands.cpp:23
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:236
Dim3 BaseGroup
The base workgroup offset.
Definition: Commands.h:306
std::vector< VkClearAttachment > ClearAttachments
The attachments to clear.
Definition: Commands.h:141
std::shared_ptr< RenderPassInstance > RPI
The render pass instance.
Definition: Commands.h:88
This class encapsulates information about a copy buffer to image command.
Definition: Commands.h:200
uint8_t * Data
The data to update the buffer with.
Definition: Commands.h:553
const Image & SrcImage
The source image.
Definition: Commands.h:108
const Image & SrcImage
The source image.
Definition: Commands.h:268
This class encapsulates information about a begin render pass command.
Definition: Commands.h:74
This class represents an image object.
Definition: Image.h:24
uint64_t DstAddr
The memory address of the destination buffer.
Definition: Commands.h:193
void setRenderPassInstance(const std::shared_ptr< RenderPassInstance > RPI)
Set the render pass instance used by this command.
Definition: Commands.h:350
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:349
std::shared_ptr< RenderPassInstance > RPI
The render pass instance.
Definition: Commands.h:454
uint64_t NumBytes
The number of bytes to fill.
Definition: Commands.h:475
This class encapsulates information about an indexed draw command.
Definition: Commands.h:395
SetEventCommand(volatile bool *Event)
Create a new SetEventCommand.
Definition: Commands.h:521
This class encapsulates information about a copy buffer command.
Definition: Commands.h:174
BeginRenderPassCommand(std::shared_ptr< RenderPassInstance > RPI)
Create a new BeginRenderPassCommand for a RenderPassInstance.
Definition: Commands.h:78
Type getType() const
Returns the type of this command.
Definition: Commands.h:58
This class encapsulates information about an update buffer command.
Definition: Commands.h:533
NextSubpassCommand(std::shared_ptr< RenderPassInstance > RPI)
Create a new NextSubpassCommand for a RenderPassInstance.
Definition: Commands.h:486
const RenderPassInstance & RPI
The render pass instance this command is operating inside.
Definition: Commands.h:138
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:362
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:176
This class encapsulates information about a next subpass command.
Definition: Commands.h:482
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:356
uint32_t VertexOffset
Offset of first vertex.
Definition: Commands.h:365
DrawIndexedCommand(const PipelineContext &PC, const std::shared_ptr< RenderPassInstance > RPI, uint32_t NumVertices, uint32_t IndexOffset, uint32_t VertexOffset, uint32_t NumInstances, uint32_t InstanceOffset, uint64_t IndexBaseAddress, VkIndexType IndexType)
Create a new DrawIndexedCommand.
Definition: Commands.h:409
std::vector< VkImageBlit > Regions
The regions to copy.
Definition: Commands.h:114
std::vector< VkBufferCopy > Regions
The regions to copy.
Definition: Commands.h:196
EndRenderPassCommand(std::shared_ptr< RenderPassInstance > RPI)
Create a new EndRenderPassCommand for a RenderPassInstance.
Definition: Commands.h:444
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:383
uint32_t getIndexOffset() const
Returns the offset of the first index.
Definition: Commands.h:424
WaitEventsCommand(std::vector< volatile bool * > Events)
Create a new WaitEventsCommand.
Definition: Commands.h:561
This class encapsulates information about a compute kernel launch.
Definition: Commands.h:278
VkFilter Filter
The filter to use when scaling.
Definition: Commands.h:117
std::vector< VkBufferImageCopy > Regions
The regions to copy.
Definition: Commands.h:222
std::vector< VkBufferImageCopy > Regions
The regions to copy.
Definition: Commands.h:274
uint32_t Data
The data to fill the buffer with.
Definition: Commands.h:478
uint64_t getIndexBaseAddress() const
Returns the address in memory of the indices.
Definition: Commands.h:421
std::vector< VkClearRect > ClearRects
The regions to clear.
Definition: Commands.h:144
const RenderPassInstance & getRenderPassInstance() const
Returns the render pass instance used by this command.
Definition: Commands.h:344
std::vector< volatile bool * > Events
The events to wait for.
Definition: Commands.h:571
uint64_t Base
The memory address to begin updating from.
Definition: Commands.h:547
This class is a base class for all commands.
Definition: Commands.h:31
This class represents an instance of a render pass being used for drawing.
Definition: RenderPass.h:95
This class encapsulates pipeline state and bound resources.
Dim3 getNumGroups() const
Returns the number of workgroups this command launches.
Definition: Commands.h:294
ResetEventCommand(volatile bool *Event)
Create a new ResetEventCommand.
Definition: Commands.h:504
std::vector< VkImageSubresourceRange > Ranges
The image subranges to clear.
Definition: Commands.h:170
const PipelineContext & getPipelineContext() const
Returns the pipeline context.
Definition: Commands.h:341
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:289
FillBufferCommand(uint64_t Base, uint64_t NumBytes, uint32_t Data)
Create a new FillBufferCommand.
Definition: Commands.h:462
const Image & DstImage
The destination image.
Definition: Commands.h:219
DispatchCommand(const PipelineContext &PC, Dim3 BaseGroup, Dim3 NumGroups)
Create a new DispatchCommand.
Definition: Commands.h:286
This class encapsulates information about a fill buffer command.
Definition: Commands.h:458
Class representing a 3-dimensional size or ID.
Definition: Dim3.h:22
const Image & DstImage
The image to clear.
Definition: Commands.h:164
uint32_t IndexOffset
Offset of the first index.
Definition: Commands.h:434
This is an abstract base class for draw commands.
Definition: Commands.h:311
uint64_t Base
The memory address to begin filling from.
Definition: Commands.h:472
PipelineContext PC
The pipeline context.
Definition: Commands.h:304
VkIndexType getIndexType() const
Returns the type of the indices.
Definition: Commands.h:427
std::shared_ptr< RenderPassInstance > RPI
The render pass instance.
Definition: Commands.h:496
volatile bool * Event
The flag to reset when this command executes.
Definition: Commands.h:513
const Image & SrcImage
The source image.
Definition: Commands.h:242
const Image & DstImage
The destination image.
Definition: Commands.h:245
uint32_t getInstanceOffset() const
Returns the offset of the first instance.
Definition: Commands.h:332
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:30
uint64_t SrcAddr
The memory address of the source buffer.
Definition: Commands.h:216
CopyImageToBufferCommand(const Image &SrcImage, uint64_t DstAddr, const std::vector< VkBufferImageCopy > &Regions)
Create a new CopyImageToBufferCommand.
Definition: Commands.h:256
volatile bool * Event
The flag to set when this command executes.
Definition: Commands.h:529
This file declares the Dim3 class.
This class encapsulates information about a set event command.
Definition: Commands.h:517
CopyBufferToImageCommand(uint64_t SrcAddr, const Image &DstImage, const std::vector< VkBufferImageCopy > &Regions)
Create a new CopyBufferToImageCommand.
Definition: Commands.h:204
uint64_t IndexBaseAddress
Address of the indices.
Definition: Commands.h:435
uint64_t DstAddr
The memory address of the destination buffer.
Definition: Commands.h:271
const PipelineContext & getPipelineContext() const
Returns the pipeline context.
Definition: Commands.h:297
This class encapsulates information about a wait events command.
Definition: Commands.h:557
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:366
DrawCommandBase(Type Ty, const PipelineContext &PC, const std::shared_ptr< RenderPassInstance > RPI, uint32_t NumVertices, uint32_t VertexOffset, uint32_t NumInstances, uint32_t InstanceOffset)
Create a new DrawCommandBase.
Definition: Commands.h:322
DrawCommand(const PipelineContext &PC, const std::shared_ptr< RenderPassInstance > RPI, uint32_t NumVertices, uint32_t VertexOffset, uint32_t NumInstances, uint32_t InstanceOffset)
Create a new DrawCommand.
Definition: Commands.h:382
std::vector< VkImageCopy > Regions
The regions to copy.
Definition: Commands.h:248
This class encapsulates information about a blit image command.
Definition: Commands.h:92
VkClearColorValue Color
The clear color to use.
Definition: Commands.h:167
virtual void runImpl(Device &Dev) const =0
Command execution method for subclasses.
A Device instance encapsulates properties and state for the virtual device.
Definition: Device.h:29
uint64_t NumBytes
The number of bytes to update.
Definition: Commands.h:550
BlitImageCommand(const Image &SrcImage, const Image &DstImage, const std::vector< VkImageBlit > &Regions, VkFilter Filter)
Create a new BlitImageCommand.
Definition: Commands.h:96
This class encapsulates information about a copy image command.
Definition: Commands.h:226
Type Ty
The type of this command.
Definition: Commands.h:65
This class encapsulates information about an end render pass command.
Definition: Commands.h:440
This class encapsulates information about a copy image to buffer command.
Definition: Commands.h:252
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:32
ClearColorImageCommand(const Image &DstImage, VkClearColorValue Color, const std::vector< VkImageSubresourceRange > &Ranges)
Create a new ClearColorImageCommand.
Definition: Commands.h:152
This file declares the PipelineContext class and related typedefs.
std::shared_ptr< RenderPassInstance > RPI
The render pass instance.
Definition: Commands.h:362
uint64_t SrcAddr
The memory address of the source buffer.
Definition: Commands.h:190
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:378
This class encapsulates information about a clear attachment command.
Definition: Commands.h:121
This class encapsulates information about a reset event command.
Definition: Commands.h:500
virtual void runImpl(Device &Dev) const override=0
Command execution handler.
uint32_t getNumInstances() const
Returns the number of instances.
Definition: Commands.h:335
const Image & DstImage
The destination image.
Definition: Commands.h:111
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:354
This class represents a SPIR-V type.
Definition: Type.h:33
CopyImageCommand(const Image &SrcImage, const Image &DstImage, const std::vector< VkImageCopy > &Regions)
Create a new CopyImageCommand.
Definition: Commands.h:230
Type
Identifies different Command subclasses.
Definition: Commands.h:35
uint32_t InstanceOffset
Offset of first instance.
Definition: Commands.h:367
Command(Type Ty)
Used by subclasses to initialize the command type.
Definition: Commands.h:65
This class encapsulates information about a draw command.
Definition: Commands.h:371
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:99
ClearAttachmentCommand(const RenderPassInstance &RPI, const std::vector< VkClearAttachment > &ClearAttachments, const std::vector< VkClearRect > &ClearRects)
Create a new ClearAttachmentCommand.
Definition: Commands.h:125
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:138
VkIndexType IndexType
Type of the indices;.
Definition: Commands.h:436
UpdateBufferCommand(uint64_t Base, uint64_t NumBytes, const void *Data)
Create a new UpdateBufferCommand.
Definition: Commands.cpp:368
uint32_t getNumVertices() const
Returns the number of vertices.
Definition: Commands.h:338
uint32_t NumVertices
Number of vertices.
Definition: Commands.h:364
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:339
This class encapsulates information about a clear color image command.
Definition: Commands.h:148
uint32_t NumInstances
Number of instances.
Definition: Commands.h:366
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:344
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:186
CopyBufferCommand(uint64_t SrcAddr, uint64_t DstAddr, const std::vector< VkBufferCopy > &Regions)
Create a new CopyBufferCommand.
Definition: Commands.h:178
virtual void runImpl(Device &Dev) const override
Command execution handler.
Definition: Commands.cpp:364
Dim3 getBaseGroup() const
Returns the base workgroup offset used by this command.
Definition: Commands.h:291
PipelineContext PC
The pipeline context.
Definition: Commands.h:360
uint32_t getVertexOffset() const
Returns the offset of the first vertex.
Definition: Commands.h:347
Dim3 NumGroups
The number of workgroups to launch.
Definition: Commands.h:307