载入中...
搜索中...
未找到
eve::gpgpu::ShaderSystem类 参考

EVENGINE_API_WORLD public API. 更多...

#include <ShaderSystem.h>

Public 成员函数

 ShaderSystem ()=default
 Shader system.
 
 ~ShaderSystem ()
 Shader system.
 
 ShaderSystem (const ShaderSystem &)=delete
 
ShaderSystem & operator= (const ShaderSystem &)=delete
 
void setGpgpu (Gpgpu *gpu)
 Sets the gpgpu.
 
Gpgpu * getGpgpu () const
 Returns the gpgpu.
 
void setShaderSource (const std::string &glsl)
 Sets the shader source.
 
void setShader (ComputeShader *shader, bool takeOwnership=false)
 Sets the shader.
 
ComputeShader * getShader () const
 Returns the shader.
 
void setLocalSize (int localSize)
 Sets the local size.
 
int getLocalSize () const
 Returns the local size.
 
GpuBuffer * ensureBuffer (int binding, int floatCount)
 Ensure buffer.
 
GpuBuffer * getBuffer (int binding) const
 Returns the buffer.
 
void attachBuffer (int binding, GpuBuffer *buffer)
 Attach a non-owning resident buffer produced by another GPU system.
 
void upload (int binding, const float *data, int floatCount)
 Uploads upload.
 
void download (int binding, float *out, int floatCount) const
 Downloads download.
 
void uploadRange (int binding, const float *data, int floatCount, int startFloat)
 Upload floats into an existing resident buffer range.
 
void downloadRange (int binding, float *out, int floatCount, int startFloat) const
 Download floats from an existing resident buffer range.
 
uint64_t getUploadCount () const
 Number of host-to-device uploads issued through this system.
 
uint64_t getDownloadCount () const
 Number of device-to-host downloads issued through this system.
 
uint64_t getDispatchCount () const
 Number of compute dispatches issued through this system.
 
void resetStatistics ()
 Reset transfer and dispatch counters used for profiling.
 
void upload (int binding, const std::vector< float > &data)
 Uploads upload.
 
std::vector< float > download (int binding, int floatCount) const
 Downloads download.
 
void setFloat (int index, float value)
 Sets the float.
 
float getFloat (int index) const
 Returns the float.
 
void dispatch (int entityCount, float dt=0.f)
 Dispatches dispatch.
 
void recordDispatch (Sequence *sequence, int entityCount, float dt=0.f)
 Record this system into a caller-owned sequence without submitting or waiting. The sequence and all attached buffers must remain alive through Sequence::submit().
 
void clearBuffers ()
 Clears buffers.
 

静态 Public 属性

static constexpr int kMaxBindings = ComputeShader::kMaxBindings
 
static constexpr int kDefaultLocalSize = 64
 

详细描述

EVENGINE_API_WORLD public API.

ECS ↔ GPGPU bridge: run a compute shader as an ECS System over N entities.

Layout convention (matches Gpgpu::dispatch):

  • set=0 binding i = SSBO of tightly-packed floats for that field group
  • push constants: data[0]=dt, data[1]=entityCount (float), data[2..]=user

Typical flow:

  1. setGpgpu + setShaderSource (or setShader)
  2. pack / upload float SoA-or-AoS streams per binding
  3. dispatch(entityCount)
  4. download / unpack back into components

Script: eve.ShaderSystem (extends eve.System) wraps this class. C++ ECS: use packViewComponent / unpackViewComponent in EcsGpu.h.

在文件 ShaderSystem.h 第 34 行定义.

构造及析构函数说明

◆ ShaderSystem() [1/2]

eve::gpgpu::ShaderSystem::ShaderSystem ( )
default

Shader system.

◆ ~ShaderSystem()

eve::gpgpu::ShaderSystem::~ShaderSystem ( )

Shader system.

在文件 ShaderSystem.cpp 第 13 行定义.

引用了 clearBuffers().

◆ ShaderSystem() [2/2]

eve::gpgpu::ShaderSystem::ShaderSystem ( const ShaderSystem &  )
delete

成员函数说明

◆ attachBuffer()

void eve::gpgpu::ShaderSystem::attachBuffer ( int  binding,
GpuBuffer *  buffer 
)

Attach a non-owning resident buffer produced by another GPU system.

参数
bindingDestination shader binding.
bufferBuffer whose owner must outlive this attachment and any recorded work. Reattach after the owner reallocates the buffer.

在文件 ShaderSystem.cpp 第 67 行定义.

引用了 binding, buffer , 以及 kMaxBindings.

◆ clearBuffers()

void eve::gpgpu::ShaderSystem::clearBuffers ( )

Clears buffers.

在文件 ShaderSystem.cpp 第 171 行定义.

引用了 kMaxBindings.

被这些函数引用 ~ShaderSystem().

◆ dispatch()

void eve::gpgpu::ShaderSystem::dispatch ( int  entityCount,
float  dt = 0.f 
)

Dispatches dispatch.

Bind buffers, set push[0]=dt and push[1]=entityCount, dispatch workgroups. No-op when shader/gpu missing or entityCount <= 0.

在文件 ShaderSystem.cpp 第 134 行定义.

引用了 eve::gpgpu::ComputeShader::bindBuffer(), eve::gpgpu::Gpgpu::dispatch(), groups, kDefaultLocalSize, kMaxBindings , 以及 eve::gpgpu::ComputeShader::setFloat().

被这些函数引用 eve::gpgpu::runViewComponentSystem().

◆ download() [1/2]

void eve::gpgpu::ShaderSystem::download ( int  binding,
float *  out,
int  floatCount 
) const

Downloads download.

在文件 ShaderSystem.cpp 第 83 行定义.

引用了 binding, getBuffer() , 以及 eve::gpgpu::GpuBuffer::readFloat32s().

被这些函数引用 download() , 以及 eve::gpgpu::unpackViewComponent().

◆ download() [2/2]

std::vector< float > eve::gpgpu::ShaderSystem::download ( int  binding,
int  floatCount 
) const

Downloads download.

在文件 ShaderSystem.cpp 第 118 行定义.

引用了 binding , 以及 download().

◆ downloadRange()

void eve::gpgpu::ShaderSystem::downloadRange ( int  binding,
float *  out,
int  floatCount,
int  startFloat 
) const

Download floats from an existing resident buffer range.

在文件 ShaderSystem.cpp 第 102 行定义.

引用了 binding, end, getBuffer(), eve::gpgpu::GpuBuffer::getSize() , 以及 eve::gpgpu::GpuBuffer::readFloat32s().

被这些函数引用 eve::gpgpu::unpackViewComponentRange().

◆ ensureBuffer()

GpuBuffer * eve::gpgpu::ShaderSystem::ensureBuffer ( int  binding,
int  floatCount 
)

Ensure buffer.

Ensure binding has a storage buffer with at least floatCount floats.

在文件 ShaderSystem.cpp 第 45 行定义.

引用了 binding, bytes, created, eve::gpgpu::GpuBuffer::getSize(), kMaxBindings , 以及 eve::gpgpu::Gpgpu::newBuffer().

被这些函数引用 upload().

◆ getBuffer()

GpuBuffer * eve::gpgpu::ShaderSystem::getBuffer ( int  binding) const

Returns the buffer.

在文件 ShaderSystem.cpp 第 62 行定义.

引用了 binding , 以及 kMaxBindings.

被这些函数引用 download(), downloadRange() , 以及 uploadRange().

◆ getDispatchCount()

uint64_t eve::gpgpu::ShaderSystem::getDispatchCount ( ) const
inline

Number of compute dispatches issued through this system.

在文件 ShaderSystem.h 第 101 行定义.

◆ getDownloadCount()

uint64_t eve::gpgpu::ShaderSystem::getDownloadCount ( ) const
inline

Number of device-to-host downloads issued through this system.

在文件 ShaderSystem.h 第 99 行定义.

◆ getFloat()

float eve::gpgpu::ShaderSystem::getFloat ( int  index) const

Returns the float.

在文件 ShaderSystem.cpp 第 129 行定义.

引用了 eve::gpgpu::ComputeShader::getFloat() , 以及 index.

◆ getGpgpu()

Gpgpu * eve::gpgpu::ShaderSystem::getGpgpu ( ) const
inline

Returns the gpgpu.

在文件 ShaderSystem.h 第 50 行定义.

◆ getLocalSize()

int eve::gpgpu::ShaderSystem::getLocalSize ( ) const
inline

Returns the local size.

在文件 ShaderSystem.h 第 69 行定义.

◆ getShader()

ComputeShader * eve::gpgpu::ShaderSystem::getShader ( ) const
inline

Returns the shader.

在文件 ShaderSystem.h 第 64 行定义.

◆ getUploadCount()

uint64_t eve::gpgpu::ShaderSystem::getUploadCount ( ) const
inline

Number of host-to-device uploads issued through this system.

在文件 ShaderSystem.h 第 97 行定义.

◆ operator=()

ShaderSystem & eve::gpgpu::ShaderSystem::operator= ( const ShaderSystem &  )
delete

◆ recordDispatch()

void eve::gpgpu::ShaderSystem::recordDispatch ( Sequence *  sequence,
int  entityCount,
float  dt = 0.f 
)

Record this system into a caller-owned sequence without submitting or waiting. The sequence and all attached buffers must remain alive through Sequence::submit().

在文件 ShaderSystem.cpp 第 150 行定义.

引用了 eve::gpgpu::ComputeShader::bindBuffer(), kDefaultLocalSize, kMaxBindings, sequence , 以及 eve::gpgpu::ComputeShader::setFloat().

◆ resetStatistics()

void eve::gpgpu::ShaderSystem::resetStatistics ( )

Reset transfer and dispatch counters used for profiling.

在文件 ShaderSystem.cpp 第 165 行定义.

◆ setFloat()

void eve::gpgpu::ShaderSystem::setFloat ( int  index,
float  value 
)

Sets the float.

在文件 ShaderSystem.cpp 第 124 行定义.

引用了 index, eve::gpgpu::ComputeShader::setFloat() , 以及 value.

◆ setGpgpu()

void eve::gpgpu::ShaderSystem::setGpgpu ( Gpgpu *  gpu)

Sets the gpgpu.

在文件 ShaderSystem.cpp 第 22 行定义.

◆ setLocalSize()

void eve::gpgpu::ShaderSystem::setLocalSize ( int  localSize)

Sets the local size.

在文件 ShaderSystem.cpp 第 41 行定义.

引用了 kDefaultLocalSize.

◆ setShader()

void eve::gpgpu::ShaderSystem::setShader ( ComputeShader *  shader,
bool  takeOwnership = false 
)

Sets the shader.

Use an existing ComputeShader. Does not take ownership unless takeOwnership is true.

在文件 ShaderSystem.cpp 第 32 行定义.

引用了 shader.

◆ setShaderSource()

void eve::gpgpu::ShaderSystem::setShaderSource ( const std::string &  glsl)

Sets the shader source.

Compile GLSL compute and take ownership of the resulting ComputeShader.

在文件 ShaderSystem.cpp 第 24 行定义.

引用了 eve::gpgpu::Gpgpu::newShader().

◆ upload() [1/2]

void eve::gpgpu::ShaderSystem::upload ( int  binding,
const float *  data,
int  floatCount 
)

Uploads upload.

在文件 ShaderSystem.cpp 第 76 行定义.

引用了 binding, ensureBuffer() , 以及 eve::gpgpu::GpuBuffer::writeFloat32s().

被这些函数引用 eve::gpgpu::packViewComponent() , 以及 upload().

◆ upload() [2/2]

void eve::gpgpu::ShaderSystem::upload ( int  binding,
const std::vector< float > &  data 
)

Uploads upload.

Convenience: upload from / download to a vector.

在文件 ShaderSystem.cpp 第 113 行定义.

引用了 binding , 以及 upload().

◆ uploadRange()

void eve::gpgpu::ShaderSystem::uploadRange ( int  binding,
const float *  data,
int  floatCount,
int  startFloat 
)

Upload floats into an existing resident buffer range.

在文件 ShaderSystem.cpp 第 91 行定义.

引用了 binding, end, getBuffer(), eve::gpgpu::GpuBuffer::getSize() , 以及 eve::gpgpu::GpuBuffer::writeFloat32s().

被这些函数引用 eve::gpgpu::packViewComponentRange().

类成员变量说明

◆ kDefaultLocalSize

constexpr int eve::gpgpu::ShaderSystem::kDefaultLocalSize = 64
staticconstexpr

在文件 ShaderSystem.h 第 37 行定义.

被这些函数引用 dispatch(), recordDispatch() , 以及 setLocalSize().

◆ kMaxBindings

constexpr int eve::gpgpu::ShaderSystem::kMaxBindings = ComputeShader::kMaxBindings
staticconstexpr

在文件 ShaderSystem.h 第 36 行定义.

被这些函数引用 attachBuffer(), clearBuffers(), dispatch(), ensureBuffer(), getBuffer() , 以及 recordDispatch().


该类的文档由以下文件生成: