Skip to content

Commit a048f5e

Browse files
bors[bot]kvark
andauthored
Merge #492
492: Encode render targets into the render pass blob r=grovesNL a=kvark Fixes #454 Co-authored-by: Dzmitry Malyshau <[email protected]>
2 parents 7337402 + e05471a commit a048f5e

File tree

6 files changed

+124
-155
lines changed

6 files changed

+124
-155
lines changed

ffi/wgpu.h

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
/* Generated with cbindgen:0.12.2 */
5+
/* Generated with cbindgen:0.13.1 */
66

77
/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
88
* To generate this file:
@@ -311,6 +311,8 @@ typedef uint64_t WGPUId_TextureView_Dummy;
311311

312312
typedef WGPUId_TextureView_Dummy WGPUTextureViewId;
313313

314+
typedef const WGPUTextureViewId *WGPUOptionRef_TextureViewId;
315+
314316
typedef struct {
315317
double r;
316318
double g;
@@ -326,13 +328,13 @@ typedef struct {
326328

327329
typedef struct {
328330
WGPUTextureViewId attachment;
329-
WGPUTextureViewId resolve_target;
331+
WGPUOptionRef_TextureViewId resolve_target;
330332
WGPULoadOp load_op;
331333
WGPUStoreOp store_op;
332334
WGPUColor clear_color;
333-
} WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__TextureViewId;
335+
} WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__OptionRef_TextureViewId;
334336

335-
typedef WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__TextureViewId WGPURawRenderPassColorAttachmentDescriptor;
337+
typedef WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__OptionRef_TextureViewId WGPURenderPassColorAttachmentDescriptor;
336338

337339
typedef struct {
338340
WGPUTextureViewId attachment;
@@ -346,28 +348,6 @@ typedef struct {
346348

347349
typedef WGPURenderPassDepthStencilAttachmentDescriptorBase_TextureViewId WGPURenderPassDepthStencilAttachmentDescriptor;
348350

349-
typedef struct {
350-
WGPURawRenderPassColorAttachmentDescriptor colors[WGPUMAX_COLOR_TARGETS];
351-
WGPURenderPassDepthStencilAttachmentDescriptor depth_stencil;
352-
} WGPURawRenderTargets;
353-
354-
typedef struct {
355-
WGPURawPass raw;
356-
WGPURawRenderTargets targets;
357-
} WGPURawRenderPass;
358-
359-
typedef const WGPUTextureViewId *WGPUOptionRef_TextureViewId;
360-
361-
typedef struct {
362-
WGPUTextureViewId attachment;
363-
WGPUOptionRef_TextureViewId resolve_target;
364-
WGPULoadOp load_op;
365-
WGPUStoreOp store_op;
366-
WGPUColor clear_color;
367-
} WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__OptionRef_TextureViewId;
368-
369-
typedef WGPURenderPassColorAttachmentDescriptorBase_TextureViewId__OptionRef_TextureViewId WGPURenderPassColorAttachmentDescriptor;
370-
371351
typedef struct {
372352
const WGPURenderPassColorAttachmentDescriptor *color_attachments;
373353
uintptr_t color_attachments_length;
@@ -680,7 +660,7 @@ typedef struct {
680660

681661
typedef WGPUDeviceId WGPUQueueId;
682662

683-
typedef WGPURawRenderPass *WGPURenderPassId;
663+
typedef WGPURawPass *WGPURenderPassId;
684664

685665
typedef uint64_t WGPUId_RenderBundle_Dummy;
686666

@@ -750,8 +730,8 @@ WGPURawPass *wgpu_command_encoder_begin_compute_pass(WGPUCommandEncoderId encode
750730
* (`RenderPassDescriptor::color_attachments`) is valid for
751731
* `RenderPassDescriptor::color_attachments_length` elements.
752732
*/
753-
WGPURawRenderPass *wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId encoder_id,
754-
const WGPURenderPassDescriptor *desc);
733+
WGPURawPass *wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId encoder_id,
734+
const WGPURenderPassDescriptor *desc);
755735

756736
void wgpu_command_encoder_copy_buffer_to_buffer(WGPUCommandEncoderId command_encoder_id,
757737
WGPUBufferId source,
@@ -882,26 +862,26 @@ void wgpu_queue_submit(WGPUQueueId queue_id,
882862
const WGPUCommandBufferId *command_buffers,
883863
uintptr_t command_buffers_length);
884864

885-
void wgpu_render_pass_destroy(WGPURawRenderPass *pass);
865+
void wgpu_render_pass_destroy(WGPURawPass *pass);
886866

887-
void wgpu_render_pass_draw(WGPURawRenderPass *pass,
867+
void wgpu_render_pass_draw(WGPURawPass *pass,
888868
uint32_t vertex_count,
889869
uint32_t instance_count,
890870
uint32_t first_vertex,
891871
uint32_t first_instance);
892872

893-
void wgpu_render_pass_draw_indexed(WGPURawRenderPass *pass,
873+
void wgpu_render_pass_draw_indexed(WGPURawPass *pass,
894874
uint32_t index_count,
895875
uint32_t instance_count,
896876
uint32_t first_index,
897877
int32_t base_vertex,
898878
uint32_t first_instance);
899879

900-
void wgpu_render_pass_draw_indexed_indirect(WGPURawRenderPass *pass,
880+
void wgpu_render_pass_draw_indexed_indirect(WGPURawPass *pass,
901881
WGPUBufferId buffer_id,
902882
WGPUBufferAddress offset);
903883

904-
void wgpu_render_pass_draw_indirect(WGPURawRenderPass *pass,
884+
void wgpu_render_pass_draw_indirect(WGPURawPass *pass,
905885
WGPUBufferId buffer_id,
906886
WGPUBufferAddress offset);
907887

@@ -914,59 +894,59 @@ void wgpu_render_pass_draw_indirect(WGPURawRenderPass *pass,
914894
*/
915895
void wgpu_render_pass_end_pass(WGPURenderPassId pass_id);
916896

917-
void wgpu_render_pass_execute_bundles(WGPURawRenderPass *_pass,
897+
void wgpu_render_pass_execute_bundles(WGPURawPass *_pass,
918898
const WGPURenderBundleId *_bundles,
919899
uintptr_t _bundles_length);
920900

921-
const uint8_t *wgpu_render_pass_finish(WGPURawRenderPass *pass, uintptr_t *length);
901+
const uint8_t *wgpu_render_pass_finish(WGPURawPass *pass, uintptr_t *length);
922902

923-
void wgpu_render_pass_insert_debug_marker(WGPURawRenderPass *_pass, WGPURawString _label);
903+
void wgpu_render_pass_insert_debug_marker(WGPURawPass *_pass, WGPURawString _label);
924904

925-
void wgpu_render_pass_pop_debug_group(WGPURawRenderPass *_pass);
905+
void wgpu_render_pass_pop_debug_group(WGPURawPass *_pass);
926906

927-
void wgpu_render_pass_push_debug_group(WGPURawRenderPass *_pass, WGPURawString _label);
907+
void wgpu_render_pass_push_debug_group(WGPURawPass *_pass, WGPURawString _label);
928908

929909
/**
930910
* # Safety
931911
*
932912
* This function is unsafe as there is no guarantee that the given pointer is
933913
* valid for `offset_length` elements.
934914
*/
935-
void wgpu_render_pass_set_bind_group(WGPURawRenderPass *pass,
915+
void wgpu_render_pass_set_bind_group(WGPURawPass *pass,
936916
uint32_t index,
937917
WGPUBindGroupId bind_group_id,
938918
const WGPUDynamicOffset *offsets,
939919
uintptr_t offset_length);
940920

941-
void wgpu_render_pass_set_blend_color(WGPURawRenderPass *pass, const WGPUColor *color);
921+
void wgpu_render_pass_set_blend_color(WGPURawPass *pass, const WGPUColor *color);
942922

943-
void wgpu_render_pass_set_index_buffer(WGPURawRenderPass *pass,
923+
void wgpu_render_pass_set_index_buffer(WGPURawPass *pass,
944924
WGPUBufferId buffer_id,
945925
WGPUBufferAddress offset);
946926

947-
void wgpu_render_pass_set_pipeline(WGPURawRenderPass *pass, WGPURenderPipelineId pipeline_id);
927+
void wgpu_render_pass_set_pipeline(WGPURawPass *pass, WGPURenderPipelineId pipeline_id);
948928

949-
void wgpu_render_pass_set_scissor_rect(WGPURawRenderPass *pass,
929+
void wgpu_render_pass_set_scissor_rect(WGPURawPass *pass,
950930
uint32_t x,
951931
uint32_t y,
952932
uint32_t w,
953933
uint32_t h);
954934

955-
void wgpu_render_pass_set_stencil_reference(WGPURawRenderPass *pass, uint32_t value);
935+
void wgpu_render_pass_set_stencil_reference(WGPURawPass *pass, uint32_t value);
956936

957937
/**
958938
* # Safety
959939
*
960940
* This function is unsafe as there is no guarantee that the given pointers
961941
* (`buffer_ids` and `offsets`) are valid for `length` elements.
962942
*/
963-
void wgpu_render_pass_set_vertex_buffers(WGPURawRenderPass *pass,
943+
void wgpu_render_pass_set_vertex_buffers(WGPURawPass *pass,
964944
uint32_t start_slot,
965945
const WGPUBufferId *buffer_ids,
966946
const WGPUBufferAddress *offsets,
967947
uintptr_t length);
968948

969-
void wgpu_render_pass_set_viewport(WGPURawRenderPass *pass,
949+
void wgpu_render_pass_set_viewport(WGPURawPass *pass,
970950
float x,
971951
float y,
972952
float w,

wgpu-core/src/command/mod.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,16 @@ pub struct CommandBufferDescriptor {
208208
pub todo: u32,
209209
}
210210

211-
type RawRenderPassColorAttachmentDescriptor =
211+
pub type RawRenderPassColorAttachmentDescriptor =
212212
RenderPassColorAttachmentDescriptorBase<id::TextureViewId, id::TextureViewId>;
213213

214214
#[repr(C)]
215+
#[derive(peek_poke::PeekCopy, peek_poke::Poke)]
215216
pub struct RawRenderTargets {
216217
pub colors: [RawRenderPassColorAttachmentDescriptor; MAX_COLOR_TARGETS],
217218
pub depth_stencil: RenderPassDepthStencilAttachmentDescriptor,
218219
}
219220

220-
#[repr(C)]
221-
pub struct RawRenderPass {
222-
raw: RawPass,
223-
targets: RawRenderTargets,
224-
}
225-
226221
/// # Safety
227222
///
228223
/// This function is unsafe as there is no guarantee that the given pointer
@@ -232,9 +227,14 @@ pub struct RawRenderPass {
232227
pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass(
233228
encoder_id: id::CommandEncoderId,
234229
desc: &RenderPassDescriptor,
235-
) -> *mut RawRenderPass {
236-
let mut colors: [RawRenderPassColorAttachmentDescriptor; MAX_COLOR_TARGETS] = mem::zeroed();
237-
for (color, at) in colors
230+
) -> *mut RawPass {
231+
let mut targets = RawRenderTargets {
232+
depth_stencil: desc.depth_stencil_attachment
233+
.cloned()
234+
.unwrap_or_else(|| mem::zeroed()),
235+
colors: mem::zeroed(),
236+
};
237+
for (color, at) in targets.colors
238238
.iter_mut()
239239
.zip(slice::from_raw_parts(desc.color_attachments, desc.color_attachments_length))
240240
{
@@ -246,15 +246,9 @@ pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass(
246246
clear_color: at.clear_color,
247247
};
248248
}
249-
let pass = RawRenderPass {
250-
raw: RawPass::new_render(encoder_id),
251-
targets: RawRenderTargets {
252-
colors,
253-
depth_stencil: desc.depth_stencil_attachment
254-
.cloned()
255-
.unwrap_or_else(|| mem::zeroed()),
256-
},
257-
};
249+
250+
let mut pass = RawPass::new_render(encoder_id);
251+
pass.encode(&targets);
258252
Box::into_raw(Box::new(pass))
259253
}
260254

0 commit comments

Comments
 (0)