Skip to content

Commit b8b6819

Browse files
authored
Remove receiveI64ParamAsI32s helper function (emscripten-core#19701)
I'm working on a tools that automatically converts i64 to i53 without any extra macros or helpers in the source code. This way to receiving an i64 was an outlier and removing it helps towards my goal. The other problem with this method is that it doesn't make a lot of sense in WASM_BIGINT is enabled since it needless splits the incoming argument into two.
1 parent b020474 commit b8b6819

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

src/library_webgpu.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ wgpu${type}Reference: function(id) { WebGPU.mgr${type}.reference(id) },
3535
wgpu${type}Release: function(id) { WebGPU.mgr${type}.release(id) },`;
3636
},
3737

38-
convertI32PairToI53WithSentinelAsUndefined: function(lowName, highName) {
39-
return `((${highName} === -1 && ${lowName} === -1) ? undefined : \
40-
convertI32PairToI53(${lowName}, ${highName}))`;
38+
convertSentinelToUndefined: function(name) {
39+
return `if (${name} == -1) ${name} = undefined;`;
4140
},
4241

4342
makeGetBool: function(struct, offset) {
@@ -1041,6 +1040,7 @@ var LibraryWebGPU = {
10411040
return WebGPU.mgrBindGroupLayout.create(device["createBindGroupLayout"](desc));
10421041
},
10431042

1043+
wgpuDeviceCreateBindGroup__deps: ['$readI53FromI64'],
10441044
wgpuDeviceCreateBindGroup: function(deviceId, descriptor) {
10451045
{{{ gpu.makeCheckDescriptor('descriptor') }}}
10461046

@@ -1057,16 +1057,15 @@ var LibraryWebGPU = {
10571057
var binding = {{{ gpu.makeGetU32('entryPtr', C_STRUCTS.WGPUBindGroupEntry.binding) }}};
10581058

10591059
if (bufferId) {
1060-
var size_low = {{{ makeGetValue('entryPtr', C_STRUCTS.WGPUBindGroupEntry.size, 'i32') }}};
1061-
var size_high = {{{ makeGetValue('entryPtr', C_STRUCTS.WGPUBindGroupEntry.size + 4, 'i32') }}};
1062-
var size = {{{ gpu.convertI32PairToI53WithSentinelAsUndefined('size_low', 'size_high') }}};
1060+
var size = {{{ makeGetValue('entryPtr', C_STRUCTS.WGPUBindGroupEntry.size, 'i53') }}};
1061+
{{{ gpu.convertSentinelToUndefined('size') }}}
10631062

10641063
return {
10651064
"binding": binding,
10661065
"resource": {
10671066
"buffer": WebGPU.mgrBuffer.get(bufferId),
10681067
"offset": {{{ gpu.makeGetU64('entryPtr', C_STRUCTS.WGPUBindGroupEntry.offset) }}},
1069-
"size": size,
1068+
"size": size
10701069
},
10711070
};
10721071
} else if (samplerId) {
@@ -1700,15 +1699,12 @@ var LibraryWebGPU = {
17001699

17011700
wgpuCommandEncoderClearBuffer: function(encoderId, bufferId, {{{ defineI64Param('offset') }}}, {{{ defineI64Param('size') }}}) {
17021701
var commandEncoder = WebGPU.mgrCommandEncoder.get(encoderId);
1703-
{{{ receiveI64ParamAsI32s('offset') }}}
1704-
{{{ receiveI64ParamAsI32s('size') }}}
1702+
{{{ receiveI64ParamAsI53('offset') }}}
1703+
{{{ receiveI64ParamAsI53('size') }}}
1704+
{{{ gpu.convertSentinelToUndefined('size') }}}
17051705

17061706
var buffer = WebGPU.mgrBuffer.get(bufferId);
1707-
commandEncoder["clearBuffer"](
1708-
buffer,
1709-
convertI32PairToI53(offset_low, offset_high),
1710-
convertI32PairToI53(size_low, size_high)
1711-
);
1707+
commandEncoder["clearBuffer"](buffer, offset, size);
17121708
},
17131709

17141710
wgpuCommandEncoderCopyBufferToBuffer: function(encoderId, srcId, {{{ defineI64Param('srcOffset') }}}, dstId, {{{ defineI64Param('dstOffset') }}}, {{{ defineI64Param('size') }}}) {
@@ -2159,10 +2155,10 @@ var LibraryWebGPU = {
21592155
},
21602156
wgpuRenderPassEncoderSetIndexBuffer: function(passId, bufferId, format, {{{ defineI64Param('offset') }}}, {{{ defineI64Param('size') }}}) {
21612157
{{{ receiveI64ParamAsI53('offset') }}}
2162-
{{{ receiveI64ParamAsI32s('size') }}}
2158+
{{{ receiveI64ParamAsI53('size') }}}
2159+
{{{ gpu.convertSentinelToUndefined('size') }}}
21632160
var pass = WebGPU.mgrRenderPassEncoder.get(passId);
21642161
var buffer = WebGPU.mgrBuffer.get(bufferId);
2165-
var size = {{{ gpu.convertI32PairToI53WithSentinelAsUndefined('size_low', 'size_high') }}};
21662162
pass["setIndexBuffer"](buffer, WebGPU.IndexFormat[format], offset, size);
21672163
},
21682164
wgpuRenderPassEncoderSetPipeline: function(passId, pipelineId) {
@@ -2184,10 +2180,10 @@ var LibraryWebGPU = {
21842180
},
21852181
wgpuRenderPassEncoderSetVertexBuffer: function(passId, slot, bufferId, {{{ defineI64Param('offset') }}}, {{{ defineI64Param('size') }}}) {
21862182
{{{ receiveI64ParamAsI53('offset') }}}
2187-
{{{ receiveI64ParamAsI32s('size') }}}
2183+
{{{ receiveI64ParamAsI53('size') }}}
2184+
{{{ gpu.convertSentinelToUndefined('size') }}}
21882185
var pass = WebGPU.mgrRenderPassEncoder.get(passId);
21892186
var buffer = WebGPU.mgrBuffer.get(bufferId);
2190-
var size = {{{ gpu.convertI32PairToI53WithSentinelAsUndefined('size_low', 'size_high') }}};
21912187
pass["setVertexBuffer"](slot, buffer, offset, size);
21922188
},
21932189

@@ -2295,10 +2291,10 @@ var LibraryWebGPU = {
22952291
},
22962292
wgpuRenderBundleEncoderSetIndexBuffer: function(bundleId, bufferId, format, {{{ defineI64Param('offset') }}}, {{{ defineI64Param('size') }}}) {
22972293
{{{ receiveI64ParamAsI53('offset') }}}
2298-
{{{ receiveI64ParamAsI32s('size') }}}
2294+
{{{ receiveI64ParamAsI53('size') }}}
2295+
{{{ gpu.convertSentinelToUndefined('size') }}}
22992296
var pass = WebGPU.mgrRenderBundleEncoder.get(bundleId);
23002297
var buffer = WebGPU.mgrBuffer.get(bufferId);
2301-
var size = {{{ gpu.convertI32PairToI53WithSentinelAsUndefined('size_low', 'size_high') }}};
23022298
pass["setIndexBuffer"](buffer, WebGPU.IndexFormat[format], offset, size);
23032299
},
23042300
wgpuRenderBundleEncoderSetPipeline: function(bundleId, pipelineId) {
@@ -2308,10 +2304,10 @@ var LibraryWebGPU = {
23082304
},
23092305
wgpuRenderBundleEncoderSetVertexBuffer: function(bundleId, slot, bufferId, {{{ defineI64Param('offset') }}}, {{{ defineI64Param('size') }}}) {
23102306
{{{ receiveI64ParamAsI53('offset') }}}
2311-
{{{ receiveI64ParamAsI32s('size') }}}
2307+
{{{ receiveI64ParamAsI53('size') }}}
2308+
{{{ gpu.convertSentinelToUndefined('size') }}}
23122309
var pass = WebGPU.mgrRenderBundleEncoder.get(bundleId);
23132310
var buffer = WebGPU.mgrBuffer.get(bufferId);
2314-
var size = {{{ gpu.convertI32PairToI53WithSentinelAsUndefined('size_low', 'size_high') }}};
23152311
pass["setVertexBuffer"](slot, buffer, offset, size);
23162312
},
23172313

src/parseTools.js

-7
Original file line numberDiff line numberDiff line change
@@ -873,13 +873,6 @@ function defineI64Param(name) {
873873
return `${name}_low, ${name}_high`;
874874
}
875875

876-
function receiveI64ParamAsI32s(name) {
877-
if (WASM_BIGINT) {
878-
return `var ${name}_low = Number(${name} & 0xffffffffn) | 0, ${name}_high = Number(${name} >> 32n) | 0;`;
879-
}
880-
return '';
881-
}
882-
883876
function receiveI64ParamAsI53(name, onError) {
884877
if (WASM_BIGINT) {
885878
// Just convert the bigint into a double.

src/parseTools_legacy.js

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ function receiveI64ParamAsDouble(name) {
2424
return `var ${name} = ${name}_high * 0x100000000 + (${name}_low >>> 0);`;
2525
}
2626

27+
function receiveI64ParamAsI32s(name) {
28+
if (WASM_BIGINT) {
29+
return `var ${name}_low = Number(${name} & 0xffffffffn) | 0, ${name}_high = Number(${name} >> 32n) | 0;`;
30+
}
31+
return '';
32+
}
33+
2734
function stripCorrections(param) {
2835
let m;
2936
while (true) {

0 commit comments

Comments
 (0)