summaryrefslogtreecommitdiff
path: root/src/gpu/sequence.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/sequence.cc')
-rw-r--r--src/gpu/sequence.cc56
1 files changed, 39 insertions, 17 deletions
diff --git a/src/gpu/sequence.cc b/src/gpu/sequence.cc
index 62c2933..901d560 100644
--- a/src/gpu/sequence.cc
+++ b/src/gpu/sequence.cc
@@ -42,9 +42,9 @@ NodeRegistry::~NodeRegistry() {
}
void NodeRegistry::declare_node(const std::string& name, NodeType type,
- int width, int height) {
- FATAL_CHECK(nodes_.find(name) == nodes_.end(),
- "Node already declared: %s\n", name.c_str());
+ int width, int height) {
+ FATAL_CHECK(nodes_.find(name) == nodes_.end(), "Node already declared: %s\n",
+ name.c_str());
if (width <= 0)
width = default_width_;
@@ -64,8 +64,8 @@ void NodeRegistry::declare_aliased_node(const std::string& name,
const std::string& alias_of) {
FATAL_CHECK(nodes_.find(alias_of) != nodes_.end(),
"Alias target does not exist: %s\n", alias_of.c_str());
- FATAL_CHECK(aliases_.find(name) == aliases_.end(), "Alias already exists: %s\n",
- name.c_str());
+ FATAL_CHECK(aliases_.find(name) == aliases_.end(),
+ "Alias already exists: %s\n", name.c_str());
aliases_[name] = alias_of;
}
@@ -92,6 +92,16 @@ NodeRegistry::get_output_views(const std::vector<std::string>& names) {
return views;
}
+WGPUTexture NodeRegistry::get_texture(const std::string& name) {
+ auto alias_it = aliases_.find(name);
+ if (alias_it != aliases_.end()) {
+ return get_texture(alias_it->second);
+ }
+ auto it = nodes_.find(name);
+ FATAL_CHECK(it != nodes_.end(), "Node not found: %s\n", name.c_str());
+ return it->second.texture;
+}
+
void NodeRegistry::resize(int width, int height) {
default_width_ = width;
default_height_ = height;
@@ -121,7 +131,7 @@ bool NodeRegistry::has_node(const std::string& name) const {
}
void NodeRegistry::set_external_view(const std::string& name,
- WGPUTextureView view) {
+ WGPUTextureView view) {
// Register external view (texture not owned by registry)
Node node = {};
node.view = view;
@@ -141,15 +151,25 @@ void NodeRegistry::create_texture(Node& node) {
switch (node.type) {
case NodeType::U8X4_NORM:
format = WGPUTextureFormat_RGBA8Unorm;
- usage = (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding);
+ usage =
+ (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment |
+ WGPUTextureUsage_TextureBinding |
+ WGPUTextureUsage_CopySrc | WGPUTextureUsage_CopyDst);
break;
case NodeType::F32X4:
format = WGPUTextureFormat_RGBA32Float;
- usage = (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding);
+ usage =
+ (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment |
+ WGPUTextureUsage_TextureBinding |
+ WGPUTextureUsage_CopySrc | WGPUTextureUsage_CopyDst);
break;
case NodeType::F16X8:
- format = WGPUTextureFormat_RGBA16Float; // WebGPU doesn't have 8-channel, use RGBA16
- usage = (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding);
+ format = WGPUTextureFormat_RGBA16Float; // WebGPU doesn't have 8-channel,
+ // use RGBA16
+ usage =
+ (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment |
+ WGPUTextureUsage_TextureBinding |
+ WGPUTextureUsage_CopySrc | WGPUTextureUsage_CopyDst);
break;
case NodeType::DEPTH24:
format = WGPUTextureFormat_Depth24Plus;
@@ -157,15 +177,16 @@ void NodeRegistry::create_texture(Node& node) {
break;
case NodeType::COMPUTE_F32:
format = WGPUTextureFormat_RGBA32Float;
- usage = (WGPUTextureUsage)(WGPUTextureUsage_StorageBinding | WGPUTextureUsage_TextureBinding);
+ usage = (WGPUTextureUsage)(WGPUTextureUsage_StorageBinding |
+ WGPUTextureUsage_TextureBinding);
break;
}
WGPUTextureDescriptor desc = {};
desc.usage = usage;
desc.dimension = WGPUTextureDimension_2D;
- desc.size = {static_cast<unsigned int>(node.width),
- static_cast<unsigned int>(node.height), 1};
+ desc.size = {(unsigned int)(node.width),
+ (unsigned int)(node.height), 1};
desc.format = format;
desc.mipLevelCount = 1;
desc.sampleCount = 1;
@@ -197,10 +218,11 @@ Sequence::Sequence(const GpuContext& ctx, int width, int height)
}
void Sequence::preprocess(float seq_time, float beat_time, float beat_phase,
- float audio_intensity) {
- params_.resolution = {static_cast<float>(width_), static_cast<float>(height_)};
+ float audio_intensity) {
+ params_.resolution = {(float)(width_),
+ (float)(height_)};
params_.aspect_ratio =
- static_cast<float>(width_) / static_cast<float>(height_);
+ (float)(width_) / (float)(height_);
params_.time = seq_time;
params_.beat_time = beat_time;
params_.beat_phase = beat_phase;
@@ -218,7 +240,7 @@ void Sequence::postprocess(WGPUCommandEncoder encoder) {
void Sequence::render_effects(WGPUCommandEncoder encoder) {
// Execute DAG in topological order (pre-sorted by compiler)
for (const auto& dag_node : effect_dag_) {
- dag_node.effect->render(encoder, params_, nodes_);
+ dag_node.effect->dispatch_render(encoder, params_, nodes_);
}
}