1 // Copyright 2021 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <string>
16 #include "tests/unittests/validation/ValidationTest.h"
17 #include "utils/ComboRenderBundleEncoderDescriptor.h"
18 #include "utils/ComboRenderPipelineDescriptor.h"
19 #include "utils/WGPUHelpers.h"
20
21 class LabelTest : public ValidationTest {};
22
TEST_F(LabelTest,BindGroup)23 TEST_F(LabelTest, BindGroup) {
24 DAWN_SKIP_TEST_IF(UsesWire());
25 std::string label = "test";
26 wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {});
27
28 wgpu::BindGroupDescriptor descriptor;
29 descriptor.layout = layout;
30 descriptor.entryCount = 0;
31 descriptor.entries = nullptr;
32
33 // The label should be empty if one was not set.
34 {
35 wgpu::BindGroup bindGroup = device.CreateBindGroup(&descriptor);
36 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(bindGroup.Get());
37 ASSERT_TRUE(readbackLabel.empty());
38 }
39
40 // Test setting a label through API
41 {
42 wgpu::BindGroup bindGroup = device.CreateBindGroup(&descriptor);
43 bindGroup.SetLabel(label.c_str());
44 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(bindGroup.Get());
45 ASSERT_EQ(label, readbackLabel);
46 }
47
48 // Test setting a label through the descriptor.
49 {
50 descriptor.label = label.c_str();
51 wgpu::BindGroup bindGroup = device.CreateBindGroup(&descriptor);
52 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(bindGroup.Get());
53 ASSERT_EQ(label, readbackLabel);
54 }
55 }
56
TEST_F(LabelTest,BindGroupLayout)57 TEST_F(LabelTest, BindGroupLayout) {
58 DAWN_SKIP_TEST_IF(UsesWire());
59 std::string label = "test";
60
61 wgpu::BindGroupLayoutDescriptor descriptor = {};
62 descriptor.entryCount = 0;
63 descriptor.entries = nullptr;
64
65 // The label should be empty if one was not set.
66 {
67 wgpu::BindGroupLayout bindGroupLayout = device.CreateBindGroupLayout(&descriptor);
68 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(bindGroupLayout.Get());
69 ASSERT_TRUE(readbackLabel.empty());
70 }
71
72 // Test setting a label through API
73 {
74 wgpu::BindGroupLayout bindGroupLayout = device.CreateBindGroupLayout(&descriptor);
75 bindGroupLayout.SetLabel(label.c_str());
76 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(bindGroupLayout.Get());
77 ASSERT_EQ(label, readbackLabel);
78 }
79
80 // Test setting a label through the descriptor.
81 {
82 descriptor.label = label.c_str();
83 wgpu::BindGroupLayout bindGroupLayout = device.CreateBindGroupLayout(&descriptor);
84 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(bindGroupLayout.Get());
85 ASSERT_EQ(label, readbackLabel);
86 }
87 }
88
TEST_F(LabelTest,Buffer)89 TEST_F(LabelTest, Buffer) {
90 DAWN_SKIP_TEST_IF(UsesWire());
91 std::string label = "test";
92 wgpu::BufferDescriptor descriptor;
93 descriptor.size = 4;
94 descriptor.usage = wgpu::BufferUsage::Uniform;
95
96 // The label should be empty if one was not set.
97 {
98 wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
99 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(buffer.Get());
100 ASSERT_TRUE(readbackLabel.empty());
101 }
102
103 // Test setting a label through API
104 {
105 wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
106 buffer.SetLabel(label.c_str());
107 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(buffer.Get());
108 ASSERT_EQ(label, readbackLabel);
109 }
110
111 // Test setting a label through the descriptor.
112 {
113 descriptor.label = label.c_str();
114 wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
115 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(buffer.Get());
116 ASSERT_EQ(label, readbackLabel);
117 }
118 }
119
TEST_F(LabelTest,CommandBuffer)120 TEST_F(LabelTest, CommandBuffer) {
121 DAWN_SKIP_TEST_IF(UsesWire());
122 std::string label = "test";
123 wgpu::CommandBufferDescriptor descriptor;
124
125 // The label should be empty if one was not set.
126 {
127 wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
128 wgpu::CommandBuffer commandBuffer = encoder.Finish(&descriptor);
129 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(commandBuffer.Get());
130 ASSERT_TRUE(readbackLabel.empty());
131 }
132
133 // Test setting a label through API
134 {
135 wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
136 wgpu::CommandBuffer commandBuffer = encoder.Finish(&descriptor);
137 commandBuffer.SetLabel(label.c_str());
138 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(commandBuffer.Get());
139 ASSERT_EQ(label, readbackLabel);
140 }
141
142 // Test setting a label through the descriptor.
143 {
144 descriptor.label = label.c_str();
145 wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
146 wgpu::CommandBuffer commandBuffer = encoder.Finish(&descriptor);
147 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(commandBuffer.Get());
148 ASSERT_EQ(label, readbackLabel);
149 }
150 }
151
TEST_F(LabelTest,CommandEncoder)152 TEST_F(LabelTest, CommandEncoder) {
153 DAWN_SKIP_TEST_IF(UsesWire());
154 std::string label = "test";
155 wgpu::CommandEncoderDescriptor descriptor;
156
157 // The label should be empty if one was not set.
158 {
159 wgpu::CommandEncoder encoder = device.CreateCommandEncoder(&descriptor);
160 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
161 ASSERT_TRUE(readbackLabel.empty());
162 }
163
164 // Test setting a label through API
165 {
166 wgpu::CommandEncoder encoder = device.CreateCommandEncoder(&descriptor);
167 encoder.SetLabel(label.c_str());
168 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
169 ASSERT_EQ(label, readbackLabel);
170 }
171
172 // Test setting a label through the descriptor.
173 {
174 descriptor.label = label.c_str();
175 wgpu::CommandEncoder encoder = device.CreateCommandEncoder(&descriptor);
176 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
177 ASSERT_EQ(label, readbackLabel);
178 }
179 }
180
TEST_F(LabelTest,ComputePassEncoder)181 TEST_F(LabelTest, ComputePassEncoder) {
182 DAWN_SKIP_TEST_IF(UsesWire());
183 std::string label = "test";
184 wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
185
186 wgpu::ComputePassDescriptor descriptor;
187
188 // The label should be empty if one was not set.
189 {
190 wgpu::ComputePassEncoder encoder = commandEncoder.BeginComputePass(&descriptor);
191 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
192 ASSERT_TRUE(readbackLabel.empty());
193 encoder.EndPass();
194 }
195
196 // Test setting a label through API
197 {
198 wgpu::ComputePassEncoder encoder = commandEncoder.BeginComputePass(&descriptor);
199 encoder.SetLabel(label.c_str());
200 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
201 ASSERT_EQ(label, readbackLabel);
202 encoder.EndPass();
203 }
204
205 // Test setting a label through the descriptor.
206 {
207 descriptor.label = label.c_str();
208 wgpu::ComputePassEncoder encoder = commandEncoder.BeginComputePass(&descriptor);
209 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
210 ASSERT_EQ(label, readbackLabel);
211 encoder.EndPass();
212 }
213 }
214
TEST_F(LabelTest,ExternalTexture)215 TEST_F(LabelTest, ExternalTexture) {
216 DAWN_SKIP_TEST_IF(UsesWire());
217 std::string label = "test";
218 wgpu::TextureDescriptor textureDescriptor;
219 textureDescriptor.size.width = 1;
220 textureDescriptor.size.height = 1;
221 textureDescriptor.size.depthOrArrayLayers = 1;
222 textureDescriptor.mipLevelCount = 1;
223 textureDescriptor.sampleCount = 1;
224 textureDescriptor.dimension = wgpu::TextureDimension::e2D;
225 textureDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
226 textureDescriptor.usage =
227 wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::RenderAttachment;
228 wgpu::Texture texture = device.CreateTexture(&textureDescriptor);
229
230 wgpu::ExternalTextureDescriptor descriptor;
231 descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
232 descriptor.plane0 = texture.CreateView();
233
234 // The label should be empty if one was not set.
235 {
236 wgpu::ExternalTexture externalTexture = device.CreateExternalTexture(&descriptor);
237 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(externalTexture.Get());
238 ASSERT_TRUE(readbackLabel.empty());
239 }
240
241 // Test setting a label through API
242 {
243 wgpu::ExternalTexture externalTexture = device.CreateExternalTexture(&descriptor);
244 externalTexture.SetLabel(label.c_str());
245 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(externalTexture.Get());
246 ASSERT_EQ(label, readbackLabel);
247 }
248
249 // Test setting a label through the descriptor.
250 {
251 descriptor.label = label.c_str();
252 wgpu::ExternalTexture externalTexture = device.CreateExternalTexture(&descriptor);
253 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(externalTexture.Get());
254 ASSERT_EQ(label, readbackLabel);
255 }
256 }
257
TEST_F(LabelTest,PipelineLayout)258 TEST_F(LabelTest, PipelineLayout) {
259 DAWN_SKIP_TEST_IF(UsesWire());
260 std::string label = "test";
261 wgpu::BindGroupLayout layout = utils::MakeBindGroupLayout(device, {});
262
263 wgpu::PipelineLayoutDescriptor descriptor;
264 descriptor.bindGroupLayoutCount = 1;
265 descriptor.bindGroupLayouts = &layout;
266
267 // The label should be empty if one was not set.
268 {
269 wgpu::PipelineLayout pipelineLayout = device.CreatePipelineLayout(&descriptor);
270 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(pipelineLayout.Get());
271 ASSERT_TRUE(readbackLabel.empty());
272 }
273
274 // Test setting a label through API
275 {
276 wgpu::PipelineLayout pipelineLayout = device.CreatePipelineLayout(&descriptor);
277 pipelineLayout.SetLabel(label.c_str());
278 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(pipelineLayout.Get());
279 ASSERT_EQ(label, readbackLabel);
280 }
281
282 // Test setting a label through the descriptor.
283 {
284 descriptor.label = label.c_str();
285 wgpu::PipelineLayout pipelineLayout = device.CreatePipelineLayout(&descriptor);
286 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(pipelineLayout.Get());
287 ASSERT_EQ(label, readbackLabel);
288 }
289 }
290
TEST_F(LabelTest,QuerySet)291 TEST_F(LabelTest, QuerySet) {
292 DAWN_SKIP_TEST_IF(UsesWire());
293 std::string label = "test";
294 wgpu::QuerySetDescriptor descriptor;
295 descriptor.type = wgpu::QueryType::Occlusion;
296 descriptor.count = 1;
297
298 // The label should be empty if one was not set.
299 {
300 wgpu::QuerySet querySet = device.CreateQuerySet(&descriptor);
301 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(querySet.Get());
302 ASSERT_TRUE(readbackLabel.empty());
303 }
304
305 // Test setting a label through API
306 {
307 wgpu::QuerySet querySet = device.CreateQuerySet(&descriptor);
308 querySet.SetLabel(label.c_str());
309 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(querySet.Get());
310 ASSERT_EQ(label, readbackLabel);
311 }
312
313 // Test setting a label through the descriptor.
314 {
315 descriptor.label = label.c_str();
316 wgpu::QuerySet querySet = device.CreateQuerySet(&descriptor);
317 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(querySet.Get());
318 ASSERT_EQ(label, readbackLabel);
319 }
320 }
321
TEST_F(LabelTest,RenderBundleEncoder)322 TEST_F(LabelTest, RenderBundleEncoder) {
323 DAWN_SKIP_TEST_IF(UsesWire());
324 std::string label = "test";
325
326 utils::ComboRenderBundleEncoderDescriptor descriptor = {};
327 descriptor.colorFormatsCount = 1;
328 descriptor.cColorFormats[0] = wgpu::TextureFormat::RGBA8Unorm;
329
330 // The label should be empty if one was not set.
331 {
332 wgpu::RenderBundleEncoder encoder = device.CreateRenderBundleEncoder(&descriptor);
333 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
334 ASSERT_TRUE(readbackLabel.empty());
335 }
336
337 // Test setting a label through API
338 {
339 wgpu::RenderBundleEncoder encoder = device.CreateRenderBundleEncoder(&descriptor);
340 encoder.SetLabel(label.c_str());
341 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
342 ASSERT_EQ(label, readbackLabel);
343 }
344
345 // Test setting a label through the descriptor.
346 {
347 descriptor.label = label.c_str();
348 wgpu::RenderBundleEncoder encoder = device.CreateRenderBundleEncoder(&descriptor);
349 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
350 ASSERT_EQ(label, readbackLabel);
351 }
352 }
353
TEST_F(LabelTest,RenderPassEncoder)354 TEST_F(LabelTest, RenderPassEncoder) {
355 DAWN_SKIP_TEST_IF(UsesWire());
356 std::string label = "test";
357 wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
358
359 wgpu::TextureDescriptor textureDescriptor;
360 textureDescriptor.size = {1, 1, 1};
361 textureDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
362 textureDescriptor.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::RenderAttachment;
363 wgpu::Texture texture = device.CreateTexture(&textureDescriptor);
364
365 utils::ComboRenderPassDescriptor descriptor({texture.CreateView()});
366
367 // The label should be empty if one was not set.
368 {
369 wgpu::RenderPassEncoder encoder = commandEncoder.BeginRenderPass(&descriptor);
370 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
371 ASSERT_TRUE(readbackLabel.empty());
372 encoder.EndPass();
373 }
374
375 // Test setting a label through API
376 {
377 wgpu::RenderPassEncoder encoder = commandEncoder.BeginRenderPass(&descriptor);
378 encoder.SetLabel(label.c_str());
379 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
380 ASSERT_EQ(label, readbackLabel);
381 encoder.EndPass();
382 }
383
384 // Test setting a label through the descriptor.
385 {
386 descriptor.label = label.c_str();
387 wgpu::RenderPassEncoder encoder = commandEncoder.BeginRenderPass(&descriptor);
388 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(encoder.Get());
389 ASSERT_EQ(label, readbackLabel);
390 encoder.EndPass();
391 }
392 }
393
TEST_F(LabelTest,Sampler)394 TEST_F(LabelTest, Sampler) {
395 DAWN_SKIP_TEST_IF(UsesWire());
396 std::string label = "test";
397 wgpu::SamplerDescriptor descriptor;
398
399 // The label should be empty if one was not set.
400 {
401 wgpu::Sampler sampler = device.CreateSampler(&descriptor);
402 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(sampler.Get());
403 ASSERT_TRUE(readbackLabel.empty());
404 }
405
406 // Test setting a label through API
407 {
408 wgpu::Sampler sampler = device.CreateSampler(&descriptor);
409 sampler.SetLabel(label.c_str());
410 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(sampler.Get());
411 ASSERT_EQ(label, readbackLabel);
412 }
413
414 // Test setting a label through the descriptor.
415 {
416 descriptor.label = label.c_str();
417 wgpu::Sampler sampler = device.CreateSampler(&descriptor);
418 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(sampler.Get());
419 ASSERT_EQ(label, readbackLabel);
420 }
421 }
422
TEST_F(LabelTest,Texture)423 TEST_F(LabelTest, Texture) {
424 DAWN_SKIP_TEST_IF(UsesWire());
425 std::string label = "test";
426 wgpu::TextureDescriptor descriptor;
427 descriptor.size.width = 1;
428 descriptor.size.height = 1;
429 descriptor.size.depthOrArrayLayers = 1;
430 descriptor.mipLevelCount = 1;
431 descriptor.sampleCount = 1;
432 descriptor.dimension = wgpu::TextureDimension::e2D;
433 descriptor.format = wgpu::TextureFormat::RGBA8Uint;
434 descriptor.usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::TextureBinding;
435
436 // The label should be empty if one was not set.
437 {
438 wgpu::Texture texture = device.CreateTexture(&descriptor);
439 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(texture.Get());
440 ASSERT_TRUE(readbackLabel.empty());
441 }
442
443 // Test setting a label through API
444 {
445 wgpu::Texture texture = device.CreateTexture(&descriptor);
446 texture.SetLabel(label.c_str());
447 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(texture.Get());
448 ASSERT_EQ(label, readbackLabel);
449 }
450
451 // Test setting a label through the descriptor.
452 {
453 descriptor.label = label.c_str();
454 wgpu::Texture texture = device.CreateTexture(&descriptor);
455 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(texture.Get());
456 ASSERT_EQ(label, readbackLabel);
457 }
458 }
459
TEST_F(LabelTest,TextureView)460 TEST_F(LabelTest, TextureView) {
461 DAWN_SKIP_TEST_IF(UsesWire());
462 std::string label = "test";
463 wgpu::TextureDescriptor descriptor;
464 descriptor.size.width = 1;
465 descriptor.size.height = 1;
466 descriptor.size.depthOrArrayLayers = 1;
467 descriptor.mipLevelCount = 1;
468 descriptor.sampleCount = 1;
469 descriptor.dimension = wgpu::TextureDimension::e2D;
470 descriptor.format = wgpu::TextureFormat::RGBA8Uint;
471 descriptor.usage = wgpu::TextureUsage::RenderAttachment | wgpu::TextureUsage::TextureBinding;
472
473 wgpu::Texture texture = device.CreateTexture(&descriptor);
474
475 // The label should be empty if one was not set.
476 {
477 wgpu::TextureView textureView = texture.CreateView();
478 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(textureView.Get());
479 ASSERT_TRUE(readbackLabel.empty());
480 }
481
482 // Test setting a label through API
483 {
484 wgpu::TextureView textureView = texture.CreateView();
485 textureView.SetLabel(label.c_str());
486 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(textureView.Get());
487 ASSERT_EQ(label, readbackLabel);
488 }
489
490 // Test setting a label through the descriptor.
491 {
492 wgpu::TextureViewDescriptor viewDescriptor;
493 viewDescriptor.label = label.c_str();
494 wgpu::TextureView textureView = texture.CreateView(&viewDescriptor);
495 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(textureView.Get());
496 ASSERT_EQ(label, readbackLabel);
497 }
498 }
499
TEST_F(LabelTest,RenderPipeline)500 TEST_F(LabelTest, RenderPipeline) {
501 DAWN_SKIP_TEST_IF(UsesWire());
502 std::string label = "test";
503
504 wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"(
505 [[stage(vertex)]] fn main() -> [[builtin(position)]] vec4<f32> {
506 return vec4<f32>(0.0, 0.0, 0.0, 1.0);
507 })");
508
509 wgpu::ShaderModule fsModule = utils::CreateShaderModule(device, R"(
510 [[stage(fragment)]] fn main() -> [[location(0)]] vec4<f32> {
511 return vec4<f32>(0.0, 1.0, 0.0, 1.0);
512 })");
513
514 utils::ComboRenderPipelineDescriptor descriptor;
515 descriptor.vertex.module = vsModule;
516 descriptor.cFragment.module = fsModule;
517
518 // The label should be empty if one was not set.
519 {
520 wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
521 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(pipeline.Get());
522 ASSERT_TRUE(readbackLabel.empty());
523 }
524
525 // Test setting a label through API
526 {
527 wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
528 pipeline.SetLabel(label.c_str());
529 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(pipeline.Get());
530 ASSERT_EQ(label, readbackLabel);
531 }
532
533 // Test setting a label through the descriptor.
534 {
535 descriptor.label = label.c_str();
536 wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
537 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(pipeline.Get());
538 ASSERT_EQ(label, readbackLabel);
539 }
540 }
541
TEST_F(LabelTest,ComputePipeline)542 TEST_F(LabelTest, ComputePipeline) {
543 DAWN_SKIP_TEST_IF(UsesWire());
544 std::string label = "test";
545
546 wgpu::ShaderModule computeModule = utils::CreateShaderModule(device, R"(
547 [[stage(compute), workgroup_size(1)]] fn main() {
548 })");
549 wgpu::PipelineLayout pl = utils::MakeBasicPipelineLayout(device, nullptr);
550 wgpu::ComputePipelineDescriptor descriptor;
551 descriptor.layout = pl;
552 descriptor.compute.module = computeModule;
553 descriptor.compute.entryPoint = "main";
554
555 // The label should be empty if one was not set.
556 {
557 wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&descriptor);
558 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(pipeline.Get());
559 ASSERT_TRUE(readbackLabel.empty());
560 }
561
562 // Test setting a label through API
563 {
564 wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&descriptor);
565 pipeline.SetLabel(label.c_str());
566 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(pipeline.Get());
567 ASSERT_EQ(label, readbackLabel);
568 }
569
570 // Test setting a label through the descriptor.
571 {
572 descriptor.label = label.c_str();
573 wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&descriptor);
574 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(pipeline.Get());
575 ASSERT_EQ(label, readbackLabel);
576 }
577 }
578
TEST_F(LabelTest,ShaderModule)579 TEST_F(LabelTest, ShaderModule) {
580 DAWN_SKIP_TEST_IF(UsesWire());
581 std::string label = "test";
582
583 const char* source = R"(
584 [[stage(compute), workgroup_size(1)]] fn main() {
585 })";
586
587 wgpu::ShaderModuleWGSLDescriptor wgslDesc;
588 wgslDesc.source = source;
589 wgpu::ShaderModuleDescriptor descriptor;
590 descriptor.nextInChain = &wgslDesc;
591
592 // The label should be empty if one was not set.
593 {
594 wgpu::ShaderModule shaderModule = device.CreateShaderModule(&descriptor);
595 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(shaderModule.Get());
596 ASSERT_TRUE(readbackLabel.empty());
597 }
598
599 // Test setting a label through API
600 {
601 wgpu::ShaderModule shaderModule = device.CreateShaderModule(&descriptor);
602 shaderModule.SetLabel(label.c_str());
603 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(shaderModule.Get());
604 ASSERT_EQ(label, readbackLabel);
605 }
606
607 // Test setting a label through the descriptor.
608 {
609 descriptor.label = label.c_str();
610 wgpu::ShaderModule shaderModule = device.CreateShaderModule(&descriptor);
611 std::string readbackLabel = dawn_native::GetObjectLabelForTesting(shaderModule.Get());
612 ASSERT_EQ(label, readbackLabel);
613 }
614 }