Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PipelineStage.cpp
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 #include "talvos/PipelineStage.h"
10 #include "talvos/EntryPoint.h"
11 #include "talvos/Instruction.h"
12 #include "talvos/Invocation.h"
13 #include "talvos/Module.h"
14 
15 namespace talvos
16 {
17 
18 PipelineStage::PipelineStage(Device &D, std::shared_ptr<const Module> M,
19  const EntryPoint *EP, const SpecConstantMap &SM)
20  : Mod(M), EP(EP)
21 {
22  Objects = M->getObjects();
23 
24  // Update objects with specialization constant values.
25  for (auto SE : SM)
26  Objects[M->getSpecConstant(SE.first)] = SE.second;
27 
28  // Evaluate OpSpecConstantOp instructions.
29  // Create a dummy invocation to dispatch the instructions to.
30  Invocation I(D, Objects);
31  for (const Instruction *Op : M->getSpecConstantOps())
32  {
33  // Evaluate instruction.
34  I.execute(Op);
35 
36  // Copy result into object map.
37  uint32_t Id = Op->getOperand(1);
38  Objects[Id] = I.getObject(Id);
39  }
40 
41  // Get local size from execution mode, but override with WorkgroupSize
42  // decoration if present.
43  this->GroupSize = M->getLocalSize(EP->getId());
44  if (uint32_t WorkgroupSizeId = M->getWorkgroupSizeId())
45  {
46  const Object &WorkgroupSize = Objects[WorkgroupSizeId];
47  this->GroupSize.X = WorkgroupSize.get<uint32_t>(0);
48  this->GroupSize.Y = WorkgroupSize.get<uint32_t>(1);
49  this->GroupSize.Z = WorkgroupSize.get<uint32_t>(2);
50  }
51 }
52 
53 } // namespace talvos
uint32_t Y
Definition: Dim3.h:30
std::vector< Object > Objects
The result objects in this pipeline stage, after specialization.
Definition: PipelineStage.h:70
This file declares the Module class.
uint32_t getId() const
Returns the SPIR-V result ID of this entry point.
Definition: EntryPoint.h:41
This file declares the EntryPoint class.
uint32_t Z
Definition: Dim3.h:30
This class represents a single execution of a SPIR-V entry point.
Definition: Invocation.h:33
This file declares the Instruction class.
void execute(const Instruction *Inst)
Execute Inst in this invocation.
Definition: Invocation.cpp:91
This file declares the PipelineStage class.
A Device instance encapsulates properties and state for the virtual device.
Definition: Device.h:29
uint32_t X
Definition: Dim3.h:30
This file declares the Invocation class.
Object getObject(uint32_t Id) const
Returns the object with the specified ID.
PipelineStage(Device &D, std::shared_ptr< const Module > M, const EntryPoint *EP, const SpecConstantMap &SM={})
Create a new PipelineStage.
This class represents an instruction result.
Definition: Object.h:51
This class represents a SPIR-V instruction.
Definition: Instruction.h:27
Dim3 GroupSize
The size of each workgroup.
Definition: PipelineStage.h:67
T get(uint32_t Element=0) const
Get the value of this object as a scalar of type T.
Definition: Object.cpp:97
This class represents a shader entry point.
Definition: EntryPoint.h:25
std::map< uint32_t, Object > SpecConstantMap
Mapping from specialization constant ID to Object values.
Definition: PipelineStage.h:24