Skip to content

Commit 9aaaacf

Browse files
shrekshaokainino0x
andauthored
Update WebGPU: GPURenderPassDepthStencilAttachment (#16429)
* Update WebGPU: GPURenderPassDepthStencilAttachment * include cmath instead * fixes multiple load op, store op; remove deprecations clear colors etc. * fix StoreOp helper * fix loadOp, storeOp library_webgpu impl * add support for deprecated * fix loadOp int * small fixes * fix compile issue; use new depth/stencil clear value for deprecated fields Co-authored-by: Kai Ninomiya <[email protected]>
1 parent 30697b5 commit 9aaaacf

File tree

7 files changed

+57
-42
lines changed

7 files changed

+57
-42
lines changed

src/library_webgpu.js

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@
112112
Fifo: 2,
113113
},
114114
LoadOp: {
115-
Clear: 0,
116-
Load: 1,
115+
Undefined: 0,
116+
Clear: 1,
117+
Load: 2,
118+
},
119+
StoreOp: {
120+
Undefined: 0,
121+
Store: 1,
122+
Discard: 2,
117123
},
118124
MapMode: {
119125
None: 0,
@@ -391,6 +397,11 @@ var LibraryWebGPU = {
391397
'uint16',
392398
'uint32',
393399
],
400+
LoadOp: [
401+
undefined,
402+
'clear',
403+
'load',
404+
],
394405
PipelineStatisticName: [
395406
'vertex-shader-invocations',
396407
'clipper-invocations',
@@ -1491,19 +1502,26 @@ var LibraryWebGPU = {
14911502
function makeColorAttachment(caPtr) {
14921503
var loadOpInt = {{{ gpu.makeGetU32('caPtr', C_STRUCTS.WGPURenderPassColorAttachment.loadOp) }}};
14931504
#if ASSERTIONS
1494-
assert(loadOpInt === {{{ gpu.LoadOp.Clear }}} || loadOpInt === {{{ gpu.LoadOp.Load }}});
1505+
assert(loadOpInt !== {{{ gpu.LoadOp.Undefined }}});
1506+
#endif
1507+
1508+
var storeOpInt = {{{ gpu.makeGetU32('caPtr', C_STRUCTS.WGPURenderPassColorAttachment.storeOp) }}};
1509+
#if ASSERTIONS
1510+
assert(storeOpInt !== {{{ gpu.StoreOp.Undefined }}});
14951511
#endif
1496-
var loadValue = loadOpInt ? 'load' :
1497-
WebGPU.makeColor(caPtr + {{{ C_STRUCTS.WGPURenderPassColorAttachment.clearColor }}});
1512+
1513+
var clearValue = WebGPU.makeColor(caPtr + {{{ C_STRUCTS.WGPURenderPassColorAttachment.clearValue }}});
14981514

14991515
return {
15001516
"view": WebGPU.mgrTextureView.get(
15011517
{{{ gpu.makeGetU32('caPtr', C_STRUCTS.WGPURenderPassColorAttachment.view) }}}),
15021518
"resolveTarget": WebGPU.mgrTextureView.get(
15031519
{{{ gpu.makeGetU32('caPtr', C_STRUCTS.WGPURenderPassColorAttachment.resolveTarget) }}}),
1504-
"storeOp": WebGPU.StoreOp[
1505-
{{{ gpu.makeGetU32('caPtr', C_STRUCTS.WGPURenderPassColorAttachment.storeOp) }}}],
1506-
"loadValue": loadValue,
1520+
"clearValue": clearValue,
1521+
"loadOp": WebGPU.LoadOp[loadOpInt],
1522+
"storeOp": WebGPU.StoreOp[storeOpInt],
1523+
// TODO(shrekshao): remove deprecated path once browser (chrome) API update comes to stable (M101)
1524+
"loadValue": loadOpInt === {{{ gpu.LoadOp.Load }}} ? 'load' : clearValue,
15071525
};
15081526
}
15091527

@@ -1519,30 +1537,26 @@ var LibraryWebGPU = {
15191537
if (dsaPtr === 0) return undefined;
15201538

15211539
var depthLoadOpInt = {{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.depthLoadOp) }}};
1522-
#if ASSERTIONS
1523-
assert(depthLoadOpInt === {{{ gpu.LoadOp.Clear }}} || depthLoadOpInt === {{{ gpu.LoadOp.Load }}});
1524-
#endif
1525-
var depthLoadValue = depthLoadOpInt ? 'load' :
1526-
{{{ makeGetValue('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.clearDepth, 'float') }}};
1527-
1540+
var depthClearValue = {{{ makeGetValue('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.depthClearValue, 'float') }}};
15281541
var stencilLoadOpInt = {{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.stencilLoadOp) }}};
1529-
#if ASSERTIONS
1530-
assert(stencilLoadOpInt === {{{ gpu.LoadOp.Clear }}} || stencilLoadOpInt === {{{ gpu.LoadOp.Load }}});
1531-
#endif
1532-
var stencilLoadValue = stencilLoadOpInt ? 'load' :
1533-
{{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.clearStencil) }}};
1542+
var stencilClearValue = {{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.stencilClearValue) }}};
15341543

15351544
return {
15361545
"view": WebGPU.mgrTextureView.get(
15371546
{{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.view) }}}),
1547+
"depthClearValue": depthClearValue,
1548+
"depthLoadOp": WebGPU.LoadOp[depthLoadOpInt],
15381549
"depthStoreOp": WebGPU.StoreOp[
15391550
{{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.depthStoreOp) }}}],
1540-
"depthLoadValue": depthLoadValue,
15411551
"depthReadOnly": {{{ gpu.makeGetBool('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.depthReadOnly) }}},
1552+
"stencilClearValue": stencilClearValue,
1553+
"stencilLoadOp": WebGPU.LoadOp[stencilLoadOpInt],
15421554
"stencilStoreOp": WebGPU.StoreOp[
15431555
{{{ gpu.makeGetU32('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.stencilStoreOp) }}}],
1544-
"stencilLoadValue": stencilLoadValue,
15451556
"stencilReadOnly": {{{ gpu.makeGetBool('dsaPtr', C_STRUCTS.WGPURenderPassDepthStencilAttachment.stencilReadOnly) }}},
1557+
// TODO(shrekshao): remove deprecated path once browser (chrome) API update comes to stable (M101)
1558+
"depthLoadValue": depthLoadOpInt === {{{ gpu.LoadOp.Load }}} ? 'load' : depthClearValue,
1559+
"stencilLoadValue": stencilLoadOpInt === {{{ gpu.LoadOp.Load }}} ? 'load' : stencilClearValue,
15461560
};
15471561
}
15481562

@@ -1576,9 +1590,9 @@ var LibraryWebGPU = {
15761590

15771591
var buffer = WebGPU.mgrBuffer.get(bufferId);
15781592
commandEncoder["clearBuffer"](
1579-
buffer,
1593+
buffer,
15801594
{{{ gpu.makeU64ToNumber('offset_low', 'offset_high') }}},
1581-
{{{ gpu.makeU64ToNumber('size_low', 'size_high') }}}
1595+
{{{ gpu.makeU64ToNumber('size_low', 'size_high') }}}
15821596
);
15831597
},
15841598

src/struct_info.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,11 +1288,11 @@
12881288
"view",
12891289
"depthLoadOp",
12901290
"depthStoreOp",
1291-
"clearDepth",
1291+
"depthClearValue",
12921292
"depthReadOnly",
12931293
"stencilLoadOp",
12941294
"stencilStoreOp",
1295-
"clearStencil",
1295+
"stencilClearValue",
12961296
"stencilReadOnly"
12971297
],
12981298
"WGPURequestAdapterOptions": [
@@ -1451,7 +1451,7 @@
14511451
"resolveTarget",
14521452
"loadOp",
14531453
"storeOp",
1454-
"clearColor"
1454+
"clearValue"
14551455
],
14561456
"WGPURequiredLimits": [
14571457
"nextInChain",

system/include/webgpu/webgpu.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,11 @@ typedef struct WGPURenderPassDepthStencilAttachment {
808808
WGPUTextureView view;
809809
WGPULoadOp depthLoadOp;
810810
WGPUStoreOp depthStoreOp;
811-
float clearDepth;
811+
float depthClearValue;
812812
bool depthReadOnly;
813813
WGPULoadOp stencilLoadOp;
814814
WGPUStoreOp stencilStoreOp;
815-
uint32_t clearStencil;
815+
uint32_t stencilClearValue;
816816
bool stencilReadOnly;
817817
} WGPURenderPassDepthStencilAttachment;
818818

@@ -995,7 +995,7 @@ typedef struct WGPURenderPassColorAttachment {
995995
WGPUTextureView resolveTarget;
996996
WGPULoadOp loadOp;
997997
WGPUStoreOp storeOp;
998-
WGPUColor clearColor;
998+
WGPUColor clearValue;
999999
} WGPURenderPassColorAttachment;
10001000

10011001
typedef struct WGPURequiredLimits {

system/include/webgpu/webgpu_cpp.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "webgpu/webgpu.h"
55

66
#include <type_traits>
7+
#include <cmath>
78

89
namespace wgpu {
910

@@ -1372,11 +1373,11 @@ namespace wgpu {
13721373
TextureView view;
13731374
LoadOp depthLoadOp = LoadOp::Undefined;
13741375
StoreOp depthStoreOp = StoreOp::Undefined;
1375-
float clearDepth = 0;
1376+
float depthClearValue = 0;
13761377
bool depthReadOnly = false;
13771378
LoadOp stencilLoadOp = LoadOp::Undefined;
13781379
StoreOp stencilStoreOp = StoreOp::Undefined;
1379-
uint32_t clearStencil = 0;
1380+
uint32_t stencilClearValue = 0;
13801381
bool stencilReadOnly = false;
13811382
};
13821383

@@ -1565,7 +1566,7 @@ namespace wgpu {
15651566
TextureView resolveTarget = nullptr;
15661567
LoadOp loadOp;
15671568
StoreOp storeOp;
1568-
Color clearColor;
1569+
Color clearValue;
15691570
};
15701571

15711572
struct RequiredLimits {

system/lib/webgpu/webgpu_cpp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -998,16 +998,16 @@ namespace wgpu {
998998
"offsetof mismatch for RenderPassDepthStencilAttachment::depthLoadOp");
999999
static_assert(offsetof(RenderPassDepthStencilAttachment, depthStoreOp) == offsetof(WGPURenderPassDepthStencilAttachment, depthStoreOp),
10001000
"offsetof mismatch for RenderPassDepthStencilAttachment::depthStoreOp");
1001-
static_assert(offsetof(RenderPassDepthStencilAttachment, clearDepth) == offsetof(WGPURenderPassDepthStencilAttachment, clearDepth),
1002-
"offsetof mismatch for RenderPassDepthStencilAttachment::clearDepth");
1001+
static_assert(offsetof(RenderPassDepthStencilAttachment, depthClearValue) == offsetof(WGPURenderPassDepthStencilAttachment, depthClearValue),
1002+
"offsetof mismatch for RenderPassDepthStencilAttachment::depthClearValue");
10031003
static_assert(offsetof(RenderPassDepthStencilAttachment, depthReadOnly) == offsetof(WGPURenderPassDepthStencilAttachment, depthReadOnly),
10041004
"offsetof mismatch for RenderPassDepthStencilAttachment::depthReadOnly");
10051005
static_assert(offsetof(RenderPassDepthStencilAttachment, stencilLoadOp) == offsetof(WGPURenderPassDepthStencilAttachment, stencilLoadOp),
10061006
"offsetof mismatch for RenderPassDepthStencilAttachment::stencilLoadOp");
10071007
static_assert(offsetof(RenderPassDepthStencilAttachment, stencilStoreOp) == offsetof(WGPURenderPassDepthStencilAttachment, stencilStoreOp),
10081008
"offsetof mismatch for RenderPassDepthStencilAttachment::stencilStoreOp");
1009-
static_assert(offsetof(RenderPassDepthStencilAttachment, clearStencil) == offsetof(WGPURenderPassDepthStencilAttachment, clearStencil),
1010-
"offsetof mismatch for RenderPassDepthStencilAttachment::clearStencil");
1009+
static_assert(offsetof(RenderPassDepthStencilAttachment, stencilClearValue) == offsetof(WGPURenderPassDepthStencilAttachment, stencilClearValue),
1010+
"offsetof mismatch for RenderPassDepthStencilAttachment::stencilClearValue");
10111011
static_assert(offsetof(RenderPassDepthStencilAttachment, stencilReadOnly) == offsetof(WGPURenderPassDepthStencilAttachment, stencilReadOnly),
10121012
"offsetof mismatch for RenderPassDepthStencilAttachment::stencilReadOnly");
10131013

@@ -1366,8 +1366,8 @@ namespace wgpu {
13661366
"offsetof mismatch for RenderPassColorAttachment::loadOp");
13671367
static_assert(offsetof(RenderPassColorAttachment, storeOp) == offsetof(WGPURenderPassColorAttachment, storeOp),
13681368
"offsetof mismatch for RenderPassColorAttachment::storeOp");
1369-
static_assert(offsetof(RenderPassColorAttachment, clearColor) == offsetof(WGPURenderPassColorAttachment, clearColor),
1370-
"offsetof mismatch for RenderPassColorAttachment::clearColor");
1369+
static_assert(offsetof(RenderPassColorAttachment, clearValue) == offsetof(WGPURenderPassColorAttachment, clearValue),
1370+
"offsetof mismatch for RenderPassColorAttachment::clearValue");
13711371

13721372
// RequiredLimits
13731373

tests/reference_struct_info.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,19 +1015,19 @@
10151015
},
10161016
"WGPURenderPassColorAttachment": {
10171017
"__size__": 48,
1018-
"clearColor": 16,
1018+
"clearValue": 16,
10191019
"loadOp": 8,
10201020
"resolveTarget": 4,
10211021
"storeOp": 12,
10221022
"view": 0
10231023
},
10241024
"WGPURenderPassDepthStencilAttachment": {
10251025
"__size__": 36,
1026-
"clearDepth": 12,
1027-
"clearStencil": 28,
1026+
"depthClearValue": 12,
10281027
"depthLoadOp": 4,
10291028
"depthReadOnly": 16,
10301029
"depthStoreOp": 8,
1030+
"stencilClearValue": 28,
10311031
"stencilLoadOp": 20,
10321032
"stencilReadOnly": 32,
10331033
"stencilStoreOp": 24,

tests/webgpu_basic_rendering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void render(wgpu::TextureView view) {
121121
attachment.view = view;
122122
attachment.loadOp = wgpu::LoadOp::Clear;
123123
attachment.storeOp = wgpu::StoreOp::Store;
124-
attachment.clearColor = {0, 0, 0, 1};
124+
attachment.clearValue = {0, 0, 0, 1};
125125

126126
wgpu::RenderPassDescriptor renderpass{};
127127
renderpass.colorAttachmentCount = 1;

0 commit comments

Comments
 (0)