diff --git a/cts_runner/Cargo.toml b/cts_runner/Cargo.toml index c63feb5ce3..a6aa10a89e 100644 --- a/cts_runner/Cargo.toml +++ b/cts_runner/Cargo.toml @@ -11,11 +11,11 @@ publish = false resolver = "2" [dependencies] -deno_console = "0.42.0" -deno_core = "0.124.0" -deno_url = "0.42.0" -deno_web = "0.73.0" -deno_webidl = "0.42.0" +deno_console = "0.43.0" +deno_core = "0.125.0" +deno_url = "0.43.0" +deno_web = "0.74.0" +deno_webidl = "0.43.0" deno_webgpu = { path = "../deno_webgpu" } tokio = { version = "1.15.0", features = ["full"] } termcolor = "1.1.2" diff --git a/deno_webgpu/01_webgpu.js b/deno_webgpu/01_webgpu.js index 9803fed6a5..ebb3182a8e 100644 --- a/deno_webgpu/01_webgpu.js +++ b/deno_webgpu/01_webgpu.js @@ -196,7 +196,8 @@ const { err, ...data } = await core.opAsync( "op_webgpu_request_adapter", - { ...options }, + options.powerPreference, + options.forceFallbackAdapter, ); if (err) { @@ -295,12 +296,10 @@ const { rid, features, limits } = await core.opAsync( "op_webgpu_request_device", - { - adapterRid: this[_adapter].rid, - label: descriptor.label, - requiredFeatures, - requiredLimits, - }, + this[_adapter].rid, + descriptor.label, + requiredFeatures, + requiredLimits, ); const inner = new InnerGPUDevice({ @@ -838,10 +837,14 @@ context: "Argument 1", }); const device = assertDevice(this, { prefix, context: "this" }); - const { rid, err } = core.opSync("op_webgpu_create_buffer", { - deviceRid: device.rid, - ...descriptor, - }); + const { rid, err } = core.opSync( + "op_webgpu_create_buffer", + device.rid, + descriptor.label, + descriptor.size, + descriptor.usage, + descriptor.mappedAtCreation, + ); device.pushError(err); /** @type {CreateGPUBufferOptions} */ let options; @@ -955,10 +958,9 @@ const { rid, err } = core.opSync( "op_webgpu_create_bind_group_layout", - { - deviceRid: device.rid, - ...descriptor, - }, + device.rid, + descriptor.label, + descriptor.entries, ); device.pushError(err); @@ -997,11 +999,12 @@ return rid; }, ); - const { rid, err } = core.opSync("op_webgpu_create_pipeline_layout", { - deviceRid: device.rid, - label: descriptor.label, + const { rid, err } = core.opSync( + "op_webgpu_create_pipeline_layout", + device.rid, + descriptor.label, bindGroupLayouts, - }); + ); device.pushError(err); const pipelineLayout = createGPUPipelineLayout( @@ -1122,12 +1125,10 @@ const device = assertDevice(this, { prefix, context: "this" }); const { rid, err } = core.opSync( "op_webgpu_create_shader_module", - { - deviceRid: device.rid, - label: descriptor.label, - code: descriptor.code, - sourceMap: descriptor.sourceMap, - }, + device.rid, + descriptor.label, + descriptor.code, + descriptor.sourceMap, ); device.pushError(err); @@ -1175,15 +1176,13 @@ const { rid, err } = core.opSync( "op_webgpu_create_compute_pipeline", + device.rid, + descriptor.label, + layout, { - deviceRid: device.rid, - label: descriptor.label, - layout, - compute: { - module, - entryPoint: descriptor.compute.entryPoint, - constants: descriptor.compute.constants, - }, + module, + entryPoint: descriptor.compute.entryPoint, + constants: descriptor.compute.constants, }, ); device.pushError(err); @@ -1294,10 +1293,11 @@ context: "Argument 1", }); const device = assertDevice(this, { prefix, context: "this" }); - const { rid, err } = core.opSync("op_webgpu_create_command_encoder", { - deviceRid: device.rid, - ...descriptor, - }); + const { rid, err } = core.opSync( + "op_webgpu_create_command_encoder", + device.rid, + descriptor.label, + ); device.pushError(err); const commandEncoder = createGPUCommandEncoder( @@ -1491,10 +1491,11 @@ return rid; }, ); - const { err } = core.opSync("op_webgpu_queue_submit", { - queueRid: device.rid, - commandBuffers: commandBufferRids, - }); + const { err } = core.opSync( + "op_webgpu_queue_submit", + device.rid, + commandBufferRids, + ); for (const commandBuffer of commandBuffers) { commandBuffer[_rid] = undefined; } @@ -1551,13 +1552,11 @@ }); const { err } = core.opSync( "op_webgpu_write_buffer", - { - queueRid: device.rid, - buffer: bufferRid, - bufferOffset, - dataOffset, - size, - }, + device.rid, + bufferRid, + bufferOffset, + dataOffset, + size, new Uint8Array(ArrayBufferIsView(data) ? data.buffer : data), ); device.pushError(err); @@ -1601,19 +1600,17 @@ }); const { err } = core.opSync( "op_webgpu_write_texture", + device.rid, { - queueRid: device.rid, - destination: { - texture: textureRid, - mipLevel: destination.mipLevel, - origin: destination.origin - ? normalizeGPUOrigin3D(destination.origin) - : undefined, - aspect: destination.aspect, - }, - dataLayout, - size: normalizeGPUExtent3D(size), + texture: textureRid, + mipLevel: destination.mipLevel, + origin: destination.origin + ? normalizeGPUOrigin3D(destination.origin) + : undefined, + aspect: destination.aspect, }, + dataLayout, + normalizeGPUExtent3D(size), new Uint8Array(ArrayBufferIsView(data) ? data.buffer : data), ); device.pushError(err); @@ -1803,13 +1800,11 @@ const promise = PromisePrototypeThen( core.opAsync( "op_webgpu_buffer_get_map_async", - { - bufferRid, - deviceRid: device.rid, - mode, - offset, - size: rangeSize, - }, + bufferRid, + device.rid, + mode, + offset, + rangeSize, ), ({ err }) => err, ); @@ -1872,11 +1867,9 @@ const buffer = new ArrayBuffer(rangeSize); const { rid } = core.opSync( "op_webgpu_buffer_get_mapped_range", - { - bufferRid, - offset, - size, - }, + bufferRid, + offset, + size, new Uint8Array(buffer), ); @@ -1927,10 +1920,12 @@ throw new DOMException(`${prefix}: invalid state.`, "OperationError"); } for (const [buffer, mappedRid] of mappedRanges) { - const { err } = core.opSync("op_webgpu_buffer_unmap", { + const { err } = core.opSync( + "op_webgpu_buffer_unmap", bufferRid, mappedRid, - }, ...new SafeArrayIterator(write ? [new Uint8Array(buffer)] : [])); + ...new SafeArrayIterator(write ? [new Uint8Array(buffer)] : []), + ); device.pushError(err); if (err) return; } @@ -2452,7 +2447,8 @@ }); const { rid, label, err } = core.opSync( "op_webgpu_compute_pipeline_get_bind_group_layout", - { computePipelineRid, index }, + computePipelineRid, + index, ); device.pushError(err); @@ -2528,7 +2524,8 @@ }); const { rid, label, err } = core.opSync( "op_webgpu_render_pipeline_get_bind_group_layout", - { renderPipelineRid, index }, + renderPipelineRid, + index, ); device.pushError(err); @@ -2723,12 +2720,10 @@ const { rid } = core.opSync( "op_webgpu_command_encoder_begin_render_pass", - { - commandEncoderRid, - ...descriptor, - colorAttachments, - depthStencilAttachment, - }, + commandEncoderRid, + descriptor.label, + colorAttachments, + depthStencilAttachment, ); const renderPassEncoder = createGPURenderPassEncoder( @@ -2760,10 +2755,8 @@ const { rid } = core.opSync( "op_webgpu_command_encoder_begin_compute_pass", - { - commandEncoderRid, - ...descriptor, - }, + commandEncoderRid, + descriptor.label, ); const computePassEncoder = createGPUComputePassEncoder( @@ -2839,14 +2832,12 @@ const { err } = core.opSync( "op_webgpu_command_encoder_copy_buffer_to_buffer", - { - commandEncoderRid, - source: sourceRid, - sourceOffset, - destination: destinationRid, - destinationOffset, - size, - }, + commandEncoderRid, + sourceRid, + sourceOffset, + destinationRid, + destinationOffset, + size, ); device.pushError(err); } @@ -2899,22 +2890,20 @@ const { err } = core.opSync( "op_webgpu_command_encoder_copy_buffer_to_texture", + commandEncoderRid, { - commandEncoderRid, - source: { - ...source, - buffer: sourceBufferRid, - }, - destination: { - texture: destinationTextureRid, - mipLevel: destination.mipLevel, - origin: destination.origin - ? normalizeGPUOrigin3D(destination.origin) - : undefined, - aspect: destination.aspect, - }, - copySize: normalizeGPUExtent3D(copySize), + ...source, + buffer: sourceBufferRid, }, + { + texture: destinationTextureRid, + mipLevel: destination.mipLevel, + origin: destination.origin + ? normalizeGPUOrigin3D(destination.origin) + : undefined, + aspect: destination.aspect, + }, + normalizeGPUExtent3D(copySize), ); device.pushError(err); } @@ -2966,22 +2955,20 @@ }); const { err } = core.opSync( "op_webgpu_command_encoder_copy_texture_to_buffer", + commandEncoderRid, { - commandEncoderRid, - source: { - texture: sourceTextureRid, - mipLevel: source.mipLevel, - origin: source.origin - ? normalizeGPUOrigin3D(source.origin) - : undefined, - aspect: source.aspect, - }, - destination: { - ...destination, - buffer: destinationBufferRid, - }, - copySize: normalizeGPUExtent3D(copySize), + texture: sourceTextureRid, + mipLevel: source.mipLevel, + origin: source.origin + ? normalizeGPUOrigin3D(source.origin) + : undefined, + aspect: source.aspect, + }, + { + ...destination, + buffer: destinationBufferRid, }, + normalizeGPUExtent3D(copySize), ); device.pushError(err); } @@ -3033,26 +3020,24 @@ }); const { err } = core.opSync( "op_webgpu_command_encoder_copy_texture_to_texture", + commandEncoderRid, { - commandEncoderRid, - source: { - texture: sourceTextureRid, - mipLevel: source.mipLevel, - origin: source.origin - ? normalizeGPUOrigin3D(source.origin) - : undefined, - aspect: source.aspect, - }, - destination: { - texture: destinationTextureRid, - mipLevel: destination.mipLevel, - origin: destination.origin - ? normalizeGPUOrigin3D(destination.origin) - : undefined, - aspect: source.aspect, - }, - copySize: normalizeGPUExtent3D(copySize), + texture: sourceTextureRid, + mipLevel: source.mipLevel, + origin: source.origin + ? normalizeGPUOrigin3D(source.origin) + : undefined, + aspect: source.aspect, }, + { + texture: destinationTextureRid, + mipLevel: destination.mipLevel, + origin: destination.origin + ? normalizeGPUOrigin3D(destination.origin) + : undefined, + aspect: source.aspect, + }, + normalizeGPUExtent3D(copySize), ); device.pushError(err); } @@ -3089,12 +3074,10 @@ }); const { err } = core.opSync( "op_webgpu_command_encoder_clear_buffer", - { - commandEncoderRid, - bufferRid, - offset, - size, - }, + commandEncoderRid, + bufferRid, + offset, + size, ); device.pushError(err); } @@ -3118,10 +3101,8 @@ }); const { err } = core.opSync( "op_webgpu_command_encoder_push_debug_group", - { - commandEncoderRid, - groupLabel, - }, + commandEncoderRid, + groupLabel, ); device.pushError(err); } @@ -3136,9 +3117,7 @@ }); const { err } = core.opSync( "op_webgpu_command_encoder_pop_debug_group", - { - commandEncoderRid, - }, + commandEncoderRid, ); device.pushError(err); } @@ -3162,10 +3141,8 @@ }); const { err } = core.opSync( "op_webgpu_command_encoder_insert_debug_marker", - { - commandEncoderRid, - markerLabel, - }, + commandEncoderRid, + markerLabel, ); device.pushError(err); } @@ -3203,11 +3180,9 @@ }); const { err } = core.opSync( "op_webgpu_command_encoder_write_timestamp", - { - commandEncoderRid, - querySet: querySetRid, - queryIndex, - }, + commandEncoderRid, + querySetRid, + queryIndex, ); device.pushError(err); } @@ -3275,14 +3250,12 @@ }); const { err } = core.opSync( "op_webgpu_command_encoder_resolve_query_set", - { - commandEncoderRid, - querySet: querySetRid, - firstQuery, - queryCount, - destination: destinationRid, - destinationOffset, - }, + commandEncoderRid, + querySetRid, + firstQuery, + queryCount, + destinationRid, + destinationOffset, ); device.pushError(err); } @@ -3303,10 +3276,11 @@ prefix, context: "this", }); - const { rid, err } = core.opSync("op_webgpu_command_encoder_finish", { + const { rid, err } = core.opSync( + "op_webgpu_command_encoder_finish", commandEncoderRid, - ...descriptor, - }); + descriptor.label, + ); device.pushError(err); /** @type {number | undefined} */ this[_rid] = undefined; @@ -3451,13 +3425,14 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_render_pass_set_scissor_rect", { + core.opSync( + "op_webgpu_render_pass_set_scissor_rect", renderPassRid, x, y, width, height, - }); + ); } /** @@ -3481,10 +3456,11 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_render_pass_set_blend_constant", { + core.opSync( + "op_webgpu_render_pass_set_blend_constant", renderPassRid, - color: normalizeGPUColor(color), - }); + normalizeGPUColor(color), + ); } /** @@ -3508,10 +3484,11 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_render_pass_set_stencil_reference", { + core.opSync( + "op_webgpu_render_pass_set_stencil_reference", renderPassRid, reference, - }); + ); } beginOcclusionQuery(_queryIndex) { @@ -3557,11 +3534,12 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_render_pass_begin_pipeline_statistics_query", { + core.opSync( + "op_webgpu_render_pass_begin_pipeline_statistics_query", renderPassRid, - querySet: querySetRid, + querySetRid, queryIndex, - }); + ); } endPipelineStatisticsQuery() { @@ -3577,9 +3555,10 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_render_pass_end_pipeline_statistics_query", { + core.opSync( + "op_webgpu_render_pass_end_pipeline_statistics_query", renderPassRid, - }); + ); } /** @@ -3617,11 +3596,12 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_render_pass_write_timestamp", { + core.opSync( + "op_webgpu_render_pass_write_timestamp", renderPassRid, - querySet: querySetRid, + querySetRid, queryIndex, - }); + ); } /** @@ -3655,10 +3635,11 @@ }); return rid; }); - core.opSync("op_webgpu_render_pass_execute_bundles", { + core.opSync( + "op_webgpu_render_pass_execute_bundles", renderPassRid, - bundles: bundleRids, - }); + bundleRids, + ); } end() { @@ -3673,10 +3654,11 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - const { err } = core.opSync("op_webgpu_render_pass_end", { + const { err } = core.opSync( + "op_webgpu_render_pass_end", commandEncoderRid, renderPassRid, - }); + ); device.pushError(err); this[_rid] = undefined; } @@ -3720,14 +3702,15 @@ dynamicOffsetsDataStart = 0; dynamicOffsetsDataLength = dynamicOffsetsData.length; } - core.opSync("op_webgpu_render_pass_set_bind_group", { + core.opSync( + "op_webgpu_render_pass_set_bind_group", renderPassRid, index, - bindGroup: bindGroupRid, + bindGroupRid, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength, - }); + ); } /** @@ -3751,10 +3734,11 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_render_pass_push_debug_group", { + core.opSync( + "op_webgpu_render_pass_push_debug_group", renderPassRid, groupLabel, - }); + ); } popDebugGroup() { @@ -3770,9 +3754,7 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_render_pass_pop_debug_group", { - renderPassRid, - }); + core.opSync("op_webgpu_render_pass_pop_debug_group", renderPassRid); } /** @@ -3796,10 +3778,11 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_render_pass_insert_debug_marker", { + core.opSync( + "op_webgpu_render_pass_insert_debug_marker", renderPassRid, markerLabel, - }); + ); } /** @@ -3832,10 +3815,11 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_render_pass_set_pipeline", { + core.opSync( + "op_webgpu_render_pass_set_pipeline", renderPassRid, - pipeline: pipelineRid, - }); + pipelineRid, + ); } /** @@ -3885,13 +3869,14 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_render_pass_set_index_buffer", { + core.opSync( + "op_webgpu_render_pass_set_index_buffer", renderPassRid, - buffer: bufferRid, + bufferRid, indexFormat, offset, size, - }); + ); } /** @@ -3941,13 +3926,14 @@ resourceContext: "Argument 2", selfContext: "this", }); - core.opSync("op_webgpu_render_pass_set_vertex_buffer", { + core.opSync( + "op_webgpu_render_pass_set_vertex_buffer", renderPassRid, slot, - buffer: bufferRid, + bufferRid, offset, size, - }); + ); } /** @@ -3985,13 +3971,14 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_render_pass_draw", { + core.opSync( + "op_webgpu_render_pass_draw", renderPassRid, vertexCount, instanceCount, firstVertex, firstInstance, - }); + ); } /** @@ -4041,14 +4028,15 @@ context: "encoder referenced by this", }); const renderPassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_render_pass_draw_indexed", { + core.opSync( + "op_webgpu_render_pass_draw_indexed", renderPassRid, indexCount, instanceCount, firstIndex, baseVertex, firstInstance, - }); + ); } /** @@ -4086,11 +4074,12 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_render_pass_draw_indirect", { + core.opSync( + "op_webgpu_render_pass_draw_indirect", renderPassRid, - indirectBuffer: indirectBufferRid, + indirectBufferRid, indirectOffset, - }); + ); } /** @@ -4128,11 +4117,12 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_render_pass_draw_indexed_indirect", { + core.opSync( + "op_webgpu_render_pass_draw_indexed_indirect", renderPassRid, - indirectBuffer: indirectBufferRid, + indirectBufferRid, indirectOffset, - }); + ); } [SymbolFor("Deno.privateCustomInspect")](inspect) { @@ -4211,10 +4201,11 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_compute_pass_set_pipeline", { + core.opSync( + "op_webgpu_compute_pass_set_pipeline", computePassRid, - pipeline: pipelineRid, - }); + pipelineRid, + ); } /** @@ -4247,12 +4238,13 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_compute_pass_dispatch", { + core.opSync( + "op_webgpu_compute_pass_dispatch", computePassRid, - x: workgroupCountX, - y: workgroupCountY, - z: workgroupCountZ, - }); + workgroupCountX, + workgroupCountY, + workgroupCountZ, + ); } /** @@ -4290,11 +4282,12 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_compute_pass_dispatch_indirect", { - computePassRid: computePassRid, - indirectBuffer: indirectBufferRid, + core.opSync( + "op_webgpu_compute_pass_dispatch_indirect", + computePassRid, + indirectBufferRid, indirectOffset, - }); + ); } /** @@ -4334,11 +4327,9 @@ }); core.opSync( "op_webgpu_compute_pass_begin_pipeline_statistics_query", - { - computePassRid, - querySet: querySetRid, - queryIndex, - }, + computePassRid, + querySetRid, + queryIndex, ); } @@ -4355,9 +4346,10 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_compute_pass_end_pipeline_statistics_query", { + core.opSync( + "op_webgpu_compute_pass_end_pipeline_statistics_query", computePassRid, - }); + ); } /** @@ -4395,11 +4387,12 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_compute_pass_write_timestamp", { + core.opSync( + "op_webgpu_compute_pass_write_timestamp", computePassRid, - querySet: querySetRid, + querySetRid, queryIndex, - }); + ); } end() { @@ -4414,10 +4407,11 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - const { err } = core.opSync("op_webgpu_compute_pass_end", { + const { err } = core.opSync( + "op_webgpu_compute_pass_end", commandEncoderRid, computePassRid, - }); + ); device.pushError(err); this[_rid] = undefined; } @@ -4461,14 +4455,15 @@ dynamicOffsetsDataStart = 0; dynamicOffsetsDataLength = dynamicOffsetsData.length; } - core.opSync("op_webgpu_compute_pass_set_bind_group", { + core.opSync( + "op_webgpu_compute_pass_set_bind_group", computePassRid, index, - bindGroup: bindGroupRid, + bindGroupRid, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength, - }); + ); } /** @@ -4492,10 +4487,11 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_compute_pass_push_debug_group", { + core.opSync( + "op_webgpu_compute_pass_push_debug_group", computePassRid, groupLabel, - }); + ); } popDebugGroup() { @@ -4511,9 +4507,7 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_compute_pass_pop_debug_group", { - computePassRid, - }); + core.opSync("op_webgpu_compute_pass_pop_debug_group", computePassRid); } /** @@ -4537,10 +4531,11 @@ context: "encoder referenced by this", }); const computePassRid = assertResource(this, { prefix, context: "this" }); - core.opSync("op_webgpu_compute_pass_insert_debug_marker", { + core.opSync( + "op_webgpu_compute_pass_insert_debug_marker", computePassRid, markerLabel, - }); + ); } [SymbolFor("Deno.privateCustomInspect")](inspect) { @@ -4649,10 +4644,8 @@ }); const { rid, err } = core.opSync( "op_webgpu_render_bundle_encoder_finish", - { - renderBundleEncoderRid, - ...descriptor, - }, + renderBundleEncoderRid, + descriptor.label, ); device.pushError(err); this[_rid] = undefined; @@ -4701,14 +4694,15 @@ dynamicOffsetsDataStart = 0; dynamicOffsetsDataLength = dynamicOffsetsData.length; } - core.opSync("op_webgpu_render_bundle_encoder_set_bind_group", { + core.opSync( + "op_webgpu_render_bundle_encoder_set_bind_group", renderBundleEncoderRid, index, - bindGroup: bindGroupRid, + bindGroupRid, dynamicOffsetsData, dynamicOffsetsDataStart, dynamicOffsetsDataLength, - }); + ); } /** @@ -4728,10 +4722,11 @@ prefix, context: "this", }); - core.opSync("op_webgpu_render_bundle_encoder_push_debug_group", { + core.opSync( + "op_webgpu_render_bundle_encoder_push_debug_group", renderBundleEncoderRid, groupLabel, - }); + ); } popDebugGroup() { @@ -4743,9 +4738,10 @@ prefix, context: "this", }); - core.opSync("op_webgpu_render_bundle_encoder_pop_debug_group", { + core.opSync( + "op_webgpu_render_bundle_encoder_pop_debug_group", renderBundleEncoderRid, - }); + ); } /** @@ -4765,10 +4761,11 @@ prefix, context: "this", }); - core.opSync("op_webgpu_render_bundle_encoder_push_debug_group", { + core.opSync( + "op_webgpu_render_bundle_encoder_insert_debug_marker", renderBundleEncoderRid, markerLabel, - }); + ); } /** @@ -4797,10 +4794,11 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_render_bundle_encoder_set_pipeline", { + core.opSync( + "op_webgpu_render_bundle_encoder_set_pipeline", renderBundleEncoderRid, - pipeline: pipelineRid, - }); + pipelineRid, + ); } /** @@ -4844,13 +4842,14 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_render_bundle_encoder_set_index_buffer", { + core.opSync( + "op_webgpu_render_bundle_encoder_set_index_buffer", renderBundleEncoderRid, - buffer: bufferRid, + bufferRid, indexFormat, offset, size, - }); + ); } /** @@ -4894,13 +4893,14 @@ resourceContext: "Argument 2", selfContext: "this", }); - core.opSync("op_webgpu_render_bundle_encoder_set_vertex_buffer", { + core.opSync( + "op_webgpu_render_bundle_encoder_set_vertex_buffer", renderBundleEncoderRid, slot, - buffer: bufferRid, + bufferRid, offset, size, - }); + ); } /** @@ -4934,13 +4934,14 @@ prefix, context: "this", }); - core.opSync("op_webgpu_render_bundle_encoder_draw", { + core.opSync( + "op_webgpu_render_bundle_encoder_draw", renderBundleEncoderRid, vertexCount, instanceCount, firstVertex, firstInstance, - }); + ); } /** @@ -4986,14 +4987,15 @@ prefix, context: "this", }); - core.opSync("op_webgpu_render_bundle_encoder_draw_indexed", { + core.opSync( + "op_webgpu_render_bundle_encoder_draw_indexed", renderBundleEncoderRid, indexCount, instanceCount, firstIndex, baseVertex, firstInstance, - }); + ); } /** @@ -5027,11 +5029,12 @@ resourceContext: "Argument 1", selfContext: "this", }); - core.opSync("op_webgpu_render_bundle_encoder_draw_indirect", { + core.opSync( + "op_webgpu_render_bundle_encoder_draw_indirect", renderBundleEncoderRid, - indirectBuffer: indirectBufferRid, + indirectBufferRid, indirectOffset, - }); + ); } drawIndexedIndirect(_indirectBuffer, _indirectOffset) { diff --git a/deno_webgpu/Cargo.toml b/deno_webgpu/Cargo.toml index d7a6a76583..80a914fbb1 100644 --- a/deno_webgpu/Cargo.toml +++ b/deno_webgpu/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_webgpu" -version = "0.17.0" +version = "0.44.0" authors = ["the Deno authors"] edition = "2018" license = "MIT" @@ -11,7 +11,7 @@ repository = "https://github.com/gfx-rs/wgpu" description = "WebGPU implementation for Deno" [dependencies] -deno_core = "0.124.0" +deno_core = "0.125.0" serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.10", features = ["full"] } wgpu-core = { path = "../wgpu-core", features = ["trace", "replay", "serde"] } diff --git a/deno_webgpu/src/binding.rs b/deno_webgpu/src/binding.rs index 2685ca7780..3cd5c975aa 100644 --- a/deno_webgpu/src/binding.rs +++ b/deno_webgpu/src/binding.rs @@ -7,8 +7,6 @@ use deno_core::Resource; use deno_core::ResourceId; use serde::Deserialize; use std::borrow::Cow; -use std::convert::TryFrom; -use std::convert::TryInto; use super::error::WebGpuResult; @@ -120,7 +118,7 @@ impl From for wgpu_types::StorageTextureAccess { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct GpuBindGroupLayoutEntry { +pub struct GpuBindGroupLayoutEntry { binding: u32, visibility: u32, #[serde(flatten)] @@ -136,11 +134,9 @@ enum GpuBindingType { StorageTexture(GpuStorageTextureBindingLayout), } -impl TryFrom for wgpu_types::BindingType { - type Error = AnyError; - - fn try_from(binding_type: GpuBindingType) -> Result { - let binding_type = match binding_type { +impl From for wgpu_types::BindingType { + fn from(binding_type: GpuBindingType) -> wgpu_types::BindingType { + match binding_type { GpuBindingType::Buffer(buffer) => wgpu_types::BindingType::Buffer { ty: buffer.r#type.into(), has_dynamic_offset: buffer.has_dynamic_offset, @@ -159,43 +155,37 @@ impl TryFrom for wgpu_types::BindingType { view_dimension: storage_texture.view_dimension, } } - }; - Ok(binding_type) + } } } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateBindGroupLayoutArgs { - device_rid: ResourceId, - label: Option, - entries: Vec, -} - #[op] pub fn op_webgpu_create_bind_group_layout( state: &mut OpState, - args: CreateBindGroupLayoutArgs, + device_rid: ResourceId, + label: Option, + entries: Vec, ) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table - .get::(args.device_rid)?; + .get::(device_rid)?; let device = device_resource.0; - let mut entries = vec![]; - - for entry in args.entries { - entries.push(wgpu_types::BindGroupLayoutEntry { - binding: entry.binding, - visibility: wgpu_types::ShaderStages::from_bits(entry.visibility).unwrap(), - ty: entry.binding_type.try_into()?, - count: None, // native-only - }); - } + let entries = entries + .into_iter() + .map(|entry| { + wgpu_types::BindGroupLayoutEntry { + binding: entry.binding, + visibility: wgpu_types::ShaderStages::from_bits(entry.visibility).unwrap(), + ty: entry.binding_type.into(), + count: None, // native-only + } + }) + .collect::>(); let descriptor = wgpu_core::binding_model::BindGroupLayoutDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), entries: Cow::from(entries), }; @@ -206,34 +196,29 @@ pub fn op_webgpu_create_bind_group_layout( ) => state, WebGpuBindGroupLayout) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreatePipelineLayoutArgs { - device_rid: ResourceId, - label: Option, - bind_group_layouts: Vec, -} - #[op] pub fn op_webgpu_create_pipeline_layout( state: &mut OpState, - args: CreatePipelineLayoutArgs, + device_rid: ResourceId, + label: Option, + bind_group_layouts: Vec, ) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table - .get::(args.device_rid)?; + .get::(device_rid)?; let device = device_resource.0; - let mut bind_group_layouts = vec![]; - - for rid in &args.bind_group_layouts { - let bind_group_layout = state.resource_table.get::(*rid)?; - bind_group_layouts.push(bind_group_layout.0); - } + let bind_group_layouts = bind_group_layouts + .into_iter() + .map(|rid| { + let bind_group_layout = state.resource_table.get::(rid)?; + Ok(bind_group_layout.0) + }) + .collect::, AnyError>>()?; let descriptor = wgpu_core::binding_model::PipelineLayoutDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), bind_group_layouts: Cow::from(bind_group_layouts), push_constant_ranges: Default::default(), }; @@ -247,7 +232,7 @@ pub fn op_webgpu_create_pipeline_layout( #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct GpuBindGroupEntry { +pub struct GpuBindGroupEntry { binding: u32, kind: String, resource: ResourceId, @@ -255,69 +240,63 @@ struct GpuBindGroupEntry { size: Option, } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateBindGroupArgs { +#[op] +pub fn op_webgpu_create_bind_group( + state: &mut OpState, device_rid: ResourceId, label: Option, layout: ResourceId, entries: Vec, -} - -#[op] -pub fn op_webgpu_create_bind_group( - state: &mut OpState, - args: CreateBindGroupArgs, ) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table - .get::(args.device_rid)?; + .get::(device_rid)?; let device = device_resource.0; - let mut entries = vec![]; - - for entry in &args.entries { - let e = wgpu_core::binding_model::BindGroupEntry { - binding: entry.binding, - resource: match entry.kind.as_str() { - "GPUSampler" => { - let sampler_resource = state - .resource_table - .get::(entry.resource)?; - wgpu_core::binding_model::BindingResource::Sampler(sampler_resource.0) - } - "GPUTextureView" => { - let texture_view_resource = - state + let entries = entries + .into_iter() + .map(|entry| { + Ok(wgpu_core::binding_model::BindGroupEntry { + binding: entry.binding, + resource: match entry.kind.as_str() { + "GPUSampler" => { + let sampler_resource = state .resource_table - .get::(entry.resource)?; - wgpu_core::binding_model::BindingResource::TextureView(texture_view_resource.0) - } - "GPUBufferBinding" => { - let buffer_resource = state - .resource_table - .get::(entry.resource)?; - wgpu_core::binding_model::BindingResource::Buffer( - wgpu_core::binding_model::BufferBinding { - buffer_id: buffer_resource.0, - offset: entry.offset.unwrap_or(0), - size: std::num::NonZeroU64::new(entry.size.unwrap_or(0)), - }, - ) - } - _ => unreachable!(), - }, - }; - entries.push(e); - } - - let bind_group_layout = state - .resource_table - .get::(args.layout)?; + .get::(entry.resource)?; + wgpu_core::binding_model::BindingResource::Sampler(sampler_resource.0) + } + "GPUTextureView" => { + let texture_view_resource = + state + .resource_table + .get::(entry.resource)?; + wgpu_core::binding_model::BindingResource::TextureView( + texture_view_resource.0, + ) + } + "GPUBufferBinding" => { + let buffer_resource = state + .resource_table + .get::(entry.resource)?; + wgpu_core::binding_model::BindingResource::Buffer( + wgpu_core::binding_model::BufferBinding { + buffer_id: buffer_resource.0, + offset: entry.offset.unwrap_or(0), + size: std::num::NonZeroU64::new(entry.size.unwrap_or(0)), + }, + ) + } + _ => unreachable!(), + }, + }) + }) + .collect::, AnyError>>()?; + + let bind_group_layout = state.resource_table.get::(layout)?; let descriptor = wgpu_core::binding_model::BindGroupDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), layout: bind_group_layout.0, entries: Cow::from(entries), }; diff --git a/deno_webgpu/src/buffer.rs b/deno_webgpu/src/buffer.rs index 30c0d2173f..845f218372 100644 --- a/deno_webgpu/src/buffer.rs +++ b/deno_webgpu/src/buffer.rs @@ -8,7 +8,6 @@ use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use deno_core::ZeroCopyBuf; -use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; use std::convert::TryFrom; @@ -32,33 +31,27 @@ impl Resource for WebGpuBufferMapped { } } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateBufferArgs { +#[op] +pub fn op_webgpu_create_buffer( + state: &mut OpState, device_rid: ResourceId, label: Option, size: u64, usage: u32, mapped_at_creation: bool, -} - -#[op] -pub fn op_webgpu_create_buffer( - state: &mut OpState, - args: CreateBufferArgs, ) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table - .get::(args.device_rid)?; + .get::(device_rid)?; let device = device_resource.0; let descriptor = wgpu_core::resource::BufferDescriptor { - label: args.label.map(Cow::from), - size: args.size, - usage: wgpu_types::BufferUsages::from_bits(args.usage) + label: label.map(Cow::from), + size, + usage: wgpu_types::BufferUsages::from_bits(usage) .ok_or_else(|| type_error("usage is not valid"))?, - mapped_at_creation: args.mapped_at_creation, + mapped_at_creation, }; gfx_put!(device => instance.device_create_buffer( @@ -68,20 +61,14 @@ pub fn op_webgpu_create_buffer( ) => state, WebGpuBuffer) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct BufferGetMapAsyncArgs { +#[op] +pub async fn op_webgpu_buffer_get_map_async( + state: Rc>, buffer_rid: ResourceId, device_rid: ResourceId, mode: u32, offset: u64, size: u64, -} - -#[op] -pub async fn op_webgpu_buffer_get_map_async( - state: Rc>, - args: BufferGetMapAsyncArgs, ) -> Result { let (sender, receiver) = oneshot::channel::>(); @@ -89,11 +76,11 @@ pub async fn op_webgpu_buffer_get_map_async( { let state_ = state.borrow(); let instance = state_.borrow::(); - let buffer_resource = state_.resource_table.get::(args.buffer_rid)?; + let buffer_resource = state_.resource_table.get::(buffer_rid)?; let buffer = buffer_resource.0; let device_resource = state_ .resource_table - .get::(args.device_rid)?; + .get::(device_rid)?; device = device_resource.0; let boxed_sender = Box::new(sender); @@ -116,9 +103,9 @@ pub async fn op_webgpu_buffer_get_map_async( // TODO(lucacasonato): error handling let maybe_err = gfx_select!(buffer => instance.buffer_map_async( buffer, - args.offset..(args.offset + args.size), + offset..(offset + size), wgpu_core::resource::BufferMapOperation { - host: match args.mode { + host: match mode { 1 => wgpu_core::device::HostMap::Read, 2 => wgpu_core::device::HostMap::Write, _ => unreachable!(), @@ -160,33 +147,27 @@ pub async fn op_webgpu_buffer_get_map_async( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct BufferGetMappedRangeArgs { - buffer_rid: ResourceId, - offset: u64, - size: Option, -} - #[op] pub fn op_webgpu_buffer_get_mapped_range( state: &mut OpState, - args: BufferGetMappedRangeArgs, - mut zero_copy: ZeroCopyBuf, + buffer_rid: ResourceId, + offset: u64, + size: Option, + mut buf: ZeroCopyBuf, ) -> Result { let instance = state.borrow::(); - let buffer_resource = state.resource_table.get::(args.buffer_rid)?; + let buffer_resource = state.resource_table.get::(buffer_rid)?; let buffer = buffer_resource.0; let (slice_pointer, range_size) = gfx_select!(buffer => instance.buffer_get_mapped_range( buffer, - args.offset, - args.size + offset, + size )) .map_err(|e| DomExceptionOperationError::new(&e.to_string()))?; let slice = unsafe { std::slice::from_raw_parts_mut(slice_pointer, range_size as usize) }; - zero_copy.copy_from_slice(slice); + buf.copy_from_slice(slice); let rid = state .resource_table @@ -195,32 +176,23 @@ pub fn op_webgpu_buffer_get_mapped_range( Ok(WebGpuResult::rid(rid)) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct BufferUnmapArgs { - buffer_rid: ResourceId, - mapped_rid: ResourceId, -} - #[op] pub fn op_webgpu_buffer_unmap( state: &mut OpState, - args: BufferUnmapArgs, - zero_copy: Option, + buffer_rid: ResourceId, + mapped_rid: ResourceId, + buf: Option, ) -> Result { let mapped_resource = state .resource_table - .take::(args.mapped_rid)?; + .take::(mapped_rid)?; let instance = state.borrow::(); - let buffer_resource = state.resource_table.get::(args.buffer_rid)?; + let buffer_resource = state.resource_table.get::(buffer_rid)?; let buffer = buffer_resource.0; - let slice_pointer = mapped_resource.0; - let size = mapped_resource.1; - - if let Some(buffer) = zero_copy { - let slice = unsafe { std::slice::from_raw_parts_mut(slice_pointer, size) }; - slice.copy_from_slice(&buffer); + if let Some(buf) = buf { + let slice = unsafe { std::slice::from_raw_parts_mut(mapped_resource.0, mapped_resource.1) }; + slice.copy_from_slice(&buf); } gfx_ok!(buffer => instance.buffer_unmap(buffer)) diff --git a/deno_webgpu/src/bundle.rs b/deno_webgpu/src/bundle.rs index a284274eb9..d75d0c5710 100644 --- a/deno_webgpu/src/bundle.rs +++ b/deno_webgpu/src/bundle.rs @@ -49,15 +49,13 @@ pub fn op_webgpu_create_render_bundle_encoder( .get::(args.device_rid)?; let device = device_resource.0; - let depth_stencil = if let Some(format) = args.depth_stencil_format { - Some(wgpu_types::RenderBundleDepthStencil { - format, - depth_read_only: args.depth_read_only, - stencil_read_only: args.stencil_read_only, - }) - } else { - None - }; + let depth_stencil = + args.depth_stencil_format + .map(|format| wgpu_types::RenderBundleDepthStencil { + format, + depth_read_only: args.depth_read_only, + stencil_read_only: args.stencil_read_only, + }); let descriptor = wgpu_core::command::RenderBundleEncoderDescriptor { label: args.label.map(Cow::from), @@ -85,21 +83,15 @@ pub fn op_webgpu_create_render_bundle_encoder( Ok(WebGpuResult::rid_err(rid, maybe_err)) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderFinishArgs { - render_bundle_encoder_rid: ResourceId, - label: Option, -} - #[op] pub fn op_webgpu_render_bundle_encoder_finish( state: &mut OpState, - args: RenderBundleEncoderFinishArgs, + render_bundle_encoder_rid: ResourceId, + label: Option, ) -> Result { let render_bundle_encoder_resource = state .resource_table - .take::(args.render_bundle_encoder_rid)?; + .take::(render_bundle_encoder_rid)?; let render_bundle_encoder = Rc::try_unwrap(render_bundle_encoder_resource) .ok() .expect("unwrapping render_bundle_encoder_resource should succeed") @@ -110,46 +102,39 @@ pub fn op_webgpu_render_bundle_encoder_finish( gfx_put!(render_bundle_encoder.parent() => instance.render_bundle_encoder_finish( render_bundle_encoder, &wgpu_core::command::RenderBundleDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), }, std::marker::PhantomData ) => state, WebGpuRenderBundle) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderSetBindGroupArgs { +#[op] +pub fn op_webgpu_render_bundle_encoder_set_bind_group( + state: &mut OpState, render_bundle_encoder_rid: ResourceId, index: u32, bind_group: ResourceId, dynamic_offsets_data: ZeroCopyBuf, dynamic_offsets_data_start: usize, dynamic_offsets_data_length: usize, -} - -#[op] -pub fn op_webgpu_render_bundle_encoder_set_bind_group( - state: &mut OpState, - args: RenderBundleEncoderSetBindGroupArgs, ) -> Result { let bind_group_resource = state .resource_table - .get::(args.bind_group)?; + .get::(bind_group)?; let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; // Align the data - assert!(args.dynamic_offsets_data.len() % std::mem::size_of::() == 0); + assert!(dynamic_offsets_data.len() % std::mem::size_of::() == 0); // SAFETY: A u8 to u32 cast is safe because we asserted that the length is a // multiple of 4. - let (prefix, dynamic_offsets_data, suffix) = - unsafe { args.dynamic_offsets_data.align_to::() }; + let (prefix, dynamic_offsets_data, suffix) = unsafe { dynamic_offsets_data.align_to::() }; assert!(prefix.is_empty()); assert!(suffix.is_empty()); - let start = args.dynamic_offsets_data_start; - let len = args.dynamic_offsets_data_length; + let start = dynamic_offsets_data_start; + let len = dynamic_offsets_data_length; // Assert that length and start are both in bounds assert!(start <= dynamic_offsets_data.len()); @@ -162,7 +147,7 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group( unsafe { wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_bind_group( &mut render_bundle_encoder_resource.0.borrow_mut(), - args.index, + index, bind_group_resource.0, dynamic_offsets_data.as_ptr(), dynamic_offsets_data.len(), @@ -172,23 +157,17 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderPushDebugGroupArgs { - render_bundle_encoder_rid: ResourceId, - group_label: String, -} - #[op] pub fn op_webgpu_render_bundle_encoder_push_debug_group( state: &mut OpState, - args: RenderBundleEncoderPushDebugGroupArgs, + render_bundle_encoder_rid: ResourceId, + group_label: String, ) -> Result { let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; - let label = std::ffi::CString::new(args.group_label).unwrap(); + let label = std::ffi::CString::new(group_label).unwrap(); // SAFETY: the string the raw pointer points to lives longer than the below // function invocation. unsafe { @@ -201,20 +180,14 @@ pub fn op_webgpu_render_bundle_encoder_push_debug_group( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderPopDebugGroupArgs { - render_bundle_encoder_rid: ResourceId, -} - #[op] pub fn op_webgpu_render_bundle_encoder_pop_debug_group( state: &mut OpState, - args: RenderBundleEncoderPopDebugGroupArgs, + render_bundle_encoder_rid: ResourceId, ) -> Result { let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; wgpu_core::command::bundle_ffi::wgpu_render_bundle_pop_debug_group( &mut render_bundle_encoder_resource.0.borrow_mut(), @@ -223,23 +196,17 @@ pub fn op_webgpu_render_bundle_encoder_pop_debug_group( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderInsertDebugMarkerArgs { - render_bundle_encoder_rid: ResourceId, - marker_label: String, -} - #[op] pub fn op_webgpu_render_bundle_encoder_insert_debug_marker( state: &mut OpState, - args: RenderBundleEncoderInsertDebugMarkerArgs, + render_bundle_encoder_rid: ResourceId, + marker_label: String, ) -> Result { let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; - let label = std::ffi::CString::new(args.marker_label).unwrap(); + let label = std::ffi::CString::new(marker_label).unwrap(); // SAFETY: the string the raw pointer points to lives longer than the below // function invocation. unsafe { @@ -252,24 +219,18 @@ pub fn op_webgpu_render_bundle_encoder_insert_debug_marker( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderSetPipelineArgs { - render_bundle_encoder_rid: ResourceId, - pipeline: ResourceId, -} - #[op] pub fn op_webgpu_render_bundle_encoder_set_pipeline( state: &mut OpState, - args: RenderBundleEncoderSetPipelineArgs, + render_bundle_encoder_rid: ResourceId, + pipeline: ResourceId, ) -> Result { let render_pipeline_resource = state .resource_table - .get::(args.pipeline)?; + .get::(pipeline)?; let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_pipeline( &mut render_bundle_encoder_resource.0.borrow_mut(), @@ -279,160 +240,130 @@ pub fn op_webgpu_render_bundle_encoder_set_pipeline( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderSetIndexBufferArgs { +#[op] +pub fn op_webgpu_render_bundle_encoder_set_index_buffer( + state: &mut OpState, render_bundle_encoder_rid: ResourceId, buffer: ResourceId, index_format: wgpu_types::IndexFormat, offset: u64, size: u64, -} - -#[op] -pub fn op_webgpu_render_bundle_encoder_set_index_buffer( - state: &mut OpState, - args: RenderBundleEncoderSetIndexBufferArgs, ) -> Result { let buffer_resource = state .resource_table - .get::(args.buffer)?; + .get::(buffer)?; let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; render_bundle_encoder_resource .0 .borrow_mut() .set_index_buffer( buffer_resource.0, - args.index_format, - args.offset, - std::num::NonZeroU64::new(args.size), + index_format, + offset, + std::num::NonZeroU64::new(size), ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderSetVertexBufferArgs { +#[op] +pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer( + state: &mut OpState, render_bundle_encoder_rid: ResourceId, slot: u32, buffer: ResourceId, offset: u64, size: u64, -} - -#[op] -pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer( - state: &mut OpState, - args: RenderBundleEncoderSetVertexBufferArgs, ) -> Result { let buffer_resource = state .resource_table - .get::(args.buffer)?; + .get::(buffer)?; let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_vertex_buffer( &mut render_bundle_encoder_resource.0.borrow_mut(), - args.slot, + slot, buffer_resource.0, - args.offset, - std::num::NonZeroU64::new(args.size), + offset, + std::num::NonZeroU64::new(size), ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderDrawArgs { +#[op] +pub fn op_webgpu_render_bundle_encoder_draw( + state: &mut OpState, render_bundle_encoder_rid: ResourceId, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32, -} - -#[op] -pub fn op_webgpu_render_bundle_encoder_draw( - state: &mut OpState, - args: RenderBundleEncoderDrawArgs, ) -> Result { let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw( &mut render_bundle_encoder_resource.0.borrow_mut(), - args.vertex_count, - args.instance_count, - args.first_vertex, - args.first_instance, + vertex_count, + instance_count, + first_vertex, + first_instance, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderDrawIndexedArgs { +#[op] +pub fn op_webgpu_render_bundle_encoder_draw_indexed( + state: &mut OpState, render_bundle_encoder_rid: ResourceId, index_count: u32, instance_count: u32, first_index: u32, base_vertex: i32, first_instance: u32, -} - -#[op] -pub fn op_webgpu_render_bundle_encoder_draw_indexed( - state: &mut OpState, - args: RenderBundleEncoderDrawIndexedArgs, ) -> Result { let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw_indexed( &mut render_bundle_encoder_resource.0.borrow_mut(), - args.index_count, - args.instance_count, - args.first_index, - args.base_vertex, - args.first_instance, + index_count, + instance_count, + first_index, + base_vertex, + first_instance, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderBundleEncoderDrawIndirectArgs { - render_bundle_encoder_rid: ResourceId, - indirect_buffer: ResourceId, - indirect_offset: u64, -} - #[op] pub fn op_webgpu_render_bundle_encoder_draw_indirect( state: &mut OpState, - args: RenderBundleEncoderDrawIndirectArgs, + render_bundle_encoder_rid: ResourceId, + indirect_buffer: ResourceId, + indirect_offset: u64, ) -> Result { let buffer_resource = state .resource_table - .get::(args.indirect_buffer)?; + .get::(indirect_buffer)?; let render_bundle_encoder_resource = state .resource_table - .get::(args.render_bundle_encoder_rid)?; + .get::(render_bundle_encoder_rid)?; wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw_indirect( &mut render_bundle_encoder_resource.0.borrow_mut(), buffer_resource.0, - args.indirect_offset, + indirect_offset, ); Ok(WebGpuResult::empty()) diff --git a/deno_webgpu/src/command_encoder.rs b/deno_webgpu/src/command_encoder.rs index a92d2679ab..3064f5c297 100644 --- a/deno_webgpu/src/command_encoder.rs +++ b/deno_webgpu/src/command_encoder.rs @@ -26,27 +26,20 @@ impl Resource for WebGpuCommandBuffer { } } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateCommandEncoderArgs { - device_rid: ResourceId, - label: Option, - _measure_execution_time: Option, // not yet implemented -} - #[op] pub fn op_webgpu_create_command_encoder( state: &mut OpState, - args: CreateCommandEncoderArgs, + device_rid: ResourceId, + label: Option, ) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table - .get::(args.device_rid)?; + .get::(device_rid)?; let device = device_resource.0; let descriptor = wgpu_types::CommandEncoderDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), }; gfx_put!(device => instance.device_create_command_encoder( @@ -68,7 +61,7 @@ pub struct GpuRenderPassColorAttachment { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct GpuRenderPassDepthStencilAttachment { +pub struct GpuRenderPassDepthStencilAttachment { view: ResourceId, depth_clear_value: f32, depth_load_op: wgpu_core::command::LoadOp, @@ -80,84 +73,78 @@ struct GpuRenderPassDepthStencilAttachment { stencil_read_only: bool, } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderBeginRenderPassArgs { +#[op] +pub fn op_webgpu_command_encoder_begin_render_pass( + state: &mut OpState, command_encoder_rid: ResourceId, label: Option, color_attachments: Vec, depth_stencil_attachment: Option, _occlusion_query_set: Option, // not yet implemented -} - -#[op] -pub fn op_webgpu_command_encoder_begin_render_pass( - state: &mut OpState, - args: CommandEncoderBeginRenderPassArgs, ) -> Result { let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; - - let mut color_attachments = vec![]; - - for color_attachment in args.color_attachments { - let texture_view_resource = state - .resource_table - .get::(color_attachment.view)?; - - let resolve_target = color_attachment - .resolve_target - .map(|rid| { - state - .resource_table - .get::(rid) + .get::(command_encoder_rid)?; + + let color_attachments = color_attachments + .into_iter() + .map(|color_attachment| { + let texture_view_resource = state + .resource_table + .get::(color_attachment.view)?; + + let resolve_target = color_attachment + .resolve_target + .map(|rid| { + state + .resource_table + .get::(rid) + }) + .transpose()? + .map(|texture| texture.0); + + Ok(wgpu_core::command::RenderPassColorAttachment { + view: texture_view_resource.0, + resolve_target, + channel: wgpu_core::command::PassChannel { + load_op: color_attachment.load_op, + store_op: color_attachment.store_op, + clear_value: color_attachment.clear_value.unwrap_or_default(), + read_only: false, + }, }) - .transpose()? - .map(|texture| texture.0); - - let attachment = wgpu_core::command::RenderPassColorAttachment { - view: texture_view_resource.0, - resolve_target, - channel: wgpu_core::command::PassChannel { - load_op: color_attachment.load_op, - store_op: color_attachment.store_op, - clear_value: color_attachment.clear_value.unwrap_or_default(), - read_only: false, - }, - }; - - color_attachments.push(attachment) - } + }) + .collect::, AnyError>>()?; - let mut depth_stencil_attachment = None; + let mut processed_depth_stencil_attachment = None; - if let Some(attachment) = args.depth_stencil_attachment { + if let Some(attachment) = depth_stencil_attachment { let texture_view_resource = state .resource_table .get::(attachment.view)?; - depth_stencil_attachment = Some(wgpu_core::command::RenderPassDepthStencilAttachment { - view: texture_view_resource.0, - depth: wgpu_core::command::PassChannel { - load_op: attachment.depth_load_op, - store_op: attachment.depth_store_op, - clear_value: attachment.depth_clear_value, - read_only: attachment.depth_read_only, - }, - stencil: wgpu_core::command::PassChannel { - load_op: attachment.stencil_load_op, - store_op: attachment.stencil_store_op, - clear_value: attachment.stencil_clear_value, - read_only: attachment.stencil_read_only, - }, - }); + processed_depth_stencil_attachment = + Some(wgpu_core::command::RenderPassDepthStencilAttachment { + view: texture_view_resource.0, + depth: wgpu_core::command::PassChannel { + load_op: attachment.depth_load_op, + store_op: attachment.depth_store_op, + clear_value: attachment.depth_clear_value, + read_only: attachment.depth_read_only, + }, + stencil: wgpu_core::command::PassChannel { + load_op: attachment.stencil_load_op, + store_op: attachment.stencil_store_op, + clear_value: attachment.stencil_clear_value, + read_only: attachment.stencil_read_only, + }, + }); } let descriptor = wgpu_core::command::RenderPassDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), color_attachments: Cow::from(color_attachments), - depth_stencil_attachment: depth_stencil_attachment.as_ref(), + depth_stencil_attachment: processed_depth_stencil_attachment.as_ref(), }; let render_pass = wgpu_core::command::RenderPass::new(command_encoder_resource.0, &descriptor); @@ -171,24 +158,18 @@ pub fn op_webgpu_command_encoder_begin_render_pass( Ok(WebGpuResult::rid(rid)) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderBeginComputePassArgs { - command_encoder_rid: ResourceId, - label: Option, -} - #[op] pub fn op_webgpu_command_encoder_begin_compute_pass( state: &mut OpState, - args: CommandEncoderBeginComputePassArgs, + command_encoder_rid: ResourceId, + label: Option, ) -> Result { let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let descriptor = wgpu_core::command::ComputePassDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), }; let compute_pass = @@ -203,43 +184,37 @@ pub fn op_webgpu_command_encoder_begin_compute_pass( Ok(WebGpuResult::rid(rid)) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderCopyBufferToBufferArgs { +#[op] +pub fn op_webgpu_command_encoder_copy_buffer_to_buffer( + state: &mut OpState, command_encoder_rid: ResourceId, source: ResourceId, source_offset: u64, destination: ResourceId, destination_offset: u64, size: u64, -} - -#[op] -pub fn op_webgpu_command_encoder_copy_buffer_to_buffer( - state: &mut OpState, - args: CommandEncoderCopyBufferToBufferArgs, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let source_buffer_resource = state .resource_table - .get::(args.source)?; + .get::(source)?; let source_buffer = source_buffer_resource.0; let destination_buffer_resource = state .resource_table - .get::(args.destination)?; + .get::(destination)?; let destination_buffer = destination_buffer_resource.0; gfx_ok!(command_encoder => instance.command_encoder_copy_buffer_to_buffer( command_encoder, source_buffer, - args.source_offset, + source_offset, destination_buffer, - args.destination_offset, - args.size + destination_offset, + size )) } @@ -261,332 +236,271 @@ pub struct GpuImageCopyTexture { pub aspect: wgpu_types::TextureAspect, } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderCopyBufferToTextureArgs { +#[op] +pub fn op_webgpu_command_encoder_copy_buffer_to_texture( + state: &mut OpState, command_encoder_rid: ResourceId, source: GpuImageCopyBuffer, destination: GpuImageCopyTexture, copy_size: wgpu_types::Extent3d, -} - -#[op] -pub fn op_webgpu_command_encoder_copy_buffer_to_texture( - state: &mut OpState, - args: CommandEncoderCopyBufferToTextureArgs, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let source_buffer_resource = state .resource_table - .get::(args.source.buffer)?; + .get::(source.buffer)?; let destination_texture_resource = state .resource_table - .get::(args.destination.texture)?; + .get::(destination.texture)?; let source = wgpu_core::command::ImageCopyBuffer { buffer: source_buffer_resource.0, layout: wgpu_types::ImageDataLayout { - offset: args.source.offset, - bytes_per_row: NonZeroU32::new(args.source.bytes_per_row.unwrap_or(0)), - rows_per_image: NonZeroU32::new(args.source.rows_per_image.unwrap_or(0)), + offset: source.offset, + bytes_per_row: NonZeroU32::new(source.bytes_per_row.unwrap_or(0)), + rows_per_image: NonZeroU32::new(source.rows_per_image.unwrap_or(0)), }, }; let destination = wgpu_core::command::ImageCopyTexture { texture: destination_texture_resource.0, - mip_level: args.destination.mip_level, - origin: args.destination.origin, - aspect: args.destination.aspect, + mip_level: destination.mip_level, + origin: destination.origin, + aspect: destination.aspect, }; gfx_ok!(command_encoder => instance.command_encoder_copy_buffer_to_texture( command_encoder, &source, &destination, - &args.copy_size + ©_size )) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderCopyTextureToBufferArgs { +#[op] +pub fn op_webgpu_command_encoder_copy_texture_to_buffer( + state: &mut OpState, command_encoder_rid: ResourceId, source: GpuImageCopyTexture, destination: GpuImageCopyBuffer, copy_size: wgpu_types::Extent3d, -} - -#[op] -pub fn op_webgpu_command_encoder_copy_texture_to_buffer( - state: &mut OpState, - args: CommandEncoderCopyTextureToBufferArgs, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let source_texture_resource = state .resource_table - .get::(args.source.texture)?; + .get::(source.texture)?; let destination_buffer_resource = state .resource_table - .get::(args.destination.buffer)?; + .get::(destination.buffer)?; let source = wgpu_core::command::ImageCopyTexture { texture: source_texture_resource.0, - mip_level: args.source.mip_level, - origin: args.source.origin, - aspect: args.source.aspect, + mip_level: source.mip_level, + origin: source.origin, + aspect: source.aspect, }; let destination = wgpu_core::command::ImageCopyBuffer { buffer: destination_buffer_resource.0, layout: wgpu_types::ImageDataLayout { - offset: args.destination.offset, - bytes_per_row: NonZeroU32::new(args.destination.bytes_per_row.unwrap_or(0)), - rows_per_image: NonZeroU32::new(args.destination.rows_per_image.unwrap_or(0)), + offset: destination.offset, + bytes_per_row: NonZeroU32::new(destination.bytes_per_row.unwrap_or(0)), + rows_per_image: NonZeroU32::new(destination.rows_per_image.unwrap_or(0)), }, }; gfx_ok!(command_encoder => instance.command_encoder_copy_texture_to_buffer( command_encoder, &source, &destination, - &args.copy_size + ©_size )) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderCopyTextureToTextureArgs { +#[op] +pub fn op_webgpu_command_encoder_copy_texture_to_texture( + state: &mut OpState, command_encoder_rid: ResourceId, source: GpuImageCopyTexture, destination: GpuImageCopyTexture, copy_size: wgpu_types::Extent3d, -} - -#[op] -pub fn op_webgpu_command_encoder_copy_texture_to_texture( - state: &mut OpState, - args: CommandEncoderCopyTextureToTextureArgs, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let source_texture_resource = state .resource_table - .get::(args.source.texture)?; + .get::(source.texture)?; let destination_texture_resource = state .resource_table - .get::(args.destination.texture)?; + .get::(destination.texture)?; let source = wgpu_core::command::ImageCopyTexture { texture: source_texture_resource.0, - mip_level: args.source.mip_level, - origin: args.source.origin, - aspect: args.source.aspect, + mip_level: source.mip_level, + origin: source.origin, + aspect: source.aspect, }; let destination = wgpu_core::command::ImageCopyTexture { texture: destination_texture_resource.0, - mip_level: args.destination.mip_level, - origin: args.destination.origin, - aspect: args.destination.aspect, + mip_level: destination.mip_level, + origin: destination.origin, + aspect: destination.aspect, }; gfx_ok!(command_encoder => instance.command_encoder_copy_texture_to_texture( command_encoder, &source, &destination, - &args.copy_size + ©_size )) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderClearBufferArgs { +#[op] +pub fn op_webgpu_command_encoder_clear_buffer( + state: &mut OpState, command_encoder_rid: u32, buffer_rid: u32, offset: u64, size: u64, -} - -#[op] -pub fn op_webgpu_command_encoder_clear_buffer( - state: &mut OpState, - args: CommandEncoderClearBufferArgs, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let destination_resource = state .resource_table - .get::(args.buffer_rid)?; + .get::(buffer_rid)?; gfx_ok!(command_encoder => instance.command_encoder_clear_buffer( command_encoder, destination_resource.0, - args.offset, - std::num::NonZeroU64::new(args.size) + offset, + std::num::NonZeroU64::new(size) )) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderPushDebugGroupArgs { - command_encoder_rid: ResourceId, - group_label: String, -} - #[op] pub fn op_webgpu_command_encoder_push_debug_group( state: &mut OpState, - args: CommandEncoderPushDebugGroupArgs, + command_encoder_rid: ResourceId, + group_label: String, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; - gfx_ok!(command_encoder => instance - .command_encoder_push_debug_group(command_encoder, &args.group_label)) -} - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderPopDebugGroupArgs { - command_encoder_rid: ResourceId, + gfx_ok!(command_encoder => instance.command_encoder_push_debug_group(command_encoder, &group_label)) } #[op] pub fn op_webgpu_command_encoder_pop_debug_group( state: &mut OpState, - args: CommandEncoderPopDebugGroupArgs, + command_encoder_rid: ResourceId, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; gfx_ok!(command_encoder => instance.command_encoder_pop_debug_group(command_encoder)) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderInsertDebugMarkerArgs { - command_encoder_rid: ResourceId, - marker_label: String, -} - #[op] pub fn op_webgpu_command_encoder_insert_debug_marker( state: &mut OpState, - args: CommandEncoderInsertDebugMarkerArgs, + command_encoder_rid: ResourceId, + marker_label: String, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; gfx_ok!(command_encoder => instance.command_encoder_insert_debug_marker( command_encoder, - &args.marker_label + &marker_label )) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderWriteTimestampArgs { - command_encoder_rid: ResourceId, - query_set: ResourceId, - query_index: u32, -} - #[op] pub fn op_webgpu_command_encoder_write_timestamp( state: &mut OpState, - args: CommandEncoderWriteTimestampArgs, + command_encoder_rid: ResourceId, + query_set: ResourceId, + query_index: u32, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let query_set_resource = state .resource_table - .get::(args.query_set)?; + .get::(query_set)?; gfx_ok!(command_encoder => instance.command_encoder_write_timestamp( command_encoder, query_set_resource.0, - args.query_index + query_index )) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderResolveQuerySetArgs { +#[op] +pub fn op_webgpu_command_encoder_resolve_query_set( + state: &mut OpState, command_encoder_rid: ResourceId, query_set: ResourceId, first_query: u32, query_count: u32, destination: ResourceId, destination_offset: u64, -} - -#[op] -pub fn op_webgpu_command_encoder_resolve_query_set( - state: &mut OpState, - args: CommandEncoderResolveQuerySetArgs, ) -> Result { let instance = state.borrow::(); let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let query_set_resource = state .resource_table - .get::(args.query_set)?; + .get::(query_set)?; let destination_resource = state .resource_table - .get::(args.destination)?; + .get::(destination)?; gfx_ok!(command_encoder => instance.command_encoder_resolve_query_set( command_encoder, query_set_resource.0, - args.first_query, - args.query_count, + first_query, + query_count, destination_resource.0, - args.destination_offset + destination_offset )) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CommandEncoderFinishArgs { - command_encoder_rid: ResourceId, - label: Option, -} - #[op] pub fn op_webgpu_command_encoder_finish( state: &mut OpState, - args: CommandEncoderFinishArgs, + command_encoder_rid: ResourceId, + label: Option, ) -> Result { let command_encoder_resource = state .resource_table - .take::(args.command_encoder_rid)?; + .take::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let instance = state.borrow::(); let descriptor = wgpu_types::CommandBufferDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), }; gfx_put!(command_encoder => instance.command_encoder_finish( diff --git a/deno_webgpu/src/compute_pass.rs b/deno_webgpu/src/compute_pass.rs index dc74bd8b4c..6ecae3505b 100644 --- a/deno_webgpu/src/compute_pass.rs +++ b/deno_webgpu/src/compute_pass.rs @@ -6,7 +6,6 @@ use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; use deno_core::ZeroCopyBuf; -use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; @@ -19,24 +18,18 @@ impl Resource for WebGpuComputePass { } } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassSetPipelineArgs { - compute_pass_rid: ResourceId, - pipeline: ResourceId, -} - #[op] pub fn op_webgpu_compute_pass_set_pipeline( state: &mut OpState, - args: ComputePassSetPipelineArgs, + compute_pass_rid: ResourceId, + pipeline: ResourceId, ) -> Result { let compute_pipeline_resource = state .resource_table - .get::(args.pipeline)?; + .get::(pipeline)?; let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; wgpu_core::command::compute_ffi::wgpu_compute_pass_set_pipeline( &mut compute_pass_resource.0.borrow_mut(), @@ -46,106 +39,82 @@ pub fn op_webgpu_compute_pass_set_pipeline( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassDispatchArgs { +#[op] +pub fn op_webgpu_compute_pass_dispatch( + state: &mut OpState, compute_pass_rid: ResourceId, x: u32, y: u32, z: u32, -} - -#[op] -pub fn op_webgpu_compute_pass_dispatch( - state: &mut OpState, - args: ComputePassDispatchArgs, ) -> Result { let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch( &mut compute_pass_resource.0.borrow_mut(), - args.x, - args.y, - args.z, + x, + y, + z, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassDispatchIndirectArgs { - compute_pass_rid: ResourceId, - indirect_buffer: ResourceId, - indirect_offset: u64, -} - #[op] pub fn op_webgpu_compute_pass_dispatch_indirect( state: &mut OpState, - args: ComputePassDispatchIndirectArgs, + compute_pass_rid: ResourceId, + indirect_buffer: ResourceId, + indirect_offset: u64, ) -> Result { let buffer_resource = state .resource_table - .get::(args.indirect_buffer)?; + .get::(indirect_buffer)?; let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch_indirect( &mut compute_pass_resource.0.borrow_mut(), buffer_resource.0, - args.indirect_offset, + indirect_offset, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassBeginPipelineStatisticsQueryArgs { - compute_pass_rid: ResourceId, - query_set: ResourceId, - query_index: u32, -} - #[op] pub fn op_webgpu_compute_pass_begin_pipeline_statistics_query( state: &mut OpState, - args: ComputePassBeginPipelineStatisticsQueryArgs, + compute_pass_rid: ResourceId, + query_set: ResourceId, + query_index: u32, ) -> Result { let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; let query_set_resource = state .resource_table - .get::(args.query_set)?; + .get::(query_set)?; wgpu_core::command::compute_ffi::wgpu_compute_pass_begin_pipeline_statistics_query( &mut compute_pass_resource.0.borrow_mut(), query_set_resource.0, - args.query_index, + query_index, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassEndPipelineStatisticsQueryArgs { - compute_pass_rid: ResourceId, -} - #[op] pub fn op_webgpu_compute_pass_end_pipeline_statistics_query( state: &mut OpState, - args: ComputePassEndPipelineStatisticsQueryArgs, + compute_pass_rid: ResourceId, ) -> Result { let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; wgpu_core::command::compute_ffi::wgpu_compute_pass_end_pipeline_statistics_query( &mut compute_pass_resource.0.borrow_mut(), @@ -154,55 +123,43 @@ pub fn op_webgpu_compute_pass_end_pipeline_statistics_query( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassWriteTimestampArgs { - compute_pass_rid: ResourceId, - query_set: ResourceId, - query_index: u32, -} - #[op] pub fn op_webgpu_compute_pass_write_timestamp( state: &mut OpState, - args: ComputePassWriteTimestampArgs, + compute_pass_rid: ResourceId, + query_set: ResourceId, + query_index: u32, ) -> Result { let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; let query_set_resource = state .resource_table - .get::(args.query_set)?; + .get::(query_set)?; wgpu_core::command::compute_ffi::wgpu_compute_pass_write_timestamp( &mut compute_pass_resource.0.borrow_mut(), query_set_resource.0, - args.query_index, + query_index, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassEndArgs { - command_encoder_rid: ResourceId, - compute_pass_rid: ResourceId, -} - #[op] pub fn op_webgpu_compute_pass_end( state: &mut OpState, - args: ComputePassEndArgs, + command_encoder_rid: ResourceId, + compute_pass_rid: ResourceId, ) -> Result { let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let compute_pass_resource = state .resource_table - .take::(args.compute_pass_rid)?; + .take::(compute_pass_rid)?; let compute_pass = &compute_pass_resource.0.borrow(); let instance = state.borrow::(); @@ -212,40 +169,33 @@ pub fn op_webgpu_compute_pass_end( )) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassSetBindGroupArgs { +#[op] +pub fn op_webgpu_compute_pass_set_bind_group( + state: &mut OpState, compute_pass_rid: ResourceId, index: u32, bind_group: ResourceId, dynamic_offsets_data: ZeroCopyBuf, dynamic_offsets_data_start: usize, dynamic_offsets_data_length: usize, -} - -#[op] -pub fn op_webgpu_compute_pass_set_bind_group( - state: &mut OpState, - args: ComputePassSetBindGroupArgs, ) -> Result { let bind_group_resource = state .resource_table - .get::(args.bind_group)?; + .get::(bind_group)?; let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; // Align the data - assert!(args.dynamic_offsets_data_start % std::mem::size_of::() == 0); + assert!(dynamic_offsets_data_start % std::mem::size_of::() == 0); // SAFETY: A u8 to u32 cast is safe because we asserted that the length is a // multiple of 4. - let (prefix, dynamic_offsets_data, suffix) = - unsafe { args.dynamic_offsets_data.align_to::() }; + let (prefix, dynamic_offsets_data, suffix) = unsafe { dynamic_offsets_data.align_to::() }; assert!(prefix.is_empty()); assert!(suffix.is_empty()); - let start = args.dynamic_offsets_data_start; - let len = args.dynamic_offsets_data_length; + let start = dynamic_offsets_data_start; + let len = dynamic_offsets_data_length; // Assert that length and start are both in bounds assert!(start <= dynamic_offsets_data.len()); @@ -258,7 +208,7 @@ pub fn op_webgpu_compute_pass_set_bind_group( unsafe { wgpu_core::command::compute_ffi::wgpu_compute_pass_set_bind_group( &mut compute_pass_resource.0.borrow_mut(), - args.index, + index, bind_group_resource.0, dynamic_offsets_data.as_ptr(), dynamic_offsets_data.len(), @@ -268,23 +218,17 @@ pub fn op_webgpu_compute_pass_set_bind_group( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassPushDebugGroupArgs { - compute_pass_rid: ResourceId, - group_label: String, -} - #[op] pub fn op_webgpu_compute_pass_push_debug_group( state: &mut OpState, - args: ComputePassPushDebugGroupArgs, + compute_pass_rid: ResourceId, + group_label: String, ) -> Result { let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; - let label = std::ffi::CString::new(args.group_label).unwrap(); + let label = std::ffi::CString::new(group_label).unwrap(); // SAFETY: the string the raw pointer points to lives longer than the below // function invocation. unsafe { @@ -298,20 +242,14 @@ pub fn op_webgpu_compute_pass_push_debug_group( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassPopDebugGroupArgs { - compute_pass_rid: ResourceId, -} - #[op] pub fn op_webgpu_compute_pass_pop_debug_group( state: &mut OpState, - args: ComputePassPopDebugGroupArgs, + compute_pass_rid: ResourceId, ) -> Result { let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; wgpu_core::command::compute_ffi::wgpu_compute_pass_pop_debug_group( &mut compute_pass_resource.0.borrow_mut(), @@ -320,23 +258,17 @@ pub fn op_webgpu_compute_pass_pop_debug_group( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePassInsertDebugMarkerArgs { - compute_pass_rid: ResourceId, - marker_label: String, -} - #[op] pub fn op_webgpu_compute_pass_insert_debug_marker( state: &mut OpState, - args: ComputePassInsertDebugMarkerArgs, + compute_pass_rid: ResourceId, + marker_label: String, ) -> Result { let compute_pass_resource = state .resource_table - .get::(args.compute_pass_rid)?; + .get::(compute_pass_rid)?; - let label = std::ffi::CString::new(args.marker_label).unwrap(); + let label = std::ffi::CString::new(marker_label).unwrap(); // SAFETY: the string the raw pointer points to lives longer than the below // function invocation. unsafe { diff --git a/deno_webgpu/src/error.rs b/deno_webgpu/src/error.rs index 709b0619fd..541fa9d908 100644 --- a/deno_webgpu/src/error.rs +++ b/deno_webgpu/src/error.rs @@ -59,14 +59,14 @@ impl WebGpuResult { pub fn rid_err>(rid: ResourceId, err: Option) -> Self { Self { rid: Some(rid), - err: err.map(|e| e.into()), + err: err.map(Into::into), } } pub fn maybe_err>(err: Option) -> Self { Self { rid: None, - err: err.map(|e| e.into()), + err: err.map(Into::into), } } diff --git a/deno_webgpu/src/lib.rs b/deno_webgpu/src/lib.rs index fd5501dbf4..63bd720ebb 100644 --- a/deno_webgpu/src/lib.rs +++ b/deno_webgpu/src/lib.rs @@ -16,7 +16,6 @@ use std::convert::TryFrom; use std::rc::Rc; pub use wgpu_core; pub use wgpu_types; -use wgpu_types::PowerPreference; use error::DomExceptionOperationError; use error::WebGpuResult; @@ -202,13 +201,6 @@ fn deserialize_features(features: &wgpu_types::Features) -> Vec<&'static str> { return_features } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RequestAdapterArgs { - power_preference: Option, - force_fallback_adapter: bool, -} - #[derive(Serialize)] #[serde(untagged)] pub enum GpuAdapterDeviceOrErr { @@ -229,15 +221,15 @@ pub struct GpuAdapterDevice { #[op] pub async fn op_webgpu_request_adapter( state: Rc>, - args: RequestAdapterArgs, + power_preference: Option, + force_fallback_adapter: bool, ) -> Result { let mut state = state.borrow_mut(); check_unstable(&state, "navigator.gpu.requestAdapter"); - let backends = std::env::var("DENO_WEBGPU_BACKEND") - .ok() - .map_or_else(wgpu_types::Backends::all, |s| { - wgpu_core::instance::parse_backends_from_comma_list(&s) - }); + let backends = std::env::var("DENO_WEBGPU_BACKEND").map_or_else( + |_| wgpu_types::Backends::all(), + |s| wgpu_core::instance::parse_backends_from_comma_list(&s), + ); let instance = if let Some(instance) = state.try_borrow::() { instance } else { @@ -250,11 +242,8 @@ pub async fn op_webgpu_request_adapter( }; let descriptor = wgpu_core::instance::RequestAdapterOptions { - power_preference: match args.power_preference { - Some(power_preference) => power_preference, - None => PowerPreference::default(), - }, - force_fallback_adapter: args.force_fallback_adapter, + power_preference: power_preference.unwrap_or_default(), + force_fallback_adapter, compatible_surface: None, // windowless }; let res = instance.request_adapter( @@ -286,15 +275,6 @@ pub async fn op_webgpu_request_adapter( })) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RequestDeviceArgs { - adapter_rid: ResourceId, - label: Option, - required_features: Option, - required_limits: Option, -} - #[derive(Deserialize)] pub struct GpuRequiredFeatures(HashSet); @@ -409,19 +389,20 @@ impl From for wgpu_types::Features { #[op] pub async fn op_webgpu_request_device( state: Rc>, - args: RequestDeviceArgs, + adapter_rid: ResourceId, + label: Option, + required_features: Option, + required_limits: Option, ) -> Result { let mut state = state.borrow_mut(); - let adapter_resource = state - .resource_table - .get::(args.adapter_rid)?; + let adapter_resource = state.resource_table.get::(adapter_rid)?; let adapter = adapter_resource.0; let instance = state.borrow::(); let descriptor = wgpu_types::DeviceDescriptor { - label: args.label.map(Cow::from), - features: args.required_features.map(Into::into).unwrap_or_default(), - limits: args.required_limits.map(Into::into).unwrap_or_default(), + label: label.map(Cow::from), + features: required_features.map(Into::into).unwrap_or_default(), + limits: required_limits.map(Into::into).unwrap_or_default(), }; let (device, maybe_err) = gfx_select!(adapter => instance.adapter_request_device( diff --git a/deno_webgpu/src/pipeline.rs b/deno_webgpu/src/pipeline.rs index 05c38455ca..63958ac7ed 100644 --- a/deno_webgpu/src/pipeline.rs +++ b/deno_webgpu/src/pipeline.rs @@ -8,8 +8,6 @@ use deno_core::ResourceId; use serde::Deserialize; use serde::Serialize; use std::borrow::Cow; -use std::convert::TryFrom; -use std::convert::TryInto; use super::error::WebGpuError; use super::error::WebGpuResult; @@ -39,33 +37,27 @@ impl Resource for WebGpuRenderPipeline { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct GpuProgrammableStage { +pub struct GpuProgrammableStage { module: ResourceId, entry_point: String, // constants: HashMap } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateComputePipelineArgs { +#[op] +pub fn op_webgpu_create_compute_pipeline( + state: &mut OpState, device_rid: ResourceId, label: Option, layout: Option, compute: GpuProgrammableStage, -} - -#[op] -pub fn op_webgpu_create_compute_pipeline( - state: &mut OpState, - args: CreateComputePipelineArgs, ) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table - .get::(args.device_rid)?; + .get::(device_rid)?; let device = device_resource.0; - let pipeline_layout = if let Some(rid) = args.layout { + let pipeline_layout = if let Some(rid) = layout { let id = state.resource_table.get::(rid)?; Some(id.0) } else { @@ -74,18 +66,18 @@ pub fn op_webgpu_create_compute_pipeline( let compute_shader_module_resource = state .resource_table - .get::(args.compute.module)?; + .get::(compute.module)?; let descriptor = wgpu_core::pipeline::ComputePipelineDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), layout: pipeline_layout, stage: wgpu_core::pipeline::ProgrammableStageDescriptor { module: compute_shader_module_resource.0, - entry_point: Cow::from(args.compute.entry_point), + entry_point: Cow::from(compute.entry_point), // TODO(lucacasonato): support args.compute.constants }, }; - let implicit_pipelines = match args.layout { + let implicit_pipelines = match layout { Some(_) => None, None => Some(wgpu_core::device::ImplicitPipelineIds { root_id: std::marker::PhantomData, @@ -107,13 +99,6 @@ pub fn op_webgpu_create_compute_pipeline( Ok(WebGpuResult::rid_err(rid, maybe_err)) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct ComputePipelineGetBindGroupLayoutArgs { - compute_pipeline_rid: ResourceId, - index: u32, -} - #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct PipelineLayout { @@ -125,15 +110,16 @@ pub struct PipelineLayout { #[op] pub fn op_webgpu_compute_pipeline_get_bind_group_layout( state: &mut OpState, - args: ComputePipelineGetBindGroupLayoutArgs, + compute_pipeline_rid: ResourceId, + index: u32, ) -> Result { let instance = state.borrow::(); let compute_pipeline_resource = state .resource_table - .get::(args.compute_pipeline_rid)?; + .get::(compute_pipeline_rid)?; let compute_pipeline = compute_pipeline_resource.0; - let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, args.index, std::marker::PhantomData)); + let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, index, std::marker::PhantomData)); let label = gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout)); @@ -206,10 +192,9 @@ struct GpuDepthStencilState { depth_bias_clamp: f32, } -impl TryFrom for wgpu_types::DepthStencilState { - type Error = AnyError; - fn try_from(state: GpuDepthStencilState) -> Result { - Ok(wgpu_types::DepthStencilState { +impl From for wgpu_types::DepthStencilState { + fn from(state: GpuDepthStencilState) -> wgpu_types::DepthStencilState { + wgpu_types::DepthStencilState { format: state.format, depth_write_enabled: state.depth_write_enabled, depth_compare: state.depth_compare, @@ -224,7 +209,7 @@ impl TryFrom for wgpu_types::DepthStencilState { slope_scale: state.depth_bias_slope_scale, clamp: state.depth_bias_clamp, }, - }) + } } } @@ -352,7 +337,7 @@ pub fn op_webgpu_create_render_pipeline( buffers: Cow::Owned(vertex_buffers), }, primitive: args.primitive.into(), - depth_stencil: args.depth_stencil.map(TryInto::try_into).transpose()?, + depth_stencil: args.depth_stencil.map(Into::into), multisample: args.multisample, fragment, multiview: None, @@ -380,25 +365,19 @@ pub fn op_webgpu_create_render_pipeline( Ok(WebGpuResult::rid_err(rid, maybe_err)) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPipelineGetBindGroupLayoutArgs { - render_pipeline_rid: ResourceId, - index: u32, -} - #[op] pub fn op_webgpu_render_pipeline_get_bind_group_layout( state: &mut OpState, - args: RenderPipelineGetBindGroupLayoutArgs, + render_pipeline_rid: ResourceId, + index: u32, ) -> Result { let instance = state.borrow::(); let render_pipeline_resource = state .resource_table - .get::(args.render_pipeline_rid)?; + .get::(render_pipeline_rid)?; let render_pipeline = render_pipeline_resource.0; - let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, args.index, std::marker::PhantomData)); + let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, index, std::marker::PhantomData)); let label = gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout)); diff --git a/deno_webgpu/src/queue.rs b/deno_webgpu/src/queue.rs index 93a6c9e83e..a5e830663e 100644 --- a/deno_webgpu/src/queue.rs +++ b/deno_webgpu/src/queue.rs @@ -13,34 +13,29 @@ use super::error::WebGpuResult; type WebGpuQueue = super::WebGpuDevice; -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct QueueSubmitArgs { - queue_rid: ResourceId, - command_buffers: Vec, -} - #[op] pub fn op_webgpu_queue_submit( state: &mut OpState, - args: QueueSubmitArgs, + queue_rid: ResourceId, + command_buffers: Vec, ) -> Result { let instance = state.borrow::(); - let queue_resource = state.resource_table.get::(args.queue_rid)?; + let queue_resource = state.resource_table.get::(queue_rid)?; let queue = queue_resource.0; - let mut ids = vec![]; - - for rid in &args.command_buffers { - let buffer_resource = state - .resource_table - .get::(*rid)?; - ids.push(buffer_resource.0); - } + let ids = command_buffers + .iter() + .map(|rid| { + let buffer_resource = state + .resource_table + .get::(*rid)?; + Ok(buffer_resource.0) + }) + .collect::, AnyError>>()?; let maybe_err = gfx_select!(queue => instance.queue_submit(queue, &ids)).err(); - for rid in args.command_buffers { + for rid in command_buffers { state.resource_table.close(rid)?; } @@ -49,7 +44,7 @@ pub fn op_webgpu_queue_submit( #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct GpuImageDataLayout { +pub struct GpuImageDataLayout { offset: u64, bytes_per_row: Option, rows_per_image: Option, @@ -65,38 +60,32 @@ impl From for wgpu_types::ImageDataLayout { } } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct QueueWriteBufferArgs { +#[op] +pub fn op_webgpu_write_buffer( + state: &mut OpState, queue_rid: ResourceId, buffer: ResourceId, buffer_offset: u64, data_offset: usize, size: Option, -} - -#[op] -pub fn op_webgpu_write_buffer( - state: &mut OpState, - args: QueueWriteBufferArgs, - zero_copy: ZeroCopyBuf, + buf: ZeroCopyBuf, ) -> Result { let instance = state.borrow::(); let buffer_resource = state .resource_table - .get::(args.buffer)?; + .get::(buffer)?; let buffer = buffer_resource.0; - let queue_resource = state.resource_table.get::(args.queue_rid)?; + let queue_resource = state.resource_table.get::(queue_rid)?; let queue = queue_resource.0; - let data = match args.size { - Some(size) => &zero_copy[args.data_offset..(args.data_offset + size)], - None => &zero_copy[args.data_offset..], + let data = match size { + Some(size) => &buf[data_offset..(data_offset + size)], + None => &buf[data_offset..], }; let maybe_err = gfx_select!(queue => instance.queue_write_buffer( queue, buffer, - args.buffer_offset, + buffer_offset, data )) .err(); @@ -104,41 +93,35 @@ pub fn op_webgpu_write_buffer( Ok(WebGpuResult::maybe_err(maybe_err)) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct QueueWriteTextureArgs { +#[op] +pub fn op_webgpu_write_texture( + state: &mut OpState, queue_rid: ResourceId, destination: super::command_encoder::GpuImageCopyTexture, data_layout: GpuImageDataLayout, size: wgpu_types::Extent3d, -} - -#[op] -pub fn op_webgpu_write_texture( - state: &mut OpState, - args: QueueWriteTextureArgs, - zero_copy: ZeroCopyBuf, + buf: ZeroCopyBuf, ) -> Result { let instance = state.borrow::(); let texture_resource = state .resource_table - .get::(args.destination.texture)?; - let queue_resource = state.resource_table.get::(args.queue_rid)?; + .get::(destination.texture)?; + let queue_resource = state.resource_table.get::(queue_rid)?; let queue = queue_resource.0; let destination = wgpu_core::command::ImageCopyTexture { texture: texture_resource.0, - mip_level: args.destination.mip_level, - origin: args.destination.origin, - aspect: args.destination.aspect, + mip_level: destination.mip_level, + origin: destination.origin, + aspect: destination.aspect, }; - let data_layout = args.data_layout.into(); + let data_layout = data_layout.into(); gfx_ok!(queue => instance.queue_write_texture( queue, &destination, - &*zero_copy, + &*buf, &data_layout, - &args.size + &size )) } diff --git a/deno_webgpu/src/render_pass.rs b/deno_webgpu/src/render_pass.rs index da3024a5ea..30a966e70e 100644 --- a/deno_webgpu/src/render_pass.rs +++ b/deno_webgpu/src/render_pass.rs @@ -54,127 +54,97 @@ pub fn op_webgpu_render_pass_set_viewport( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassSetScissorRectArgs { +#[op] +pub fn op_webgpu_render_pass_set_scissor_rect( + state: &mut OpState, render_pass_rid: ResourceId, x: u32, y: u32, width: u32, height: u32, -} - -#[op] -pub fn op_webgpu_render_pass_set_scissor_rect( - state: &mut OpState, - args: RenderPassSetScissorRectArgs, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_set_scissor_rect( &mut render_pass_resource.0.borrow_mut(), - args.x, - args.y, - args.width, - args.height, + x, + y, + width, + height, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassSetBlendConstantArgs { - render_pass_rid: ResourceId, - color: wgpu_types::Color, -} - #[op] pub fn op_webgpu_render_pass_set_blend_constant( state: &mut OpState, - args: RenderPassSetBlendConstantArgs, + render_pass_rid: ResourceId, + color: wgpu_types::Color, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_set_blend_constant( &mut render_pass_resource.0.borrow_mut(), - &args.color, + &color, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassSetStencilReferenceArgs { - render_pass_rid: ResourceId, - reference: u32, -} - #[op] pub fn op_webgpu_render_pass_set_stencil_reference( state: &mut OpState, - args: RenderPassSetStencilReferenceArgs, + render_pass_rid: ResourceId, + reference: u32, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_set_stencil_reference( &mut render_pass_resource.0.borrow_mut(), - args.reference, + reference, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassBeginPipelineStatisticsQueryArgs { - render_pass_rid: ResourceId, - query_set: u32, - query_index: u32, -} - #[op] pub fn op_webgpu_render_pass_begin_pipeline_statistics_query( state: &mut OpState, - args: RenderPassBeginPipelineStatisticsQueryArgs, + render_pass_rid: ResourceId, + query_set: u32, + query_index: u32, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; let query_set_resource = state .resource_table - .get::(args.query_set)?; + .get::(query_set)?; wgpu_core::command::render_ffi::wgpu_render_pass_begin_pipeline_statistics_query( &mut render_pass_resource.0.borrow_mut(), query_set_resource.0, - args.query_index, + query_index, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassEndPipelineStatisticsQueryArgs { - render_pass_rid: ResourceId, -} - #[op] pub fn op_webgpu_render_pass_end_pipeline_statistics_query( state: &mut OpState, - args: RenderPassEndPipelineStatisticsQueryArgs, + render_pass_rid: ResourceId, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_end_pipeline_statistics_query( &mut render_pass_resource.0.borrow_mut(), @@ -183,133 +153,109 @@ pub fn op_webgpu_render_pass_end_pipeline_statistics_query( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassWriteTimestampArgs { - render_pass_rid: ResourceId, - query_set: u32, - query_index: u32, -} - #[op] pub fn op_webgpu_render_pass_write_timestamp( state: &mut OpState, - args: RenderPassWriteTimestampArgs, + render_pass_rid: ResourceId, + query_set: u32, + query_index: u32, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; let query_set_resource = state .resource_table - .get::(args.query_set)?; + .get::(query_set)?; wgpu_core::command::render_ffi::wgpu_render_pass_write_timestamp( &mut render_pass_resource.0.borrow_mut(), query_set_resource.0, - args.query_index, + query_index, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassExecuteBundlesArgs { - render_pass_rid: ResourceId, - bundles: Vec, -} - #[op] pub fn op_webgpu_render_pass_execute_bundles( state: &mut OpState, - args: RenderPassExecuteBundlesArgs, + render_pass_rid: ResourceId, + bundles: Vec, ) -> Result { - let mut render_bundle_ids = vec![]; - - for rid in &args.bundles { - let render_bundle_resource = state - .resource_table - .get::(*rid)?; - render_bundle_ids.push(render_bundle_resource.0); - } + let bundles = bundles + .iter() + .map(|rid| { + let render_bundle_resource = state + .resource_table + .get::(*rid)?; + Ok(render_bundle_resource.0) + }) + .collect::, AnyError>>()?; let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; // SAFETY: the raw pointer and length are of the same slice, and that slice // lives longer than the below function invocation. unsafe { wgpu_core::command::render_ffi::wgpu_render_pass_execute_bundles( &mut render_pass_resource.0.borrow_mut(), - render_bundle_ids.as_ptr(), - render_bundle_ids.len(), + bundles.as_ptr(), + bundles.len(), ); } Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassEndArgs { - command_encoder_rid: ResourceId, - render_pass_rid: ResourceId, -} - #[op] pub fn op_webgpu_render_pass_end( state: &mut OpState, - args: RenderPassEndArgs, + command_encoder_rid: ResourceId, + render_pass_rid: ResourceId, ) -> Result { let command_encoder_resource = state .resource_table - .get::(args.command_encoder_rid)?; + .get::(command_encoder_rid)?; let command_encoder = command_encoder_resource.0; let render_pass_resource = state .resource_table - .take::(args.render_pass_rid)?; + .take::(render_pass_rid)?; let render_pass = &render_pass_resource.0.borrow(); let instance = state.borrow::(); gfx_ok!(command_encoder => instance.command_encoder_run_render_pass(command_encoder, render_pass)) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassSetBindGroupArgs { +#[op] +pub fn op_webgpu_render_pass_set_bind_group( + state: &mut OpState, render_pass_rid: ResourceId, index: u32, bind_group: u32, dynamic_offsets_data: ZeroCopyBuf, dynamic_offsets_data_start: usize, dynamic_offsets_data_length: usize, -} - -#[op] -pub fn op_webgpu_render_pass_set_bind_group( - state: &mut OpState, - args: RenderPassSetBindGroupArgs, ) -> Result { let bind_group_resource = state .resource_table - .get::(args.bind_group)?; + .get::(bind_group)?; let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; // Align the data - assert!(args.dynamic_offsets_data_start % std::mem::size_of::() == 0); + assert_eq!(dynamic_offsets_data_start % std::mem::size_of::(), 0); // SAFETY: A u8 to u32 cast is safe because we asserted that the length is a // multiple of 4. - let (prefix, dynamic_offsets_data, suffix) = - unsafe { args.dynamic_offsets_data.align_to::() }; + let (prefix, dynamic_offsets_data, suffix) = unsafe { dynamic_offsets_data.align_to::() }; assert!(prefix.is_empty()); assert!(suffix.is_empty()); - let start = args.dynamic_offsets_data_start; - let len = args.dynamic_offsets_data_length; + let start = dynamic_offsets_data_start; + let len = dynamic_offsets_data_length; // Assert that length and start are both in bounds assert!(start <= dynamic_offsets_data.len()); @@ -322,7 +268,7 @@ pub fn op_webgpu_render_pass_set_bind_group( unsafe { wgpu_core::command::render_ffi::wgpu_render_pass_set_bind_group( &mut render_pass_resource.0.borrow_mut(), - args.index, + index, bind_group_resource.0, dynamic_offsets_data.as_ptr(), dynamic_offsets_data.len(), @@ -332,23 +278,17 @@ pub fn op_webgpu_render_pass_set_bind_group( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassPushDebugGroupArgs { - render_pass_rid: ResourceId, - group_label: String, -} - #[op] pub fn op_webgpu_render_pass_push_debug_group( state: &mut OpState, - args: RenderPassPushDebugGroupArgs, + render_pass_rid: ResourceId, + group_label: String, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; - let label = std::ffi::CString::new(args.group_label).unwrap(); + let label = std::ffi::CString::new(group_label).unwrap(); // SAFETY: the string the raw pointer points to lives longer than the below // function invocation. unsafe { @@ -362,20 +302,14 @@ pub fn op_webgpu_render_pass_push_debug_group( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassPopDebugGroupArgs { - render_pass_rid: ResourceId, -} - #[op] pub fn op_webgpu_render_pass_pop_debug_group( state: &mut OpState, - args: RenderPassPopDebugGroupArgs, + render_pass_rid: ResourceId, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_pop_debug_group( &mut render_pass_resource.0.borrow_mut(), @@ -384,23 +318,17 @@ pub fn op_webgpu_render_pass_pop_debug_group( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassInsertDebugMarkerArgs { - render_pass_rid: ResourceId, - marker_label: String, -} - #[op] pub fn op_webgpu_render_pass_insert_debug_marker( state: &mut OpState, - args: RenderPassInsertDebugMarkerArgs, + render_pass_rid: ResourceId, + marker_label: String, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; - let label = std::ffi::CString::new(args.marker_label).unwrap(); + let label = std::ffi::CString::new(marker_label).unwrap(); // SAFETY: the string the raw pointer points to lives longer than the below // function invocation. unsafe { @@ -414,24 +342,18 @@ pub fn op_webgpu_render_pass_insert_debug_marker( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassSetPipelineArgs { - render_pass_rid: ResourceId, - pipeline: u32, -} - #[op] pub fn op_webgpu_render_pass_set_pipeline( state: &mut OpState, - args: RenderPassSetPipelineArgs, + render_pass_rid: ResourceId, + pipeline: u32, ) -> Result { let render_pipeline_resource = state .resource_table - .get::(args.pipeline)?; + .get::(pipeline)?; let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_set_pipeline( &mut render_pass_resource.0.borrow_mut(), @@ -441,29 +363,23 @@ pub fn op_webgpu_render_pass_set_pipeline( Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassSetIndexBufferArgs { +#[op] +pub fn op_webgpu_render_pass_set_index_buffer( + state: &mut OpState, render_pass_rid: ResourceId, buffer: u32, index_format: wgpu_types::IndexFormat, offset: u64, size: Option, -} - -#[op] -pub fn op_webgpu_render_pass_set_index_buffer( - state: &mut OpState, - args: RenderPassSetIndexBufferArgs, ) -> Result { let buffer_resource = state .resource_table - .get::(args.buffer)?; + .get::(buffer)?; let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; - let size = if let Some(size) = args.size { + let size = if let Some(size) = size { Some( std::num::NonZeroU64::new(size) .ok_or_else(|| type_error("size must be larger than 0"))?, @@ -474,37 +390,31 @@ pub fn op_webgpu_render_pass_set_index_buffer( render_pass_resource.0.borrow_mut().set_index_buffer( buffer_resource.0, - args.index_format, - args.offset, + index_format, + offset, size, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassSetVertexBufferArgs { +#[op] +pub fn op_webgpu_render_pass_set_vertex_buffer( + state: &mut OpState, render_pass_rid: ResourceId, slot: u32, buffer: u32, offset: u64, size: Option, -} - -#[op] -pub fn op_webgpu_render_pass_set_vertex_buffer( - state: &mut OpState, - args: RenderPassSetVertexBufferArgs, ) -> Result { let buffer_resource = state .resource_table - .get::(args.buffer)?; + .get::(buffer)?; let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; - let size = if let Some(size) = args.size { + let size = if let Some(size) = size { Some( std::num::NonZeroU64::new(size) .ok_or_else(|| type_error("size must be larger than 0"))?, @@ -515,130 +425,106 @@ pub fn op_webgpu_render_pass_set_vertex_buffer( wgpu_core::command::render_ffi::wgpu_render_pass_set_vertex_buffer( &mut render_pass_resource.0.borrow_mut(), - args.slot, + slot, buffer_resource.0, - args.offset, + offset, size, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassDrawArgs { +#[op] +pub fn op_webgpu_render_pass_draw( + state: &mut OpState, render_pass_rid: ResourceId, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32, -} - -#[op] -pub fn op_webgpu_render_pass_draw( - state: &mut OpState, - args: RenderPassDrawArgs, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_draw( &mut render_pass_resource.0.borrow_mut(), - args.vertex_count, - args.instance_count, - args.first_vertex, - args.first_instance, + vertex_count, + instance_count, + first_vertex, + first_instance, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassDrawIndexedArgs { +#[op] +pub fn op_webgpu_render_pass_draw_indexed( + state: &mut OpState, render_pass_rid: ResourceId, index_count: u32, instance_count: u32, first_index: u32, base_vertex: i32, first_instance: u32, -} - -#[op] -pub fn op_webgpu_render_pass_draw_indexed( - state: &mut OpState, - args: RenderPassDrawIndexedArgs, ) -> Result { let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_draw_indexed( &mut render_pass_resource.0.borrow_mut(), - args.index_count, - args.instance_count, - args.first_index, - args.base_vertex, - args.first_instance, + index_count, + instance_count, + first_index, + base_vertex, + first_instance, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassDrawIndirectArgs { - render_pass_rid: ResourceId, - indirect_buffer: u32, - indirect_offset: u64, -} - #[op] pub fn op_webgpu_render_pass_draw_indirect( state: &mut OpState, - args: RenderPassDrawIndirectArgs, + render_pass_rid: ResourceId, + indirect_buffer: u32, + indirect_offset: u64, ) -> Result { let buffer_resource = state .resource_table - .get::(args.indirect_buffer)?; + .get::(indirect_buffer)?; let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_draw_indirect( &mut render_pass_resource.0.borrow_mut(), buffer_resource.0, - args.indirect_offset, + indirect_offset, ); Ok(WebGpuResult::empty()) } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct RenderPassDrawIndexedIndirectArgs { - render_pass_rid: ResourceId, - indirect_buffer: u32, - indirect_offset: u64, -} - #[op] pub fn op_webgpu_render_pass_draw_indexed_indirect( state: &mut OpState, - args: RenderPassDrawIndexedIndirectArgs, + render_pass_rid: ResourceId, + indirect_buffer: u32, + indirect_offset: u64, ) -> Result { let buffer_resource = state .resource_table - .get::(args.indirect_buffer)?; + .get::(indirect_buffer)?; let render_pass_resource = state .resource_table - .get::(args.render_pass_rid)?; + .get::(render_pass_rid)?; wgpu_core::command::render_ffi::wgpu_render_pass_draw_indexed_indirect( &mut render_pass_resource.0.borrow_mut(), buffer_resource.0, - args.indirect_offset, + indirect_offset, ); Ok(WebGpuResult::empty()) diff --git a/deno_webgpu/src/shader.rs b/deno_webgpu/src/shader.rs index f4155f42b2..b963f88542 100644 --- a/deno_webgpu/src/shader.rs +++ b/deno_webgpu/src/shader.rs @@ -5,7 +5,6 @@ use deno_core::op; use deno_core::OpState; use deno_core::Resource; use deno_core::ResourceId; -use serde::Deserialize; use std::borrow::Cow; use super::error::WebGpuResult; @@ -17,30 +16,24 @@ impl Resource for WebGpuShaderModule { } } -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CreateShaderModuleArgs { +#[op] +pub fn op_webgpu_create_shader_module( + state: &mut OpState, device_rid: ResourceId, label: Option, code: String, _source_map: Option<()>, // not yet implemented -} - -#[op] -pub fn op_webgpu_create_shader_module( - state: &mut OpState, - args: CreateShaderModuleArgs, ) -> Result { let instance = state.borrow::(); let device_resource = state .resource_table - .get::(args.device_rid)?; + .get::(device_rid)?; let device = device_resource.0; - let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(args.code)); + let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(code)); let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor { - label: args.label.map(Cow::from), + label: label.map(Cow::from), shader_bound_checks: wgpu_types::ShaderBoundChecks::default(), };