summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/effects/hybrid3_d_effect.cc28
-rw-r--r--src/effects/rotating_cube_effect.cc20
-rw-r--r--src/gpu/sequence.cc16
-rw-r--r--src/gpu/sequence.h3
4 files changed, 60 insertions, 7 deletions
diff --git a/src/effects/hybrid3_d_effect.cc b/src/effects/hybrid3_d_effect.cc
index 0e44853..c13c1e9 100644
--- a/src/effects/hybrid3_d_effect.cc
+++ b/src/effects/hybrid3_d_effect.cc
@@ -4,6 +4,7 @@
#include "util/fatal_error.h"
#include "effects/hybrid3_d_effect.h"
+#include "gpu/gpu.h"
#include <cmath>
Hybrid3D::Hybrid3D(const GpuContext& ctx,
@@ -113,6 +114,29 @@ void Hybrid3D::render(WGPUCommandEncoder encoder,
WGPUTextureView color_view = nodes.get_view(output_nodes_[0]);
WGPUTextureView depth_view = nodes.get_view(depth_node_);
- // Render 3D scene
- renderer_.render(scene_, camera_, params.time, color_view, depth_view);
+ // Render 3D scene using sequence encoder
+ WGPURenderPassColorAttachment color_attachment = {};
+#if !defined(DEMO_CROSS_COMPILE_WIN32)
+ color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
+#endif
+ color_attachment.view = color_view;
+ color_attachment.loadOp = WGPULoadOp_Clear;
+ color_attachment.storeOp = WGPUStoreOp_Store;
+ color_attachment.clearValue = {0.05f, 0.05f, 0.05f, 1.0f};
+
+ WGPURenderPassDepthStencilAttachment depth_attachment = {};
+ depth_attachment.view = depth_view;
+ depth_attachment.depthLoadOp = WGPULoadOp_Clear;
+ depth_attachment.depthStoreOp = WGPUStoreOp_Store;
+ depth_attachment.depthClearValue = 1.0f;
+
+ WGPURenderPassDescriptor pass_desc = {};
+ pass_desc.colorAttachmentCount = 1;
+ pass_desc.colorAttachments = &color_attachment;
+ pass_desc.depthStencilAttachment = &depth_attachment;
+
+ WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ renderer_.draw(pass, scene_, camera_, params.time);
+ wgpuRenderPassEncoderEnd(pass);
+ wgpuRenderPassEncoderRelease(pass);
}
diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc
index 1f56b8b..a91bc78 100644
--- a/src/effects/rotating_cube_effect.cc
+++ b/src/effects/rotating_cube_effect.cc
@@ -156,6 +156,21 @@ void RotatingCube::render(WGPUCommandEncoder encoder,
wgpuQueueWriteBuffer(ctx_.queue, object_buffer_.buffer, 0, &obj_data,
sizeof(ObjectData));
+ // Blit input to output if compositing (not reading from source)
+ if (!input_nodes_.empty() && input_nodes_[0] != "source") {
+ WGPUTexture input_tex = nodes.get_texture(input_nodes_[0]);
+ WGPUTexture output_tex = nodes.get_texture(output_nodes_[0]);
+ if (input_tex && output_tex) {
+ WGPUTexelCopyTextureInfo src = {
+ .texture = input_tex, .mipLevel = 0, .aspect = WGPUTextureAspect_All};
+ WGPUTexelCopyTextureInfo dst = {
+ .texture = output_tex, .mipLevel = 0, .aspect = WGPUTextureAspect_All};
+ WGPUExtent3D copy_size = {(uint32_t)params.resolution.x,
+ (uint32_t)params.resolution.y, 1};
+ wgpuCommandEncoderCopyTextureToTexture(encoder, &src, &dst, &copy_size);
+ }
+ }
+
// Get output views
WGPUTextureView color_view = nodes.get_view(output_nodes_[0]);
WGPUTextureView depth_view = nodes.get_view(depth_node_);
@@ -164,9 +179,10 @@ void RotatingCube::render(WGPUCommandEncoder encoder,
WGPURenderPassColorAttachment color_attachment = {
.view = color_view,
.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
- .loadOp = WGPULoadOp_Clear,
+// .loadOp = WGPULoadOp_Clear,
+ .loadOp = WGPULoadOp_Load,
.storeOp = WGPUStoreOp_Store,
- .clearValue = {0.0, 0.0, 0.0, 1.0}};
+ .clearValue = {0.0, 0.0, 0.0, 0.0}};
WGPURenderPassDepthStencilAttachment depth_attachment = {
.view = depth_view,
diff --git a/src/gpu/sequence.cc b/src/gpu/sequence.cc
index 62c2933..0a0cb1e 100644
--- a/src/gpu/sequence.cc
+++ b/src/gpu/sequence.cc
@@ -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;
@@ -141,15 +151,15 @@ 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);
+ usage = (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopySrc | WGPUTextureUsage_CopyDst);
break;
case NodeType::DEPTH24:
format = WGPUTextureFormat_Depth24Plus;
diff --git a/src/gpu/sequence.h b/src/gpu/sequence.h
index a33dedb..e96e183 100644
--- a/src/gpu/sequence.h
+++ b/src/gpu/sequence.h
@@ -62,6 +62,9 @@ class NodeRegistry {
std::vector<WGPUTextureView>
get_output_views(const std::vector<std::string>& names);
+ // Retrieve texture (for blits)
+ WGPUTexture get_texture(const std::string& name);
+
// Resize all nodes
void resize(int width, int height);