当使用WebGPU渲染时,我需要设置一个神奇的标志来正确清除背景吗?我的渲染运行良好,除了,无论我使用什么设置,我看到最后显示的垃圾是在浏览器窗口中,而不是背景颜色(如果我在附件中设置了一个非零的clearColor,那么它将不断累积相同的颜色,直到它的max‘out):

我通过emscripten CPP接口使用WebGPU,并在Windows上运行Chrome Canary (版本90.0.4407.0 (官方版本) canary (64位))。
我的帧渲染看起来像这样(从js端的requestAnimationFrame调用):
WGPUSwapChain swapChain = _pWindow->swapChain();
WGPUTextureView backbufferView = wgpuSwapChainGetCurrentTextureView(swapChain);
WGPURenderPassDescriptor renderpassInfo = {};
WGPURenderPassColorAttachmentDescriptor colorAttachment = {};
{
colorAttachment.attachment = backbufferView;
colorAttachment.resolveTarget = nullptr;
colorAttachment.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
colorAttachment.loadOp = WGPULoadOp_Clear;
colorAttachment.storeOp = WGPUStoreOp_Store;
renderpassInfo.colorAttachmentCount = 1;
renderpassInfo.colorAttachments = &colorAttachment;
renderpassInfo.depthStencilAttachment = nullptr;
}
WGPUCommandBuffer commands;
{
WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(_device, nullptr);
WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &renderpassInfo);
wgpuRenderPassEncoderSetPipeline(pass, _pipeline);
wgpuRenderPassEncoderSetVertexBuffer(pass, 0, _vb, 0, 0);
wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
wgpuRenderPassEncoderEndPass(pass);
wgpuRenderPassEncoderRelease(pass);
commands = wgpuCommandEncoderFinish(encoder, nullptr);
wgpuCommandEncoderRelease(encoder);
}
wgpuQueueSubmit(_queue, 1, &commands);
wgpuCommandBufferRelease(commands);
wgpuTextureViewRelease(backbufferView);使用以下设置设置管道:
WGPURenderPipelineDescriptor descriptor = {};
WGPUBlendDescriptor blendDescriptor = {};
blendDescriptor.operation = WGPUBlendOperation_Add;
blendDescriptor.srcFactor = WGPUBlendFactor_One;
blendDescriptor.dstFactor = WGPUBlendFactor_Zero;
WGPUColorStateDescriptor colorStateDescriptor = {};
colorStateDescriptor.format = _colorFormat;
colorStateDescriptor.alphaBlend = blendDescriptor;
colorStateDescriptor.colorBlend = blendDescriptor;
colorStateDescriptor.writeMask = WGPUColorWriteMask_All;
descriptor.colorStateCount = 1;
descriptor.colorStates = &colorStateDescriptor;有没有我遗漏的设置,或者这是一个金丝雀bug?
发布于 2021-02-04 13:29:43
有一个0的alpha值,这就把它搞乱了:(在clearColor字段中将它改为1可以很好地工作:
colorAttachment.clearColor = { 0.0f, 0.0f, 0.0f, 1.0f };https://stackoverflow.com/questions/66039687
复制相似问题