Fix WebGPU in non-Debug builds
This commit is contained in:
@@ -76,6 +76,8 @@ void GPUContextWebGPU::FrameBegin()
|
||||
_renderPassDirty = false;
|
||||
_pipelineDirty = false;
|
||||
_bindGroupDirty = false;
|
||||
_viewportDirty = false;
|
||||
_scissorRectDirty = false;
|
||||
_indexBufferDirty = false;
|
||||
_vertexBufferDirty = false;
|
||||
_indexBuffer32Bit = false;
|
||||
@@ -479,15 +481,13 @@ void GPUContextWebGPU::EndQuery(uint64 queryID)
|
||||
void GPUContextWebGPU::SetViewport(const Viewport& viewport)
|
||||
{
|
||||
_viewport = viewport;
|
||||
if (_renderPass && !_renderPassDirty)
|
||||
wgpuRenderPassEncoderSetViewport(_renderPass, viewport.X, viewport.Y, viewport.Width, viewport.Height, viewport.MinDepth, viewport.MaxDepth);
|
||||
_viewportDirty = true;
|
||||
}
|
||||
|
||||
void GPUContextWebGPU::SetScissor(const Rectangle& scissorRect)
|
||||
{
|
||||
_scissorRect = scissorRect;
|
||||
if (_renderPass && !_renderPassDirty)
|
||||
wgpuRenderPassEncoderSetScissorRect(_renderPass, (uint32_t)scissorRect.GetX(), (uint32_t)scissorRect.GetY(), (uint32_t)scissorRect.GetWidth(), (uint32_t)scissorRect.GetHeight());
|
||||
_scissorRectDirty = true;
|
||||
}
|
||||
|
||||
void GPUContextWebGPU::SetDepthBounds(float minDepth, float maxDepth)
|
||||
@@ -880,6 +880,16 @@ void GPUContextWebGPU::OnDrawCall()
|
||||
// Invalidate bind groups (layout might change)
|
||||
_bindGroupDirty = true;
|
||||
}
|
||||
if (_scissorRectDirty)
|
||||
{
|
||||
_scissorRectDirty = false;
|
||||
wgpuRenderPassEncoderSetScissorRect(_renderPass, (uint32_t)_scissorRect.GetX(), (uint32_t)_scissorRect.GetY(), (uint32_t)_scissorRect.GetWidth(), (uint32_t)_scissorRect.GetHeight());
|
||||
}
|
||||
if (_viewportDirty)
|
||||
{
|
||||
_viewportDirty = false;
|
||||
wgpuRenderPassEncoderSetViewport(_renderPass, _viewport.X, _viewport.Y, _viewport.Width, _viewport.Height, _viewport.MinDepth, _viewport.MaxDepth);
|
||||
}
|
||||
if (_indexBufferDirty && _indexBuffer.Buffer)
|
||||
{
|
||||
_indexBufferDirty = false;
|
||||
@@ -1054,12 +1064,6 @@ void GPUContextWebGPU::FlushRenderPass()
|
||||
// Apply pending state
|
||||
if (_stencilRef != 0)
|
||||
wgpuRenderPassEncoderSetStencilReference(_renderPass, _stencilRef);
|
||||
auto scissorRect = _scissorRect;
|
||||
if (scissorRect != Rectangle(0, 0, attachmentSize.Width, attachmentSize.Height))
|
||||
wgpuRenderPassEncoderSetScissorRect(_renderPass, (uint32_t)scissorRect.GetX(), (uint32_t)scissorRect.GetY(), (uint32_t)scissorRect.GetWidth(), (uint32_t)scissorRect.GetHeight());
|
||||
auto viewport = _viewport;
|
||||
if (viewport != Viewport(Float2(attachmentSize.Width, attachmentSize.Height)))
|
||||
wgpuRenderPassEncoderSetViewport(_renderPass, viewport.X, viewport.Y, viewport.Width, viewport.Height, viewport.MinDepth, viewport.MaxDepth);
|
||||
|
||||
// Auto-dirty pipeline when new render pass starts
|
||||
if (_pipelineState)
|
||||
@@ -1069,6 +1073,8 @@ void GPUContextWebGPU::FlushRenderPass()
|
||||
_bindGroupDirty = true;
|
||||
if (_blendFactorSet)
|
||||
_blendFactorDirty = true;
|
||||
_scissorRectDirty |= _scissorRect != Rectangle(0, 0, attachmentSize.Width, attachmentSize.Height);
|
||||
_viewportDirty |= _viewport != Viewport(Float2(attachmentSize.Width, attachmentSize.Height));
|
||||
}
|
||||
|
||||
void GPUContextWebGPU::FlushBindGroup()
|
||||
|
||||
@@ -52,6 +52,8 @@ private:
|
||||
uint32 _renderPassDirty : 1;
|
||||
uint32 _pipelineDirty : 1;
|
||||
uint32 _bindGroupDirty : 1;
|
||||
uint32 _viewportDirty : 1;
|
||||
uint32 _scissorRectDirty : 1;
|
||||
uint32 _vertexBufferDirty : 1;
|
||||
uint32 _indexBufferDirty : 1;
|
||||
uint32 _indexBuffer32Bit : 1;
|
||||
|
||||
@@ -543,9 +543,10 @@ WGPURenderPipeline GPUPipelineStateWebGPU::GetPipeline(const PipelineKey& key, c
|
||||
InitLayout(bindings);
|
||||
|
||||
// Build final pipeline description
|
||||
auto desc = PipelineDesc;
|
||||
_depthStencilDesc.format = (WGPUTextureFormat)key.DepthStencilFormat;
|
||||
PipelineDesc.depthStencil = key.DepthStencilFormat ? &_depthStencilDesc : nullptr; // Unbind depth stencil state when no debug buffer is bound
|
||||
PipelineDesc.multisample.count = key.MultiSampleCount;
|
||||
desc.depthStencil = key.DepthStencilFormat ? PipelineDesc.depthStencil : nullptr; // Unbind depth stencil state when no debug buffer is bound
|
||||
desc.multisample.count = key.MultiSampleCount;
|
||||
if (PS)
|
||||
{
|
||||
_fragmentDesc.targetCount = key.RenderTargetCount;
|
||||
@@ -564,8 +565,8 @@ WGPURenderPipeline GPUPipelineStateWebGPU::GetPipeline(const PipelineKey& key, c
|
||||
|
||||
// Build attributes list
|
||||
WGPUVertexAttribute attributes[GPU_MAX_VS_ELEMENTS];
|
||||
PipelineDesc.vertex.bufferCount = 0;
|
||||
PipelineDesc.vertex.buffers = buffers;
|
||||
desc.vertex.bufferCount = 0;
|
||||
desc.vertex.buffers = buffers;
|
||||
int32 attributeIndex = 0;
|
||||
auto& elements = mergedVertexLayout->GetElements();
|
||||
#if WEBGPU_LOG_PSO
|
||||
@@ -594,7 +595,7 @@ WGPURenderPipeline GPUPipelineStateWebGPU::GetPipeline(const PipelineKey& key, c
|
||||
if (element.PerInstance)
|
||||
buffer.stepMode = WGPUVertexStepMode_Instance;
|
||||
buffer.arrayStride = Math::Max<uint64>(buffer.arrayStride, element.Offset + PixelFormatExtensions::SizeInBytes(element.Format));
|
||||
PipelineDesc.vertex.bufferCount = Math::Max<size_t>(PipelineDesc.vertex.bufferCount, bufferIndex + 1);
|
||||
desc.vertex.bufferCount = Math::Max<size_t>(desc.vertex.bufferCount, bufferIndex + 1);
|
||||
#if WEBGPU_LOG_PSO
|
||||
if (log)
|
||||
LOG(Info, " > [{}] slot {}: {} ({} bytes at offset {}) at shader location: {} (per-instance: {})", attributeIndex - 1, element.Slot, ScriptingEnum::ToString(element.Format), PixelFormatExtensions::SizeInBytes(element.Format), element.Offset, dst.shaderLocation, element.PerInstance);
|
||||
@@ -605,12 +606,12 @@ WGPURenderPipeline GPUPipelineStateWebGPU::GetPipeline(const PipelineKey& key, c
|
||||
else
|
||||
{
|
||||
// No vertex input
|
||||
PipelineDesc.vertex.bufferCount = 0;
|
||||
PipelineDesc.vertex.buffers = nullptr;
|
||||
desc.vertex.bufferCount = 0;
|
||||
desc.vertex.buffers = nullptr;
|
||||
}
|
||||
|
||||
// Create object
|
||||
pipeline = wgpuDeviceCreateRenderPipeline(_device->Device, &PipelineDesc);
|
||||
pipeline = wgpuDeviceCreateRenderPipeline(_device->Device, &desc);
|
||||
if (!pipeline)
|
||||
{
|
||||
#if GPU_ENABLE_RESOURCE_NAMING
|
||||
@@ -706,22 +707,19 @@ bool GPUPipelineStateWebGPU::Init(const Description& desc)
|
||||
break;
|
||||
}
|
||||
PipelineDesc.primitive.unclippedDepth = !desc.DepthClipEnable && _device->Limits.HasDepthClip;
|
||||
if (desc.DepthEnable || desc.StencilEnable)
|
||||
PipelineDesc.depthStencil = &_depthStencilDesc;
|
||||
_depthStencilDesc = WGPU_DEPTH_STENCIL_STATE_INIT;
|
||||
_depthStencilDesc.depthWriteEnabled = desc.DepthEnable && desc.DepthWriteEnable ? WGPUOptionalBool_True : WGPUOptionalBool_False;
|
||||
_depthStencilDesc.depthCompare = ToCompareFunction(desc.DepthFunc);
|
||||
if (desc.StencilEnable)
|
||||
{
|
||||
PipelineDesc.depthStencil = &_depthStencilDesc;
|
||||
_depthStencilDesc = WGPU_DEPTH_STENCIL_STATE_INIT;
|
||||
_depthStencilDesc.depthWriteEnabled = desc.DepthEnable && desc.DepthWriteEnable ? WGPUOptionalBool_True : WGPUOptionalBool_False;
|
||||
_depthStencilDesc.depthCompare = ToCompareFunction(desc.DepthFunc);
|
||||
if (desc.StencilEnable)
|
||||
{
|
||||
_depthStencilDesc.stencilFront.compare = ToCompareFunction(desc.StencilFunc);
|
||||
_depthStencilDesc.stencilFront.failOp = ToStencilOperation(desc.StencilFailOp);
|
||||
_depthStencilDesc.stencilFront.depthFailOp = ToStencilOperation(desc.StencilDepthFailOp);
|
||||
_depthStencilDesc.stencilFront.passOp = ToStencilOperation(desc.StencilPassOp);
|
||||
_depthStencilDesc.stencilBack = _depthStencilDesc.stencilFront;
|
||||
_depthStencilDesc.stencilReadMask = desc.StencilReadMask;
|
||||
_depthStencilDesc.stencilWriteMask = desc.StencilWriteMask;
|
||||
}
|
||||
_depthStencilDesc.stencilFront.compare = ToCompareFunction(desc.StencilFunc);
|
||||
_depthStencilDesc.stencilFront.failOp = ToStencilOperation(desc.StencilFailOp);
|
||||
_depthStencilDesc.stencilFront.depthFailOp = ToStencilOperation(desc.StencilDepthFailOp);
|
||||
_depthStencilDesc.stencilFront.passOp = ToStencilOperation(desc.StencilPassOp);
|
||||
_depthStencilDesc.stencilBack = _depthStencilDesc.stencilFront;
|
||||
_depthStencilDesc.stencilReadMask = desc.StencilReadMask;
|
||||
_depthStencilDesc.stencilWriteMask = desc.StencilWriteMask;
|
||||
}
|
||||
PipelineDesc.multisample.alphaToCoverageEnabled = desc.BlendMode.AlphaToCoverageEnable;
|
||||
if (desc.PS)
|
||||
|
||||
@@ -76,11 +76,8 @@ bool LightPass::setupResources()
|
||||
psDesc = GPUPipelineState::Description::DefaultFullscreenTriangle;
|
||||
psDesc.BlendMode = BlendingMode::Add;
|
||||
psDesc.BlendMode.RenderTargetWriteMask = BlendingMode::ColorWrite::RGB;
|
||||
if (_depthBounds)
|
||||
{
|
||||
psDesc.DepthEnable = psDesc.DepthBoundsEnable = true;
|
||||
psDesc.DepthWriteEnable = false;
|
||||
}
|
||||
psDesc.DepthWriteEnable = false;
|
||||
psDesc.DepthEnable = psDesc.DepthBoundsEnable = _depthBounds;
|
||||
if (_psLightDir.Create(psDesc, shader, "PS_Directional"))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -519,11 +519,8 @@ bool ShadowsPass::setupResources()
|
||||
{
|
||||
psDesc = GPUPipelineState::Description::DefaultFullscreenTriangle;
|
||||
psDesc.BlendMode.RenderTargetWriteMask = BlendingMode::ColorWrite::RG;
|
||||
if (_depthBounds)
|
||||
{
|
||||
psDesc.DepthEnable = psDesc.DepthBoundsEnable = true;
|
||||
psDesc.DepthWriteEnable = false;
|
||||
}
|
||||
psDesc.DepthWriteEnable = false;
|
||||
psDesc.DepthEnable = psDesc.DepthBoundsEnable = _depthBounds;
|
||||
if (_psShadowDir.Create(psDesc, shader, "PS_DirLight"))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "Engine/Graphics/RenderTools.h"
|
||||
#include "Engine/Platform/CPUInfo.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Profiler/ProfilerMemory.h"
|
||||
#include <ThirdParty/basis_universal/transcoder/basisu_transcoder.h>
|
||||
#if USE_EDITOR
|
||||
#include <ThirdParty/basis_universal/encoder/basisu_comp.h>
|
||||
|
||||
Reference in New Issue
Block a user