Minor renames to address the review comments

This commit is contained in:
Dzmitry Malyshau 2019-08-16 00:15:51 -04:00
parent 37afa0d98a
commit f82ceba3c2
12 changed files with 102 additions and 78 deletions

View File

@ -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 .

View File

@ -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;
@ -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"
}});
@ -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);

View File

@ -36,7 +36,7 @@ int main() {
WGPUInstanceId instance = wgpu_create_instance();
WGPUAdapterId adapter = wgpu_instance_request_adapter(instance,
&(WGPUAdapterDescriptor){
&(WGPURequestAdapterOptions){
.power_preference = WGPUPowerPreference_LowPower,
});
@ -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,
@ -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);

View File

@ -47,7 +47,7 @@ typedef struct {
typedef struct {
WGPUPowerPreference power_preference;
} WGPUAdapterDescriptor;
} WGPURequestAdapterOptions;
typedef struct {
WGPUClientFactory *factory;
@ -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);

View File

@ -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;
@ -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 {
@ -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 {
@ -606,7 +610,7 @@ typedef WGPUDeviceId WGPUQueueId;
typedef struct {
WGPUPowerPreference power_preference;
} WGPUAdapterDescriptor;
} WGPURequestAdapterOptions;
typedef WGPUId WGPURenderBundleId;
@ -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,
@ -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);
@ -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,
@ -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);

View File

@ -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

View File

@ -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();
@ -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,
@ -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,
@ -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();

View File

@ -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) => {
@ -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(
@ -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,
})
};

View File

@ -26,23 +26,29 @@ pub enum PowerPreference {
HighPerformance = 2,
}
impl Default for PowerPreference {
fn default() -> Self {
PowerPreference::Default
}
}
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))]
pub struct AdapterDescriptor {
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "remote", derive(Serialize, Deserialize))]
pub struct RequestAdapterOptions {
pub power_preference: PowerPreference,
}
#[repr(C)]
#[derive(Debug, Default)]
#[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))]
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "remote", derive(Serialize, Deserialize))]
pub struct Extensions {
pub anisotropic_filtering: bool,
}
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "remote", derive(Serialize, Deserialize))]
pub struct Limits {
pub max_bind_groups: u32,
}
@ -56,8 +62,8 @@ impl Default for Limits {
}
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "remote", derive(Clone, Serialize, Deserialize))]
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "remote", derive(Serialize, Deserialize))]
pub struct DeviceDescriptor {
pub extensions: Extensions,
pub limits: Limits,
@ -204,7 +210,7 @@ pub fn wgpu_instance_get_gl_surface(instance_id: InstanceId) -> SurfaceId {
pub fn instance_get_adapter(
instance_id: InstanceId,
desc: &AdapterDescriptor,
desc: &RequestAdapterOptions,
token: &mut Token<Root>,
) -> AdapterHandle {
#[cfg(not(feature = "gfx-backend-gl"))]
@ -258,10 +264,10 @@ pub fn instance_get_adapter(
#[no_mangle]
pub extern "C" fn wgpu_instance_request_adapter(
instance_id: InstanceId,
desc: &AdapterDescriptor,
desc: Option<&RequestAdapterOptions>,
) -> AdapterId {
let mut token = Token::root();
let adapter = instance_get_adapter(instance_id, desc, &mut token);
let adapter = instance_get_adapter(instance_id, &desc.cloned().unwrap_or_default(), &mut token);
let limits = adapter.physical_device.limits();
info!("Adapter {:?}", adapter.info);
@ -295,9 +301,13 @@ pub fn adapter_create_device(
#[no_mangle]
pub extern "C" fn wgpu_adapter_request_device(
adapter_id: AdapterId,
desc: &DeviceDescriptor,
desc: Option<&DeviceDescriptor>,
) -> DeviceId {
let mut token = Token::root();
let device = adapter_create_device(adapter_id, desc, &mut token);
let device = adapter_create_device(
adapter_id,
&desc.cloned().unwrap_or_default(),
&mut token,
);
HUB.devices.register_local(device, &mut token)
}

View File

@ -248,7 +248,7 @@ pub struct ShaderModuleDescriptor {
#[repr(C)]
#[derive(Debug)]
pub struct PipelineStageDescriptor {
pub struct ProgrammableStageDescriptor {
pub module: ShaderModuleId,
pub entry_point: RawString,
}
@ -257,7 +257,7 @@ pub struct PipelineStageDescriptor {
#[derive(Debug)]
pub struct ComputePipelineDescriptor {
pub layout: PipelineLayoutId,
pub compute_stage: PipelineStageDescriptor,
pub compute_stage: ProgrammableStageDescriptor,
}
#[derive(Debug)]
@ -304,7 +304,7 @@ impl Default for CullMode {
}
#[repr(C)]
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct RasterizationStateDescriptor {
pub front_face: FrontFace,
pub cull_mode: CullMode,
@ -317,17 +317,17 @@ pub struct RasterizationStateDescriptor {
#[derive(Debug)]
pub struct RenderPipelineDescriptor {
pub layout: PipelineLayoutId,
pub vertex_stage: PipelineStageDescriptor,
pub fragment_stage: *const PipelineStageDescriptor,
pub vertex_stage: ProgrammableStageDescriptor,
pub fragment_stage: *const ProgrammableStageDescriptor,
pub primitive_topology: PrimitiveTopology,
pub rasterization_state: RasterizationStateDescriptor,
pub rasterization_state: *const RasterizationStateDescriptor,
pub color_states: *const ColorStateDescriptor,
pub color_states_length: usize,
pub depth_stencil_state: *const DepthStencilStateDescriptor,
pub vertex_input: VertexInputDescriptor,
pub sample_count: u32,
pub sample_mask: u32,
pub alpha_coverage_enabled: bool,
pub alpha_to_coverage_enabled: bool,
}
bitflags! {

View File

@ -16,7 +16,7 @@ mod server;
#[derive(Serialize, Deserialize, Debug)]
enum InstanceMessage {
Create(wgn::InstanceId),
InstanceGetAdapter(wgn::InstanceId, wgn::AdapterDescriptor, wgn::AdapterId),
InstanceRequestAdapter(wgn::InstanceId, wgn::RequestAdapterOptions, wgn::AdapterId),
AdapterCreateDevice(wgn::AdapterId, wgn::DeviceDescriptor, wgn::DeviceId),
Destroy(wgn::InstanceId),
}
@ -115,10 +115,10 @@ pub extern "C" fn wgpu_client_destroy(factory: &ClientFactory, client: *mut Clie
#[no_mangle]
pub extern "C" fn wgpu_client_get_adapter(
client: &Client,
desc: &wgn::AdapterDescriptor,
desc: &wgn::RequestAdapterOptions,
) -> wgn::AdapterId {
let adapter_id = client.identity.lock().adapters.alloc();
let msg = GlobalMessage::Instance(InstanceMessage::InstanceGetAdapter(
let msg = GlobalMessage::Instance(InstanceMessage::InstanceRequestAdapter(
client.instance_id,
desc.clone(),
adapter_id,

View File

@ -27,7 +27,7 @@ fn process(message: GlobalMessage) -> ControlFlow {
let instance = wgn::create_instance();
wgn::HUB.instances.register(instance_id, instance, &mut token);
}
InstanceMessage::InstanceGetAdapter(instance_id, ref desc, id) => {
InstanceMessage::InstanceRequestAdapter(instance_id, ref desc, id) => {
let adapter = wgn::instance_get_adapter(instance_id, desc, &mut token);
wgn::HUB.adapters.register(id, adapter, &mut token);
}