Skip to content

Commit

Permalink
Added set_push_constants to RenderPass
Browse files Browse the repository at this point in the history
  • Loading branch information
Neo-Zhixing committed Mar 3, 2021
1 parent 1fcafc4 commit 655053d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/bevy_render/src/pass/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use crate::{
};
use bevy_asset::Handle;
use std::ops::Range;
use crate::pipeline::BindingShaderStage;

pub trait RenderPass {
fn get_render_context(&self) -> &dyn RenderContext;
fn set_index_buffer(&mut self, buffer: BufferId, offset: u64, index_format: IndexFormat);
fn set_vertex_buffer(&mut self, start_slot: u32, buffer: BufferId, offset: u64);
fn set_push_constants(&mut self, stages: BindingShaderStage, offset: u32, data: &[u8]);
fn set_pipeline(&mut self, pipeline_handle: &Handle<PipelineDescriptor>);
fn set_viewport(&mut self, x: f32, y: f32, w: f32, h: f32, min_depth: f32, max_depth: f32);
fn set_scissor_rect(&mut self, x: u32, y: u32, w: u32, h: u32);
Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_wgpu/src/wgpu_render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bevy_render::{
};
use bevy_utils::tracing::trace;
use std::ops::Range;
use bevy_render::pipeline::BindingShaderStage;

#[derive(Debug)]
pub struct WgpuRenderPass<'a> {
Expand Down Expand Up @@ -46,6 +47,11 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {
.set_index_buffer(buffer.slice(offset..), index_format.wgpu_into());
}

fn set_push_constants(&mut self, stages: BindingShaderStage, offset: u32, data: &[u8]) {
self.render_pass
.set_push_constants(stages.wgpu_into(), offset, data);
}

fn draw_indexed(&mut self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>) {
self.render_pass
.draw_indexed(indices, base_vertex, instances);
Expand Down
17 changes: 17 additions & 0 deletions crates/bevy_wgpu/src/wgpu_type_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use bevy_render::{
};
use bevy_window::Window;
use wgpu::BufferBindingType;
use bevy_render::pipeline::BindingShaderStage;

pub trait WgpuFrom<T> {
fn from(val: T) -> Self;
Expand Down Expand Up @@ -230,6 +231,22 @@ impl WgpuFrom<&BindType> for wgpu::BindingType {
}
}

impl WgpuFrom<BindingShaderStage> for wgpu::ShaderStage {
fn from(val: BindingShaderStage) -> Self {
let mut wgpu_val = wgpu::ShaderStage::NONE;
if val.contains(BindingShaderStage::VERTEX) {
wgpu_val.insert(wgpu::ShaderStage::VERTEX);
}
if val.contains(BindingShaderStage::FRAGMENT) {
wgpu_val.insert(wgpu::ShaderStage::FRAGMENT);
}
if val.contains(BindingShaderStage::COMPUTE) {
wgpu_val.insert(wgpu::ShaderStage::COMPUTE);
}
wgpu_val
}
}

impl WgpuFrom<TextureSampleType> for wgpu::TextureSampleType {
fn from(texture_component_type: TextureSampleType) -> Self {
match texture_component_type {
Expand Down

0 comments on commit 655053d

Please sign in to comment.