[Dawn] Add multiple color-attachment support#594
Conversation
dneto0
left a comment
There was a problem hiding this comment.
Do any tests start passing for Dawn, with this change?
src/dawn/engine_dawn.cc
Outdated
| ::dawn::Buffer copy_buffer = device.CreateBuffer(&descriptor); | ||
|
|
||
| ::dawn::BufferCopyView copy_buffer_view = | ||
| CreateBufferCopyView(copy_buffer, 0, dawn_row_pitch, 0); |
There was a problem hiding this comment.
Seems you can pull the creation of the buffer and the buffer view outside the the loop. Their parameters are independent of i.
src/dawn/engine_dawn.cc
Outdated
| if (!mapped_device_texture.result.IsSuccess()) | ||
| return mapped_device_texture.result; | ||
|
|
||
| if (i < render_pipeline.pipeline->GetColorAttachments().size()) { |
There was a problem hiding this comment.
This is a bit weird. Why is the for loop at line 581 up to kMaxColorAttachments but then we only restrict this later part to colour attachments attached to this pipeline? It seems weird that we would be copying buffers back to the host when they are not attached to the pipeline and hence not accessible to the pipeline.??
There was a problem hiding this comment.
i has not changed since it was bounds-checked at line 596. So this "if" should disappear. Its condition always evaluates to true. Replace this if construct by its "then" body.
| rpd.colorAttachmentCount = 1; | ||
| rpd.colorAttachments = color_attachment_descriptor; | ||
| rpd.depthStencilAttachment = depth_stencil_descriptor; | ||
| DawnPipelineHelper helper; |
There was a problem hiding this comment.
This whole routine is a lot simpler now! :-)
|
../amber/tests/cases/draw_rect_multiple_color_attachment.amber |
src/dawn/engine_dawn.cc
Outdated
| if (!mapped_device_texture.result.IsSuccess()) | ||
| return mapped_device_texture.result; | ||
|
|
||
| if (i < render_pipeline.pipeline->GetColorAttachments().size()) { |
There was a problem hiding this comment.
i has not changed since it was bounds-checked at line 596. So this "if" should disappear. Its condition always evaluates to true. Replace this if construct by its "then" body.
|
|
||
| RUN my_pipeline DRAW_RECT POS 0 0 SIZE 800 600 | ||
| EXPECT framebuffer IDX 0 0 SIZE 800 600 EQ_RGBA 0 128 0 204 | ||
| EXPECT framebuffer IDX 0 0 SIZE 800 600 EQ_RGBA 0 127 0 204 |
There was a problem hiding this comment.
Hm, I think this will fail on a vulkan host now (as it worked previously). Is this just a numerical difference between the dawn and vulkan engines?
There was a problem hiding this comment.
I see your point however right now Vulkan fails with 128 and passes with 127, at least on my machine. Is there any reasons for this to behave differently on different machines?
There was a problem hiding this comment.
Maybe? But, if both Vulkan and Dawn engines pass with this on your machine then I'm good with it. Maybe add a comment that we flipped the 128 to a 127 and if folks see this failing we need to find a better solution than changing the number? Just so we don't end up constantly flipping it back and forth, heh.
There was a problem hiding this comment.
How about changing 0.5 to 0.499 to eliminate the confusion?
There was a problem hiding this comment.
Yeah, I suspect something funny with quantization of the very-low-precision floating point used in rendering. I could see it flipping back and forth.
All the other AmberScript scripts in the tests/cases directory use 127, except for the clear_color.amber script, but it's using an explicit 128 in that component of the clear color and it's using a UNORM so that's right in the middle of the range.
In short, I'm ok with this change. But let's keep an eye on this as an issue coming up.
There was a problem hiding this comment.
FYI. This is what Vulkan says about how UNORM and SNORM are treated
https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#fundamentals-fpfixedconv
There was a problem hiding this comment.
I particular "Implementations should round to nearest. If r is equal to an integer, then that integer value must be returned."
So we could put 127.0/255.0 and it should get it. (that's 0.4980 while 128/255 is .50196) So 0.499 should be sufficient.
dneto0
left a comment
There was a problem hiding this comment.
For what it's worth, I ran this version of the test, and it passes on my old NV Quadro K2000 desktop GPU. It used to fail with the 128 expectation.
|
|
||
| RUN my_pipeline DRAW_RECT POS 0 0 SIZE 800 600 | ||
| EXPECT framebuffer IDX 0 0 SIZE 800 600 EQ_RGBA 0 128 0 204 | ||
| EXPECT framebuffer IDX 0 0 SIZE 800 600 EQ_RGBA 0 127 0 204 |
There was a problem hiding this comment.
FYI. This is what Vulkan says about how UNORM and SNORM are treated
https://www.khronos.org/registry/vulkan/specs/1.1/html/vkspec.html#fundamentals-fpfixedconv
|
|
||
| RUN my_pipeline DRAW_RECT POS 0 0 SIZE 800 600 | ||
| EXPECT framebuffer IDX 0 0 SIZE 800 600 EQ_RGBA 0 128 0 204 | ||
| EXPECT framebuffer IDX 0 0 SIZE 800 600 EQ_RGBA 0 127 0 204 |
There was a problem hiding this comment.
I particular "Implementations should round to nearest. If r is equal to an integer, then that integer value must be returned."
So we could put 127.0/255.0 and it should get it. (that's 0.4980 while 128/255 is .50196) So 0.499 should be sufficient.
fixs #547 and simplifies DoClear by using helper functions