Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
talvos::PipelineExecutor Class Reference

An internal class that handles pipeline execution, including the interactive debugger. More...

#include </home/travis/build/talvos/talvos/lib/talvos/PipelineExecutor.h>

Classes

struct  Fragment
 Internal structure to hold fragment data. More...
 
struct  PointPrimitive
 Point primitive data, used for rasterization. More...
 
struct  RenderPipelineState
 State to be carried through the execution of a render pipeline. More...
 
struct  TrianglePrimitive
 Triangle primitive data, used for rasterization. More...
 
struct  VertexOutput
 Outputs from a vertex shading stage. More...
 

Public Member Functions

 PipelineExecutor (PipelineExecutorKey Key, Device &Dev)
 Create a pipeline executor on Dev. More...
 
 ~PipelineExecutor ()
 Destroy a pipeline executor. More...
 
const InvocationgetCurrentInvocation () const
 Returns the current invocation being executed. More...
 
const WorkgroupgetCurrentWorkgroup () const
 Returns the current workgroup being executed. More...
 
const PipelineStagegetCurrentStage () const
 Returns the pipeline stage that is currently being executed. More...
 
bool isWorkerThread () const
 Returns true if the calling thread is a PipelineExecutor worker thread. More...
 
void run (const DispatchCommand &Cmd)
 Run a compute dispatch command to completion. More...
 
void run (const DrawCommandBase &Cmd)
 Run a draw command to completion. More...
 
void signalError ()
 Signal that an error has occurred, breaking the interactive debugger. More...
 
 PipelineExecutor (const PipelineExecutor &)=delete
 
PipelineExecutoroperator= (const PipelineExecutor &)=delete
 

Private Member Functions

void doWork (std::function< void()> Task)
 Execute a function on every worker thread. More...
 
void runWorker ()
 Worker thread entry point. More...
 
void runComputeWorker ()
 Worker thread entry point for compute shaders. More...
 
void runTriangleFragmentWorker (TrianglePrimitive Primitive, const PipelineContext &PC, const RenderPassInstance &RPI, const VkViewport &Viewport)
 Worker thread entry point for triangle rasterization. More...
 
void runPointFragmentWorker (PointPrimitive Primitive, const RenderPassInstance &RPI)
 Worker thread entry point for point rasterization. More...
 
void runVertexWorker (RenderPipelineState *State, uint32_t InstanceIndex)
 Worker thread entry point for vertex shaders. More...
 
void finalizeVariables (const DescriptorSetMap &DSM)
 Finalize variables. More...
 
void initializeVariables (const DescriptorSetMap &DSM, uint64_t PushConstantAddress)
 Initialize variables. More...
 
void buildPendingFragments (const DrawCommandBase &Cmd, int XMinFB, int XMaxFB, int YMinFB, int YMaxFB)
 Helper function to build list of pending fragments in a bounding box. More...
 
void processFragment (const Fragment &Frag, const RenderPassInstance &RPI, std::function< void(uint32_t, uint32_t, const Variable *, const Type *, Memory *, uint64_t)> GenLocData)
 Helper function to process a fragment. More...
 
void rasterizePoint (const DrawCommandBase &Cmd, const VkViewport &Viewport, const VertexOutput &Vertex)
 Helper function to rasterize a point primitive. More...
 
void rasterizeTriangle (const DrawCommandBase &Cmd, const VkViewport &Viewport, const VertexOutput &VA, const VertexOutput &VB, const VertexOutput &VC)
 Helper function to rasterize a triangle primitive. More...
 
void loadVertexInput (const PipelineContext &PC, Memory *PipelineMemory, uint64_t Address, uint32_t VertexIndex, uint32_t InstanceIndex, uint32_t Location, uint32_t Component, const Type *ElemTy) const
 Helper function to copy vertex input data to pipeline memory. More...
 
WorkgroupcreateWorkgroup (Dim3 GroupId) const
 Create a compute shader workgroup and its work-item invocations. More...
 
void interact ()
 Trigger interaction with the user (if necessary). More...
 
void printContext () const
 Print the context for the current invocation. More...
 
Interactive command handlers.

Return true when the interpreter should resume executing instructions.

bool brk (const std::vector< std::string > &Args)
 
bool breakpoint (const std::vector< std::string > &Args)
 
bool cont (const std::vector< std::string > &Args)
 
bool help (const std::vector< std::string > &Args)
 
bool print (const std::vector< std::string > &Args)
 
bool quit (const std::vector< std::string > &Args)
 
bool step (const std::vector< std::string > &Args)
 
bool swtch (const std::vector< std::string > &Args)
 

Static Private Member Functions

static Vec4 getPosition (const VertexOutput &Out)
 Helper function to get the position from vertex output builtin data. More...
 

Private Attributes

DeviceDev
 The device this shader is executing on. More...
 
const CommandCurrentCommand
 The command currently being executed. More...
 
const PipelineStageCurrentStage
 The pipeline stage currently being executed. More...
 
std::vector< ObjectObjects
 The initial object values for each invocation. More...
 
unsigned NumThreads
 The number of worker threads currently executing. More...
 
std::vector< std::thread > WorkerThreads
 List of worker threads. More...
 
bool ShutDownWorkers
 Signal to shut down worker threads. More...
 
std::function< void()> CurrentTask
 The function that worker threads should execute. More...
 
uint32_t CurrentTaskID = 0
 ID used to identify the current task. More...
 
std::mutex WorkerMutex
 Mutex used to synchronize with worker threads. More...
 
std::condition_variable WorkerSignal
 Condition variable used to wake worker threads. More...
 
std::condition_variable MasterSignal
 Condition variable used to notify master thread that work is complete. More...
 
std::atomic< uint32_t > NumWorkersFinished
 Tally of the number of workers that have finished the current task. More...
 
std::atomic< size_t > NextWorkIndex
 Index of next item of work to execute in the current task. More...
 
std::vector< Dim3PendingGroups
 Pool of group IDs pending creation and execution. More...
 
std::vector< Workgroup * > RunningGroups
 Pool of groups that have begun execution and been suspended. More...
 
std::vector< Dim3PendingFragments
 Pool of framebuffer coordinates pending fragment processing. More...
 
bool Continue
 True when the user has used continue command. More...
 
bool Interactive
 True when interactive mode is enabled. More...
 
std::vector< std::string > LastLine
 Tokens for the most recent interactive command entered. More...
 

Static Private Attributes

static uint32_t NextBreakpoint = 1
 Index of the next breakpoint to create. More...
 
static std::map< uint32_t,
uint32_t > 
Breakpoints
 Map from breakpoint ID to instruction result ID. More...
 

Detailed Description

An internal class that handles pipeline execution, including the interactive debugger.

Definition at line 54 of file PipelineExecutor.h.

Constructor & Destructor Documentation

talvos::PipelineExecutor::PipelineExecutor ( PipelineExecutorKey  Key,
Device Dev 
)

Create a pipeline executor on Dev.

Definition at line 109 of file PipelineExecutor.cpp.

talvos::PipelineExecutor::~PipelineExecutor ( )

Destroy a pipeline executor.

Definition at line 123 of file PipelineExecutor.cpp.

talvos::PipelineExecutor::PipelineExecutor ( const PipelineExecutor )
delete

Member Function Documentation

bool talvos::PipelineExecutor::breakpoint ( const std::vector< std::string > &  Args)
private

Definition at line 1915 of file PipelineExecutor.cpp.

bool talvos::PipelineExecutor::brk ( const std::vector< std::string > &  Args)
private

Definition at line 1889 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::buildPendingFragments ( const DrawCommandBase Cmd,
int  XMinFB,
int  XMaxFB,
int  YMinFB,
int  YMaxFB 
)
private

Helper function to build list of pending fragments in a bounding box.

Definition at line 475 of file PipelineExecutor.cpp.

bool talvos::PipelineExecutor::cont ( const std::vector< std::string > &  Args)
private

Definition at line 1965 of file PipelineExecutor.cpp.

Workgroup * talvos::PipelineExecutor::createWorkgroup ( Dim3  GroupId) const
private

Create a compute shader workgroup and its work-item invocations.

Definition at line 136 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::doWork ( std::function< void()>  Task)
private

Execute a function on every worker thread.

Definition at line 985 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::finalizeVariables ( const DescriptorSetMap DSM)
private

Finalize variables.

Definition at line 1382 of file PipelineExecutor.cpp.

const Invocation * talvos::PipelineExecutor::getCurrentInvocation ( ) const

Returns the current invocation being executed.

Definition at line 206 of file PipelineExecutor.cpp.

const PipelineStage& talvos::PipelineExecutor::getCurrentStage ( ) const
inline

Returns the pipeline stage that is currently being executed.

Definition at line 76 of file PipelineExecutor.h.

const Workgroup * talvos::PipelineExecutor::getCurrentWorkgroup ( ) const

Returns the current workgroup being executed.

Definition at line 211 of file PipelineExecutor.cpp.

Vec4 talvos::PipelineExecutor::getPosition ( const VertexOutput Out)
staticprivate

Helper function to get the position from vertex output builtin data.

Definition at line 1589 of file PipelineExecutor.cpp.

bool talvos::PipelineExecutor::help ( const std::vector< std::string > &  Args)
private

Definition at line 1971 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::initializeVariables ( const DescriptorSetMap DSM,
uint64_t  PushConstantAddress 
)
private

Initialize variables.

Definition at line 1423 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::interact ( )
private

Trigger interaction with the user (if necessary).

Map a command with a long and short name to a handler function.

Definition at line 1742 of file PipelineExecutor.cpp.

bool talvos::PipelineExecutor::isWorkerThread ( ) const

Returns true if the calling thread is a PipelineExecutor worker thread.

Definition at line 216 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::loadVertexInput ( const PipelineContext PC,
Memory PipelineMemory,
uint64_t  Address,
uint32_t  VertexIndex,
uint32_t  InstanceIndex,
uint32_t  Location,
uint32_t  Component,
const Type ElemTy 
) const
private

Helper function to copy vertex input data to pipeline memory.

Definition at line 1614 of file PipelineExecutor.cpp.

PipelineExecutor& talvos::PipelineExecutor::operator= ( const PipelineExecutor )
delete
bool talvos::PipelineExecutor::print ( const std::vector< std::string > &  Args)
private

Definition at line 1988 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::printContext ( ) const
private

Print the context for the current invocation.

Definition at line 1849 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::processFragment ( const Fragment Frag,
const RenderPassInstance RPI,
std::function< void(uint32_t, uint32_t, const Variable *, const Type *, Memory *, uint64_t)>  GenLocData 
)
private

Helper function to process a fragment.

Definition at line 776 of file PipelineExecutor.cpp.

bool talvos::PipelineExecutor::quit ( const std::vector< std::string > &  Args)
private

Definition at line 2020 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::rasterizePoint ( const DrawCommandBase Cmd,
const VkViewport &  Viewport,
const VertexOutput Vertex 
)
private

Helper function to rasterize a point primitive.

Definition at line 1498 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::rasterizeTriangle ( const DrawCommandBase Cmd,
const VkViewport &  Viewport,
const VertexOutput VA,
const VertexOutput VB,
const VertexOutput VC 
)
private

Helper function to rasterize a triangle primitive.

Definition at line 1532 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::run ( const DispatchCommand Cmd)

Run a compute dispatch command to completion.

Definition at line 218 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::run ( const DrawCommandBase Cmd)

Run a draw command to completion.

Definition at line 263 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::runComputeWorker ( )
private

Worker thread entry point for compute shaders.

Definition at line 378 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::runPointFragmentWorker ( PointPrimitive  Primitive,
const RenderPassInstance RPI 
)
private

Worker thread entry point for point rasterization.

Definition at line 1011 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::runTriangleFragmentWorker ( TrianglePrimitive  Primitive,
const PipelineContext PC,
const RenderPassInstance RPI,
const VkViewport &  Viewport 
)
private

Worker thread entry point for triangle rasterization.

Definition at line 1051 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::runVertexWorker ( RenderPipelineState State,
uint32_t  InstanceIndex 
)
private

Worker thread entry point for vertex shaders.

Definition at line 1187 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::runWorker ( )
private

Worker thread entry point.

Definition at line 951 of file PipelineExecutor.cpp.

void talvos::PipelineExecutor::signalError ( )

Signal that an error has occurred, breaking the interactive debugger.

Definition at line 1579 of file PipelineExecutor.cpp.

bool talvos::PipelineExecutor::step ( const std::vector< std::string > &  Args)
private

Definition at line 2022 of file PipelineExecutor.cpp.

bool talvos::PipelineExecutor::swtch ( const std::vector< std::string > &  Args)
private

Definition at line 2038 of file PipelineExecutor.cpp.

Member Data Documentation

std::map< uint32_t, uint32_t > talvos::PipelineExecutor::Breakpoints
staticprivate

Map from breakpoint ID to instruction result ID.

Definition at line 240 of file PipelineExecutor.h.

bool talvos::PipelineExecutor::Continue
private

True when the user has used continue command.

Definition at line 224 of file PipelineExecutor.h.

const Command* talvos::PipelineExecutor::CurrentCommand
private

The command currently being executed.

Definition at line 173 of file PipelineExecutor.h.

const PipelineStage* talvos::PipelineExecutor::CurrentStage
private

The pipeline stage currently being executed.

Definition at line 176 of file PipelineExecutor.h.

std::function<void()> talvos::PipelineExecutor::CurrentTask
private

The function that worker threads should execute.

Definition at line 191 of file PipelineExecutor.h.

uint32_t talvos::PipelineExecutor::CurrentTaskID = 0
private

ID used to identify the current task.

Definition at line 194 of file PipelineExecutor.h.

Device& talvos::PipelineExecutor::Dev
private

The device this shader is executing on.

Definition at line 170 of file PipelineExecutor.h.

bool talvos::PipelineExecutor::Interactive
private

True when interactive mode is enabled.

Definition at line 225 of file PipelineExecutor.h.

std::vector<std::string> talvos::PipelineExecutor::LastLine
private

Tokens for the most recent interactive command entered.

Definition at line 234 of file PipelineExecutor.h.

std::condition_variable talvos::PipelineExecutor::MasterSignal
private

Condition variable used to notify master thread that work is complete.

Definition at line 203 of file PipelineExecutor.h.

uint32_t talvos::PipelineExecutor::NextBreakpoint = 1
staticprivate

Index of the next breakpoint to create.

Definition at line 237 of file PipelineExecutor.h.

std::atomic<size_t> talvos::PipelineExecutor::NextWorkIndex
private

Index of next item of work to execute in the current task.

Definition at line 209 of file PipelineExecutor.h.

unsigned talvos::PipelineExecutor::NumThreads
private

The number of worker threads currently executing.

Definition at line 182 of file PipelineExecutor.h.

std::atomic<uint32_t> talvos::PipelineExecutor::NumWorkersFinished
private

Tally of the number of workers that have finished the current task.

Definition at line 206 of file PipelineExecutor.h.

std::vector<Object> talvos::PipelineExecutor::Objects
private

The initial object values for each invocation.

Definition at line 179 of file PipelineExecutor.h.

std::vector<Dim3> talvos::PipelineExecutor::PendingFragments
private

Pool of framebuffer coordinates pending fragment processing.

Definition at line 218 of file PipelineExecutor.h.

std::vector<Dim3> talvos::PipelineExecutor::PendingGroups
private

Pool of group IDs pending creation and execution.

Definition at line 212 of file PipelineExecutor.h.

std::vector<Workgroup *> talvos::PipelineExecutor::RunningGroups
private

Pool of groups that have begun execution and been suspended.

Definition at line 215 of file PipelineExecutor.h.

bool talvos::PipelineExecutor::ShutDownWorkers
private

Signal to shut down worker threads.

Definition at line 188 of file PipelineExecutor.h.

std::mutex talvos::PipelineExecutor::WorkerMutex
private

Mutex used to synchronize with worker threads.

Definition at line 197 of file PipelineExecutor.h.

std::condition_variable talvos::PipelineExecutor::WorkerSignal
private

Condition variable used to wake worker threads.

Definition at line 200 of file PipelineExecutor.h.

std::vector<std::thread> talvos::PipelineExecutor::WorkerThreads
private

List of worker threads.

Definition at line 185 of file PipelineExecutor.h.