Fixes and missing changes

This commit is contained in:
Wojtek Figat
2026-02-24 17:59:42 +01:00
parent 7ea3fb1500
commit 195d5b1aa2
10 changed files with 37 additions and 26 deletions

View File

@@ -440,6 +440,14 @@ void GPUContextWebGPU::Flush()
return;
PROFILE_CPU();
// End existing pass (if any)
if (_renderPass)
{
wgpuRenderPassEncoderEnd(_renderPass);
wgpuRenderPassEncoderRelease(_renderPass);
}
// End commands recording
WGPUCommandBufferDescriptor commandBufferDesc = WGPU_COMMAND_BUFFER_DESCRIPTOR_INIT;
WGPUCommandBuffer commandBuffer = wgpuCommandEncoderFinish(Encoder, &commandBufferDesc);
wgpuCommandEncoderRelease(Encoder);
@@ -706,7 +714,7 @@ void GPUContextWebGPU::OnDrawCall()
colorAttachment.clearValue = { clear.RGBA[0], clear.RGBA[1], clear.RGBA[2], clear.RGBA[3] };
}
_pipelineKey.MultiSampleCount = (int32)renderTarget->GetMSAA();
_pipelineKey.RenderTargetFormats[i] = RenderToolsWebGPU::ToTextureFormat(renderTarget->GetFormat());
_pipelineKey.RenderTargetFormats[i] = renderTarget->Format;
}
if (_depthStencil)
{
@@ -738,7 +746,7 @@ void GPUContextWebGPU::OnDrawCall()
depthStencilAttachment.stencilClearValue = clear.Stencil;
}
}
_pipelineKey.DepthStencilFormat = RenderToolsWebGPU::ToTextureFormat(_depthStencil->GetFormat());
_pipelineKey.DepthStencilFormat = _depthStencil->Format;
}
else
{
@@ -752,9 +760,7 @@ void GPUContextWebGPU::OnDrawCall()
// Apply pending state
if (_stencilRef != 0)
{
wgpuRenderPassEncoderSetStencilReference(_renderPass, _stencilRef);
}
auto scissorRect = _scissorRect;
// TODO: skip calling this if scissorRect is default (0, 0, attachment width, attachment height)
wgpuRenderPassEncoderSetScissorRect(_renderPass, (uint32_t)scissorRect.GetX(), (uint32_t)scissorRect.GetY(), (uint32_t)scissorRect.GetWidth(), (uint32_t)scissorRect.GetHeight());
@@ -780,7 +786,7 @@ void GPUContextWebGPU::OnDrawCall()
wgpuRenderPassEncoderSetPipeline(_renderPass, pipeline);
RENDER_STAT_PS_STATE_CHANGE();
}
if (_indexBufferDirty)
if (_indexBufferDirty && _indexBuffer.Buffer)
{
_indexBufferDirty = false;
wgpuRenderPassEncoderSetIndexBuffer(_renderPass, _indexBuffer.Buffer, _indexBuffer32Bit ? WGPUIndexFormat_Uint32 : WGPUIndexFormat_Uint16, _indexBuffer.Offset, _indexBuffer.Size);

View File

@@ -39,7 +39,6 @@ GPUVertexLayoutWebGPU::GPUVertexLayoutWebGPU(GPUDeviceWebGPU* device, const Elem
dst.nextInChain = nullptr;
dst.format = RenderToolsWebGPU::ToVertexFormat(src.Format);
dst.offset = src.Offset;
dst.shaderLocation = src.Slot;
if (src.PerInstance)
Layout.stepMode = WGPUVertexStepMode_Instance;
}
@@ -360,10 +359,8 @@ bool GPUDeviceWebGPU::Init()
WGPUDevice Device = nullptr;
};
AsyncCallbackWebGPU<WGPURequestDeviceCallbackInfo, DeviceUserData> deviceRequest(WGPU_REQUEST_DEVICE_CALLBACK_INFO_INIT);
#if GPU_ENABLE_RESOURCE_NAMING
deviceDesc.label = WEBGPU_STR("Flax Device");
deviceDesc.defaultQueue.label = WEBGPU_STR("Flax Queue");
#endif
deviceRequest.Info.callback = [](WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, WGPU_NULLABLE void* userdata1, WGPU_NULLABLE void* userdata2)
{
DeviceUserData& userData = *reinterpret_cast<DeviceUserData*>(userdata1);

View File

@@ -87,9 +87,11 @@ void GPUSwapChainWebGPU::Present(bool vsync)
// Release the texture
auto surfaceTexture = _surfaceView.Texture;
ASSERT(surfaceTexture);
_surfaceView.Release();
wgpuTextureRelease(surfaceTexture);
if (surfaceTexture)
{
_surfaceView.Release();
wgpuTextureRelease(surfaceTexture);
}
// Base
GPUSwapChain::Present(vsync);

View File

@@ -19,6 +19,7 @@ void GPUTextureViewWebGPU::Create(WGPUTexture texture, WGPUTextureViewDescriptor
LOG(Error, "Failed to create a view for texture '{}'", GetParent() ? GetParent()->GetName() : StringView::Empty);
#endif
}
Format = desc ? desc->format : wgpuTextureGetFormat(texture);
}
void GPUTextureViewWebGPU::Release()
@@ -178,18 +179,22 @@ void GPUTextureWebGPU::InitHandles()
// Init per slice views
_handlesPerSlice.Resize(Depth(), false);
viewDesc.dimension = WGPUTextureViewDimension_2D;
//viewDesc.dimension = WGPUTextureViewDimension_2DArray;
if (_desc.HasPerSliceViews() && IsRenderTarget())
{
for (int32 sliceIndex = 0; sliceIndex < Depth(); sliceIndex++)
{
//viewDesc.baseArrayLayer = sliceIndex;
//viewDesc.arrayLayerCount = 1;
auto& view = _handlesPerSlice[sliceIndex];
view.Init(this, format, msaa);
view.Create(Texture, &viewDesc);
view.DepthSlice = sliceIndex;
}
}
viewDesc.dimension = _viewDimension;
//viewDesc.baseArrayLayer = 0;
//viewDesc.arrayLayerCount = MipLevels();
//viewDesc.dimension = _viewDimension;
}
else if (IsArray())
{

View File

@@ -34,6 +34,7 @@ public:
bool HasStencil = false;
bool ReadOnly = false;
uint32 DepthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
WGPUTextureFormat Format = WGPUTextureFormat_Undefined;
GPUResourceViewPtrWebGPU Ptr;
public: