Skip to content

Commit

Permalink
Minor renames to address the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Aug 17, 2019
1 parent 37afa0d commit f82ceba
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 78 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ lib-remote: Cargo.lock wgpu-remote/Cargo.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE)
cargo build --manifest-path wgpu-remote/Cargo.toml --features $(FEATURE_RUST)

$(FFI_DIR)/wgpu.h: wgpu-native/cbindgen.toml $(WILDCARD_WGPU_NATIVE)
rustup run nightly cbindgen wgpu-native > $(FFI_DIR)/wgpu.h
rustup run nightly cbindgen -o $(FFI_DIR)/wgpu.h wgpu-native

$(FFI_DIR)/wgpu-remote.h: wgpu-remote/cbindgen.toml $(WILDCARD_WGPU_NATIVE_AND_REMOTE)
rustup run nightly cbindgen wgpu-remote > $(FFI_DIR)/wgpu-remote.h
rustup run nightly cbindgen -o $(FFI_DIR)/wgpu-remote.h wgpu-remote

example-compute: lib-native $(FFI_DIR)/wgpu.h examples/compute/main.c
cd examples/compute && $(CREATE_BUILD_DIR) && cd build && cmake .. -DBACKEND=$(FEATURE_RUST) $(GENERATOR_PLATFORM) && cmake --build .
Expand Down
16 changes: 4 additions & 12 deletions examples/compute/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,8 @@ int main(
uint32_t numbers_length = size / sizeof(uint32_t);

WGPUInstanceId instance = wgpu_create_instance();

WGPUAdapterId adapter = wgpu_instance_request_adapter(instance,
&(WGPUAdapterDescriptor){
.power_preference = WGPUPowerPreference_LowPower,
});

WGPUDeviceId device = wgpu_adapter_request_device(adapter,
&(WGPUDeviceDescriptor){
.extensions = NULL
});
WGPUAdapterId adapter = wgpu_instance_request_adapter(instance, NULL);
WGPUDeviceId device = wgpu_adapter_request_device(adapter, NULL);

uint8_t *staging_memory;

Expand Down Expand Up @@ -100,7 +92,7 @@ int main(
wgpu_device_create_compute_pipeline(device,
&(WGPUComputePipelineDescriptor){
.layout = pipeline_layout,
.compute_stage = (WGPUPipelineStageDescriptor){
.compute_stage = (WGPUProgrammableStageDescriptor){
.module = shader_module,
.entry_point = "main"
}});
Expand All @@ -126,7 +118,7 @@ int main(

WGPUQueueId queue = wgpu_device_get_queue(device);

WGPUCommandBufferId command_buffer = wgpu_command_encoder_finish(encoder);
WGPUCommandBufferId command_buffer = wgpu_command_encoder_finish(encoder, NULL);

wgpu_queue_submit(queue, &command_buffer, 1);

Expand Down
10 changes: 5 additions & 5 deletions examples/triangle/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main() {
WGPUInstanceId instance = wgpu_create_instance();

WGPUAdapterId adapter = wgpu_instance_request_adapter(instance,
&(WGPUAdapterDescriptor){
&(WGPURequestAdapterOptions){
.power_preference = WGPUPowerPreference_LowPower,
});

Expand Down Expand Up @@ -88,17 +88,17 @@ int main() {
&(WGPURenderPipelineDescriptor){
.layout = pipeline_layout,
.vertex_stage =
(WGPUPipelineStageDescriptor){
(WGPUProgrammableStageDescriptor){
.module = vertex_shader,
.entry_point = "main",
},
.fragment_stage =
&(WGPUPipelineStageDescriptor){
&(WGPUProgrammableStageDescriptor){
.module = fragment_shader,
.entry_point = "main",
},
.rasterization_state =
(WGPURasterizationStateDescriptor){
&(WGPURasterizationStateDescriptor){
.front_face = WGPUFrontFace_Ccw,
.cull_mode = WGPUCullMode_None,
.depth_bias = 0,
Expand Down Expand Up @@ -238,7 +238,7 @@ int main() {
wgpu_render_pass_draw(rpass, 3, 1, 0, 0);
WGPUQueueId queue = wgpu_device_get_queue(device);
wgpu_render_pass_end_pass(rpass);
WGPUCommandBufferId cmd_buf = wgpu_command_encoder_finish(cmd_encoder);
WGPUCommandBufferId cmd_buf = wgpu_command_encoder_finish(cmd_encoder, NULL);
wgpu_queue_submit(queue, &cmd_buf, 1);
wgpu_swap_chain_present(swap_chain);

Expand Down
5 changes: 3 additions & 2 deletions ffi/wgpu-remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef struct {

typedef struct {
WGPUPowerPreference power_preference;
} WGPUAdapterDescriptor;
} WGPURequestAdapterOptions;

typedef struct {
WGPUClientFactory *factory;
Expand All @@ -63,7 +63,8 @@ WGPUClient *wgpu_client_create(const WGPUClientFactory *factory);

void wgpu_client_destroy(const WGPUClientFactory *factory, WGPUClient *client);

WGPUAdapterId wgpu_client_get_adapter(const WGPUClient *client, const WGPUAdapterDescriptor *desc);
WGPUAdapterId wgpu_client_get_adapter(const WGPUClient *client,
const WGPURequestAdapterOptions *desc);

WGPUInfrastructure wgpu_initialize(void);

Expand Down
32 changes: 19 additions & 13 deletions ffi/wgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ typedef struct {
const WGPURenderPassDepthStencilAttachmentDescriptor_TextureViewId *depth_stencil_attachment;
} WGPURenderPassDescriptor;

typedef struct {
uint32_t todo;
} WGPUCommandBufferDescriptor;

typedef const char *WGPURawString;

typedef WGPUId WGPUComputePipelineId;
Expand Down Expand Up @@ -454,11 +458,11 @@ typedef WGPUId WGPUShaderModuleId;
typedef struct {
WGPUShaderModuleId module;
WGPURawString entry_point;
} WGPUPipelineStageDescriptor;
} WGPUProgrammableStageDescriptor;

typedef struct {
WGPUPipelineLayoutId layout;
WGPUPipelineStageDescriptor compute_stage;
WGPUProgrammableStageDescriptor compute_stage;
} WGPUComputePipelineDescriptor;

typedef struct {
Expand Down Expand Up @@ -537,17 +541,17 @@ typedef struct {

typedef struct {
WGPUPipelineLayoutId layout;
WGPUPipelineStageDescriptor vertex_stage;
const WGPUPipelineStageDescriptor *fragment_stage;
WGPUProgrammableStageDescriptor vertex_stage;
const WGPUProgrammableStageDescriptor *fragment_stage;
WGPUPrimitiveTopology primitive_topology;
WGPURasterizationStateDescriptor rasterization_state;
const WGPURasterizationStateDescriptor *rasterization_state;
const WGPUColorStateDescriptor *color_states;
uintptr_t color_states_length;
const WGPUDepthStencilStateDescriptor *depth_stencil_state;
WGPUVertexInputDescriptor vertex_input;
uint32_t sample_count;
uint32_t sample_mask;
bool alpha_coverage_enabled;
bool alpha_to_coverage_enabled;
} WGPURenderPipelineDescriptor;

typedef struct {
Expand Down Expand Up @@ -606,7 +610,7 @@ typedef WGPUDeviceId WGPUQueueId;

typedef struct {
WGPUPowerPreference power_preference;
} WGPUAdapterDescriptor;
} WGPURequestAdapterOptions;

typedef WGPUId WGPURenderBundleId;

Expand Down Expand Up @@ -649,10 +653,10 @@ void wgpu_buffer_map_write_async(WGPUBufferId buffer_id,
void wgpu_buffer_unmap(WGPUBufferId buffer_id);

void wgpu_command_buffer_copy_buffer_to_buffer(WGPUCommandBufferId command_buffer_id,
WGPUBufferId src,
WGPUBufferAddress src_offset,
WGPUBufferId dst,
WGPUBufferAddress dst_offset,
WGPUBufferId source,
WGPUBufferAddress source_offset,
WGPUBufferId destination,
WGPUBufferAddress destination_offset,
WGPUBufferAddress size);

void wgpu_command_buffer_copy_buffer_to_texture(WGPUCommandBufferId command_buffer_id,
Expand All @@ -679,7 +683,8 @@ WGPURenderPassId wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId com
const WGPURenderPassDescriptor *desc);
#endif

WGPUCommandBufferId wgpu_command_encoder_finish(WGPUCommandEncoderId command_encoder_id);
WGPUCommandBufferId wgpu_command_encoder_finish(WGPUCommandEncoderId command_encoder_id,
const WGPUCommandBufferDescriptor *_desc);

void wgpu_compute_pass_dispatch(WGPUComputePassId pass_id, uint32_t x, uint32_t y, uint32_t z);

Expand Down Expand Up @@ -795,7 +800,7 @@ WGPUSurfaceId wgpu_instance_create_surface_from_xlib(WGPUInstanceId instance_id,

#if defined(WGPU_LOCAL)
WGPUAdapterId wgpu_instance_request_adapter(WGPUInstanceId instance_id,
const WGPUAdapterDescriptor *desc);
const WGPURequestAdapterOptions *desc);
#endif

void wgpu_queue_submit(WGPUQueueId queue_id,
Expand Down Expand Up @@ -858,6 +863,7 @@ void wgpu_render_pass_set_scissor_rect(WGPURenderPassId pass_id,
void wgpu_render_pass_set_stencil_reference(WGPURenderPassId pass_id, uint32_t value);

void wgpu_render_pass_set_vertex_buffers(WGPURenderPassId pass_id,
uint32_t start_slot,
const WGPUBufferId *buffers,
const WGPUBufferAddress *offsets,
uintptr_t length);
Expand Down
7 changes: 7 additions & 0 deletions wgpu-native/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,16 @@ pub struct CommandEncoderDescriptor {
pub todo: u32,
}

#[repr(C)]
#[derive(Debug)]
pub struct CommandBufferDescriptor {
pub todo: u32,
}

#[no_mangle]
pub extern "C" fn wgpu_command_encoder_finish(
command_encoder_id: CommandEncoderId,
_desc: Option<&CommandBufferDescriptor>,
) -> CommandBufferId {
let mut token = Token::root();
//TODO: actually close the last recorded command buffer
Expand Down
16 changes: 8 additions & 8 deletions wgpu-native/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ impl TextureCopyView {
#[no_mangle]
pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer(
command_buffer_id: CommandBufferId,
src: BufferId,
src_offset: BufferAddress,
dst: BufferId,
dst_offset: BufferAddress,
source: BufferId,
source_offset: BufferAddress,
destination: BufferId,
destination_offset: BufferAddress,
size: BufferAddress,
) {
let mut token = Token::root();
Expand All @@ -84,7 +84,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer(
let (src_buffer, src_pending) = cmb
.trackers
.buffers
.use_replace(&*buffer_guard, src, (), BufferUsage::COPY_SRC);
.use_replace(&*buffer_guard, source, (), BufferUsage::COPY_SRC);
barriers.extend(src_pending.map(|pending| hal::memory::Barrier::Buffer {
states: pending.to_states(),
target: &src_buffer.raw,
Expand All @@ -95,7 +95,7 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer(
let (dst_buffer, dst_pending) = cmb
.trackers
.buffers
.use_replace(&*buffer_guard, dst, (), BufferUsage::COPY_DST);
.use_replace(&*buffer_guard, destination, (), BufferUsage::COPY_DST);
barriers.extend(dst_pending.map(|pending| hal::memory::Barrier::Buffer {
states: pending.to_states(),
target: &dst_buffer.raw,
Expand All @@ -104,8 +104,8 @@ pub extern "C" fn wgpu_command_buffer_copy_buffer_to_buffer(
}));

let region = hal::command::BufferCopy {
src: src_offset,
dst: dst_offset,
src: source_offset,
dst: destination_offset,
size,
};
let cmb_raw = cmb.raw.last_mut().unwrap();
Expand Down
30 changes: 19 additions & 11 deletions wgpu-native/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,16 +1166,20 @@ pub fn device_create_bind_group(
.use_extend(&*buffer_guard, bb.buffer, (), usage)
.unwrap();

let start = bb.offset;
let end = bb.offset + bb.size;
assert!(
end <= buffer.size,
"Bound buffer range {:?} does not fit in buffer size {}",
start .. end,
buffer.size
);
let end = if bb.size == 0 {
None
} else {
let end = bb.offset + bb.size;
assert!(
end <= buffer.size,
"Bound buffer range {:?} does not fit in buffer size {}",
bb.offset .. end,
buffer.size
);
Some(end)
};

let range = Some(start) .. Some(end);
let range = Some(bb.offset) .. end;
hal::pso::Descriptor::Buffer(&buffer.raw, range)
}
binding_model::BindingResource::Sampler(id) => {
Expand Down Expand Up @@ -1603,7 +1607,11 @@ pub fn device_create_render_pipeline(
geometry: None,
fragment,
};
let rasterizer = conv::map_rasterization_state_descriptor(&desc.rasterization_state);
let rasterizer = conv::map_rasterization_state_descriptor(
&unsafe { desc.rasterization_state.as_ref() }
.cloned()
.unwrap_or_default(),
);

let desc_vbs = unsafe {
slice::from_raw_parts(
Expand Down Expand Up @@ -1665,7 +1673,7 @@ pub fn device_create_render_pipeline(
rasterization_samples: sc,
sample_shading: None,
sample_mask: !0,
alpha_coverage: false,
alpha_coverage: desc.alpha_to_coverage_enabled,
alpha_to_one: false,
})
};
Expand Down
Loading

0 comments on commit f82ceba

Please sign in to comment.