Crafter.Graphics/implementations/Crafter.Graphics-WebGPUComputeShader.cpp

45 lines
1.4 KiB
C++
Raw Permalink Normal View History

2026-05-18 05:39:17 +02:00
/*
Crafter®.Graphics
Copyright (C) 2026 Catcrafts®
catcrafts.net
*/
module Crafter.Graphics:WebGPUComputeShader_impl;
import :WebGPUComputeShader;
import :WebGPU;
import std;
using namespace Crafter;
void WebGPUComputeShader::Load(std::string_view wgsl,
2026-05-18 18:43:30 +02:00
std::span<const UICustomBinding> bindings,
bool rayQuery) {
2026-05-18 05:39:17 +02:00
customBindings.assign(bindings.begin(), bindings.end());
2026-05-18 18:43:30 +02:00
rayQueryCapable = rayQuery;
2026-05-18 05:39:17 +02:00
pipelineHandle = WebGPU::wgpuLoadCustomShader(
wgsl.data(),
static_cast<std::int32_t>(wgsl.size()),
customBindings.data(),
2026-05-18 18:43:30 +02:00
static_cast<std::int32_t>(customBindings.size()),
rayQuery ? 1 : 0
2026-05-18 05:39:17 +02:00
);
}
void WebGPUComputeShader::Load(const std::filesystem::path& wgslPath,
2026-05-18 18:43:30 +02:00
std::span<const UICustomBinding> bindings,
bool rayQuery) {
2026-05-18 05:39:17 +02:00
std::ifstream f(wgslPath, std::ios::binary | std::ios::ate);
if (!f.is_open()) {
std::println("WebGPUComputeShader::Load: cannot open {}", wgslPath.string());
return;
}
auto size = f.tellg();
if (size <= 0) {
std::println("WebGPUComputeShader::Load: empty file {}", wgslPath.string());
return;
}
f.seekg(0, std::ios::beg);
std::string src(static_cast<std::size_t>(size), '\0');
f.read(src.data(), size);
2026-05-18 18:43:30 +02:00
Load(std::string_view{src}, bindings, rayQuery);
2026-05-18 05:39:17 +02:00
}