Commit 171850d2 authored by Kai Ninomiya's avatar Kai Ninomiya Committed by Commit Bot

dawn_conversions: replace CString with std::unique_ptr<char[]>

CString is being removed. Also, this was sort of relying on
an implementation detail of CString, and this fixes that.

Bug: 950077
Change-Id: I4fab8de0ef8f3202c0144dcea8eeedf89e90ce77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1648712Reviewed-by: default avatarAustin Eng <enga@chromium.org>
Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Reviewed-by: default avatarGyuyoung Kim <gyuyoung@igalia.com>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667238}
parent fcb965b0
......@@ -577,18 +577,24 @@ DawnOrigin3D AsDawnType(const GPUOrigin3D* webgpu_origin) {
return dawn_origin;
}
std::tuple<DawnPipelineStageDescriptor, CString> AsDawnType(
OwnedPipelineStageDescriptor AsDawnType(
const GPUPipelineStageDescriptor* webgpu_stage) {
DCHECK(webgpu_stage);
CString entry_point_string(webgpu_stage->entryPoint().Ascii().c_str());
std::string entry_point = webgpu_stage->entryPoint().Ascii();
// length() is in bytes (not utf-8 characters or something), so this is ok.
size_t byte_size = entry_point.length() + 1;
std::unique_ptr<char[]> entry_point_keepalive =
std::make_unique<char[]>(byte_size);
char* entry_point_ptr = entry_point_keepalive.get();
memcpy(entry_point_ptr, entry_point.c_str(), byte_size);
DawnPipelineStageDescriptor dawn_stage;
dawn_stage.module = webgpu_stage->module()->GetHandle();
dawn_stage.entryPoint = entry_point_string.data();
dawn_stage.entryPoint = entry_point_ptr;
// CString holds a scoped_refptr to the string data so it is valid to move
// it into the return value without invalidating the entryPoint.
return std::make_tuple(dawn_stage, std::move(entry_point_string));
return std::make_tuple(dawn_stage, std::move(entry_point_keepalive));
}
} // namespace blink
......@@ -40,8 +40,10 @@ DawnEnum AsDawnEnum(const WTF::String& webgpu_enum);
DawnColor AsDawnType(const GPUColor*);
DawnExtent3D AsDawnType(const GPUExtent3D*);
DawnOrigin3D AsDawnType(const GPUOrigin3D*);
std::tuple<DawnPipelineStageDescriptor, CString> AsDawnType(
const GPUPipelineStageDescriptor*);
using OwnedPipelineStageDescriptor =
std::tuple<DawnPipelineStageDescriptor, std::unique_ptr<char[]>>;
OwnedPipelineStageDescriptor AsDawnType(const GPUPipelineStageDescriptor*);
// WebGPU objects are converted to Dawn objects by getting the opaque handle
// which can be passed to Dawn.
......
......@@ -209,13 +209,12 @@ GPURenderPipeline* GPURenderPipeline::Create(
dawn_desc.nextInChain = nullptr;
dawn_desc.layout = AsDawnType(webgpu_desc->layout());
using PipelineStageInfo = std::tuple<DawnPipelineStageDescriptor, CString>;
PipelineStageInfo vertex_stage_info = AsDawnType(webgpu_desc->vertexStage());
OwnedPipelineStageDescriptor vertex_stage_info =
AsDawnType(webgpu_desc->vertexStage());
dawn_desc.vertexStage = &std::get<0>(vertex_stage_info);
// TODO(crbug.com/dawn/136): Support vertex-only pipelines.
PipelineStageInfo fragment_stage_info =
OwnedPipelineStageDescriptor fragment_stage_info =
AsDawnType(webgpu_desc->fragmentStage());
dawn_desc.fragmentStage = &std::get<0>(fragment_stage_info);
......
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