Skip to content

Commit

Permalink
Some day I will learn to run cargo fmt and check compile before merges
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 committed Oct 20, 2024
1 parent 24ec452 commit 620405f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 51 deletions.
86 changes: 42 additions & 44 deletions examples/push_constants/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,26 @@
#define LOG_PREFIX "[push_constants]"

static void handle_request_adapter(WGPURequestAdapterStatus status,
WGPUAdapter adapter, char const *message,
void *userdata) {
WGPUAdapter adapter, WGPUStringView message,
void *userdata1, void *userdata2) {
UNUSED(status)
UNUSED(message)
*(WGPUAdapter *)userdata = adapter;
UNUSED(userdata2)
*(WGPUAdapter *)userdata1 = adapter;
}
static void handle_request_device(WGPURequestDeviceStatus status,
WGPUDevice device, char const *message,
void *userdata) {
WGPUDevice device, WGPUStringView message,
void *userdata1, void *userdata2) {
UNUSED(status)
UNUSED(message)
*(WGPUDevice *)userdata = device;
UNUSED(userdata2)
*(WGPUDevice *)userdata1 = device;
}
static void handle_buffer_map(WGPUBufferMapAsyncStatus status, void *userdata) {
UNUSED(userdata)
static void handle_buffer_map(WGPUMapAsyncStatus status,
WGPUStringView message,
void *userdata1, void *userdata2) {
UNUSED(userdata1)
UNUSED(userdata2)
printf(LOG_PREFIX " buffer_map status=%#.8x\n", status);
}

Expand All @@ -39,50 +44,41 @@ int main(int argc, char *argv[]) {
assert(instance);

WGPUAdapter adapter = NULL;
wgpuInstanceRequestAdapter(instance, NULL, handle_request_adapter,
(void *)&adapter);
wgpuInstanceRequestAdapter(instance, NULL,
(const WGPURequestAdapterCallbackInfo){
.callback = handle_request_adapter,
.userdata1 = &adapter
});
assert(adapter);

WGPUSupportedLimitsExtras supported_limits_extras = {
WGPUNativeLimits supported_limits_extras = {
.chain =
{
.sType = WGPUSType_SupportedLimitsExtras,
},
.limits =
{
.maxPushConstantSize = 0,
.sType = WGPUSType_NativeLimits,
},
.maxPushConstantSize = 0,
};
WGPUSupportedLimits supported_limits = {
WGPULimits supported_limits = {
.nextInChain = &supported_limits_extras.chain,
};
wgpuAdapterGetLimits(adapter, &supported_limits);

WGPURequiredLimitsExtras required_limits_extras = {
.chain =
{
.sType = WGPUSType_RequiredLimitsExtras,
},
.limits = supported_limits_extras.limits,
};
WGPURequiredLimits required_limits = {
.nextInChain = &required_limits_extras.chain,
.limits = supported_limits.limits,
};

WGPUFeatureName requiredFeatures[] = {
WGPUNativeFeature_PushConstants,
};
WGPUDeviceDescriptor device_desc = {
.label = "compute_device",
.label = {"compute_device", WGPU_STRLEN},
.requiredFeatures = requiredFeatures,
.requiredFeatureCount = 1,
.requiredLimits = &required_limits,
.requiredLimits = &supported_limits,
};

WGPUDevice device = NULL;
wgpuAdapterRequestDevice(adapter, &device_desc, handle_request_device,
(void *)&device);
wgpuAdapterRequestDevice(adapter, &device_desc,
(const WGPURequestDeviceCallbackInfo){
.callback = handle_request_device,
.userdata1 = &device
});
assert(device);

WGPUQueue queue = wgpuDeviceGetQueue(device);
Expand All @@ -94,7 +90,7 @@ int main(int argc, char *argv[]) {

WGPUBuffer storage_buffer = wgpuDeviceCreateBuffer(
device, &(const WGPUBufferDescriptor){
.label = "storage_buffer",
.label = {"storage_buffer", WGPU_STRLEN},
.usage = WGPUBufferUsage_Storage | WGPUBufferUsage_CopyDst |
WGPUBufferUsage_CopySrc,
.size = numbers_size,
Expand All @@ -104,7 +100,7 @@ int main(int argc, char *argv[]) {

WGPUBuffer staging_buffer = wgpuDeviceCreateBuffer(
device, &(const WGPUBufferDescriptor){
.label = "staging_buffer",
.label = {"staging_buffer", WGPU_STRLEN},
.usage = WGPUBufferUsage_MapRead | WGPUBufferUsage_CopyDst,
.size = numbers_size,
.mappedAtCreation = false,
Expand Down Expand Up @@ -137,7 +133,7 @@ int main(int argc, char *argv[]) {
},
};
WGPUBindGroupLayoutDescriptor bind_group_layout_desc = {
.label = "bind_group_layout",
.label = {"bind_group_layout", WGPU_STRLEN},
.nextInChain = NULL,
.entryCount = 1,
.entries = bind_group_layout_entries,
Expand All @@ -147,7 +143,7 @@ int main(int argc, char *argv[]) {
assert(bind_group_layout);

WGPUPipelineLayoutDescriptor pipeline_layout_desc = {
.label = "pipeline_layout",
.label = {"pipeline_layout", WGPU_STRLEN},
.nextInChain = &pipeline_layout_extras.chain,
.bindGroupLayouts = &bind_group_layout,
.bindGroupLayoutCount = 1,
Expand All @@ -158,19 +154,19 @@ int main(int argc, char *argv[]) {

WGPUComputePipeline compute_pipeline = wgpuDeviceCreateComputePipeline(
device, &(const WGPUComputePipelineDescriptor){
.label = "compute_pipeline",
.label = {"compute_pipeline", WGPU_STRLEN},
.compute =
(const WGPUProgrammableStageDescriptor){
.module = shader_module,
.entryPoint = "main",
.entryPoint = {"main", WGPU_STRLEN},
},
.layout = pipeline_layout,
});
assert(compute_pipeline);

WGPUBindGroup bind_group = wgpuDeviceCreateBindGroup(
device, &(const WGPUBindGroupDescriptor){
.label = "bind_group",
.label = {"bind_group", WGPU_STRLEN},
.layout = bind_group_layout,
.entryCount = 1,
.entries =
Expand All @@ -187,14 +183,14 @@ int main(int argc, char *argv[]) {

WGPUCommandEncoder command_encoder = wgpuDeviceCreateCommandEncoder(
device, &(const WGPUCommandEncoderDescriptor){
.label = "command_encoder",
.label = {"command_encoder", WGPU_STRLEN},
});
assert(command_encoder);

WGPUComputePassEncoder compute_pass_encoder =
wgpuCommandEncoderBeginComputePass(command_encoder,
&(const WGPUComputePassDescriptor){
.label = "compute_pass",
.label = {"compute_pass", WGPU_STRLEN},
});
assert(compute_pass_encoder);

Expand All @@ -219,15 +215,17 @@ int main(int argc, char *argv[]) {

WGPUCommandBuffer command_buffer = wgpuCommandEncoderFinish(
command_encoder, &(const WGPUCommandBufferDescriptor){
.label = "command_buffer",
.label = {"command_buffer", WGPU_STRLEN},
});
assert(command_buffer);

wgpuQueueWriteBuffer(queue, storage_buffer, 0, &numbers, numbers_size);
wgpuQueueSubmit(queue, 1, &command_buffer);

wgpuBufferMapAsync(staging_buffer, WGPUMapMode_Read, 0, numbers_size,
handle_buffer_map, NULL);
(const WGPUBufferMapCallbackInfo){
.callback = handle_buffer_map
});
wgpuDevicePoll(device, true, NULL);

uint32_t *buf =
Expand Down
4 changes: 2 additions & 2 deletions ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ typedef struct WGPUDeviceExtras {

typedef struct WGPUNativeLimits {
/** This struct chain is used as mutable in some places and immutable in others. */
WGPUChainedStructOut * nextInChain;
WGPUChainedStructOut chain;
uint32_t maxPushConstantSize;
uint32_t maxNonSamplerBindings;
} WGPUNativeLimits;
Expand Down Expand Up @@ -173,7 +173,7 @@ typedef struct WGPUShaderModuleGLSLDescriptor {
} WGPUShaderModuleGLSLDescriptor;

typedef struct WGPUShaderModuleDescriptorSpirV {
char const * label;
WGPUStringView label;
uint32_t sourceSize;
uint32_t const * source;
} WGPUShaderModuleDescriptorSpirV;
Expand Down
5 changes: 1 addition & 4 deletions src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,7 @@ pub unsafe fn map_pipeline_layout_descriptor<'a>(
}

#[inline]
pub fn write_limits_struct(
wgt_limits: wgt::Limits,
limits: &mut native::WGPULimits,
) {
pub fn write_limits_struct(wgt_limits: wgt::Limits, limits: &mut native::WGPULimits) {
limits.maxTextureDimension1D = wgt_limits.max_texture_dimension_1d;
limits.maxTextureDimension2D = wgt_limits.max_texture_dimension_2d;
limits.maxTextureDimension3D = wgt_limits.max_texture_dimension_3d;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4357,7 +4357,7 @@ pub unsafe extern "C" fn wgpuDeviceCreateShaderModuleSpirV(
let descriptor = descriptor.expect("invalid descriptor");

let desc = wgc::pipeline::ShaderModuleDescriptor {
label: ptr_into_label(descriptor.label),
label: string_view_into_label(descriptor.label),
shader_bound_checks: unsafe { wgt::ShaderBoundChecks::unchecked() },
};

Expand Down

0 comments on commit 620405f

Please sign in to comment.