Commit e5c77b35 authored by Kai Ninomiya's avatar Kai Ninomiya Committed by Commit Bot

Fix more use-after-frees of strings in WebGPU

Bug: 1115412
Change-Id: I65d01c7fad045e11ef45180e882079ef398fe59f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353368Reviewed-by: default avatarAustin Eng <enga@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797483}
parent 45701c29
......@@ -58,13 +58,15 @@ GPUBindGroup* GPUBindGroup::Create(GPUDevice* device,
entries = AsDawnType(webgpu_desc->entries());
}
std::string label;
WGPUBindGroupDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
dawn_desc.layout = AsDawnType(webgpu_desc->layout());
dawn_desc.entryCount = entry_count;
dawn_desc.entries = entries.get();
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str();
}
return MakeGarbageCollected<GPUBindGroup>(
......
......@@ -70,12 +70,14 @@ GPUBindGroupLayout* GPUBindGroupLayout::Create(
entries = AsDawnType(webgpu_desc->entries(), device);
}
std::string label;
WGPUBindGroupLayoutDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
dawn_desc.entryCount = entry_count;
dawn_desc.entries = entries.get();
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str();
}
return MakeGarbageCollected<GPUBindGroupLayout>(
......
......@@ -59,8 +59,10 @@ bool ValidateRangeCreation(ExceptionState& exception_state,
return true;
}
WGPUBufferDescriptor AsDawnType(const GPUBufferDescriptor* webgpu_desc) {
WGPUBufferDescriptor AsDawnType(const GPUBufferDescriptor* webgpu_desc,
std::string* label) {
DCHECK(webgpu_desc);
DCHECK(label);
WGPUBufferDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
......@@ -68,7 +70,8 @@ WGPUBufferDescriptor AsDawnType(const GPUBufferDescriptor* webgpu_desc) {
dawn_desc.size = webgpu_desc->size();
dawn_desc.mappedAtCreation = webgpu_desc->mappedAtCreation();
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
*label = webgpu_desc->label().Utf8();
dawn_desc.label = label->c_str();
}
return dawn_desc;
......@@ -81,7 +84,8 @@ GPUBuffer* GPUBuffer::Create(GPUDevice* device,
const GPUBufferDescriptor* webgpu_desc) {
DCHECK(device);
WGPUBufferDescriptor dawn_desc = AsDawnType(webgpu_desc);
std::string label;
WGPUBufferDescriptor dawn_desc = AsDawnType(webgpu_desc, &label);
return MakeGarbageCollected<GPUBuffer>(
device, dawn_desc.size, dawn_desc.mappedAtCreation,
device->GetProcs().deviceCreateBuffer(device->GetHandle(), &dawn_desc));
......@@ -94,7 +98,8 @@ std::pair<GPUBuffer*, DOMArrayBuffer*> GPUBuffer::CreateMapped(
ExceptionState& exception_state) {
DCHECK(device);
WGPUBufferDescriptor dawn_desc = AsDawnType(webgpu_desc);
std::string label;
WGPUBufferDescriptor dawn_desc = AsDawnType(webgpu_desc, &label);
if (!ValidateRangeCreation(exception_state, "createBufferMapped", 0,
dawn_desc.size, kLargestMappableSize)) {
......
......@@ -122,13 +122,16 @@ WGPUBufferCopyView AsDawnType(const GPUBufferCopyView* webgpu_view) {
}
WGPUCommandEncoderDescriptor AsDawnType(
const GPUCommandEncoderDescriptor* webgpu_desc) {
const GPUCommandEncoderDescriptor* webgpu_desc,
std::string* label) {
DCHECK(webgpu_desc);
DCHECK(label);
WGPUCommandEncoderDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
*label = webgpu_desc->label().Utf8();
dawn_desc.label = label->c_str();
}
return dawn_desc;
......@@ -144,10 +147,11 @@ GPUCommandEncoder* GPUCommandEncoder::Create(
DCHECK(webgpu_desc);
ALLOW_UNUSED_LOCAL(webgpu_desc);
std::string label;
WGPUCommandEncoderDescriptor dawn_desc = {};
const WGPUCommandEncoderDescriptor* dawn_desc_ptr = nullptr;
if (webgpu_desc) {
dawn_desc = AsDawnType(webgpu_desc);
dawn_desc = AsDawnType(webgpu_desc, &label);
dawn_desc_ptr = &dawn_desc;
}
......@@ -189,11 +193,13 @@ GPURenderPassEncoder* GPUCommandEncoder::beginRenderPass(
}
}
std::string label;
WGPURenderPassDescriptor dawn_desc = {};
dawn_desc.colorAttachmentCount = color_attachment_count;
dawn_desc.colorAttachments = nullptr;
if (descriptor->hasLabel()) {
dawn_desc.label = descriptor->label().Utf8().data();
label = descriptor->label().Utf8();
dawn_desc.label = label.c_str();
}
std::unique_ptr<WGPURenderPassColorAttachmentDescriptor[]> color_attachments;
......@@ -218,9 +224,11 @@ GPURenderPassEncoder* GPUCommandEncoder::beginRenderPass(
GPUComputePassEncoder* GPUCommandEncoder::beginComputePass(
const GPUComputePassDescriptor* descriptor) {
std::string label;
WGPUComputePassDescriptor dawn_desc = {};
if (descriptor->hasLabel()) {
dawn_desc.label = descriptor->label().Utf8().data();
label = descriptor->label().Utf8();
dawn_desc.label = label.c_str();
}
return MakeGarbageCollected<GPUComputePassEncoder>(
......@@ -302,8 +310,8 @@ void GPUCommandEncoder::copyTextureToTexture(
}
void GPUCommandEncoder::pushDebugGroup(String groupLabel) {
GetProcs().commandEncoderPushDebugGroup(GetHandle(),
groupLabel.Utf8().data());
std::string label = groupLabel.Utf8();
GetProcs().commandEncoderPushDebugGroup(GetHandle(), label.c_str());
}
void GPUCommandEncoder::popDebugGroup() {
......@@ -311,15 +319,17 @@ void GPUCommandEncoder::popDebugGroup() {
}
void GPUCommandEncoder::insertDebugMarker(String markerLabel) {
GetProcs().commandEncoderInsertDebugMarker(GetHandle(),
markerLabel.Utf8().data());
std::string label = markerLabel.Utf8();
GetProcs().commandEncoderInsertDebugMarker(GetHandle(), label.c_str());
}
GPUCommandBuffer* GPUCommandEncoder::finish(
const GPUCommandBufferDescriptor* descriptor) {
std::string label;
WGPUCommandBufferDescriptor dawn_desc = {};
if (descriptor->hasLabel()) {
dawn_desc.label = descriptor->label().Utf8().data();
label = descriptor->label().Utf8();
dawn_desc.label = label.c_str();
}
return MakeGarbageCollected<GPUCommandBuffer>(
......
......@@ -54,8 +54,8 @@ void GPUComputePassEncoder::setBindGroup(
}
void GPUComputePassEncoder::pushDebugGroup(String groupLabel) {
GetProcs().computePassEncoderPushDebugGroup(GetHandle(),
groupLabel.Utf8().data());
std::string label = groupLabel.Utf8();
GetProcs().computePassEncoderPushDebugGroup(GetHandle(), label.c_str());
}
void GPUComputePassEncoder::popDebugGroup() {
......@@ -63,8 +63,8 @@ void GPUComputePassEncoder::popDebugGroup() {
}
void GPUComputePassEncoder::insertDebugMarker(String markerLabel) {
GetProcs().computePassEncoderInsertDebugMarker(GetHandle(),
markerLabel.Utf8().data());
std::string label = markerLabel.Utf8();
GetProcs().computePassEncoderInsertDebugMarker(GetHandle(), label.c_str());
}
void GPUComputePassEncoder::setPipeline(GPUComputePipeline* pipeline) {
......
......@@ -21,13 +21,15 @@ GPUComputePipeline* GPUComputePipeline::Create(
DCHECK(device);
DCHECK(webgpu_desc);
std::string label;
WGPUComputePipelineDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
if (webgpu_desc->hasLayout()) {
dawn_desc.layout = AsDawnType(webgpu_desc->layout());
}
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str();
}
auto compute_stage = AsDawnType(webgpu_desc->computeStage());
......
......@@ -25,12 +25,14 @@ GPUPipelineLayout* GPUPipelineLayout::Create(
bind_group_layout_count != 0 ? AsDawnType(webgpu_desc->bindGroupLayouts())
: nullptr;
std::string label;
WGPUPipelineLayoutDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
dawn_desc.bindGroupLayoutCount = bind_group_layout_count;
dawn_desc.bindGroupLayouts = bind_group_layouts.get();
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str();
}
return MakeGarbageCollected<GPUPipelineLayout>(
......
......@@ -161,11 +161,13 @@ void GPUQueue::signal(GPUFence* fence, uint64_t signal_value) {
GPUFence* GPUQueue::createFence(const GPUFenceDescriptor* descriptor) {
DCHECK(descriptor);
std::string label;
WGPUFenceDescriptor desc = {};
desc.nextInChain = nullptr;
desc.initialValue = descriptor->initialValue();
if (descriptor->hasLabel()) {
desc.label = descriptor->label().Utf8().data();
label = descriptor->label().Utf8();
desc.label = label.c_str();
}
return MakeGarbageCollected<GPUFence>(
......
......@@ -32,6 +32,7 @@ GPURenderBundleEncoder* GPURenderBundleEncoder::Create(
AsDawnEnum<WGPUTextureFormat>(webgpu_desc->depthStencilFormat());
}
std::string label;
WGPURenderBundleEncoderDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
dawn_desc.colorFormatsCount = color_formats_count;
......@@ -39,7 +40,8 @@ GPURenderBundleEncoder* GPURenderBundleEncoder::Create(
dawn_desc.depthStencilFormat = depth_stencil_format;
dawn_desc.sampleCount = webgpu_desc->sampleCount();
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str();
}
return MakeGarbageCollected<GPURenderBundleEncoder>(
......@@ -90,8 +92,8 @@ void GPURenderBundleEncoder::setBindGroup(
}
void GPURenderBundleEncoder::pushDebugGroup(String groupLabel) {
GetProcs().renderBundleEncoderPushDebugGroup(GetHandle(),
groupLabel.Utf8().data());
std::string label = groupLabel.Utf8();
GetProcs().renderBundleEncoderPushDebugGroup(GetHandle(), label.c_str());
}
void GPURenderBundleEncoder::popDebugGroup() {
......@@ -99,8 +101,8 @@ void GPURenderBundleEncoder::popDebugGroup() {
}
void GPURenderBundleEncoder::insertDebugMarker(String markerLabel) {
GetProcs().renderBundleEncoderInsertDebugMarker(GetHandle(),
markerLabel.Utf8().data());
std::string label = markerLabel.Utf8();
GetProcs().renderBundleEncoderInsertDebugMarker(GetHandle(), label.c_str());
}
void GPURenderBundleEncoder::setPipeline(GPURenderPipeline* pipeline) {
......@@ -154,10 +156,12 @@ void GPURenderBundleEncoder::drawIndexedIndirect(GPUBuffer* indirectBuffer,
GPURenderBundle* GPURenderBundleEncoder::finish(
const GPURenderBundleDescriptor* webgpu_desc) {
std::string label;
WGPURenderBundleDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str();
}
WGPURenderBundle render_bundle =
......
......@@ -58,8 +58,8 @@ void GPURenderPassEncoder::setBindGroup(
}
void GPURenderPassEncoder::pushDebugGroup(String groupLabel) {
GetProcs().renderPassEncoderPushDebugGroup(GetHandle(),
groupLabel.Utf8().data());
std::string label = groupLabel.Utf8();
GetProcs().renderPassEncoderPushDebugGroup(GetHandle(), label.c_str());
}
void GPURenderPassEncoder::popDebugGroup() {
......@@ -67,8 +67,8 @@ void GPURenderPassEncoder::popDebugGroup() {
}
void GPURenderPassEncoder::insertDebugMarker(String markerLabel) {
GetProcs().renderPassEncoderInsertDebugMarker(GetHandle(),
markerLabel.Utf8().data());
std::string label = markerLabel.Utf8();
GetProcs().renderPassEncoderInsertDebugMarker(GetHandle(), label.c_str());
}
void GPURenderPassEncoder::setPipeline(GPURenderPipeline* pipeline) {
......
......@@ -214,13 +214,15 @@ GPURenderPipeline* GPURenderPipeline::Create(
DCHECK(device);
DCHECK(webgpu_desc);
std::string label;
WGPURenderPipelineDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
if (webgpu_desc->hasLayout()) {
dawn_desc.layout = AsDawnType(webgpu_desc->layout());
}
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str();
}
OwnedProgrammableStageDescriptor vertex_stage_info =
......
......@@ -12,8 +12,10 @@ namespace blink {
namespace {
WGPUSamplerDescriptor AsDawnType(const GPUSamplerDescriptor* webgpu_desc) {
WGPUSamplerDescriptor AsDawnType(const GPUSamplerDescriptor* webgpu_desc,
std::string* label) {
DCHECK(webgpu_desc);
DCHECK(label);
WGPUSamplerDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
......@@ -33,7 +35,8 @@ WGPUSamplerDescriptor AsDawnType(const GPUSamplerDescriptor* webgpu_desc) {
dawn_desc.compare = AsDawnEnum<WGPUCompareFunction>(webgpu_desc->compare());
}
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
*label = webgpu_desc->label().Utf8();
dawn_desc.label = label->c_str();
}
return dawn_desc;
......@@ -46,7 +49,8 @@ GPUSampler* GPUSampler::Create(GPUDevice* device,
const GPUSamplerDescriptor* webgpu_desc) {
DCHECK(device);
DCHECK(webgpu_desc);
WGPUSamplerDescriptor dawn_desc = AsDawnType(webgpu_desc);
std::string label;
WGPUSamplerDescriptor dawn_desc = AsDawnType(webgpu_desc, &label);
return MakeGarbageCollected<GPUSampler>(
device,
device->GetProcs().deviceCreateSampler(device->GetHandle(), &dawn_desc));
......
......@@ -18,10 +18,11 @@ GPUShaderModule* GPUShaderModule::Create(
DCHECK(device);
DCHECK(webgpu_desc);
WGPUShaderModuleDescriptor dawn_desc = {};
std::string wgsl_code;
WGPUShaderModuleWGSLDescriptor wgsl_desc = {};
WGPUShaderModuleSPIRVDescriptor spirv_desc = {};
std::string wgsl_code;
std::string label;
WGPUShaderModuleDescriptor dawn_desc = {};
auto wgsl_or_spirv = webgpu_desc->code();
if (wgsl_or_spirv.IsUSVString()) {
......@@ -49,7 +50,6 @@ GPUShaderModule* GPUShaderModule::Create(
dawn_desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&spirv_desc);
}
std::string label;
if (webgpu_desc->hasLabel()) {
label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str();
......
......@@ -15,8 +15,11 @@ namespace blink {
namespace {
WGPUTextureDescriptor AsDawnType(const GPUTextureDescriptor* webgpu_desc,
std::string* label,
GPUDevice* device) {
DCHECK(webgpu_desc);
DCHECK(label);
DCHECK(device);
WGPUTextureDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
......@@ -29,15 +32,18 @@ WGPUTextureDescriptor AsDawnType(const GPUTextureDescriptor* webgpu_desc,
dawn_desc.sampleCount = webgpu_desc->sampleCount();
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
*label = webgpu_desc->label().Utf8();
dawn_desc.label = label->c_str();
}
return dawn_desc;
}
WGPUTextureViewDescriptor AsDawnType(
const GPUTextureViewDescriptor* webgpu_desc) {
const GPUTextureViewDescriptor* webgpu_desc,
std::string* label) {
DCHECK(webgpu_desc);
DCHECK(label);
WGPUTextureViewDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr;
......@@ -50,7 +56,8 @@ WGPUTextureViewDescriptor AsDawnType(
dawn_desc.arrayLayerCount = webgpu_desc->arrayLayerCount();
dawn_desc.aspect = AsDawnEnum<WGPUTextureAspect>(webgpu_desc->aspect());
if (webgpu_desc->hasLabel()) {
dawn_desc.label = webgpu_desc->label().Utf8().data();
*label = webgpu_desc->label().Utf8();
dawn_desc.label = label->c_str();
}
return dawn_desc;
......@@ -74,7 +81,8 @@ GPUTexture* GPUTexture::Create(GPUDevice* device,
return nullptr;
}
WGPUTextureDescriptor dawn_desc = AsDawnType(webgpu_desc, device);
std::string label;
WGPUTextureDescriptor dawn_desc = AsDawnType(webgpu_desc, &label, device);
return MakeGarbageCollected<GPUTexture>(
device,
......@@ -98,7 +106,8 @@ GPUTextureView* GPUTexture::createView(
const GPUTextureViewDescriptor* webgpu_desc) {
DCHECK(webgpu_desc);
WGPUTextureViewDescriptor dawn_desc = AsDawnType(webgpu_desc);
std::string label;
WGPUTextureViewDescriptor dawn_desc = AsDawnType(webgpu_desc, &label);
return MakeGarbageCollected<GPUTextureView>(
device_, GetProcs().textureCreateView(GetHandle(), &dawn_desc));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment