-
I'm using wgpu and trying to render from one texture to another, and then render from the second texture to the screen, but I can't seem to get it to work. Here's my render function: I'm using a struct Target {
bind_group: BindGroup,
texture: Texture,
texture_view: TextureView,
} The renderer has two targets. Here, I zero-initialize self.target[0].texture: Then in the first pass I render using target 0 as the source, target 1 as the destination, and with the shader uniform i set to 0, which should cause it to sample target 0 and invert the sampled color: And then in the second pass I render using target 1 as the source, and the current frame as the destination, with shader uniform set to 1, which should cause it to sample target 1 and pass through the sampled color: However, when I render, the output is black when it should be white. Am I doing something that's obviously silly here? I'm on MacOS, btw. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You’re interleaving calls to queue.write_texture(...0x00...)
queue.write_buffer({i: 0})
queue.write_buffer({i: 1})
queue.submit([encoder.finish()]) So, all of your draw calls are executed with To make this work as you want, you can do one of these things:
|
Beta Was this translation helpful? Give feedback.
You’re interleaving calls to
wgpu::Queue
with constructing a singlewgpu::CommandEncoder
, which doesn’t work the way you intend. Operations are executed in the order they are put on theQueue
, and so all commands you encoded were enqueued at the point you submitted the command buffer to the queue, not when you encoded them. Here’s the sequence of your queue usage:So, all of your draw calls are executed with
i = 1
, because all of them executed after you wrote1
to the buffer.To make this work as you want, you can do one of these things: