Skip to content

Commit

Permalink
IDL: Add depthSlice to GPURenderPassColorAttachment. gpuweb/gpuweb#4254
Browse files Browse the repository at this point in the history
  • Loading branch information
juj committed Mar 7, 2024
1 parent eb4da35 commit 331aed2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions idl/webgpu.idl
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ dictionary GPURenderPassDescriptor

dictionary GPURenderPassColorAttachment {
required GPUTextureView view;
GPUIntegerCoordinate depthSlice;
GPUTextureView resolveTarget;

GPUColor clearValue;
Expand Down
3 changes: 3 additions & 0 deletions lib/lib_webgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,7 @@ void wgpu_render_pass_encoder_execute_bundles(WGpuRenderPassEncoder encoder, con
/*
dictionary GPURenderPassColorAttachment {
required GPUTextureView view;
GPUIntegerCoordinate depthSlice;
GPUTextureView resolveTarget;
GPUColor clearValue;
Expand Down Expand Up @@ -2861,10 +2862,12 @@ extern const WGpuRenderPassDescriptor WGPU_RENDER_PASS_DESCRIPTOR_DEFAULT_INITIA
typedef struct WGpuRenderPassColorAttachment
{
WGpuTextureView view;
int depthSlice;
WGpuTextureView resolveTarget;

WGPU_STORE_OP storeOp; // Required, be sure to set to WGPU_STORE_OP_STORE (default) or WGPU_STORE_OP_DISCARD
WGPU_LOAD_OP loadOp; // Either WGPU_LOAD_OP_LOAD (== default, 0) or WGPU_LOAD_OP_CLEAR.
int dummyDoublePadding; // unused, added to pad the doubles in clearValue to 8-byte multiples.
WGpuColor clearValue; // Used if loadOp == WGPU_LOAD_OP_CLEAR. Default value = { r = 0.0, g = 0.0, b = 0.0, a = 1.0 }
} WGpuRenderPassColorAttachment;
extern const WGpuRenderPassColorAttachment WGPU_RENDER_PASS_COLOR_ATTACHMENT_DEFAULT_INITIALIZER;
Expand Down
22 changes: 12 additions & 10 deletions lib/lib_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@ let api = {
let colorAttachments = [],
numColorAttachments = HEAP32[descriptor++],
colorAttachmentsIdx = {{{ shiftPtr('HEAPU32[descriptor++]', 2) }}},
colorAttachmentsIdxDbl = {{{ shiftPtr('colorAttachmentsIdx + 4', 1) }}}, // Alias the view for HEAPF64.
colorAttachmentsIdxDbl = {{{ shiftPtr('colorAttachmentsIdx + 6', 1) }}}, // Alias the view for HEAPF64.
depthStencilView = wgpu[HEAPU32[descriptor]];

{{{ wassert('colorAttachmentsIdx % 2 == 0'); }}} // Must be aligned at double boundary
Expand All @@ -1930,15 +1930,16 @@ let api = {
// If view is 0, then this attachment is to be sparse.
colorAttachments.push(HEAPU32[colorAttachmentsIdx] ? {
'view': wgpu[HEAPU32[colorAttachmentsIdx]],
'resolveTarget': wgpu[HEAPU32[colorAttachmentsIdx+1]],
'storeOp': GPUStoreOps[HEAPU32[colorAttachmentsIdx+2]],
'loadOp': GPULoadOps[HEAPU32[colorAttachmentsIdx+3]],
'depthSlice': HEAP32[colorAttachmentsIdx+1] < 0 ? undefined : HEAP32[colorAttachmentsIdx+1], // Awkward polymorphism: spec does not allow 'depthSlice' to be given a value (even 0) if attachment is not a 3D texture.
'resolveTarget': wgpu[HEAPU32[colorAttachmentsIdx+2]],
'storeOp': GPUStoreOps[HEAPU32[colorAttachmentsIdx+3]],
'loadOp': GPULoadOps[HEAPU32[colorAttachmentsIdx+4]],
'clearValue': [HEAPF64[colorAttachmentsIdxDbl ], HEAPF64[colorAttachmentsIdxDbl+1],
HEAPF64[colorAttachmentsIdxDbl+2], HEAPF64[colorAttachmentsIdxDbl+3]]
} : null);

colorAttachmentsIdx += 12;
colorAttachmentsIdxDbl += 6;
colorAttachmentsIdx += 14;
colorAttachmentsIdxDbl += 7;
}

{{{ wassert('Number.isSafeInteger(HEAPF64[descriptor+10>>1])'); }}} // 'maxDrawCount' is a double_int53_t
Expand Down Expand Up @@ -1992,16 +1993,17 @@ let api = {
{{{ wassert('HEAPU32[descriptor+2] == 0'); }}} // Must be passing no depth-stencil target.

let colorAttachmentsIdx = {{{ shiftPtr('HEAPU32[descriptor+1]', 2) }}},
colorAttachmentsIdxDbl = {{{ shiftPtr('colorAttachmentsIdx + 4', 1) }}}; // Alias the view for HEAPF64.
colorAttachmentsIdxDbl = {{{ shiftPtr('colorAttachmentsIdx + 6', 1) }}}; // Alias the view for HEAPF64.

{{{ wassert('colorAttachmentsIdx % 2 == 0'); }}} // Must be aligned at double boundary

return wgpuStore(debugDir(wgpu[commandEncoder]['beginRenderPass'](debugDir({
'colorAttachments': [{
'view': wgpu[HEAPU32[colorAttachmentsIdx]],
'resolveTarget': wgpu[HEAPU32[colorAttachmentsIdx+1]],
'storeOp': GPUStoreOps[HEAPU32[colorAttachmentsIdx+2]],
'loadOp': GPULoadOps[HEAPU32[colorAttachmentsIdx+3]],
'depthSlice': HEAP32[colorAttachmentsIdx+1] < 0 ? undefined : HEAP32[colorAttachmentsIdx+1], // Awkward polymorphism: spec does not allow 'depthSlice' to be given a value (even 0) if attachment is not a 3D texture.
'resolveTarget': wgpu[HEAPU32[colorAttachmentsIdx+2]],
'storeOp': GPUStoreOps[HEAPU32[colorAttachmentsIdx+3]],
'loadOp': GPULoadOps[HEAPU32[colorAttachmentsIdx+4]],
'clearValue': [HEAPF64[colorAttachmentsIdxDbl ], HEAPF64[colorAttachmentsIdxDbl+1],
HEAPF64[colorAttachmentsIdxDbl+2], HEAPF64[colorAttachmentsIdxDbl+3]]
}]
Expand Down
2 changes: 2 additions & 0 deletions lib/lib_webgpu_cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ extern const WGpuExtent3D WGPU_EXTENT_3D_DEFAULT_INITIALIZER = {

extern const WGpuRenderPassColorAttachment WGPU_RENDER_PASS_COLOR_ATTACHMENT_DEFAULT_INITIALIZER = {
0, /* view */
-1, /* depthSlice */
0, /* resolveTarget */
WGPU_STORE_OP_STORE, /* storeOp */
WGPU_LOAD_OP_LOAD, /* loadOp */
0, /* dummyDoublePadding */
{ /* clearValue */
0.0f,
0.0f,
Expand Down
1 change: 1 addition & 0 deletions lib/lib_webgpu_cpp20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ extern const WGpuExtent3D WGPU_EXTENT_3D_DEFAULT_INITIALIZER = {
};

extern const WGpuRenderPassColorAttachment WGPU_RENDER_PASS_COLOR_ATTACHMENT_DEFAULT_INITIALIZER = {
.depthSlice = -1,
.storeOp = WGPU_STORE_OP_STORE,
.loadOp = WGPU_LOAD_OP_LOAD,
.clearValue = (WGpuColor) {
Expand Down
2 changes: 1 addition & 1 deletion lib/lib_webgpu_dawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1992,11 +1992,11 @@ static WGPURenderPassColorAttachment getColorAttachInfo(const WGpuRenderPassColo

WGPURenderPassColorAttachment _attachment = {};
_attachment.view = _wgpu_get_dawn<WGPUTextureView>(colorAttachment.view);
_attachment.depthSlice = colorAttachment.depthSlice < 0 ? wgpu::kDepthSliceUndefined : colorAttachment.depthSlice;
_attachment.resolveTarget = _wgpu_get_dawn<WGPUTextureView>(colorAttachment.resolveTarget);
_attachment.loadOp = wgpu_load_op_to_dawn(colorAttachment.loadOp);
_attachment.storeOp = wgpu_store_op_to_dawn(colorAttachment.storeOp);
_attachment.clearValue = WGPUColor{ colorAttachment.clearValue.r, colorAttachment.clearValue.g, colorAttachment.clearValue.b, colorAttachment.clearValue.a };
_attachment.depthSlice = wgpu::kDepthSliceUndefined;
return _attachment;
}

Expand Down

0 comments on commit 331aed2

Please sign in to comment.