1
1

DRW: Change binding API

Using bind() overload is too error prone.
This commit is contained in:
2022-08-30 21:11:23 +02:00
parent 57ea861692
commit d371dfbe2c
12 changed files with 251 additions and 244 deletions

View File

@@ -245,10 +245,10 @@ void DepthOfField::bokeh_lut_pass_sync()
/* Precompute bokeh texture. */ /* Precompute bokeh texture. */
bokeh_lut_ps_.init(); bokeh_lut_ps_.init();
bokeh_lut_ps_.shader_set(inst_.shaders.static_shader_get(DOF_BOKEH_LUT)); bokeh_lut_ps_.shader_set(inst_.shaders.static_shader_get(DOF_BOKEH_LUT));
bokeh_lut_ps_.bind("dof_buf", data_); bokeh_lut_ps_.bind_ubo("dof_buf", data_);
bokeh_lut_ps_.bind("out_gather_lut_img", as_image(&bokeh_gather_lut_tx_)); bokeh_lut_ps_.bind_image("out_gather_lut_img", &bokeh_gather_lut_tx_);
bokeh_lut_ps_.bind("out_scatter_lut_img", as_image(&bokeh_scatter_lut_tx_)); bokeh_lut_ps_.bind_image("out_scatter_lut_img", &bokeh_scatter_lut_tx_);
bokeh_lut_ps_.bind("out_resolve_lut_img", as_image(&bokeh_resolve_lut_tx_)); bokeh_lut_ps_.bind_image("out_resolve_lut_img", &bokeh_resolve_lut_tx_);
bokeh_lut_ps_.dispatch(int3(1, 1, 1)); bokeh_lut_ps_.dispatch(int3(1, 1, 1));
} }
@@ -258,11 +258,11 @@ void DepthOfField::setup_pass_sync()
setup_ps_.init(); setup_ps_.init();
setup_ps_.shader_set(inst_.shaders.static_shader_get(DOF_SETUP)); setup_ps_.shader_set(inst_.shaders.static_shader_get(DOF_SETUP));
setup_ps_.bind("color_tx", &input_color_tx_, no_filter); setup_ps_.bind_texture("color_tx", &input_color_tx_, no_filter);
setup_ps_.bind("depth_tx", &render_buffers.depth_tx, no_filter); setup_ps_.bind_texture("depth_tx", &render_buffers.depth_tx, no_filter);
setup_ps_.bind("dof_buf", data_); setup_ps_.bind_ubo("dof_buf", data_);
setup_ps_.bind("out_color_img", as_image(&setup_color_tx_)); setup_ps_.bind_image("out_color_img", &setup_color_tx_);
setup_ps_.bind("out_coc_img", as_image(&setup_coc_tx_)); setup_ps_.bind_image("out_coc_img", &setup_coc_tx_);
setup_ps_.dispatch(&dispatch_setup_size_); setup_ps_.dispatch(&dispatch_setup_size_);
setup_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH); setup_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH);
} }
@@ -274,20 +274,20 @@ void DepthOfField::stabilize_pass_sync()
stabilize_ps_.init(); stabilize_ps_.init();
stabilize_ps_.shader_set(inst_.shaders.static_shader_get(DOF_STABILIZE)); stabilize_ps_.shader_set(inst_.shaders.static_shader_get(DOF_STABILIZE));
stabilize_ps_.bind("camera_prev", &(*velocity.camera_steps[STEP_PREVIOUS])); stabilize_ps_.bind_ubo("camera_prev", &(*velocity.camera_steps[STEP_PREVIOUS]));
stabilize_ps_.bind("camera_curr", &(*velocity.camera_steps[STEP_CURRENT])); stabilize_ps_.bind_ubo("camera_curr", &(*velocity.camera_steps[STEP_CURRENT]));
/* This is only for temporal stability. The next step is not needed. */ /* This is only for temporal stability. The next step is not needed. */
stabilize_ps_.bind("camera_next", &(*velocity.camera_steps[STEP_PREVIOUS])); stabilize_ps_.bind_ubo("camera_next", &(*velocity.camera_steps[STEP_PREVIOUS]));
stabilize_ps_.bind("coc_tx", &setup_coc_tx_, no_filter); stabilize_ps_.bind_texture("coc_tx", &setup_coc_tx_, no_filter);
stabilize_ps_.bind("color_tx", &setup_color_tx_, no_filter); stabilize_ps_.bind_texture("color_tx", &setup_color_tx_, no_filter);
stabilize_ps_.bind("velocity_tx", &render_buffers.vector_tx, no_filter); stabilize_ps_.bind_texture("velocity_tx", &render_buffers.vector_tx, no_filter);
stabilize_ps_.bind("in_history_tx", &stabilize_input_, with_filter); stabilize_ps_.bind_texture("in_history_tx", &stabilize_input_, with_filter);
stabilize_ps_.bind("depth_tx", &render_buffers.depth_tx, no_filter); stabilize_ps_.bind_texture("depth_tx", &render_buffers.depth_tx, no_filter);
stabilize_ps_.bind("dof_buf", data_); stabilize_ps_.bind_ubo("dof_buf", data_);
stabilize_ps_.push_constant("use_history", &stabilize_valid_history_, 1); stabilize_ps_.push_constant("use_history", &stabilize_valid_history_, 1);
stabilize_ps_.bind("out_coc_img", as_image(reduced_coc_tx_.mip_view(0))); stabilize_ps_.bind_image("out_coc_img", reduced_coc_tx_.mip_view(0));
stabilize_ps_.bind("out_color_img", as_image(reduced_color_tx_.mip_view(0))); stabilize_ps_.bind_image("out_color_img", reduced_color_tx_.mip_view(0));
stabilize_ps_.bind("out_history_img", as_image(&stabilize_output_tx_)); stabilize_ps_.bind_image("out_history_img", &stabilize_output_tx_);
stabilize_ps_.dispatch(&dispatch_stabilize_size_); stabilize_ps_.dispatch(&dispatch_stabilize_size_);
stabilize_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_IMAGE_ACCESS); stabilize_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_IMAGE_ACCESS);
} }
@@ -296,9 +296,9 @@ void DepthOfField::downsample_pass_sync()
{ {
downsample_ps_.init(); downsample_ps_.init();
downsample_ps_.shader_set(inst_.shaders.static_shader_get(DOF_DOWNSAMPLE)); downsample_ps_.shader_set(inst_.shaders.static_shader_get(DOF_DOWNSAMPLE));
downsample_ps_.bind("color_tx", reduced_color_tx_.mip_view(0), no_filter); downsample_ps_.bind_texture("color_tx", reduced_color_tx_.mip_view(0), no_filter);
downsample_ps_.bind("coc_tx", reduced_coc_tx_.mip_view(0), no_filter); downsample_ps_.bind_texture("coc_tx", reduced_coc_tx_.mip_view(0), no_filter);
downsample_ps_.bind("out_color_img", as_image(&downsample_tx_)); downsample_ps_.bind_image("out_color_img", &downsample_tx_);
downsample_ps_.dispatch(&dispatch_downsample_size_); downsample_ps_.dispatch(&dispatch_downsample_size_);
downsample_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH); downsample_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH);
} }
@@ -307,20 +307,20 @@ void DepthOfField::reduce_pass_sync()
{ {
reduce_ps_.init(); reduce_ps_.init();
reduce_ps_.shader_set(inst_.shaders.static_shader_get(DOF_REDUCE)); reduce_ps_.shader_set(inst_.shaders.static_shader_get(DOF_REDUCE));
reduce_ps_.bind("dof_buf", data_); reduce_ps_.bind_ubo("dof_buf", data_);
reduce_ps_.bind("downsample_tx", &downsample_tx_, no_filter); reduce_ps_.bind_texture("downsample_tx", &downsample_tx_, no_filter);
reduce_ps_.bind("scatter_fg_list_buf", scatter_fg_list_buf_); reduce_ps_.bind_ssbo("scatter_fg_list_buf", scatter_fg_list_buf_);
reduce_ps_.bind("scatter_bg_list_buf", scatter_bg_list_buf_); reduce_ps_.bind_ssbo("scatter_bg_list_buf", scatter_bg_list_buf_);
reduce_ps_.bind("scatter_fg_indirect_buf", scatter_fg_indirect_buf_); reduce_ps_.bind_ssbo("scatter_fg_indirect_buf", scatter_fg_indirect_buf_);
reduce_ps_.bind("scatter_bg_indirect_buf", scatter_bg_indirect_buf_); reduce_ps_.bind_ssbo("scatter_bg_indirect_buf", scatter_bg_indirect_buf_);
reduce_ps_.bind("inout_color_lod0_img", as_image(reduced_color_tx_.mip_view(0))); reduce_ps_.bind_image("inout_color_lod0_img", reduced_color_tx_.mip_view(0));
reduce_ps_.bind("out_color_lod1_img", as_image(reduced_color_tx_.mip_view(1))); reduce_ps_.bind_image("out_color_lod1_img", reduced_color_tx_.mip_view(1));
reduce_ps_.bind("out_color_lod2_img", as_image(reduced_color_tx_.mip_view(2))); reduce_ps_.bind_image("out_color_lod2_img", reduced_color_tx_.mip_view(2));
reduce_ps_.bind("out_color_lod3_img", as_image(reduced_color_tx_.mip_view(3))); reduce_ps_.bind_image("out_color_lod3_img", reduced_color_tx_.mip_view(3));
reduce_ps_.bind("in_coc_lod0_img", as_image(reduced_coc_tx_.mip_view(0))); reduce_ps_.bind_image("in_coc_lod0_img", reduced_coc_tx_.mip_view(0));
reduce_ps_.bind("out_coc_lod1_img", as_image(reduced_coc_tx_.mip_view(1))); reduce_ps_.bind_image("out_coc_lod1_img", reduced_coc_tx_.mip_view(1));
reduce_ps_.bind("out_coc_lod2_img", as_image(reduced_coc_tx_.mip_view(2))); reduce_ps_.bind_image("out_coc_lod2_img", reduced_coc_tx_.mip_view(2));
reduce_ps_.bind("out_coc_lod3_img", as_image(reduced_coc_tx_.mip_view(3))); reduce_ps_.bind_image("out_coc_lod3_img", reduced_coc_tx_.mip_view(3));
reduce_ps_.dispatch(&dispatch_reduce_size_); reduce_ps_.dispatch(&dispatch_reduce_size_);
/* NOTE: Command buffer barrier is done automatically by the GPU backend. */ /* NOTE: Command buffer barrier is done automatically by the GPU backend. */
reduce_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_STORAGE); reduce_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_STORAGE);
@@ -333,9 +333,9 @@ void DepthOfField::tiles_flatten_pass_sync()
/* NOTE(fclem): We should use the reduced_coc_tx_ as it is stable, but we need the slight focus /* NOTE(fclem): We should use the reduced_coc_tx_ as it is stable, but we need the slight focus
* flag from the setup pass. A better way would be to do the brute-force in focus gather without * flag from the setup pass. A better way would be to do the brute-force in focus gather without
* this. */ * this. */
tiles_flatten_ps_.bind("coc_tx", &setup_coc_tx_, no_filter); tiles_flatten_ps_.bind_texture("coc_tx", &setup_coc_tx_, no_filter);
tiles_flatten_ps_.bind("out_tiles_fg_img", as_image(&tiles_fg_tx_.current())); tiles_flatten_ps_.bind_image("out_tiles_fg_img", &tiles_fg_tx_.current());
tiles_flatten_ps_.bind("out_tiles_bg_img", as_image(&tiles_bg_tx_.current())); tiles_flatten_ps_.bind_image("out_tiles_bg_img", &tiles_bg_tx_.current());
tiles_flatten_ps_.dispatch(&dispatch_tiles_flatten_size_); tiles_flatten_ps_.dispatch(&dispatch_tiles_flatten_size_);
tiles_flatten_ps_.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS); tiles_flatten_ps_.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS);
} }
@@ -347,10 +347,10 @@ void DepthOfField::tiles_dilate_pass_sync()
eShaderType sh_type = (pass == 0) ? DOF_TILES_DILATE_MINMAX : DOF_TILES_DILATE_MINABS; eShaderType sh_type = (pass == 0) ? DOF_TILES_DILATE_MINMAX : DOF_TILES_DILATE_MINABS;
drw_pass.init(); drw_pass.init();
drw_pass.shader_set(inst_.shaders.static_shader_get(sh_type)); drw_pass.shader_set(inst_.shaders.static_shader_get(sh_type));
drw_pass.bind("in_tiles_fg_img", as_image(&tiles_fg_tx_.previous())); drw_pass.bind_image("in_tiles_fg_img", &tiles_fg_tx_.previous());
drw_pass.bind("in_tiles_bg_img", as_image(&tiles_bg_tx_.previous())); drw_pass.bind_image("in_tiles_bg_img", &tiles_bg_tx_.previous());
drw_pass.bind("out_tiles_fg_img", as_image(&tiles_fg_tx_.current())); drw_pass.bind_image("out_tiles_fg_img", &tiles_fg_tx_.current());
drw_pass.bind("out_tiles_bg_img", as_image(&tiles_bg_tx_.current())); drw_pass.bind_image("out_tiles_bg_img", &tiles_bg_tx_.current());
drw_pass.push_constant("ring_count", &tiles_dilate_ring_count_, 1); drw_pass.push_constant("ring_count", &tiles_dilate_ring_count_, 1);
drw_pass.push_constant("ring_width_multiplier", &tiles_dilate_ring_width_mul_, 1); drw_pass.push_constant("ring_width_multiplier", &tiles_dilate_ring_width_mul_, 1);
drw_pass.dispatch(&dispatch_tiles_dilate_size_); drw_pass.dispatch(&dispatch_tiles_dilate_size_);
@@ -371,16 +371,16 @@ void DepthOfField::gather_pass_sync()
drw_pass.init(); drw_pass.init();
inst_.sampling.bind_resources(&drw_pass); inst_.sampling.bind_resources(&drw_pass);
drw_pass.shader_set(inst_.shaders.static_shader_get(sh_type)); drw_pass.shader_set(inst_.shaders.static_shader_get(sh_type));
drw_pass.bind("dof_buf", data_); drw_pass.bind_ubo("dof_buf", data_);
drw_pass.bind("color_bilinear_tx", reduced_color_tx_, gather_bilinear); drw_pass.bind_texture("color_bilinear_tx", reduced_color_tx_, gather_bilinear);
drw_pass.bind("color_tx", reduced_color_tx_, gather_nearest); drw_pass.bind_texture("color_tx", reduced_color_tx_, gather_nearest);
drw_pass.bind("coc_tx", reduced_coc_tx_, gather_nearest); drw_pass.bind_texture("coc_tx", reduced_coc_tx_, gather_nearest);
drw_pass.bind("in_tiles_fg_img", as_image(&tiles_fg_tx_.current())); drw_pass.bind_image("in_tiles_fg_img", &tiles_fg_tx_.current());
drw_pass.bind("in_tiles_bg_img", as_image(&tiles_bg_tx_.current())); drw_pass.bind_image("in_tiles_bg_img", &tiles_bg_tx_.current());
drw_pass.bind("out_color_img", as_image(&color_chain.current())); drw_pass.bind_image("out_color_img", &color_chain.current());
drw_pass.bind("out_weight_img", as_image(&weight_chain.current())); drw_pass.bind_image("out_weight_img", &weight_chain.current());
drw_pass.bind("out_occlusion_img", as_image(&occlusion_tx_)); drw_pass.bind_image("out_occlusion_img", &occlusion_tx_);
drw_pass.bind("bokeh_lut_tx", &bokeh_gather_lut_tx_); drw_pass.bind_texture("bokeh_lut_tx", &bokeh_gather_lut_tx_);
drw_pass.dispatch(&dispatch_gather_size_); drw_pass.dispatch(&dispatch_gather_size_);
drw_pass.barrier(GPU_BARRIER_TEXTURE_FETCH); drw_pass.barrier(GPU_BARRIER_TEXTURE_FETCH);
} }
@@ -394,10 +394,10 @@ void DepthOfField::filter_pass_sync()
SwapChain<TextureFromPool, 2> &weight_chain = (pass == 0) ? weight_fg_tx_ : weight_bg_tx_; SwapChain<TextureFromPool, 2> &weight_chain = (pass == 0) ? weight_fg_tx_ : weight_bg_tx_;
drw_pass.init(); drw_pass.init();
drw_pass.shader_set(inst_.shaders.static_shader_get(DOF_FILTER)); drw_pass.shader_set(inst_.shaders.static_shader_get(DOF_FILTER));
drw_pass.bind("color_tx", &color_chain.previous()); drw_pass.bind_texture("color_tx", &color_chain.previous());
drw_pass.bind("weight_tx", &weight_chain.previous()); drw_pass.bind_texture("weight_tx", &weight_chain.previous());
drw_pass.bind("out_color_img", as_image(&color_chain.current())); drw_pass.bind_image("out_color_img", &color_chain.current());
drw_pass.bind("out_weight_img", as_image(&weight_chain.current())); drw_pass.bind_image("out_weight_img", &weight_chain.current());
drw_pass.dispatch(&dispatch_filter_size_); drw_pass.dispatch(&dispatch_filter_size_);
drw_pass.barrier(GPU_BARRIER_TEXTURE_FETCH); drw_pass.barrier(GPU_BARRIER_TEXTURE_FETCH);
} }
@@ -411,16 +411,16 @@ void DepthOfField::scatter_pass_sync()
drw_pass.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ADD_FULL); drw_pass.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ADD_FULL);
drw_pass.shader_set(inst_.shaders.static_shader_get(DOF_SCATTER)); drw_pass.shader_set(inst_.shaders.static_shader_get(DOF_SCATTER));
drw_pass.push_constant("use_bokeh_lut", use_bokeh_lut_); drw_pass.push_constant("use_bokeh_lut", use_bokeh_lut_);
drw_pass.bind("bokeh_lut_tx", &bokeh_scatter_lut_tx_); drw_pass.bind_texture("bokeh_lut_tx", &bokeh_scatter_lut_tx_);
drw_pass.bind("occlusion_tx", &occlusion_tx_); drw_pass.bind_texture("occlusion_tx", &occlusion_tx_);
if (pass == 0) { if (pass == 0) {
drw_pass.bind("scatter_list_buf", scatter_fg_list_buf_); drw_pass.bind_ssbo("scatter_list_buf", scatter_fg_list_buf_);
drw_pass.draw_procedural_indirect(GPU_PRIM_TRI_STRIP, scatter_fg_indirect_buf_); drw_pass.draw_procedural_indirect(GPU_PRIM_TRI_STRIP, scatter_fg_indirect_buf_);
/* Avoid background gather pass writing to the occlusion_tx mid pass. */ /* Avoid background gather pass writing to the occlusion_tx mid pass. */
drw_pass.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS); drw_pass.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS);
} }
else { else {
drw_pass.bind("scatter_list_buf", scatter_bg_list_buf_); drw_pass.bind_ssbo("scatter_list_buf", scatter_bg_list_buf_);
drw_pass.draw_procedural_indirect(GPU_PRIM_TRI_STRIP, scatter_bg_indirect_buf_); drw_pass.draw_procedural_indirect(GPU_PRIM_TRI_STRIP, scatter_bg_indirect_buf_);
} }
} }
@@ -431,14 +431,14 @@ void DepthOfField::hole_fill_pass_sync()
hole_fill_ps_.init(); hole_fill_ps_.init();
inst_.sampling.bind_resources(&hole_fill_ps_); inst_.sampling.bind_resources(&hole_fill_ps_);
hole_fill_ps_.shader_set(inst_.shaders.static_shader_get(DOF_GATHER_HOLE_FILL)); hole_fill_ps_.shader_set(inst_.shaders.static_shader_get(DOF_GATHER_HOLE_FILL));
hole_fill_ps_.bind("dof_buf", data_); hole_fill_ps_.bind_ubo("dof_buf", data_);
hole_fill_ps_.bind("color_bilinear_tx", reduced_color_tx_, gather_bilinear); hole_fill_ps_.bind_texture("color_bilinear_tx", reduced_color_tx_, gather_bilinear);
hole_fill_ps_.bind("color_tx", reduced_color_tx_, gather_nearest); hole_fill_ps_.bind_texture("color_tx", reduced_color_tx_, gather_nearest);
hole_fill_ps_.bind("coc_tx", reduced_coc_tx_, gather_nearest); hole_fill_ps_.bind_texture("coc_tx", reduced_coc_tx_, gather_nearest);
hole_fill_ps_.bind("in_tiles_fg_img", as_image(&tiles_fg_tx_.current())); hole_fill_ps_.bind_image("in_tiles_fg_img", &tiles_fg_tx_.current());
hole_fill_ps_.bind("in_tiles_bg_img", as_image(&tiles_bg_tx_.current())); hole_fill_ps_.bind_image("in_tiles_bg_img", &tiles_bg_tx_.current());
hole_fill_ps_.bind("out_color_img", as_image(&hole_fill_color_tx_)); hole_fill_ps_.bind_image("out_color_img", &hole_fill_color_tx_);
hole_fill_ps_.bind("out_weight_img", as_image(&hole_fill_weight_tx_)); hole_fill_ps_.bind_image("out_weight_img", &hole_fill_weight_tx_);
hole_fill_ps_.dispatch(&dispatch_gather_size_); hole_fill_ps_.dispatch(&dispatch_gather_size_);
hole_fill_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH); hole_fill_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH);
} }
@@ -452,20 +452,20 @@ void DepthOfField::resolve_pass_sync()
resolve_ps_.init(); resolve_ps_.init();
inst_.sampling.bind_resources(&resolve_ps_); inst_.sampling.bind_resources(&resolve_ps_);
resolve_ps_.shader_set(inst_.shaders.static_shader_get(sh_type)); resolve_ps_.shader_set(inst_.shaders.static_shader_get(sh_type));
resolve_ps_.bind("dof_buf", data_); resolve_ps_.bind_ubo("dof_buf", data_);
resolve_ps_.bind("depth_tx", &render_buffers.depth_tx, no_filter); resolve_ps_.bind_texture("depth_tx", &render_buffers.depth_tx, no_filter);
resolve_ps_.bind("color_tx", &input_color_tx_, no_filter); resolve_ps_.bind_texture("color_tx", &input_color_tx_, no_filter);
resolve_ps_.bind("stable_color_tx", &resolve_stable_color_tx_, no_filter); resolve_ps_.bind_texture("stable_color_tx", &resolve_stable_color_tx_, no_filter);
resolve_ps_.bind("color_bg_tx", &color_bg_tx_.current(), with_filter); resolve_ps_.bind_texture("color_bg_tx", &color_bg_tx_.current(), with_filter);
resolve_ps_.bind("color_fg_tx", &color_fg_tx_.current(), with_filter); resolve_ps_.bind_texture("color_fg_tx", &color_fg_tx_.current(), with_filter);
resolve_ps_.bind("in_tiles_fg_img", as_image(&tiles_fg_tx_.current())); resolve_ps_.bind_image("in_tiles_fg_img", &tiles_fg_tx_.current());
resolve_ps_.bind("in_tiles_bg_img", as_image(&tiles_bg_tx_.current())); resolve_ps_.bind_image("in_tiles_bg_img", &tiles_bg_tx_.current());
resolve_ps_.bind("weight_bg_tx", &weight_bg_tx_.current()); resolve_ps_.bind_texture("weight_bg_tx", &weight_bg_tx_.current());
resolve_ps_.bind("weight_fg_tx", &weight_fg_tx_.current()); resolve_ps_.bind_texture("weight_fg_tx", &weight_fg_tx_.current());
resolve_ps_.bind("color_hole_fill_tx", &hole_fill_color_tx_); resolve_ps_.bind_texture("color_hole_fill_tx", &hole_fill_color_tx_);
resolve_ps_.bind("weight_hole_fill_tx", &hole_fill_weight_tx_); resolve_ps_.bind_texture("weight_hole_fill_tx", &hole_fill_weight_tx_);
resolve_ps_.bind("bokeh_lut_tx", &bokeh_resolve_lut_tx_); resolve_ps_.bind_texture("bokeh_lut_tx", &bokeh_resolve_lut_tx_);
resolve_ps_.bind("out_color_img", as_image(&output_color_tx_)); resolve_ps_.bind_image("out_color_img", &output_color_tx_);
resolve_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH); resolve_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH);
resolve_ps_.dispatch(&dispatch_resolve_size_); resolve_ps_.dispatch(&dispatch_resolve_size_);
resolve_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH); resolve_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH);

View File

@@ -380,34 +380,34 @@ void Film::sync()
accumulate_ps_.init(); accumulate_ps_.init();
accumulate_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS); accumulate_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS);
accumulate_ps_.shader_set(inst_.shaders.static_shader_get(shader)); accumulate_ps_.shader_set(inst_.shaders.static_shader_get(shader));
accumulate_ps_.bind("film_buf", &data_); accumulate_ps_.bind_ubo("film_buf", &data_);
accumulate_ps_.bind("camera_prev", &(*velocity.camera_steps[STEP_PREVIOUS])); accumulate_ps_.bind_ubo("camera_prev", &(*velocity.camera_steps[STEP_PREVIOUS]));
accumulate_ps_.bind("camera_curr", &(*velocity.camera_steps[STEP_CURRENT])); accumulate_ps_.bind_ubo("camera_curr", &(*velocity.camera_steps[STEP_CURRENT]));
accumulate_ps_.bind("camera_next", &(*velocity.camera_steps[step_next])); accumulate_ps_.bind_ubo("camera_next", &(*velocity.camera_steps[step_next]));
accumulate_ps_.bind("depth_tx", &rbuffers.depth_tx); accumulate_ps_.bind_texture("depth_tx", &rbuffers.depth_tx);
accumulate_ps_.bind("combined_tx", &combined_final_tx_); accumulate_ps_.bind_texture("combined_tx", &combined_final_tx_);
accumulate_ps_.bind("normal_tx", &rbuffers.normal_tx); accumulate_ps_.bind_texture("normal_tx", &rbuffers.normal_tx);
accumulate_ps_.bind("vector_tx", &rbuffers.vector_tx); accumulate_ps_.bind_texture("vector_tx", &rbuffers.vector_tx);
accumulate_ps_.bind("light_tx", &rbuffers.light_tx); accumulate_ps_.bind_texture("light_tx", &rbuffers.light_tx);
accumulate_ps_.bind("diffuse_color_tx", &rbuffers.diffuse_color_tx); accumulate_ps_.bind_texture("diffuse_color_tx", &rbuffers.diffuse_color_tx);
accumulate_ps_.bind("specular_color_tx", &rbuffers.specular_color_tx); accumulate_ps_.bind_texture("specular_color_tx", &rbuffers.specular_color_tx);
accumulate_ps_.bind("volume_light_tx", &rbuffers.volume_light_tx); accumulate_ps_.bind_texture("volume_light_tx", &rbuffers.volume_light_tx);
accumulate_ps_.bind("emission_tx", &rbuffers.emission_tx); accumulate_ps_.bind_texture("emission_tx", &rbuffers.emission_tx);
accumulate_ps_.bind("environment_tx", &rbuffers.environment_tx); accumulate_ps_.bind_texture("environment_tx", &rbuffers.environment_tx);
accumulate_ps_.bind("shadow_tx", &rbuffers.shadow_tx); accumulate_ps_.bind_texture("shadow_tx", &rbuffers.shadow_tx);
accumulate_ps_.bind("ambient_occlusion_tx", &rbuffers.ambient_occlusion_tx); accumulate_ps_.bind_texture("ambient_occlusion_tx", &rbuffers.ambient_occlusion_tx);
accumulate_ps_.bind("aov_color_tx", &rbuffers.aov_color_tx); accumulate_ps_.bind_texture("aov_color_tx", &rbuffers.aov_color_tx);
accumulate_ps_.bind("aov_value_tx", &rbuffers.aov_value_tx); accumulate_ps_.bind_texture("aov_value_tx", &rbuffers.aov_value_tx);
/* NOTE(@fclem): 16 is the max number of sampled texture in many implementations. /* NOTE(@fclem): 16 is the max number of sampled texture in many implementations.
* If we need more, we need to pack more of the similar passes in the same textures as arrays or * If we need more, we need to pack more of the similar passes in the same textures as arrays or
* use image binding instead. */ * use image binding instead. */
accumulate_ps_.bind("in_weight_img", draw::as_image(&weight_tx_.current())); accumulate_ps_.bind_image("in_weight_img", &weight_tx_.current());
accumulate_ps_.bind("out_weight_img", draw::as_image(&weight_tx_.next())); accumulate_ps_.bind_image("out_weight_img", &weight_tx_.next());
accumulate_ps_.bind("in_combined_tx", &combined_tx_.current(), filter); accumulate_ps_.bind_texture("in_combined_tx", &combined_tx_.current(), filter);
accumulate_ps_.bind("out_combined_img", draw::as_image(&combined_tx_.next())); accumulate_ps_.bind_image("out_combined_img", &combined_tx_.next());
accumulate_ps_.bind("depth_img", draw::as_image(&depth_tx_)); accumulate_ps_.bind_image("depth_img", &depth_tx_);
accumulate_ps_.bind("color_accum_img", draw::as_image(&color_accum_tx_)); accumulate_ps_.bind_image("color_accum_img", &color_accum_tx_);
accumulate_ps_.bind("value_accum_img", draw::as_image(&value_accum_tx_)); accumulate_ps_.bind_image("value_accum_img", &value_accum_tx_);
/* Sync with rendering passes. */ /* Sync with rendering passes. */
accumulate_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_IMAGE_ACCESS); accumulate_ps_.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_IMAGE_ACCESS);
if (use_compute) { if (use_compute) {

View File

@@ -34,16 +34,16 @@ void HiZBuffer::sync()
{ {
hiz_update_ps_.init(); hiz_update_ps_.init();
hiz_update_ps_.shader_set(inst_.shaders.static_shader_get(HIZ_UPDATE)); hiz_update_ps_.shader_set(inst_.shaders.static_shader_get(HIZ_UPDATE));
hiz_update_ps_.bind("finished_tile_counter", atomic_tile_counter_); hiz_update_ps_.bind_ssbo("finished_tile_counter", atomic_tile_counter_);
hiz_update_ps_.bind("depth_tx", &render_buffers.depth_tx, with_filter); hiz_update_ps_.bind_texture("depth_tx", &render_buffers.depth_tx, with_filter);
hiz_update_ps_.bind("out_mip_0", as_image(hiz_tx_.mip_view(0))); hiz_update_ps_.bind_image("out_mip_0", hiz_tx_.mip_view(0));
hiz_update_ps_.bind("out_mip_1", as_image(hiz_tx_.mip_view(1))); hiz_update_ps_.bind_image("out_mip_1", hiz_tx_.mip_view(1));
hiz_update_ps_.bind("out_mip_2", as_image(hiz_tx_.mip_view(2))); hiz_update_ps_.bind_image("out_mip_2", hiz_tx_.mip_view(2));
hiz_update_ps_.bind("out_mip_3", as_image(hiz_tx_.mip_view(3))); hiz_update_ps_.bind_image("out_mip_3", hiz_tx_.mip_view(3));
hiz_update_ps_.bind("out_mip_4", as_image(hiz_tx_.mip_view(4))); hiz_update_ps_.bind_image("out_mip_4", hiz_tx_.mip_view(4));
hiz_update_ps_.bind("out_mip_5", as_image(hiz_tx_.mip_view(5))); hiz_update_ps_.bind_image("out_mip_5", hiz_tx_.mip_view(5));
hiz_update_ps_.bind("out_mip_6", as_image(hiz_tx_.mip_view(6))); hiz_update_ps_.bind_image("out_mip_6", hiz_tx_.mip_view(6));
hiz_update_ps_.bind("out_mip_7", as_image(hiz_tx_.mip_view(7))); hiz_update_ps_.bind_image("out_mip_7", hiz_tx_.mip_view(7));
/* TODO(@fclem): There might be occasions where we might not want to /* TODO(@fclem): There might be occasions where we might not want to
* copy mip 0 for performance reasons if there is no need for it. */ * copy mip 0 for performance reasons if there is no need for it. */
hiz_update_ps_.push_constant("update_mip_0", true); hiz_update_ps_.push_constant("update_mip_0", true);

View File

@@ -78,8 +78,8 @@ class HiZBuffer {
/* TODO(fclem): Hardcoded bind slots. */ /* TODO(fclem): Hardcoded bind slots. */
template<typename T> void bind_resources(draw::detail::PassBase<T> *pass) template<typename T> void bind_resources(draw::detail::PassBase<T> *pass)
{ {
pass->bind("hiz_tx", &hiz_tx_); pass->bind_texture("hiz_tx", &hiz_tx_);
pass->bind("hiz_buf", &data_); pass->bind_ubo("hiz_buf", &data_);
} }
}; };

View File

@@ -404,40 +404,40 @@ void LightModule::culling_pass_sync()
{ {
auto &sub = culling_ps_.sub("Select"); auto &sub = culling_ps_.sub("Select");
sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_SELECT)); sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_SELECT));
sub.bind("light_cull_buf", &culling_data_buf_); sub.bind_ssbo("light_cull_buf", &culling_data_buf_);
sub.bind("in_light_buf", light_buf_); sub.bind_ssbo("in_light_buf", light_buf_);
sub.bind("out_light_buf", culling_light_buf_); sub.bind_ssbo("out_light_buf", culling_light_buf_);
sub.bind("out_zdist_buf", culling_zdist_buf_); sub.bind_ssbo("out_zdist_buf", culling_zdist_buf_);
sub.bind("out_key_buf", culling_key_buf_); sub.bind_ssbo("out_key_buf", culling_key_buf_);
sub.dispatch(int3(culling_select_dispatch_size, 1, 1)); sub.dispatch(int3(culling_select_dispatch_size, 1, 1));
sub.barrier(GPU_BARRIER_SHADER_STORAGE); sub.barrier(GPU_BARRIER_SHADER_STORAGE);
} }
{ {
auto &sub = culling_ps_.sub("Sort"); auto &sub = culling_ps_.sub("Sort");
sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_SORT)); sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_SORT));
sub.bind("light_cull_buf", &culling_data_buf_); sub.bind_ssbo("light_cull_buf", &culling_data_buf_);
sub.bind("in_light_buf", light_buf_); sub.bind_ssbo("in_light_buf", light_buf_);
sub.bind("out_light_buf", culling_light_buf_); sub.bind_ssbo("out_light_buf", culling_light_buf_);
sub.bind("in_zdist_buf", culling_zdist_buf_); sub.bind_ssbo("in_zdist_buf", culling_zdist_buf_);
sub.bind("in_key_buf", culling_key_buf_); sub.bind_ssbo("in_key_buf", culling_key_buf_);
sub.dispatch(int3(culling_sort_dispatch_size, 1, 1)); sub.dispatch(int3(culling_sort_dispatch_size, 1, 1));
sub.barrier(GPU_BARRIER_SHADER_STORAGE); sub.barrier(GPU_BARRIER_SHADER_STORAGE);
} }
{ {
auto &sub = culling_ps_.sub("Zbin"); auto &sub = culling_ps_.sub("Zbin");
sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_ZBIN)); sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_ZBIN));
sub.bind("light_cull_buf", &culling_data_buf_); sub.bind_ssbo("light_cull_buf", &culling_data_buf_);
sub.bind("light_buf", culling_light_buf_); sub.bind_ssbo("light_buf", culling_light_buf_);
sub.bind("out_zbin_buf", culling_zbin_buf_); sub.bind_ssbo("out_zbin_buf", culling_zbin_buf_);
sub.dispatch(int3(1, 1, 1)); sub.dispatch(int3(1, 1, 1));
sub.barrier(GPU_BARRIER_SHADER_STORAGE); sub.barrier(GPU_BARRIER_SHADER_STORAGE);
} }
{ {
auto &sub = culling_ps_.sub("Tiles"); auto &sub = culling_ps_.sub("Tiles");
sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_TILE)); sub.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_TILE));
sub.bind("light_cull_buf", &culling_data_buf_); sub.bind_ssbo("light_cull_buf", &culling_data_buf_);
sub.bind("light_buf", culling_light_buf_); sub.bind_ssbo("light_buf", culling_light_buf_);
sub.bind("out_light_tile_buf", culling_tile_buf_); sub.bind_ssbo("out_light_tile_buf", culling_tile_buf_);
sub.dispatch(int3(culling_tile_dispatch_size, 1, 1)); sub.dispatch(int3(culling_tile_dispatch_size, 1, 1));
sub.barrier(GPU_BARRIER_SHADER_STORAGE); sub.barrier(GPU_BARRIER_SHADER_STORAGE);
} }
@@ -450,11 +450,11 @@ void LightModule::debug_pass_sync()
debug_draw_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM); debug_draw_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_CUSTOM);
debug_draw_ps_.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_DEBUG)); debug_draw_ps_.shader_set(inst_.shaders.static_shader_get(LIGHT_CULLING_DEBUG));
inst_.hiz_buffer.bind_resources(&debug_draw_ps_); inst_.hiz_buffer.bind_resources(&debug_draw_ps_);
debug_draw_ps_.bind("light_buf", &culling_light_buf_); debug_draw_ps_.bind_ssbo("light_buf", &culling_light_buf_);
debug_draw_ps_.bind("light_cull_buf", &culling_data_buf_); debug_draw_ps_.bind_ssbo("light_cull_buf", &culling_data_buf_);
debug_draw_ps_.bind("light_zbin_buf", &culling_zbin_buf_); debug_draw_ps_.bind_ssbo("light_zbin_buf", &culling_zbin_buf_);
debug_draw_ps_.bind("light_tile_buf", &culling_tile_buf_); debug_draw_ps_.bind_ssbo("light_tile_buf", &culling_tile_buf_);
debug_draw_ps_.bind("depth_tx", &inst_.render_buffers.depth_tx); debug_draw_ps_.bind_texture("depth_tx", &inst_.render_buffers.depth_tx);
debug_draw_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3); debug_draw_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
} }
} }

View File

@@ -153,10 +153,10 @@ class LightModule {
template<typename T> void bind_resources(draw::detail::PassBase<T> *pass) template<typename T> void bind_resources(draw::detail::PassBase<T> *pass)
{ {
/* Storage Buf. */ /* Storage Buf. */
pass->bind(LIGHT_CULL_BUF_SLOT, &culling_data_buf_); pass->bind_ssbo(LIGHT_CULL_BUF_SLOT, &culling_data_buf_);
pass->bind(LIGHT_BUF_SLOT, &culling_light_buf_); pass->bind_ssbo(LIGHT_BUF_SLOT, &culling_light_buf_);
pass->bind(LIGHT_ZBIN_BUF_SLOT, &culling_zbin_buf_); pass->bind_ssbo(LIGHT_ZBIN_BUF_SLOT, &culling_zbin_buf_);
pass->bind(LIGHT_TILE_BUF_SLOT, &culling_tile_buf_); pass->bind_ssbo(LIGHT_TILE_BUF_SLOT, &culling_tile_buf_);
} }
private: private:

View File

@@ -144,10 +144,10 @@ void MotionBlurModule::sync()
eShaderType shader = (inst_.is_viewport()) ? MOTION_BLUR_TILE_FLATTEN_VIEWPORT : eShaderType shader = (inst_.is_viewport()) ? MOTION_BLUR_TILE_FLATTEN_VIEWPORT :
MOTION_BLUR_TILE_FLATTEN_RENDER; MOTION_BLUR_TILE_FLATTEN_RENDER;
sub.shader_set(inst_.shaders.static_shader_get(shader)); sub.shader_set(inst_.shaders.static_shader_get(shader));
sub.bind("motion_blur_buf", data_); sub.bind_ubo("motion_blur_buf", data_);
sub.bind("depth_tx", &render_buffers.depth_tx); sub.bind_texture("depth_tx", &render_buffers.depth_tx);
sub.bind("velocity_img", as_image(&render_buffers.vector_tx)); sub.bind_image("velocity_img", &render_buffers.vector_tx);
sub.bind("out_tiles_img", as_image(&tiles_tx_)); sub.bind_image("out_tiles_img", &tiles_tx_);
sub.dispatch(&dispatch_flatten_size_); sub.dispatch(&dispatch_flatten_size_);
sub.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS | GPU_BARRIER_TEXTURE_FETCH); sub.barrier(GPU_BARRIER_SHADER_IMAGE_ACCESS | GPU_BARRIER_TEXTURE_FETCH);
} }
@@ -155,8 +155,8 @@ void MotionBlurModule::sync()
/* Expand max velocity tiles by spreading them in their neighborhood. */ /* Expand max velocity tiles by spreading them in their neighborhood. */
PassSimple::Sub &sub = motion_blur_ps_.sub("TilesDilate"); PassSimple::Sub &sub = motion_blur_ps_.sub("TilesDilate");
sub.shader_set(inst_.shaders.static_shader_get(MOTION_BLUR_TILE_DILATE)); sub.shader_set(inst_.shaders.static_shader_get(MOTION_BLUR_TILE_DILATE));
sub.bind("tile_indirection_buf", tile_indirection_buf_); sub.bind_ssbo("tile_indirection_buf", tile_indirection_buf_);
sub.bind("in_tiles_img", as_image(&tiles_tx_)); sub.bind_image("in_tiles_img", &tiles_tx_);
sub.dispatch(&dispatch_dilate_size_); sub.dispatch(&dispatch_dilate_size_);
sub.barrier(GPU_BARRIER_SHADER_STORAGE); sub.barrier(GPU_BARRIER_SHADER_STORAGE);
} }
@@ -164,13 +164,13 @@ void MotionBlurModule::sync()
/* Do the motion blur gather algorithm. */ /* Do the motion blur gather algorithm. */
PassSimple::Sub &sub = motion_blur_ps_.sub("ConvolveGather"); PassSimple::Sub &sub = motion_blur_ps_.sub("ConvolveGather");
sub.shader_set(inst_.shaders.static_shader_get(MOTION_BLUR_GATHER)); sub.shader_set(inst_.shaders.static_shader_get(MOTION_BLUR_GATHER));
sub.bind("motion_blur_buf", data_); sub.bind_ubo("motion_blur_buf", data_);
sub.bind("tile_indirection_buf", tile_indirection_buf_); sub.bind_ssbo("tile_indirection_buf", tile_indirection_buf_);
sub.bind("depth_tx", &render_buffers.depth_tx, no_filter); sub.bind_texture("depth_tx", &render_buffers.depth_tx, no_filter);
sub.bind("velocity_tx", &render_buffers.vector_tx, no_filter); sub.bind_texture("velocity_tx", &render_buffers.vector_tx, no_filter);
sub.bind("in_color_tx", &input_color_tx_, no_filter); sub.bind_texture("in_color_tx", &input_color_tx_, no_filter);
sub.bind("in_tiles_img", as_image(&tiles_tx_)); sub.bind_image("in_tiles_img", &tiles_tx_);
sub.bind("out_color_img", as_image(&output_color_tx_)); sub.bind_image("out_color_img", &output_color_tx_);
sub.dispatch(&dispatch_gather_size_); sub.dispatch(&dispatch_gather_size_);
sub.barrier(GPU_BARRIER_TEXTURE_FETCH); sub.barrier(GPU_BARRIER_TEXTURE_FETCH);

View File

@@ -33,17 +33,17 @@ void WorldPipeline::sync(GPUMaterial *gpumat)
world_ps_.state_set(DRW_STATE_WRITE_COLOR); world_ps_.state_set(DRW_STATE_WRITE_COLOR);
world_ps_.material_set(manager, gpumat); world_ps_.material_set(manager, gpumat);
world_ps_.push_constant("world_opacity_fade", inst_.film.background_opacity_get()); world_ps_.push_constant("world_opacity_fade", inst_.film.background_opacity_get());
world_ps_.bind("utility_tx", inst_.pipelines.utility_tx); world_ps_.bind_texture("utility_tx", inst_.pipelines.utility_tx);
/* AOVs. */ /* AOVs. */
world_ps_.bind("aov_color_img", as_image(&rbufs.aov_color_tx)); world_ps_.bind_image("aov_color_img", &rbufs.aov_color_tx);
world_ps_.bind("aov_value_img", as_image(&rbufs.aov_value_tx)); world_ps_.bind_image("aov_value_img", &rbufs.aov_value_tx);
world_ps_.bind("aov_buf", &inst_.film.aovs_info); world_ps_.bind_ssbo("aov_buf", &inst_.film.aovs_info);
/* RenderPasses. Cleared by background (even if bad practice). */ /* RenderPasses. Cleared by background (even if bad practice). */
world_ps_.bind("rp_normal_img", as_image(&rbufs.normal_tx)); world_ps_.bind_image("rp_normal_img", &rbufs.normal_tx);
world_ps_.bind("rp_light_img", as_image(&rbufs.light_tx)); world_ps_.bind_image("rp_light_img", &rbufs.light_tx);
world_ps_.bind("rp_diffuse_color_img", as_image(&rbufs.diffuse_color_tx)); world_ps_.bind_image("rp_diffuse_color_img", &rbufs.diffuse_color_tx);
world_ps_.bind("rp_specular_color_img", as_image(&rbufs.specular_color_tx)); world_ps_.bind_image("rp_specular_color_img", &rbufs.specular_color_tx);
world_ps_.bind("rp_emission_img", as_image(&rbufs.emission_tx)); world_ps_.bind_image("rp_emission_img", &rbufs.emission_tx);
world_ps_.draw(DRW_cache_fullscreen_quad_get(), handle); world_ps_.draw(DRW_cache_fullscreen_quad_get(), handle);
/* To allow opaque pass rendering over it. */ /* To allow opaque pass rendering over it. */
@@ -77,7 +77,7 @@ void ForwardPipeline::sync()
/* Common resources. */ /* Common resources. */
/* Textures. */ /* Textures. */
prepass_ps_.bind(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx); prepass_ps_.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
inst_.velocity.bind_resources(&prepass_ps_); inst_.velocity.bind_resources(&prepass_ps_);
inst_.sampling.bind_resources(&prepass_ps_); inst_.sampling.bind_resources(&prepass_ps_);
@@ -102,18 +102,18 @@ void ForwardPipeline::sync()
/* Common resources. */ /* Common resources. */
/* RenderPasses. */ /* RenderPasses. */
opaque_ps_.bind(RBUFS_NORMAL_SLOT, as_image(&inst_.render_buffers.normal_tx)); opaque_ps_.bind_image(RBUFS_NORMAL_SLOT, &inst_.render_buffers.normal_tx);
opaque_ps_.bind(RBUFS_LIGHT_SLOT, as_image(&inst_.render_buffers.light_tx)); opaque_ps_.bind_image(RBUFS_LIGHT_SLOT, &inst_.render_buffers.light_tx);
opaque_ps_.bind(RBUFS_DIFF_COLOR_SLOT, as_image(&inst_.render_buffers.diffuse_color_tx)); opaque_ps_.bind_image(RBUFS_DIFF_COLOR_SLOT, &inst_.render_buffers.diffuse_color_tx);
opaque_ps_.bind(RBUFS_SPEC_COLOR_SLOT, as_image(&inst_.render_buffers.specular_color_tx)); opaque_ps_.bind_image(RBUFS_SPEC_COLOR_SLOT, &inst_.render_buffers.specular_color_tx);
opaque_ps_.bind(RBUFS_EMISSION_SLOT, as_image(&inst_.render_buffers.emission_tx)); opaque_ps_.bind_image(RBUFS_EMISSION_SLOT, &inst_.render_buffers.emission_tx);
/* AOVs. */ /* AOVs. */
opaque_ps_.bind(RBUFS_AOV_COLOR_SLOT, as_image(&inst_.render_buffers.aov_color_tx)); opaque_ps_.bind_image(RBUFS_AOV_COLOR_SLOT, &inst_.render_buffers.aov_color_tx);
opaque_ps_.bind(RBUFS_AOV_VALUE_SLOT, as_image(&inst_.render_buffers.aov_value_tx)); opaque_ps_.bind_image(RBUFS_AOV_VALUE_SLOT, &inst_.render_buffers.aov_value_tx);
/* Storage Buf. */ /* Storage Buf. */
opaque_ps_.bind(RBUFS_AOV_BUF_SLOT, &inst_.film.aovs_info); opaque_ps_.bind_ssbo(RBUFS_AOV_BUF_SLOT, &inst_.film.aovs_info);
/* Textures. */ /* Textures. */
opaque_ps_.bind(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx); opaque_ps_.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
inst_.lights.bind_resources(&opaque_ps_); inst_.lights.bind_resources(&opaque_ps_);
inst_.sampling.bind_resources(&opaque_ps_); inst_.sampling.bind_resources(&opaque_ps_);
@@ -135,7 +135,7 @@ void ForwardPipeline::sync()
/* Common resources. */ /* Common resources. */
/* Textures. */ /* Textures. */
sub.bind(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx); sub.bind_texture(RBUFS_UTILITY_TEX_SLOT, inst_.pipelines.utility_tx);
inst_.lights.bind_resources(&sub); inst_.lights.bind_resources(&sub);
inst_.sampling.bind_resources(&sub); inst_.sampling.bind_resources(&sub);

View File

@@ -90,7 +90,7 @@ class Sampling {
template<typename T> void bind_resources(draw::detail::PassBase<T> *pass) template<typename T> void bind_resources(draw::detail::PassBase<T> *pass)
{ {
/* Storage Buf. */ /* Storage Buf. */
pass->bind(SAMPLING_BUF_SLOT, &data_); pass->bind_ssbo(SAMPLING_BUF_SLOT, &data_);
} }
/* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated. */ /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated. */

View File

@@ -121,15 +121,15 @@ class VelocityModule {
template<typename T> void bind_resources(draw::detail::Pass<T> *pass) template<typename T> void bind_resources(draw::detail::Pass<T> *pass)
{ {
/* Storage Buf. */ /* Storage Buf. */
pass->bind(VELOCITY_OBJ_PREV_BUF_SLOT, &(*object_steps[STEP_PREVIOUS])); pass->bind_ssbo(VELOCITY_OBJ_PREV_BUF_SLOT, &(*object_steps[STEP_PREVIOUS]));
pass->bind(VELOCITY_OBJ_NEXT_BUF_SLOT, &(*object_steps[next_step_])); pass->bind_ssbo(VELOCITY_OBJ_NEXT_BUF_SLOT, &(*object_steps[next_step_]));
pass->bind(VELOCITY_GEO_PREV_BUF_SLOT, &(*geometry_steps[STEP_PREVIOUS])); pass->bind_ssbo(VELOCITY_GEO_PREV_BUF_SLOT, &(*geometry_steps[STEP_PREVIOUS]));
pass->bind(VELOCITY_GEO_NEXT_BUF_SLOT, &(*geometry_steps[next_step_])); pass->bind_ssbo(VELOCITY_GEO_NEXT_BUF_SLOT, &(*geometry_steps[next_step_]));
pass->bind(VELOCITY_INDIRECTION_BUF_SLOT, &indirection_buf); pass->bind_ssbo(VELOCITY_INDIRECTION_BUF_SLOT, &indirection_buf);
/* Uniform Buf. */ /* Uniform Buf. */
pass->bind(VELOCITY_CAMERA_PREV_BUF, &(*camera_steps[STEP_PREVIOUS])); pass->bind_ubo(VELOCITY_CAMERA_PREV_BUF, &(*camera_steps[STEP_PREVIOUS]));
pass->bind(VELOCITY_CAMERA_CURR_BUF, &(*camera_steps[STEP_CURRENT])); pass->bind_ubo(VELOCITY_CAMERA_CURR_BUF, &(*camera_steps[STEP_CURRENT]));
pass->bind(VELOCITY_CAMERA_NEXT_BUF, &(*camera_steps[next_step_])); pass->bind_ubo(VELOCITY_CAMERA_NEXT_BUF, &(*camera_steps[next_step_]));
} }
bool camera_has_motion() const; bool camera_has_motion() const;

View File

@@ -105,6 +105,9 @@ template<
class PassBase { class PassBase {
friend Manager; friend Manager;
/** Will use texture own sampler state. */
static constexpr eGPUSamplerState sampler_auto = GPU_SAMPLER_MAX;
protected: protected:
/** Highest level of the command stream. Split command stream in different command types. */ /** Highest level of the command stream. Split command stream in different command types. */
Vector<command::Header, 0> headers_; Vector<command::Header, 0> headers_;
@@ -242,22 +245,22 @@ class PassBase {
* NOTE: Variations using slot will not query a shader interface and can be used before * NOTE: Variations using slot will not query a shader interface and can be used before
* binding a shader. * binding a shader.
*/ */
void bind(const char *name, GPUStorageBuf *buffer); void bind_image(const char *name, GPUTexture *image);
void bind(const char *name, GPUUniformBuf *buffer); void bind_image(const char *name, GPUTexture **image);
void bind(const char *name, draw::Image *image); void bind_image(int slot, GPUTexture *image);
void bind(const char *name, GPUTexture *texture, eGPUSamplerState state = GPU_SAMPLER_MAX); void bind_image(int slot, GPUTexture **image);
void bind(const char *name, GPUStorageBuf **buffer); void bind_texture(const char *name, GPUTexture *texture, eGPUSamplerState state = sampler_auto);
void bind(const char *name, GPUUniformBuf **buffer); void bind_texture(const char *name, GPUTexture **texture, eGPUSamplerState state = sampler_auto);
void bind(const char *name, draw::Image **image); void bind_texture(int slot, GPUTexture *texture, eGPUSamplerState state = sampler_auto);
void bind(const char *name, GPUTexture **texture, eGPUSamplerState state = GPU_SAMPLER_MAX); void bind_texture(int slot, GPUTexture **texture, eGPUSamplerState state = sampler_auto);
void bind(int slot, GPUStorageBuf *buffer); void bind_ssbo(const char *name, GPUStorageBuf *buffer);
void bind(int slot, GPUUniformBuf *buffer); void bind_ssbo(const char *name, GPUStorageBuf **buffer);
void bind(int slot, draw::Image *image); void bind_ssbo(int slot, GPUStorageBuf *buffer);
void bind(int slot, GPUTexture *texture, eGPUSamplerState state = GPU_SAMPLER_MAX); void bind_ssbo(int slot, GPUStorageBuf **buffer);
void bind(int slot, GPUStorageBuf **buffer); void bind_ubo(const char *name, GPUUniformBuf *buffer);
void bind(int slot, GPUUniformBuf **buffer); void bind_ubo(const char *name, GPUUniformBuf **buffer);
void bind(int slot, draw::Image **image); void bind_ubo(int slot, GPUUniformBuf *buffer);
void bind(int slot, GPUTexture **texture, eGPUSamplerState state = GPU_SAMPLER_MAX); void bind_ubo(int slot, GPUUniformBuf **buffer);
/** /**
* Update a shader constant. * Update a shader constant.
@@ -739,27 +742,27 @@ template<class T> inline void PassBase<T>::material_set(Manager &manager, GPUMat
if (tex->tiled_mapping_name[0]) { if (tex->tiled_mapping_name[0]) {
GPUTexture *tiles = BKE_image_get_gpu_tiles(tex->ima, iuser, nullptr); GPUTexture *tiles = BKE_image_get_gpu_tiles(tex->ima, iuser, nullptr);
manager.acquire_texture(tiles); manager.acquire_texture(tiles);
bind(tex->sampler_name, tiles, (eGPUSamplerState)tex->sampler_state); bind_texture(tex->sampler_name, tiles, (eGPUSamplerState)tex->sampler_state);
GPUTexture *tile_map = BKE_image_get_gpu_tilemap(tex->ima, iuser, nullptr); GPUTexture *tile_map = BKE_image_get_gpu_tilemap(tex->ima, iuser, nullptr);
manager.acquire_texture(tile_map); manager.acquire_texture(tile_map);
bind(tex->tiled_mapping_name, tile_map, (eGPUSamplerState)tex->sampler_state); bind_texture(tex->tiled_mapping_name, tile_map, (eGPUSamplerState)tex->sampler_state);
} }
else { else {
GPUTexture *texture = BKE_image_get_gpu_texture(tex->ima, iuser, nullptr); GPUTexture *texture = BKE_image_get_gpu_texture(tex->ima, iuser, nullptr);
manager.acquire_texture(texture); manager.acquire_texture(texture);
bind(tex->sampler_name, texture, (eGPUSamplerState)tex->sampler_state); bind_texture(tex->sampler_name, texture, (eGPUSamplerState)tex->sampler_state);
} }
} }
else if (tex->colorband) { else if (tex->colorband) {
/* Color Ramp */ /* Color Ramp */
bind(tex->sampler_name, *tex->colorband); bind_texture(tex->sampler_name, *tex->colorband);
} }
} }
GPUUniformBuf *ubo = GPU_material_uniform_buffer_get(material); GPUUniformBuf *ubo = GPU_material_uniform_buffer_get(material);
if (ubo != nullptr) { if (ubo != nullptr) {
bind(GPU_UBO_BLOCK_NAME, ubo); bind_ubo(GPU_UBO_BLOCK_NAME, ubo);
} }
} }
@@ -774,89 +777,93 @@ template<class T> inline int PassBase<T>::push_constant_offset(const char *name)
return GPU_shader_get_uniform(shader_, name); return GPU_shader_get_uniform(shader_, name);
} }
template<class T> inline void PassBase<T>::bind(const char *name, GPUStorageBuf *buffer) template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUStorageBuf *buffer)
{ {
bind(GPU_shader_get_ssbo(shader_, name), buffer); bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
} }
template<class T> inline void PassBase<T>::bind(const char *name, GPUUniformBuf *buffer) template<class T> inline void PassBase<T>::bind_ubo(const char *name, GPUUniformBuf *buffer)
{ {
bind(GPU_shader_get_uniform_block_binding(shader_, name), buffer); bind_ubo(GPU_shader_get_uniform_block_binding(shader_, name), buffer);
} }
template<class T> template<class T>
inline void PassBase<T>::bind(const char *name, GPUTexture *texture, eGPUSamplerState state) inline void PassBase<T>::bind_texture(const char *name,
GPUTexture *texture,
eGPUSamplerState state)
{ {
bind(GPU_shader_get_texture_binding(shader_, name), texture, state); bind_texture(GPU_shader_get_texture_binding(shader_, name), texture, state);
} }
template<class T> inline void PassBase<T>::bind(const char *name, draw::Image *image) template<class T> inline void PassBase<T>::bind_image(const char *name, GPUTexture *image)
{ {
bind(GPU_shader_get_texture_binding(shader_, name), image); bind_texture(GPU_shader_get_texture_binding(shader_, name), image);
} }
template<class T> inline void PassBase<T>::bind(int slot, GPUStorageBuf *buffer) template<class T> inline void PassBase<T>::bind_ssbo(int slot, GPUStorageBuf *buffer)
{ {
create_command(Type::ResourceBind).resource_bind = {slot, buffer}; create_command(Type::ResourceBind).resource_bind = {slot, buffer};
} }
template<class T> inline void PassBase<T>::bind(int slot, GPUUniformBuf *buffer) template<class T> inline void PassBase<T>::bind_ubo(int slot, GPUUniformBuf *buffer)
{ {
create_command(Type::ResourceBind).resource_bind = {slot, buffer}; create_command(Type::ResourceBind).resource_bind = {slot, buffer};
} }
template<class T> template<class T>
inline void PassBase<T>::bind(int slot, GPUTexture *texture, eGPUSamplerState state) inline void PassBase<T>::bind_texture(int slot, GPUTexture *texture, eGPUSamplerState state)
{ {
create_command(Type::ResourceBind).resource_bind = {slot, texture, state}; create_command(Type::ResourceBind).resource_bind = {slot, texture, state};
} }
template<class T> inline void PassBase<T>::bind(int slot, draw::Image *image) template<class T> inline void PassBase<T>::bind_image(int slot, GPUTexture *image)
{ {
create_command(Type::ResourceBind).resource_bind = {slot, image}; create_command(Type::ResourceBind).resource_bind = {slot, as_image(image)};
} }
template<class T> inline void PassBase<T>::bind(const char *name, GPUStorageBuf **buffer) template<class T> inline void PassBase<T>::bind_ssbo(const char *name, GPUStorageBuf **buffer)
{ {
bind(GPU_shader_get_ssbo(shader_, name), buffer); bind_ssbo(GPU_shader_get_ssbo(shader_, name), buffer);
} }
template<class T> inline void PassBase<T>::bind(const char *name, GPUUniformBuf **buffer) template<class T> inline void PassBase<T>::bind_ubo(const char *name, GPUUniformBuf **buffer)
{ {
bind(GPU_shader_get_uniform_block_binding(shader_, name), buffer); bind_ubo(GPU_shader_get_uniform_block_binding(shader_, name), buffer);
} }
template<class T> template<class T>
inline void PassBase<T>::bind(const char *name, GPUTexture **texture, eGPUSamplerState state) inline void PassBase<T>::bind_texture(const char *name,
GPUTexture **texture,
eGPUSamplerState state)
{ {
bind(GPU_shader_get_texture_binding(shader_, name), texture, state); bind_texture(GPU_shader_get_texture_binding(shader_, name), texture, state);
} }
template<class T> inline void PassBase<T>::bind(const char *name, draw::Image **image) template<class T> inline void PassBase<T>::bind_image(const char *name, GPUTexture **image)
{ {
bind(GPU_shader_get_texture_binding(shader_, name), image); bind_image(GPU_shader_get_texture_binding(shader_, name), image);
} }
template<class T> inline void PassBase<T>::bind(int slot, GPUStorageBuf **buffer) template<class T> inline void PassBase<T>::bind_ssbo(int slot, GPUStorageBuf **buffer)
{ {
create_command(Type::ResourceBind).resource_bind = {slot, buffer}; create_command(Type::ResourceBind).resource_bind = {slot, buffer};
} }
template<class T> inline void PassBase<T>::bind(int slot, GPUUniformBuf **buffer) template<class T> inline void PassBase<T>::bind_ubo(int slot, GPUUniformBuf **buffer)
{ {
create_command(Type::ResourceBind).resource_bind = {slot, buffer}; create_command(Type::ResourceBind).resource_bind = {slot, buffer};
} }
template<class T> template<class T>
inline void PassBase<T>::bind(int slot, GPUTexture **texture, eGPUSamplerState state) inline void PassBase<T>::bind_texture(int slot, GPUTexture **texture, eGPUSamplerState state)
{ {
create_command(Type::ResourceBind).resource_bind = {slot, texture, state}; create_command(Type::ResourceBind).resource_bind = {slot, texture, state};
} }
template<class T> inline void PassBase<T>::bind(int slot, draw::Image **image) template<class T> inline void PassBase<T>::bind_image(int slot, GPUTexture **image)
{ {
create_command(Type::ResourceBind).resource_bind = {slot, image}; create_command(Type::ResourceBind).resource_bind = {slot, as_image(image)};
} }
/** \} */ /** \} */

View File

@@ -31,14 +31,14 @@ static void test_draw_pass_all_commands()
pass.clear_color_depth_stencil(float4(0.25f, 0.5f, 100.0f, -2000.0f), 0.5f, 0xF0); pass.clear_color_depth_stencil(float4(0.25f, 0.5f, 100.0f, -2000.0f), 0.5f, 0xF0);
pass.state_stencil(0x80, 0x0F, 0x8F); pass.state_stencil(0x80, 0x0F, 0x8F);
pass.shader_set(GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE_MODULATE_ALPHA)); pass.shader_set(GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE_MODULATE_ALPHA));
pass.bind("image", tex); pass.bind_texture("image", tex);
pass.bind("image", &tex); pass.bind_texture("image", &tex);
pass.bind("missing_image", as_image(tex)); /* Should not crash. */ pass.bind_image("missing_image", tex); /* Should not crash. */
pass.bind("missing_image", as_image(&tex)); /* Should not crash. */ pass.bind_image("missing_image", &tex); /* Should not crash. */
pass.bind("missing_ubo", ubo); /* Should not crash. */ pass.bind_ubo("missing_ubo", ubo); /* Should not crash. */
pass.bind("missing_ubo", &ubo); /* Should not crash. */ pass.bind_ubo("missing_ubo", &ubo); /* Should not crash. */
pass.bind("missing_ssbo", ssbo); /* Should not crash. */ pass.bind_ssbo("missing_ssbo", ssbo); /* Should not crash. */
pass.bind("missing_ssbo", &ssbo); /* Should not crash. */ pass.bind_ssbo("missing_ssbo", &ssbo); /* Should not crash. */
pass.push_constant("alpha", alpha); pass.push_constant("alpha", alpha);
pass.push_constant("alpha", &alpha); pass.push_constant("alpha", &alpha);
pass.push_constant("ModelViewProjectionMatrix", float4x4::identity()); pass.push_constant("ModelViewProjectionMatrix", float4x4::identity());