Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .sdkmanrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=25.0.2-librca
java=25.0.3-librca
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<version.wgpu-native>v27.0.4.0</version.wgpu-native>
<version.wgpu-native>v29.0.0.0</version.wgpu-native>
<version.helidon>4.4.0</version.helidon>
<version.jspecify>1.0.0</version.jspecify>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ protected void setup(final Device device, final Queue queue) {
.build());

this.computePipeline = device.createComputePipeline(ComputePipelineDescriptor.builder()
.compute(builder -> builder
.compute(ComputeState.builder()
.module(loadShader(device, "wgsl/compute-boids-compute.wgsl"))
.entryPoint("main")
.build()
)
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected void setup(final Device device, final Queue queue) {
this.computePipeline = device.createComputePipeline(ComputePipelineDescriptor.builder()
.label("Simulation pipeline")
.layout(pipelineLayout)
.compute(ProgrammableStageDescriptor.builder()
.compute(ComputeState.builder()
.module(computeShaderModule)
.entryPoint("computeMain")
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ protected void run(final String[] args) {
final var texture = surfaceTexture.texture();

switch (surfaceTexture.status()) {
case OUT_OF_MEMORY, DEVICE_LOST, FORCE32 -> throw new OutOfMemoryError("Out of memory");
case ERROR -> {
IO.println("Error getting surface texture: %s!".formatted(surfaceTexture.status()));
continue;
}
case TIMEOUT, OUTDATED, LOST -> {
if (texture != null) {
texture.close();
Expand All @@ -134,13 +137,13 @@ protected void run(final String[] args) {
}
continue;
}
case SUCCESS_OPTIMAL, SUCCESS_SUBOPTIMAL -> {
render(device, queue, surface, texture);
// All WebGPU objects are auto-closable, but if you forgot to close them, they will be closed when
// the object being garbage collected.
texture.close();
}
}

render(device, queue, surface, texture);

// All WebGPU objects are auto-closable, but if you forgot to close them, they will be closed when
// the object being garbage collected.
texture.close();
}

surface.close();
Expand All @@ -164,6 +167,8 @@ private void configureSurface(final Surface surface, final Device device,
.format(getPreferredFormat())
.width(width)
.height(height)
.presentMode(PresentMode.FIFO)
.alphaMode(this.capabilities.getAlphaModes().getFirst())
.usage(EnumSet.of(TextureUsage.RENDER_ATTACHMENT))
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ComputePassDescriptorBlueprint extends StructBlueprint {

Optional<String> label();

Optional<ComputePassTimestampWrites> timestampWrites();
Optional<PassTimestampWrites> timestampWrites();

@Override
default MemorySegment toSegment(final Arena arena) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ComputePipelineDescriptorBlueprint extends StructBlueprint {

Optional<PipelineLayout> layout();

ProgrammableStageDescriptor compute();
ComputeStateBlueprint compute();

@Override
default MemorySegment toSegment(final Arena arena) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.bahaa.webgpu.api.model;

import io.github.bahaa.webgpu.api.ShaderModule;
import io.github.bahaa.webgpu.ffm.WGPUComputeState;
import io.github.bahaa.webgpu.ffm.WGPUConstantEntry;
import io.github.bahaa.webgpu.ffm.WGPUProgrammableStageDescriptor;
import io.helidon.builder.api.Prototype;

import java.lang.foreign.Arena;
Expand All @@ -11,7 +11,7 @@
import java.util.Optional;

@Prototype.Blueprint
interface ProgrammableStageDescriptorBlueprint extends StructBlueprint {
interface ComputeStateBlueprint extends StructBlueprint {

ShaderModule module();

Expand All @@ -21,19 +21,19 @@ interface ProgrammableStageDescriptorBlueprint extends StructBlueprint {

@Override
default MemorySegment toSegment(final Arena arena) {
final var struct = WGPUProgrammableStageDescriptor.allocate(arena);
final var struct = WGPUComputeState.allocate(arena);
updateSegment(arena, struct);
return struct;
}

@Override
default void updateSegment(final Arena arena, final MemorySegment struct) {
WGPUProgrammableStageDescriptor.module(struct, this.module().pointer());
WGPUComputeState.module(struct, this.module().pointer());

entryPoint().ifPresent(entryPoint ->
WGPUProgrammableStageDescriptor.entryPoint(struct, StringView.from(entryPoint).toSegment(arena)));
WGPUComputeState.entryPoint(struct, StringView.from(entryPoint).toSegment(arena)));

WGPUProgrammableStageDescriptor.constants(struct,
WGPUComputeState.constants(struct,
StructBlueprint.structArray(arena, WGPUConstantEntry.layout(), this.constants()));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.util.Optional;
import java.lang.foreign.ValueLayout;
import java.util.Set;

@Prototype.Blueprint
interface InstanceDescriptorBlueprint extends StructBlueprint {

/**
* Instance features to enable
*/
@Option.DefaultCode("InstanceCapabilities.builder().build()")
Optional<InstanceCapabilities> features();
@Option.Singular("requiredFeature")
@Option.DefaultCode("java.util.EnumSet.noneOf(InstanceFeatureName.class)")
Set<InstanceFeatureName> requiredFeatures();

@Override
default MemorySegment toSegment(final Arena arena) {
Expand All @@ -26,6 +28,13 @@ default MemorySegment toSegment(final Arena arena) {

@Override
default void updateSegment(final Arena arena, final MemorySegment struct) {
features().ifPresent(features -> WGPUInstanceDescriptor.features(struct, features.toSegment(arena)));
final var segment = arena.allocate(ValueLayout.JAVA_INT, this.requiredFeatures().size());
var index = 0;
for (final var feature : this.requiredFeatures()) {
segment.setAtIndex(ValueLayout.JAVA_INT, index, feature.value());
index++;
}
WGPUInstanceDescriptor.requiredFeatures(struct, segment);
WGPUInstanceDescriptor.requiredFeatureCount(struct, requiredFeatures().size());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.bahaa.webgpu.api.model;

public enum InstanceFeatureName {
TIMED_WAIT_ANY(0x00000001),
SHADER_SOURCE_SPIRV(0x00000002),
MULTIPLE_DEVICES_PER_ADAPTER(0x00000003);

private final int value;


InstanceFeatureName(final int value) {
this.value = value;
}

public int value() {
return this.value;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package io.github.bahaa.webgpu.api.model;

import io.github.bahaa.webgpu.api.QuerySet;
import io.github.bahaa.webgpu.ffm.WGPURenderPassTimestampWrites;
import io.github.bahaa.webgpu.ffm.WGPUPassTimestampWrites;
import io.helidon.builder.api.Prototype;

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;

@Prototype.Blueprint
interface RenderPassTimestampWritesBlueprint extends StructBlueprint {

interface PassTimestampWritesBlueprint extends StructBlueprint {
QuerySet querySet();

int beginningOfPassWriteIndex();
Expand All @@ -18,15 +17,15 @@ interface RenderPassTimestampWritesBlueprint extends StructBlueprint {

@Override
default MemorySegment toSegment(final Arena arena) {
final var struct = WGPURenderPassTimestampWrites.allocate(arena);
final var struct = WGPUPassTimestampWrites.allocate(arena);
updateSegment(arena, struct);
return struct;
}

@Override
default void updateSegment(final Arena arena, final MemorySegment struct) {
WGPURenderPassTimestampWrites.querySet(struct, this.querySet().pointer());
WGPURenderPassTimestampWrites.beginningOfPassWriteIndex(struct, this.beginningOfPassWriteIndex());
WGPURenderPassTimestampWrites.endOfPassWriteIndex(struct, this.endOfPassWriteIndex());
WGPUPassTimestampWrites.querySet(struct, this.querySet().pointer());
WGPUPassTimestampWrites.beginningOfPassWriteIndex(struct, this.beginningOfPassWriteIndex());
WGPUPassTimestampWrites.endOfPassWriteIndex(struct, this.endOfPassWriteIndex());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface RenderPassDescriptorBlueprint extends StructBlueprint {

Optional<QuerySet> occlusionQuerySet();

Optional<RenderPassTimestampWrites> timestampWrites();
Optional<PassTimestampWrites> timestampWrites();

@Override
default MemorySegment toSegment(final Arena arena) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum SurfaceGetCurrentTextureStatus {
SUCCESS_OPTIMAL(0x00000001),

/**
* The surface can present the frame, but may need reconfiguration.
* Still OK - the surface can present the frame, but in a suboptimal way. The surface may need reconfiguration.
*/
SUCCESS_SUBOPTIMAL(0x00000002),

Expand All @@ -25,24 +25,16 @@ public enum SurfaceGetCurrentTextureStatus {
OUTDATED(0x00000004),

/**
* The connection to the surface owner was lost.
* The connection to whatever owns the surface was lost, or generally needs to be fully reinitialized.
*/
LOST(0x00000005),

/**
* The system ran out of memory.
* There was some deterministic error (for example, the surface is not configured, or there was an
*
* @ref OutStructChainError). Should produce @ref ImplementationDefinedLogging containing details.
*/
OUT_OF_MEMORY(0x00000006),

/**
* The WGPUDevice configured on the WGPUSurface was lost.
*/
DEVICE_LOST(0x00000007),

/**
* The surface is not configured, or there was an error.
*/
ERROR(0x00000008),
ERROR(0x00000006),

FORCE32(0x7FFFFFFF);

Expand All @@ -61,7 +53,7 @@ public static SurfaceGetCurrentTextureStatus fromValue(final int value) {
return status;
}
}
return ERROR;
throw new IllegalArgumentException("invalid value %d".formatted(value));
}

public int getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ default void updateSegment(final Arena arena, final MemorySegment struct) {
index++;
}
WGPUTextureDescriptor.viewFormats(struct, segment);
WGPUTextureDescriptor.viewFormatCount(struct, this.viewFormats().size());
}
}
Loading
Loading