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, ...@@ -58,13 +58,15 @@ GPUBindGroup* GPUBindGroup::Create(GPUDevice* device,
entries = AsDawnType(webgpu_desc->entries()); entries = AsDawnType(webgpu_desc->entries());
} }
std::string label;
WGPUBindGroupDescriptor dawn_desc = {}; WGPUBindGroupDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
dawn_desc.layout = AsDawnType(webgpu_desc->layout()); dawn_desc.layout = AsDawnType(webgpu_desc->layout());
dawn_desc.entryCount = entry_count; dawn_desc.entryCount = entry_count;
dawn_desc.entries = entries.get(); dawn_desc.entries = entries.get();
if (webgpu_desc->hasLabel()) { 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>( return MakeGarbageCollected<GPUBindGroup>(
......
...@@ -70,12 +70,14 @@ GPUBindGroupLayout* GPUBindGroupLayout::Create( ...@@ -70,12 +70,14 @@ GPUBindGroupLayout* GPUBindGroupLayout::Create(
entries = AsDawnType(webgpu_desc->entries(), device); entries = AsDawnType(webgpu_desc->entries(), device);
} }
std::string label;
WGPUBindGroupLayoutDescriptor dawn_desc = {}; WGPUBindGroupLayoutDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
dawn_desc.entryCount = entry_count; dawn_desc.entryCount = entry_count;
dawn_desc.entries = entries.get(); dawn_desc.entries = entries.get();
if (webgpu_desc->hasLabel()) { 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>( return MakeGarbageCollected<GPUBindGroupLayout>(
......
...@@ -59,8 +59,10 @@ bool ValidateRangeCreation(ExceptionState& exception_state, ...@@ -59,8 +59,10 @@ bool ValidateRangeCreation(ExceptionState& exception_state,
return true; return true;
} }
WGPUBufferDescriptor AsDawnType(const GPUBufferDescriptor* webgpu_desc) { WGPUBufferDescriptor AsDawnType(const GPUBufferDescriptor* webgpu_desc,
std::string* label) {
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
DCHECK(label);
WGPUBufferDescriptor dawn_desc = {}; WGPUBufferDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
...@@ -68,7 +70,8 @@ WGPUBufferDescriptor AsDawnType(const GPUBufferDescriptor* webgpu_desc) { ...@@ -68,7 +70,8 @@ WGPUBufferDescriptor AsDawnType(const GPUBufferDescriptor* webgpu_desc) {
dawn_desc.size = webgpu_desc->size(); dawn_desc.size = webgpu_desc->size();
dawn_desc.mappedAtCreation = webgpu_desc->mappedAtCreation(); dawn_desc.mappedAtCreation = webgpu_desc->mappedAtCreation();
if (webgpu_desc->hasLabel()) { 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; return dawn_desc;
...@@ -81,7 +84,8 @@ GPUBuffer* GPUBuffer::Create(GPUDevice* device, ...@@ -81,7 +84,8 @@ GPUBuffer* GPUBuffer::Create(GPUDevice* device,
const GPUBufferDescriptor* webgpu_desc) { const GPUBufferDescriptor* webgpu_desc) {
DCHECK(device); DCHECK(device);
WGPUBufferDescriptor dawn_desc = AsDawnType(webgpu_desc); std::string label;
WGPUBufferDescriptor dawn_desc = AsDawnType(webgpu_desc, &label);
return MakeGarbageCollected<GPUBuffer>( return MakeGarbageCollected<GPUBuffer>(
device, dawn_desc.size, dawn_desc.mappedAtCreation, device, dawn_desc.size, dawn_desc.mappedAtCreation,
device->GetProcs().deviceCreateBuffer(device->GetHandle(), &dawn_desc)); device->GetProcs().deviceCreateBuffer(device->GetHandle(), &dawn_desc));
...@@ -94,7 +98,8 @@ std::pair<GPUBuffer*, DOMArrayBuffer*> GPUBuffer::CreateMapped( ...@@ -94,7 +98,8 @@ std::pair<GPUBuffer*, DOMArrayBuffer*> GPUBuffer::CreateMapped(
ExceptionState& exception_state) { ExceptionState& exception_state) {
DCHECK(device); DCHECK(device);
WGPUBufferDescriptor dawn_desc = AsDawnType(webgpu_desc); std::string label;
WGPUBufferDescriptor dawn_desc = AsDawnType(webgpu_desc, &label);
if (!ValidateRangeCreation(exception_state, "createBufferMapped", 0, if (!ValidateRangeCreation(exception_state, "createBufferMapped", 0,
dawn_desc.size, kLargestMappableSize)) { dawn_desc.size, kLargestMappableSize)) {
......
...@@ -122,13 +122,16 @@ WGPUBufferCopyView AsDawnType(const GPUBufferCopyView* webgpu_view) { ...@@ -122,13 +122,16 @@ WGPUBufferCopyView AsDawnType(const GPUBufferCopyView* webgpu_view) {
} }
WGPUCommandEncoderDescriptor AsDawnType( WGPUCommandEncoderDescriptor AsDawnType(
const GPUCommandEncoderDescriptor* webgpu_desc) { const GPUCommandEncoderDescriptor* webgpu_desc,
std::string* label) {
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
DCHECK(label);
WGPUCommandEncoderDescriptor dawn_desc = {}; WGPUCommandEncoderDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
if (webgpu_desc->hasLabel()) { 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; return dawn_desc;
...@@ -144,10 +147,11 @@ GPUCommandEncoder* GPUCommandEncoder::Create( ...@@ -144,10 +147,11 @@ GPUCommandEncoder* GPUCommandEncoder::Create(
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
ALLOW_UNUSED_LOCAL(webgpu_desc); ALLOW_UNUSED_LOCAL(webgpu_desc);
std::string label;
WGPUCommandEncoderDescriptor dawn_desc = {}; WGPUCommandEncoderDescriptor dawn_desc = {};
const WGPUCommandEncoderDescriptor* dawn_desc_ptr = nullptr; const WGPUCommandEncoderDescriptor* dawn_desc_ptr = nullptr;
if (webgpu_desc) { if (webgpu_desc) {
dawn_desc = AsDawnType(webgpu_desc); dawn_desc = AsDawnType(webgpu_desc, &label);
dawn_desc_ptr = &dawn_desc; dawn_desc_ptr = &dawn_desc;
} }
...@@ -189,11 +193,13 @@ GPURenderPassEncoder* GPUCommandEncoder::beginRenderPass( ...@@ -189,11 +193,13 @@ GPURenderPassEncoder* GPUCommandEncoder::beginRenderPass(
} }
} }
std::string label;
WGPURenderPassDescriptor dawn_desc = {}; WGPURenderPassDescriptor dawn_desc = {};
dawn_desc.colorAttachmentCount = color_attachment_count; dawn_desc.colorAttachmentCount = color_attachment_count;
dawn_desc.colorAttachments = nullptr; dawn_desc.colorAttachments = nullptr;
if (descriptor->hasLabel()) { 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; std::unique_ptr<WGPURenderPassColorAttachmentDescriptor[]> color_attachments;
...@@ -218,9 +224,11 @@ GPURenderPassEncoder* GPUCommandEncoder::beginRenderPass( ...@@ -218,9 +224,11 @@ GPURenderPassEncoder* GPUCommandEncoder::beginRenderPass(
GPUComputePassEncoder* GPUCommandEncoder::beginComputePass( GPUComputePassEncoder* GPUCommandEncoder::beginComputePass(
const GPUComputePassDescriptor* descriptor) { const GPUComputePassDescriptor* descriptor) {
std::string label;
WGPUComputePassDescriptor dawn_desc = {}; WGPUComputePassDescriptor dawn_desc = {};
if (descriptor->hasLabel()) { if (descriptor->hasLabel()) {
dawn_desc.label = descriptor->label().Utf8().data(); label = descriptor->label().Utf8();
dawn_desc.label = label.c_str();
} }
return MakeGarbageCollected<GPUComputePassEncoder>( return MakeGarbageCollected<GPUComputePassEncoder>(
...@@ -302,8 +310,8 @@ void GPUCommandEncoder::copyTextureToTexture( ...@@ -302,8 +310,8 @@ void GPUCommandEncoder::copyTextureToTexture(
} }
void GPUCommandEncoder::pushDebugGroup(String groupLabel) { void GPUCommandEncoder::pushDebugGroup(String groupLabel) {
GetProcs().commandEncoderPushDebugGroup(GetHandle(), std::string label = groupLabel.Utf8();
groupLabel.Utf8().data()); GetProcs().commandEncoderPushDebugGroup(GetHandle(), label.c_str());
} }
void GPUCommandEncoder::popDebugGroup() { void GPUCommandEncoder::popDebugGroup() {
...@@ -311,15 +319,17 @@ void GPUCommandEncoder::popDebugGroup() { ...@@ -311,15 +319,17 @@ void GPUCommandEncoder::popDebugGroup() {
} }
void GPUCommandEncoder::insertDebugMarker(String markerLabel) { void GPUCommandEncoder::insertDebugMarker(String markerLabel) {
GetProcs().commandEncoderInsertDebugMarker(GetHandle(), std::string label = markerLabel.Utf8();
markerLabel.Utf8().data()); GetProcs().commandEncoderInsertDebugMarker(GetHandle(), label.c_str());
} }
GPUCommandBuffer* GPUCommandEncoder::finish( GPUCommandBuffer* GPUCommandEncoder::finish(
const GPUCommandBufferDescriptor* descriptor) { const GPUCommandBufferDescriptor* descriptor) {
std::string label;
WGPUCommandBufferDescriptor dawn_desc = {}; WGPUCommandBufferDescriptor dawn_desc = {};
if (descriptor->hasLabel()) { if (descriptor->hasLabel()) {
dawn_desc.label = descriptor->label().Utf8().data(); label = descriptor->label().Utf8();
dawn_desc.label = label.c_str();
} }
return MakeGarbageCollected<GPUCommandBuffer>( return MakeGarbageCollected<GPUCommandBuffer>(
......
...@@ -54,8 +54,8 @@ void GPUComputePassEncoder::setBindGroup( ...@@ -54,8 +54,8 @@ void GPUComputePassEncoder::setBindGroup(
} }
void GPUComputePassEncoder::pushDebugGroup(String groupLabel) { void GPUComputePassEncoder::pushDebugGroup(String groupLabel) {
GetProcs().computePassEncoderPushDebugGroup(GetHandle(), std::string label = groupLabel.Utf8();
groupLabel.Utf8().data()); GetProcs().computePassEncoderPushDebugGroup(GetHandle(), label.c_str());
} }
void GPUComputePassEncoder::popDebugGroup() { void GPUComputePassEncoder::popDebugGroup() {
...@@ -63,8 +63,8 @@ void GPUComputePassEncoder::popDebugGroup() { ...@@ -63,8 +63,8 @@ void GPUComputePassEncoder::popDebugGroup() {
} }
void GPUComputePassEncoder::insertDebugMarker(String markerLabel) { void GPUComputePassEncoder::insertDebugMarker(String markerLabel) {
GetProcs().computePassEncoderInsertDebugMarker(GetHandle(), std::string label = markerLabel.Utf8();
markerLabel.Utf8().data()); GetProcs().computePassEncoderInsertDebugMarker(GetHandle(), label.c_str());
} }
void GPUComputePassEncoder::setPipeline(GPUComputePipeline* pipeline) { void GPUComputePassEncoder::setPipeline(GPUComputePipeline* pipeline) {
......
...@@ -21,13 +21,15 @@ GPUComputePipeline* GPUComputePipeline::Create( ...@@ -21,13 +21,15 @@ GPUComputePipeline* GPUComputePipeline::Create(
DCHECK(device); DCHECK(device);
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
std::string label;
WGPUComputePipelineDescriptor dawn_desc = {}; WGPUComputePipelineDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
if (webgpu_desc->hasLayout()) { if (webgpu_desc->hasLayout()) {
dawn_desc.layout = AsDawnType(webgpu_desc->layout()); dawn_desc.layout = AsDawnType(webgpu_desc->layout());
} }
if (webgpu_desc->hasLabel()) { 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()); auto compute_stage = AsDawnType(webgpu_desc->computeStage());
......
...@@ -25,12 +25,14 @@ GPUPipelineLayout* GPUPipelineLayout::Create( ...@@ -25,12 +25,14 @@ GPUPipelineLayout* GPUPipelineLayout::Create(
bind_group_layout_count != 0 ? AsDawnType(webgpu_desc->bindGroupLayouts()) bind_group_layout_count != 0 ? AsDawnType(webgpu_desc->bindGroupLayouts())
: nullptr; : nullptr;
std::string label;
WGPUPipelineLayoutDescriptor dawn_desc = {}; WGPUPipelineLayoutDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
dawn_desc.bindGroupLayoutCount = bind_group_layout_count; dawn_desc.bindGroupLayoutCount = bind_group_layout_count;
dawn_desc.bindGroupLayouts = bind_group_layouts.get(); dawn_desc.bindGroupLayouts = bind_group_layouts.get();
if (webgpu_desc->hasLabel()) { 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>( return MakeGarbageCollected<GPUPipelineLayout>(
......
...@@ -161,11 +161,13 @@ void GPUQueue::signal(GPUFence* fence, uint64_t signal_value) { ...@@ -161,11 +161,13 @@ void GPUQueue::signal(GPUFence* fence, uint64_t signal_value) {
GPUFence* GPUQueue::createFence(const GPUFenceDescriptor* descriptor) { GPUFence* GPUQueue::createFence(const GPUFenceDescriptor* descriptor) {
DCHECK(descriptor); DCHECK(descriptor);
std::string label;
WGPUFenceDescriptor desc = {}; WGPUFenceDescriptor desc = {};
desc.nextInChain = nullptr; desc.nextInChain = nullptr;
desc.initialValue = descriptor->initialValue(); desc.initialValue = descriptor->initialValue();
if (descriptor->hasLabel()) { if (descriptor->hasLabel()) {
desc.label = descriptor->label().Utf8().data(); label = descriptor->label().Utf8();
desc.label = label.c_str();
} }
return MakeGarbageCollected<GPUFence>( return MakeGarbageCollected<GPUFence>(
......
...@@ -32,6 +32,7 @@ GPURenderBundleEncoder* GPURenderBundleEncoder::Create( ...@@ -32,6 +32,7 @@ GPURenderBundleEncoder* GPURenderBundleEncoder::Create(
AsDawnEnum<WGPUTextureFormat>(webgpu_desc->depthStencilFormat()); AsDawnEnum<WGPUTextureFormat>(webgpu_desc->depthStencilFormat());
} }
std::string label;
WGPURenderBundleEncoderDescriptor dawn_desc = {}; WGPURenderBundleEncoderDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
dawn_desc.colorFormatsCount = color_formats_count; dawn_desc.colorFormatsCount = color_formats_count;
...@@ -39,7 +40,8 @@ GPURenderBundleEncoder* GPURenderBundleEncoder::Create( ...@@ -39,7 +40,8 @@ GPURenderBundleEncoder* GPURenderBundleEncoder::Create(
dawn_desc.depthStencilFormat = depth_stencil_format; dawn_desc.depthStencilFormat = depth_stencil_format;
dawn_desc.sampleCount = webgpu_desc->sampleCount(); dawn_desc.sampleCount = webgpu_desc->sampleCount();
if (webgpu_desc->hasLabel()) { 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>( return MakeGarbageCollected<GPURenderBundleEncoder>(
...@@ -90,8 +92,8 @@ void GPURenderBundleEncoder::setBindGroup( ...@@ -90,8 +92,8 @@ void GPURenderBundleEncoder::setBindGroup(
} }
void GPURenderBundleEncoder::pushDebugGroup(String groupLabel) { void GPURenderBundleEncoder::pushDebugGroup(String groupLabel) {
GetProcs().renderBundleEncoderPushDebugGroup(GetHandle(), std::string label = groupLabel.Utf8();
groupLabel.Utf8().data()); GetProcs().renderBundleEncoderPushDebugGroup(GetHandle(), label.c_str());
} }
void GPURenderBundleEncoder::popDebugGroup() { void GPURenderBundleEncoder::popDebugGroup() {
...@@ -99,8 +101,8 @@ void GPURenderBundleEncoder::popDebugGroup() { ...@@ -99,8 +101,8 @@ void GPURenderBundleEncoder::popDebugGroup() {
} }
void GPURenderBundleEncoder::insertDebugMarker(String markerLabel) { void GPURenderBundleEncoder::insertDebugMarker(String markerLabel) {
GetProcs().renderBundleEncoderInsertDebugMarker(GetHandle(), std::string label = markerLabel.Utf8();
markerLabel.Utf8().data()); GetProcs().renderBundleEncoderInsertDebugMarker(GetHandle(), label.c_str());
} }
void GPURenderBundleEncoder::setPipeline(GPURenderPipeline* pipeline) { void GPURenderBundleEncoder::setPipeline(GPURenderPipeline* pipeline) {
...@@ -154,10 +156,12 @@ void GPURenderBundleEncoder::drawIndexedIndirect(GPUBuffer* indirectBuffer, ...@@ -154,10 +156,12 @@ void GPURenderBundleEncoder::drawIndexedIndirect(GPUBuffer* indirectBuffer,
GPURenderBundle* GPURenderBundleEncoder::finish( GPURenderBundle* GPURenderBundleEncoder::finish(
const GPURenderBundleDescriptor* webgpu_desc) { const GPURenderBundleDescriptor* webgpu_desc) {
std::string label;
WGPURenderBundleDescriptor dawn_desc = {}; WGPURenderBundleDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
if (webgpu_desc->hasLabel()) { 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 = WGPURenderBundle render_bundle =
......
...@@ -58,8 +58,8 @@ void GPURenderPassEncoder::setBindGroup( ...@@ -58,8 +58,8 @@ void GPURenderPassEncoder::setBindGroup(
} }
void GPURenderPassEncoder::pushDebugGroup(String groupLabel) { void GPURenderPassEncoder::pushDebugGroup(String groupLabel) {
GetProcs().renderPassEncoderPushDebugGroup(GetHandle(), std::string label = groupLabel.Utf8();
groupLabel.Utf8().data()); GetProcs().renderPassEncoderPushDebugGroup(GetHandle(), label.c_str());
} }
void GPURenderPassEncoder::popDebugGroup() { void GPURenderPassEncoder::popDebugGroup() {
...@@ -67,8 +67,8 @@ void GPURenderPassEncoder::popDebugGroup() { ...@@ -67,8 +67,8 @@ void GPURenderPassEncoder::popDebugGroup() {
} }
void GPURenderPassEncoder::insertDebugMarker(String markerLabel) { void GPURenderPassEncoder::insertDebugMarker(String markerLabel) {
GetProcs().renderPassEncoderInsertDebugMarker(GetHandle(), std::string label = markerLabel.Utf8();
markerLabel.Utf8().data()); GetProcs().renderPassEncoderInsertDebugMarker(GetHandle(), label.c_str());
} }
void GPURenderPassEncoder::setPipeline(GPURenderPipeline* pipeline) { void GPURenderPassEncoder::setPipeline(GPURenderPipeline* pipeline) {
......
...@@ -214,13 +214,15 @@ GPURenderPipeline* GPURenderPipeline::Create( ...@@ -214,13 +214,15 @@ GPURenderPipeline* GPURenderPipeline::Create(
DCHECK(device); DCHECK(device);
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
std::string label;
WGPURenderPipelineDescriptor dawn_desc = {}; WGPURenderPipelineDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
if (webgpu_desc->hasLayout()) { if (webgpu_desc->hasLayout()) {
dawn_desc.layout = AsDawnType(webgpu_desc->layout()); dawn_desc.layout = AsDawnType(webgpu_desc->layout());
} }
if (webgpu_desc->hasLabel()) { 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 = OwnedProgrammableStageDescriptor vertex_stage_info =
......
...@@ -12,8 +12,10 @@ namespace blink { ...@@ -12,8 +12,10 @@ namespace blink {
namespace { namespace {
WGPUSamplerDescriptor AsDawnType(const GPUSamplerDescriptor* webgpu_desc) { WGPUSamplerDescriptor AsDawnType(const GPUSamplerDescriptor* webgpu_desc,
std::string* label) {
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
DCHECK(label);
WGPUSamplerDescriptor dawn_desc = {}; WGPUSamplerDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
...@@ -33,7 +35,8 @@ WGPUSamplerDescriptor AsDawnType(const GPUSamplerDescriptor* webgpu_desc) { ...@@ -33,7 +35,8 @@ WGPUSamplerDescriptor AsDawnType(const GPUSamplerDescriptor* webgpu_desc) {
dawn_desc.compare = AsDawnEnum<WGPUCompareFunction>(webgpu_desc->compare()); dawn_desc.compare = AsDawnEnum<WGPUCompareFunction>(webgpu_desc->compare());
} }
if (webgpu_desc->hasLabel()) { 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; return dawn_desc;
...@@ -46,7 +49,8 @@ GPUSampler* GPUSampler::Create(GPUDevice* device, ...@@ -46,7 +49,8 @@ GPUSampler* GPUSampler::Create(GPUDevice* device,
const GPUSamplerDescriptor* webgpu_desc) { const GPUSamplerDescriptor* webgpu_desc) {
DCHECK(device); DCHECK(device);
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
WGPUSamplerDescriptor dawn_desc = AsDawnType(webgpu_desc); std::string label;
WGPUSamplerDescriptor dawn_desc = AsDawnType(webgpu_desc, &label);
return MakeGarbageCollected<GPUSampler>( return MakeGarbageCollected<GPUSampler>(
device, device,
device->GetProcs().deviceCreateSampler(device->GetHandle(), &dawn_desc)); device->GetProcs().deviceCreateSampler(device->GetHandle(), &dawn_desc));
......
...@@ -18,10 +18,11 @@ GPUShaderModule* GPUShaderModule::Create( ...@@ -18,10 +18,11 @@ GPUShaderModule* GPUShaderModule::Create(
DCHECK(device); DCHECK(device);
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
WGPUShaderModuleDescriptor dawn_desc = {}; std::string wgsl_code;
WGPUShaderModuleWGSLDescriptor wgsl_desc = {}; WGPUShaderModuleWGSLDescriptor wgsl_desc = {};
WGPUShaderModuleSPIRVDescriptor spirv_desc = {}; WGPUShaderModuleSPIRVDescriptor spirv_desc = {};
std::string wgsl_code; std::string label;
WGPUShaderModuleDescriptor dawn_desc = {};
auto wgsl_or_spirv = webgpu_desc->code(); auto wgsl_or_spirv = webgpu_desc->code();
if (wgsl_or_spirv.IsUSVString()) { if (wgsl_or_spirv.IsUSVString()) {
...@@ -49,7 +50,6 @@ GPUShaderModule* GPUShaderModule::Create( ...@@ -49,7 +50,6 @@ GPUShaderModule* GPUShaderModule::Create(
dawn_desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&spirv_desc); dawn_desc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&spirv_desc);
} }
std::string label;
if (webgpu_desc->hasLabel()) { if (webgpu_desc->hasLabel()) {
label = webgpu_desc->label().Utf8(); label = webgpu_desc->label().Utf8();
dawn_desc.label = label.c_str(); dawn_desc.label = label.c_str();
......
...@@ -15,8 +15,11 @@ namespace blink { ...@@ -15,8 +15,11 @@ namespace blink {
namespace { namespace {
WGPUTextureDescriptor AsDawnType(const GPUTextureDescriptor* webgpu_desc, WGPUTextureDescriptor AsDawnType(const GPUTextureDescriptor* webgpu_desc,
std::string* label,
GPUDevice* device) { GPUDevice* device) {
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
DCHECK(label);
DCHECK(device);
WGPUTextureDescriptor dawn_desc = {}; WGPUTextureDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
...@@ -29,15 +32,18 @@ WGPUTextureDescriptor AsDawnType(const GPUTextureDescriptor* webgpu_desc, ...@@ -29,15 +32,18 @@ WGPUTextureDescriptor AsDawnType(const GPUTextureDescriptor* webgpu_desc,
dawn_desc.sampleCount = webgpu_desc->sampleCount(); dawn_desc.sampleCount = webgpu_desc->sampleCount();
if (webgpu_desc->hasLabel()) { 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; return dawn_desc;
} }
WGPUTextureViewDescriptor AsDawnType( WGPUTextureViewDescriptor AsDawnType(
const GPUTextureViewDescriptor* webgpu_desc) { const GPUTextureViewDescriptor* webgpu_desc,
std::string* label) {
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
DCHECK(label);
WGPUTextureViewDescriptor dawn_desc = {}; WGPUTextureViewDescriptor dawn_desc = {};
dawn_desc.nextInChain = nullptr; dawn_desc.nextInChain = nullptr;
...@@ -50,7 +56,8 @@ WGPUTextureViewDescriptor AsDawnType( ...@@ -50,7 +56,8 @@ WGPUTextureViewDescriptor AsDawnType(
dawn_desc.arrayLayerCount = webgpu_desc->arrayLayerCount(); dawn_desc.arrayLayerCount = webgpu_desc->arrayLayerCount();
dawn_desc.aspect = AsDawnEnum<WGPUTextureAspect>(webgpu_desc->aspect()); dawn_desc.aspect = AsDawnEnum<WGPUTextureAspect>(webgpu_desc->aspect());
if (webgpu_desc->hasLabel()) { 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; return dawn_desc;
...@@ -74,7 +81,8 @@ GPUTexture* GPUTexture::Create(GPUDevice* device, ...@@ -74,7 +81,8 @@ GPUTexture* GPUTexture::Create(GPUDevice* device,
return nullptr; return nullptr;
} }
WGPUTextureDescriptor dawn_desc = AsDawnType(webgpu_desc, device); std::string label;
WGPUTextureDescriptor dawn_desc = AsDawnType(webgpu_desc, &label, device);
return MakeGarbageCollected<GPUTexture>( return MakeGarbageCollected<GPUTexture>(
device, device,
...@@ -98,7 +106,8 @@ GPUTextureView* GPUTexture::createView( ...@@ -98,7 +106,8 @@ GPUTextureView* GPUTexture::createView(
const GPUTextureViewDescriptor* webgpu_desc) { const GPUTextureViewDescriptor* webgpu_desc) {
DCHECK(webgpu_desc); DCHECK(webgpu_desc);
WGPUTextureViewDescriptor dawn_desc = AsDawnType(webgpu_desc); std::string label;
WGPUTextureViewDescriptor dawn_desc = AsDawnType(webgpu_desc, &label);
return MakeGarbageCollected<GPUTextureView>( return MakeGarbageCollected<GPUTextureView>(
device_, GetProcs().textureCreateView(GetHandle(), &dawn_desc)); 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