Skip to content

Commit

Permalink
refactor: upgrade to bevy 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielmelody committed May 7, 2024
1 parent 124e36b commit 15c323f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
25 changes: 13 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,30 @@ repository = "https://github.com/johanhelsing/bevy_smud"
version = "0.7.0"

[dependencies]
bevy = { version = "0.12", default-features = false, features = [
bevy = { version = "0.13", default-features = false, features = [
"bevy_core_pipeline",
"bevy_render",
"bevy_asset", # needed for handle ids
]}
bytemuck = { version = "1.7", features = ["derive"] }
"bevy_asset", # needed for handle ids
] }
bytemuck = { version = "1.15.0", features = ["derive"] }
copyless = "0.1"
bitflags = "2.4"
fixedbitset = "0.4"
bitflags = "2.5"
fixedbitset = "0.5"

[dev-dependencies]
bevy = { version = "0.12", default-features = false, features = [
bevy = { version = "0.13.2", default-features = false, features = [
"bevy_winit",
"x11", # github actions runners don't have libxkbcommon installed, so can't use wayland
"x11", # github actions runners don't have libxkbcommon installed, so can't use wayland
"file_watcher",
"multi-threaded",
] }
bevy_asset_loader = "0.18"
bevy_lospec = "0.6"
bevy_pancam = "0.10"
bevy_asset_loader = "0.20"
bevy_lospec = "0.7"
bevy_pancam = "0.11"
rand = "0.8"

[profile.dev]
opt-level = 1

[profile.dev.package."*"]
opt-level = 3
opt-level = 3
8 changes: 5 additions & 3 deletions examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use rand::prelude::*;

fn main() {
App::new()
.add_state::<GameState>()
.init_state::<GameState>()
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.add_loading_state(
LoadingState::new(GameState::Loading).continue_to_state(GameState::Running),
LoadingState::new(GameState::Loading)
.continue_to_state(GameState::Running)
.load_collection::<AssetHandles>(),
)
.add_collection_to_loading_state::<_, AssetHandles>(GameState::Loading)
.add_plugins((
DefaultPlugins,
LogDiagnosticsPlugin::default(),
Expand All @@ -43,6 +44,7 @@ struct AssetHandles {
palette: Handle<bevy_lospec::Palette>,
}

#[allow(dead_code)]
#[derive(Component)]
struct Index(usize);

Expand Down
10 changes: 6 additions & 4 deletions examples/gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ use rand::prelude::*;

fn main() {
App::new()
.add_state::<GameState>()
.init_state::<GameState>()
// bevy_smud comes with anti-aliasing built into the standards fills
// which is more efficient than MSAA, and also works on Linux, wayland
.insert_resource(Msaa::Off)
.add_loading_state(
LoadingState::new(GameState::Loading).continue_to_state(GameState::Running),
LoadingState::new(GameState::Loading)
.continue_to_state(GameState::Running)
.load_collection::<AssetHandles>(),
)
.add_collection_to_loading_state::<_, AssetHandles>(GameState::Loading)
.add_plugins((
DefaultPlugins,
SmudPlugin,
Expand All @@ -39,6 +40,7 @@ struct AssetHandles {
palette: Handle<bevy_lospec::Palette>,
}

#[allow(dead_code)]
#[derive(Component)]
struct Index(usize);

Expand Down Expand Up @@ -85,7 +87,7 @@ fn setup(
asset_server.load("gallery/donut.wgsl"),
];

let fills = vec![
let fills = [
// asset_server.load("fills/simple.wgsl"),
asset_server.load("fills/cubic_falloff.wgsl"),
asset_server.load("fills/outline.wgsl"),
Expand Down
41 changes: 22 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::ops::Range;
use bevy::{
core_pipeline::core_2d::Transparent2d,
ecs::{
entity::EntityHashMap,
query::ROQueryItem,
system::{
lifetimeless::{Read, SRes},
Expand All @@ -22,11 +23,11 @@ use bevy::{
RenderPhase, SetItemPipeline, TrackedRenderPass,
},
render_resource::{
BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutDescriptor,
BindGroupLayoutEntry, BindingType, BlendState, BufferBindingType, BufferUsages,
BufferVec, CachedRenderPipelineId, ColorTargetState, ColorWrites, Face, FragmentState,
FrontFace, MultisampleState, PipelineCache, PolygonMode, PrimitiveState,
PrimitiveTopology, RenderPipelineDescriptor, ShaderImport, ShaderStages, ShaderType,
BindGroup, BindGroupEntries, BindGroupLayout, BindGroupLayoutEntry, BindingType,
BlendState, BufferBindingType, BufferUsages, BufferVec, CachedRenderPipelineId,
ColorTargetState, ColorWrites, Face, FragmentState, FrontFace, MultisampleState,
PipelineCache, PolygonMode, PrimitiveState, PrimitiveTopology,
RenderPipelineDescriptor, ShaderImport, ShaderStages, ShaderType,
SpecializedRenderPipeline, SpecializedRenderPipelines, TextureFormat, VertexAttribute,
VertexBufferLayout, VertexFormat, VertexState, VertexStepMode,
},
Expand All @@ -38,7 +39,7 @@ use bevy::{
},
Extract, MainWorld, Render, RenderApp, RenderSet,
},
utils::{EntityHashMap, FloatOrd, HashMap},
utils::{FloatOrd, HashMap},
};
use bytemuck::{Pod, Zeroable};
use fixedbitset::FixedBitSet;
Expand Down Expand Up @@ -118,13 +119,13 @@ type DrawSmudShape = (SetItemPipeline, SetShapeViewBindGroup<0>, DrawShapeBatch)
struct SetShapeViewBindGroup<const I: usize>;
impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetShapeViewBindGroup<I> {
type Param = SRes<ShapeMeta>;
type ViewWorldQuery = Read<ViewUniformOffset>;
type ItemWorldQuery = ();
type ViewQuery = Read<ViewUniformOffset>;
type ItemQuery = ();

fn render<'w>(
_item: &P,
view_uniform: ROQueryItem<'w, Self::ViewWorldQuery>,
_view: (),
view_uniform: ROQueryItem<'w, Self::ViewQuery>,
_entity: Option<ROQueryItem<'w, Self::ItemQuery>>,
shape_meta: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
Expand All @@ -140,19 +141,21 @@ impl<P: PhaseItem, const I: usize> RenderCommand<P> for SetShapeViewBindGroup<I>
struct DrawShapeBatch;
impl<P: PhaseItem> RenderCommand<P> for DrawShapeBatch {
type Param = SRes<ShapeMeta>;
type ViewWorldQuery = ();
type ItemWorldQuery = Read<ShapeBatch>;
type ViewQuery = ();
type ItemQuery = Read<ShapeBatch>;

fn render<'w>(
_item: &P,
_view: (),
batch: &'_ ShapeBatch,
batch: Option<ROQueryItem<'w, Self::ItemQuery>>,
shape_meta: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let shape_meta = shape_meta.into_inner();
pass.set_vertex_buffer(0, shape_meta.vertices.buffer().unwrap().slice(..));
pass.draw(0..4, batch.range.clone());
if let Some(batch) = batch {
pass.draw(0..4, batch.range.clone());
}
RenderCommandResult::Success
}
}
Expand All @@ -167,8 +170,9 @@ impl FromWorld for SmudPipeline {
fn from_world(world: &mut World) -> Self {
let render_device = world.get_resource::<RenderDevice>().unwrap();

let view_layout = render_device.create_bind_group_layout(&BindGroupLayoutDescriptor {
entries: &[
let view_layout = render_device.create_bind_group_layout(
Some("shape_view_layout"),
&[
BindGroupLayoutEntry {
binding: 0,
visibility: ShaderStages::VERTEX_FRAGMENT,
Expand All @@ -190,8 +194,7 @@ impl FromWorld for SmudPipeline {
count: None,
},
],
label: Some("shape_view_layout"),
});
);

Self {
view_layout,
Expand Down Expand Up @@ -397,7 +400,7 @@ struct ExtractedShape {

#[derive(Resource, Default, Debug)]
struct ExtractedShapes {
shapes: EntityHashMap<Entity, ExtractedShape>,
shapes: EntityHashMap<ExtractedShape>,
}

fn extract_shapes(
Expand Down

0 comments on commit 15c323f

Please sign in to comment.