载入中...
搜索中...
未找到
Gpgpu.cpp
浏览该文件的文档.
62 if (slot == eve::graphics::kInvalidGpuDrivenSlot || slot > static_cast<uint32_t>(std::numeric_limits<int>::max()))
77 throw Exception("Gpgpu.submitResidentInstances: bucket %d has invalid fields", static_cast<int>(i));
78 result.push_back({static_cast<uint32_t>(first), static_cast<uint32_t>(count), static_cast<uint32_t>(mesh),
84std::string submitResidentInstances(GpuBuffer *buffer, ssq::Array buckets, int instanceCount, int offsetBytes) {
101void writeGpuDrivenInstance(GpuBuffer *buffer, int instanceIndex, ssq::Array model, int meshId, int materialId,
103 if (!buffer || instanceIndex < 0 || model.size() != 16 || meshId < 0 || materialId < 0 || flags < 0 ||
112 instance.lodGroupId = lodGroupId < 0 ? eve::graphics::kInvalidGpuDrivenSlot : static_cast<uint32_t>(lodGroupId);
133 return scriptGpuDrivenSlot(gfx ? gfx->gpuDrivenMeshRecord(mesh) : eve::graphics::kInvalidGpuDrivenSlot);
139 return scriptGpuDrivenSlot(gfx ? gfx->gpuDrivenMaterialRecord(material) : eve::graphics::kInvalidGpuDrivenSlot);
184void writeGpuDrivenInstanceScript(Gpgpu *gpgpu, GpuBuffer *buffer, int instanceIndex, ssq::Array model, int meshId,
190std::string submitResidentInstancesScript(Gpgpu *gpgpu, GpuBuffer *buffer, ssq::Array buckets, int instanceCount,
208 Diagnostic::error(DiagnosticCode::Unsupported, "mesh deformation compute backend is unavailable"));
209 if (count == 0 || request.positions.size() != count * 3u || request.normals.size() != count * 3u ||
213 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid mesh deformation compute buffers"));
215 std::vector<float> positions(count * 4u), normals(count * 4u), baseline(count * 4u), targets(count * 4u);
220 baseline[i * 4u + c] = request.baseline.empty() ? positions[i * 4u + c] : request.baseline[i * 3u + c];
221 targets[i * 4u + c] = request.targets.empty() ? positions[i * 4u + c] : request.targets[i * 3u + c];
238 if(op==5){vec3 delta=outp-b.v[i].xyz;float len=length(delta);if(len>pc.d[11])delta*=pc.d[11]/len;outp=b.v[i].xyz+delta;}
247@compute @workgroup_size(64) fn main(@builtin(global_invocation_id) gid:vec3u){let i=gid.x;if(i>=u32(f(0u))){return;}
253 var outp=q+dir*w;if(op==5){var delta=outp-b.v[i].xyz;let len=length(delta);if(len>f(11u)){delta*=f(11u)/len;}outp=b.v[i].xyz+delta;}
257 std::unique_ptr<GpuBuffer> p(newBuffer(static_cast<int>(positions.size() * sizeof(float)), "storage"));
258 std::unique_ptr<GpuBuffer> n(newBuffer(static_cast<int>(normals.size() * sizeof(float)), "storage"));
259 std::unique_ptr<GpuBuffer> b(newBuffer(static_cast<int>(baseline.size() * sizeof(float)), "storage"));
260 std::unique_ptr<GpuBuffer> t(newBuffer(static_cast<int>(targets.size() * sizeof(float)), "storage"));
265 std::unique_ptr<ComputeShader> shader(newShader(currentGraphicsBackend() == "webgpu" ? wgsl : glsl));
266 shader->bindBuffer(0, p.get()); shader->bindBuffer(1, n.get()); shader->bindBuffer(2, b.get()); shader->bindBuffer(3, t.get());
269 shader->setFloat(2, request.centerX); shader->setFloat(3, request.centerY); shader->setFloat(4, request.centerZ);
270 shader->setFloat(5, request.radius); shader->setFloat(6, request.strength); shader->setFloat(7, request.falloff);
271 shader->setFloat(8, request.directionX); shader->setFloat(9, request.directionY); shader->setFloat(10, request.directionZ);
280 return Result<std::vector<float>>::failure(Diagnostic::error(DiagnosticCode::Failed, error.what()));
302 return Result<std::vector<uint32_t>>::failure(Diagnostic::error(DiagnosticCode::Failed, e.what()));
319 return Result<std::unique_ptr<ComputeShader>>::failure(Diagnostic::error(DiagnosticCode::Failed, e.what()));
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Backend-agnostic compute program. Bind storage buffers then dispatch via Gpgpu::dispatch....
Definition ComputeShader.h:15
virtual GpuBuffer * getBoundBuffer(int binding) const =0
Returns the bound buffer.
virtual void bindBuffer(int binding, GpuBuffer *buffer)=0
Bind a storage buffer to set=0 binding. binding in [0, kMaxBindings).
GPGPU module — compute shaders + storage buffers via the active Graphics backend. Uses the graphics q...
Definition Gpgpu.h:23
ComputeShader * newShaderFromSpvFile(const std::string &path)
Vulkan SPIR-V compatibility wrapper → newShaderFromBytecode.
Definition Gpgpu.cpp:359
ComputeShader * newShader(const std::string &source)
Compatibility-only raw-owning shader factory (Vulkan: GLSL; WebGPU: WGSL). Vulkan delegates to the ch...
Definition Gpgpu.cpp:324
Result< std::vector< float > > deform(MeshDeformationComputeRequest request) override
Execute mesh deformation through the active compute backend.
Definition Gpgpu.cpp:204
bool isAvailable() const
True when the active Graphics backend can run compute (device initialized).
Definition Gpgpu.cpp:284
ComputeShader * newShaderFromBytecode(const std::string &path)
Load precompiled compute bytecode from Filesystem path (Vulkan: SPIR-V).
Definition Gpgpu.cpp:341
void dispatch(ComputeShader *shader, int groupsX, int groupsY=1, int groupsZ=1)
Record + submit a compute dispatch and wait for completion (sync). groups*: workgroup counts (not thr...
Definition Gpgpu.cpp:396
GpuBuffer * newBuffer(int byteSize, const std::string &usage="storage")
Allocate a GPU buffer. usage: "storage" (SSBO, device-local) | "staging" (host-visible transfer).
Definition Gpgpu.cpp:372
Sequence * newSequence()
Create a Kompute-style command Sequence: record buffer transfers and compute dispatches into one comm...
Definition Gpgpu.cpp:384
Backend-agnostic GPU buffer for compute (storage) or CPU staging transfers. Squirrel-owned; derived c...
Definition GpuBuffer.h:18
virtual void writeData(data::ByteData *data, int dstOffset=0)=0
Writes data.
virtual void writeFloat32(int floatIndex, float value)=0
Writes float 32.
virtual data::ByteData * readData(int srcOffset=0, int size=-1)=0
Reads data.
void recordUpload(GpuBuffer *dst, const void *src, uint64_t nbytes, uint64_t dstOffset=0)
Record upload.
Definition Sequence.cpp:77
void recordDownload(GpuBuffer *src, GpuBuffer *staging, uint64_t nbytes, uint64_t srcOffset=0)
Record download.
Definition Sequence.cpp:82
void recordDispatch(ComputeShader *shader, int groupsX, int groupsY=1, int groupsZ=1)
Record dispatch.
Definition Sequence.cpp:87
std::string getStatusName() const
Stable script/debug name for getStatus().
Definition Sequence.cpp:105
uint64_t getDispatchCount() const
Number of compute dispatches issued through this system.
Definition ShaderSystem.h:101
void attachBuffer(int binding, GpuBuffer *buffer)
Attach a non-owning resident buffer produced by another GPU system.
Definition ShaderSystem.cpp:67
void resetStatistics()
Reset transfer and dispatch counters used for profiling.
Definition ShaderSystem.cpp:165
uint64_t getDownloadCount() const
Number of device-to-host downloads issued through this system.
Definition ShaderSystem.h:99
uint64_t getUploadCount() const
Number of host-to-device uploads issued through this system.
Definition ShaderSystem.h:97
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 a...
Definition ShaderSystem.cpp:150
Definition Graphics.h:125
Packages shading method + surface parameters into one attachable asset.
Definition Material.h:35
@ Exception
ComputeShader * vulkanNewShaderFromSpirv(const std::vector< uint32_t > &spv)
从 SPIR-V 字节码创建计算着色器。
Definition VulkanGpgpu.cpp:13
void webgpuDispatch(ComputeShader *shader, int groupsX, int groupsY, int groupsZ)
Webgpu dispatch.
Definition WebGpuGpgpu.cpp:231
EVENGINE_API_WORLD Result< std::unique_ptr< ComputeShader > > createComputeShader(const std::vector< uint32_t > &words)
Create an owning compute pipeline from valid SPIR-V produced by compileComputeSpirv.
Definition Gpgpu.cpp:307
std::vector< uint32_t > loadSpirvFile(const std::string &path)
Loads spirv file.
Definition VulkanUtil.cpp:81
EVENGINE_API_WORLD Result< std::vector< uint32_t > > compileComputeSpirv(const std::string &source)
Compile GLSL compute source to owning SPIR-V without accessing Graphics or a GPU.
Definition Gpgpu.cpp:294
GpuBuffer * vulkanNewBuffer(int byteSize, const std::string &usage)
创建 GPU 存储/传输缓冲区;usage 为 "storage" | "vertex" 等。
Definition VulkanGpgpu.cpp:65
WebGpuGpuBuffer * webgpuNewBuffer(int byteSize, const std::string &usage)
Webgpu new buffer.
Definition WebGpuGpgpu.cpp:150
std::vector< uint32_t > compileComputeGlsl(const std::string &glsl)
Compiles compute glsl.
Definition VulkanUtil.cpp:88
int unpackScriptEntityFloatsRange(ssq::Object entitiesObj, const std::string &slot, ssq::Object fieldsObj, GpuBuffer *buf, int firstEntity, int entityCount)
Unpack a contiguous buffer range into the matching stable ECS view range.
Definition EcsScriptPack.cpp:199
int packScriptEntityFloats(ssq::Object entitiesObj, const std::string &slot, ssq::Object fieldsObj, GpuBuffer *buf)
Pack script ECS entities' component number fields into a GpuBuffer (AoS). entities: Squirrel array of...
Definition EcsScriptPack.cpp:122
int unpackScriptEntityFloats(ssq::Object entitiesObj, const std::string &slot, ssq::Object fieldsObj, GpuBuffer *buf, int entityCount)
Inverse of packScriptEntityFloats; entityCount should match pack result.
Definition EcsScriptPack.cpp:194
int packScriptEntityFloatsRange(ssq::Object entitiesObj, const std::string &slot, ssq::Object fieldsObj, GpuBuffer *buf, int firstEntity, int entityCount)
Pack a contiguous entity range into the matching range of an existing buffer.
Definition EcsScriptPack.cpp:127
WebGpuComputeShader * webgpuNewShaderFromWgsl(const std::string &wgsl)
Webgpu new shader from wgsl.
Definition WebGpuGpgpu.cpp:84
void vulkanDispatch(ComputeShader *shader, int groupsX, int groupsY, int groupsZ)
派发计算着色器(groupsX/Y/Z 为线程组数)。
Definition VulkanGpgpu.cpp:123
constexpr uint32_t kInvalidGpuDrivenSlot
GPU-driven rendering shared constants + std430 GPU layouts.
Definition GpuDrivenTypes.h:19
GpuResidentSubmitStatus
Structured result for direct resident-instance submission.
Definition GpuDrivenTypes.h:48
@ InvalidArgument
@ Unsupported
@ Failed
constexpr uint64_t kGpuResidentStorageOffsetAlignment
Portable alignment required for resident storage-buffer slice offsets.
Definition GpuResidentBufferView.h:11
Owning, backend-neutral input for one synchronous GPU mesh deformation.
Definition MeshDeformationCompute.h:19
Per-instance GPU record (std430). Mirrors GLSL GpuInstance.
Definition GpuDrivenTypes.h:106
Direct-render description for a GPU-authored array of GpuInstance records. @ownership buckets and buf...
Definition GpuDrivenTypes.h:40
GpuResidentBufferView buffer
Definition GpuDrivenTypes.h:41
const GpuResidentInstanceBucket * buckets
Definition GpuDrivenTypes.h:42
uint32_t bucketCount
Definition GpuDrivenTypes.h:43
uint32_t instanceCount
Definition GpuDrivenTypes.h:44