Skip to content

Commit

Permalink
push constant ranges
Browse files Browse the repository at this point in the history
# Conflicts:
#	crates/bevy_render/src/pipeline/pipeline_layout.rs
#	crates/bevy_wgpu/src/wgpu_type_converter.rs
  • Loading branch information
Neo-Zhixing committed Mar 7, 2021
1 parent 9387d88 commit e149912
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 16 deletions.
6 changes: 3 additions & 3 deletions crates/bevy_render/src/draw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
pipeline::{
IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineLayout, PipelineSpecialization,
BindingShaderStage, IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineLayout,
PipelineSpecialization,
},
renderer::{
AssetRenderResourceBindings, BindGroup, BindGroupId, BufferId, RenderResource,
Expand All @@ -16,7 +17,6 @@ use bevy_ecs::{
use bevy_reflect::Reflect;
use std::{ops::Range, sync::Arc};
use thiserror::Error;
use crate::pipeline::BindingShaderStage;

/// A queued command for the renderer
#[derive(Debug, Clone, Eq, PartialEq)]
Expand All @@ -42,7 +42,7 @@ pub enum RenderCommand {
SetPushConstants {
stages: BindingShaderStage,
offset: u32,
data: Arc<[u8]>
data: Arc<[u8]>,
},
DrawIndexed {
indices: Range<u32>,
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_render/src/pass/render_pass.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{
pipeline::{BindGroupDescriptorId, IndexFormat, PipelineDescriptor},
pipeline::{BindGroupDescriptorId, BindingShaderStage, IndexFormat, PipelineDescriptor},
renderer::{BindGroupId, BufferId, RenderContext},
};
use bevy_asset::Handle;
use std::ops::Range;
use crate::pipeline::BindingShaderStage;

pub trait RenderPass {
fn get_render_context(&self) -> &dyn RenderContext;
Expand Down
17 changes: 15 additions & 2 deletions crates/bevy_render/src/pipeline/pipeline_layout.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use super::{BindGroupDescriptor, VertexBufferLayout};
use crate::shader::ShaderLayout;
use crate::{pipeline::BindingShaderStage, shader::ShaderLayout};
use bevy_utils::HashMap;
use std::hash::Hash;
use std::{hash::Hash, ops::Range};

#[derive(Clone, Debug, Default)]
pub struct PipelineLayout {
pub bind_groups: Vec<BindGroupDescriptor>,
pub vertex_buffer_descriptors: Vec<VertexBufferLayout>,
pub push_constant_ranges: Vec<PushConstantRange>,
}

impl PipelineLayout {
Expand Down Expand Up @@ -65,6 +66,8 @@ impl PipelineLayout {
PipelineLayout {
bind_groups: bind_groups_result,
vertex_buffer_descriptors,
// TODO: get push constant ranges from shader layout
push_constant_ranges: vec![],
}
}
}
Expand Down Expand Up @@ -103,3 +106,13 @@ impl UniformProperty {
}
}
}

#[derive(Hash, Clone, Debug)]
pub struct PushConstantRange {
/// Stage push constant range is visible from. Each stage can only be served by at most one range.
/// One range can serve multiple stages however.
pub stages: BindingShaderStage,
/// Range in push constant memory to use for the stage. Must be less than [`Limits::max_push_constant_size`].
/// Start and end must be aligned to the 4s.
pub range: Range<u32>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,18 @@ impl RenderResourceContext for WgpuRenderResourceContext {
.iter()
.map(|bind_group| bind_group_layouts.get(&bind_group.id).unwrap())
.collect::<Vec<&wgpu::BindGroupLayout>>();
let push_constant_ranges: Vec<wgpu::PushConstantRange> = layout
.push_constant_ranges
.iter()
.map(|range| range.clone().wgpu_into())
.collect();

let pipeline_layout = self
.device
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: bind_group_layouts.as_slice(),
push_constant_ranges: &[],
push_constant_ranges: &push_constant_ranges,
});

let owned_vertex_buffer_descriptors = layout
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_wgpu/src/wgpu_render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use crate::{renderer::WgpuRenderContext, wgpu_type_converter::WgpuInto, WgpuReso
use bevy_asset::Handle;
use bevy_render::{
pass::RenderPass,
pipeline::{BindGroupDescriptorId, IndexFormat, PipelineDescriptor},
pipeline::{BindGroupDescriptorId, BindingShaderStage, IndexFormat, PipelineDescriptor},
renderer::{BindGroupId, BufferId, RenderContext},
};
use bevy_utils::tracing::trace;
use std::ops::Range;
use bevy_render::pipeline::BindingShaderStage;

#[derive(Debug)]
pub struct WgpuRenderPass<'a> {
Expand Down
20 changes: 14 additions & 6 deletions crates/bevy_wgpu/src/wgpu_type_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use bevy_render::{
color::Color,
pass::{LoadOp, Operations},
pipeline::{
BindType, BlendFactor, BlendOperation, BlendState, ColorTargetState, ColorWrite,
CompareFunction, CullMode, DepthBiasState, DepthStencilState, FrontFace, IndexFormat,
InputStepMode, MultisampleState, PolygonMode, PrimitiveState, PrimitiveTopology,
StencilFaceState, StencilOperation, StencilState, VertexAttribute, VertexBufferLayout,
VertexFormat,
BindType, BindingShaderStage, BlendFactor, BlendOperation, BlendState, ColorTargetState,
ColorWrite, CompareFunction, CullMode, DepthBiasState, DepthStencilState, FrontFace,
IndexFormat, InputStepMode, MultisampleState, PolygonMode, PrimitiveState,
PrimitiveTopology, PushConstantRange, StencilFaceState, StencilOperation, StencilState,
VertexAttribute, VertexBufferLayout, VertexFormat,
},
renderer::BufferUsage,
texture::{
Expand All @@ -18,7 +18,6 @@ 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 @@ -247,6 +246,15 @@ impl WgpuFrom<BindingShaderStage> for wgpu::ShaderStage {
}
}

impl WgpuFrom<PushConstantRange> for wgpu::PushConstantRange {
fn from(val: PushConstantRange) -> Self {
wgpu::PushConstantRange {
stages: val.stages.wgpu_into(),
range: val.range,
}
}
}

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

0 comments on commit e149912

Please sign in to comment.