Skip to content

Commit

Permalink
Fixed GPU<->CPU sync issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundo-villa committed Jul 25, 2023
1 parent 8d7c474 commit 3292461
Show file tree
Hide file tree
Showing 11 changed files with 534 additions and 225 deletions.
2 changes: 1 addition & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl Application for GraphicsApplication {
window_system::WindowEvents::Button { pressed, button } => {
input_system.record_input_source_action(&self.mouse_device_handle, input_manager::InputSourceAction::Name("Mouse.LeftButton"), input_manager::Value::Bool(pressed));
},
window_system::WindowEvents::MouseMove { x, y } => {
window_system::WindowEvents::MouseMove { x, y, time } => {
let vec = Vector2::new((x as f32 / 1920f32 - 0.5f32) * 2f32, (y as f32 / 1080f32 - 0.5f32) * 2f32);
input_system.record_input_source_action(&self.mouse_device_handle, input_manager::InputSourceAction::Name("Mouse.Position"), input_manager::Value::Vector2(vec));
},
Expand Down
39 changes: 27 additions & 12 deletions src/input_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,17 @@ impl InputManager {
time,
};

{
let mut i = 0;
while i < self.records.len() {
if self.records[i].input_source_handle == input_source_handle {
self.records.remove(i);
} else {
i += 1;
}
}
}

self.records.push(record);

if let Value::Bool(boo) = value {
Expand All @@ -561,18 +572,19 @@ impl InputManager {

if records.len() == 0 { return; }

for record in records {
let actions_for_input_source = self.actions.iter().enumerate().filter(|(i, a)| { a.input_event_descriptions.iter().any(|ied| ied.input_source_handle == record.input_source_handle) });
for (i, action) in self.actions.iter().enumerate() {
let action_records = records.iter().filter(|r| action.input_event_descriptions.iter().any(|ied| ied.input_source_handle == r.input_source_handle));

let most_recent_record = action_records.max_by_key(|r| r.time);

for (i, action) in actions_for_input_source {
match action.type_ {
Types::Vector2 => {
let v = if let Value::Vector2(v) = record.value.clone() { v } else { panic!("Not a vector2!") };
if let Some(record) = most_recent_record {
let value = self.resolve_action_value_from_record(action, record);

match value {
Value::Vector2(v) => {
orchestrator.set_owned_property(orchestrator::InternalId(i as u32), Action::<Vector2>::value, v);
}
Types::Vector3 => {
let value = self.get_action_state(ActionHandle(i as u32), &DeviceHandle(0));
let v = if let Value::Vector3(v) = value.value { v } else { panic!("Not a vector3!") };
Value::Vector3(v) => {
orchestrator.set_owned_property(orchestrator::InternalId(i as u32), Action::<Vector3>::value, v);
}
_ => {}
Expand Down Expand Up @@ -694,9 +706,12 @@ impl InputManager {
if let Function::Sphere = function {
let r = record_value;

let x = r.x;
let y = r.y;
let z = (1f32 - (x * x + y * y)).sqrt();
let x_pi = r.x * PI;
let y_pi = r.y * PI * 0.5f32;

let x = x_pi.sin() * y_pi.cos();
let y = y_pi.sin();
let z = x_pi.cos() * y_pi.cos();

let transformation = if let Value::Vector3(transformation) = mapping.mapping { transformation } else { panic!("Not implemented!"); };

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#![feature(non_lifetime_binders)]
#![feature(downcast_unchecked)]
#![feature(const_mut_refs)]
#![feature(extract_if)]
#![warn(missing_docs)]
#![warn(missing_doc_code_examples)]

Expand Down
4 changes: 2 additions & 2 deletions src/math.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub fn look_at(direction: crate::Vector3) -> maths_rs::Mat4f {
let x_axis = maths_rs::normalize(maths_rs::cross(crate::Vector3::new(0f32, 1f32, 0f32), direction));
let y_axis = maths_rs::normalize(maths_rs::cross(direction, x_axis));
let x_axis = maths_rs::normalize(maths_rs::cross(crate::Vector3::new(0f32, 1f32, 0f32), maths_rs::normalize(direction)));
let y_axis = maths_rs::normalize(maths_rs::cross(maths_rs::normalize(direction), x_axis));

maths_rs::Mat4f::from((
maths_rs::Vec4f::from((x_axis, 0f32)),
Expand Down
5 changes: 4 additions & 1 deletion src/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ impl Orchestrator {

if ties.contains_key(&(property_function_pointer as usize)) {
let ties = ties.get_mut(&(property_function_pointer as usize)).unwrap();
ties.push(Tie { update_function, destination_system_handle: receiver_component_handle.internal_id });

if !ties.iter().any(|tie| tie.destination_system_handle == receiver_component_handle.internal_id) {
ties.push(Tie { update_function, destination_system_handle: receiver_component_handle.internal_id });
}
} else {
let mut ties_new = Vec::new();
ties_new.push(Tie { update_function, destination_system_handle: receiver_component_handle.internal_id });
Expand Down
50 changes: 44 additions & 6 deletions src/render_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ pub struct TextureCopy {
pub extent: crate::Extent,
}

#[derive(Clone, Copy)]
/// Stores the information of a buffer copy.
pub struct BufferCopy {
/// The source buffer.
pub source: Buffer,
/// The destination buffer.
pub destination: Buffer,
/// The size of the copy.
pub size: usize,
}

#[derive(Clone, Copy)]
/// Stores the information of a memory backed resource.
pub struct MemoryBackedResourceCreationResult<T> {
Expand All @@ -210,11 +221,28 @@ bitflags! {
}
}

#[derive(Clone, Copy)]
pub struct TextureState {
/// The layout of the resource.
pub layout: Layouts,
/// The format of the resource.
pub format: TextureFormats,
}

#[derive(Clone, Copy)]
/// Stores the information of a barrier.
pub enum Barrier {
/// A texture barrier.
Texture(Texture),
Texture {
source: Option<TextureState>,
destination: TextureState,
/// The texture of the barrier.
texture: Texture,
},
/// A buffer barrier.
Buffer(Buffer),
/// A memory barrier.
Memory(),
}

bitflags! {
Expand All @@ -231,6 +259,18 @@ bitflags! {
const COMPUTE = 0b00000100;
/// The transfer stage.
const TRANSFER = 0b00001000;
/// The acceleration structure stage.
const ACCELERATION_STRUCTURE = 0b00010000;
/// The presentation stage.
const PRESENTATION = 0b00100000;
/// The host stage.
const HOST = 0b01000000;
/// The all graphics stage.
const ALL_GRAPHICS = 0b10000000;
/// The all stage.
const ALL = 0b11111111;
/// The shader read stage.
const SHADER_READ = 0b00000001;
}
}

Expand All @@ -241,10 +281,6 @@ pub struct TransitionState {
pub stage: Stages,
/// The type of access that will be done on the resource by the process the operation that requires this transition.
pub access: AccessPolicies,
/// The layout of the resource.
pub layout: Layouts,
/// The format of the resource.
pub format: TextureFormats,
}

/// Stores the information of a barrier descriptor.
Expand Down Expand Up @@ -726,13 +762,15 @@ pub trait RenderBackend {
/// * `copies` - The copies to perform.
fn copy_textures(&self, command_buffer: &CommandBuffer, copies: &[TextureCopy]);

fn copy_buffers(&self, command_buffer: &CommandBuffer, copies: &[BufferCopy]);

/// Executes a command buffer.
///
/// # Arguments
/// * `command_buffer` - The command buffer to execute.
/// * `wait_for` - The synchronizer to wait for.
/// * `signal` - The synchronizer to signal.
fn execute(&self, command_buffer: &CommandBuffer, wait_for: Option<&crate::render_backend::Synchronizer>, signal: Option<&crate::render_backend::Synchronizer>, execution_completion: &crate::render_backend::Synchronizer);
fn execute(&self, command_buffer: &CommandBuffer, wait_for: &[Synchronizer], signal: &[Synchronizer], execution_completion: &crate::render_backend::Synchronizer);

/// Acquires an image from a swapchain.
///
Expand Down
Loading

0 comments on commit 3292461

Please sign in to comment.