Skip to content

Commit

Permalink
Fix linux, a few validation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
h3r2tic committed Aug 24, 2021
1 parent 66b3135 commit 08b632c
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 31 deletions.
26 changes: 15 additions & 11 deletions bake.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
export SMOL_THREADS=64
cargo build --bin bake --release
export BAKE=target/release/bake

cargo run --bin bake --release -- --scene "assets/meshes/flying_world_-_battle_of_the_trash_god/scene.gltf" --scale 0.001875 -o battle
cargo run --bin bake --release -- --scene "assets/meshes/336_lrm/scene.gltf" --scale 0.01 -o 336_lrm
cargo run --bin bake --release -- --scene "assets/meshes/pica_pica_-_mini_diorama_01/scene.gltf" --scale 0.1 -o pica
cargo run --bin bake --release -- --scene "assets/meshes/floor/scene.gltf" --scale 1.0 -o floor
cargo run --bin bake --release -- --scene "assets/meshes/testball/scene.gltf" --scale 1.0 -o testball
cargo run --bin bake --release -- --scene "assets/meshes/cornell_box/scene.gltf" --scale 2.0 -o cornell_box
cargo run --bin bake --release -- --scene "assets/meshes/gas_stations_fixed/scene.gltf" --scale 0.005 -o gas_stations
cargo run --bin bake --release -- --scene "assets/meshes/viziers_observation_deck/scene.gltf" --scale 0.0075 -o viziers
cargo run --bin bake --release -- --scene "assets/meshes/dp3_homework_4/scene.gltf" --scale 0.05 -o mini_battle
cargo run --bin bake --release -- --scene "assets/meshes/painting_xyz_homework/scene.gltf" --scale 0.0025 -o painting_xyz_homework
$BAKE --scene "assets/meshes/flying_world_-_battle_of_the_trash_god/scene.gltf" --scale 0.001875 -o battle
$BAKE --scene "assets/meshes/336_lrm/scene.gltf" --scale 0.01 -o 336_lrm
$BAKE --scene "assets/meshes/pica_pica_-_mini_diorama_01/scene.gltf" --scale 0.1 -o pica
$BAKE --scene "assets/meshes/floor/scene.gltf" --scale 1.0 -o floor
$BAKE --scene "assets/meshes/testball/scene.gltf" --scale 1.0 -o testball
$BAKE --scene "assets/meshes/cornell_box/scene.gltf" --scale 2.0 -o cornell_box
$BAKE --scene "assets/meshes/gas_stations_fixed/scene.gltf" --scale 0.005 -o gas_stations
$BAKE --scene "assets/meshes/viziers_observation_deck/scene.gltf" --scale 0.0075 -o viziers
$BAKE --scene "assets/meshes/dp3_homework_4/scene.gltf" --scale 0.05 -o mini_battle
$BAKE --scene "assets/meshes/painting_xyz_homework/scene.gltf" --scale 0.0025 -o painting_xyz_homework
$BAKE --scene "assets/meshes/conference/scene.gltf" --scale 1.0 -o conference
$BAKE --scene "assets/meshes/roughness-scale/scene.gltf" --scale 0.5 -o roughness-scale
$BAKE --scene "assets/meshes/emissive/triangle.glb" --scale 0.333 -o emissive-triangle
2 changes: 0 additions & 2 deletions build_and_run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export SMOL_THREADS=64

cargo run --bin view --release -- --scene $* --width 1920 --height 1080 --no-debug
# cargo run --bin view --release -- --scene pica --width 1920 --height 1080 --no-debug

Expand Down
5 changes: 5 additions & 0 deletions crates/lib/kajiya-backend/src/dynamic_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ pub const MAX_DYNAMIC_CONSTANTS_BYTES_PER_DISPATCH: usize = 16384;
// TODO: Must be >= `minUniformBufferOffsetAlignment`. In practice <= 256.
pub const DYNAMIC_CONSTANTS_ALIGNMENT: usize = 256;

// Sadly we can't have unsized dynamic storage buffers sub-allocated from dynamic constants because WHOLE_SIZE blows up.
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/2846#issuecomment-851744837
// For now, just a max size.
pub const MAX_DYNAMIC_CONSTANTS_STORAGE_BUFFER_BYTES: usize = 1024 * 1024;

pub struct DynamicConstants {
pub buffer: Buffer,
frame_offset_bytes: usize,
Expand Down
21 changes: 8 additions & 13 deletions crates/lib/kajiya-backend/src/rust_shader_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ impl LazyWorker for CompileRustShader {
async fn run(self, ctx: RunContext) -> Self::Output {
CompileRustShaderCrate.into_lazy().eval(&ctx).await?;

let compile_result = LoadFile::new(normalized_path_from_vfs(
"/rust-shaders/compiled/shaders.json",
)?)?
.into_lazy()
.eval(&ctx)
.await?;
let compile_result = LoadFile::new("/rust-shaders/compiled/shaders.json")?
.into_lazy()
.eval(&ctx)
.await?;

let compile_result =
RustShaderCompileResult::deserialize_json(std::str::from_utf8(&*compile_result)?)?;
Expand All @@ -42,13 +40,10 @@ impl LazyWorker for CompileRustShader {
anyhow::anyhow!("No Rust-GPU module found for entry point {}", self.entry)
})?;

let spirv_blob = LoadFile::new(normalized_path_from_vfs(format!(
"/rust-shaders/compiled/{}",
shader_file
))?)?
.into_lazy()
.eval(&ctx)
.await?;
let spirv_blob = LoadFile::new(format!("/rust-shaders/compiled/{}", shader_file))?
.into_lazy()
.eval(&ctx)
.await?;

Ok(CompiledShader {
name: "rust-gpu".to_owned(),
Expand Down
5 changes: 5 additions & 0 deletions crates/lib/kajiya-backend/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl Device {
vk::KhrDrawIndirectCountFn::name().as_ptr(),
// Rust-GPU
vk::KhrShaderFloat16Int8Fn::name().as_ptr(),
vk::KhrVulkanMemoryModelFn::name().as_ptr(),
// DLSS
#[cfg(feature = "dlss")]
{
Expand Down Expand Up @@ -252,6 +253,9 @@ impl Device {
let mut shader_float16_int8 = vk::PhysicalDeviceShaderFloat16Int8Features::default();
shader_float16_int8.shader_int8 = 1;

let mut vulkan_memory_model = vk::PhysicalDeviceVulkanMemoryModelFeaturesKHR::default();
vulkan_memory_model.vulkan_memory_model = 1;

#[cfg(feature = "ray-tracing")]
let mut acceleration_structure_features =
ash::vk::PhysicalDeviceAccelerationStructureFeaturesKHR::builder()
Expand Down Expand Up @@ -295,6 +299,7 @@ impl Device {
.push_next(&mut imageless_framebuffer)
.push_next(&mut fragment_shader_interlock)
.push_next(&mut shader_float16_int8)
.push_next(&mut vulkan_memory_model)
.push_next(&mut get_buffer_device_address_features);

#[cfg(feature = "ray-tracing")]
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/kajiya-backend/src/vulkan/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl Device {
.create_buffer(
super::buffer::BufferDesc {
size: instance_buffer_size,
usage: ash::vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS,
usage: ash::vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS | ash::vk::BufferUsageFlags::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR,
mapped: false,
},
unsafe {
Expand Down
7 changes: 5 additions & 2 deletions crates/lib/kajiya-rg/src/pass_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use super::{
use kajiya_backend::{
ash::vk,
chunky_list::TempList,
dynamic_constants::{DynamicConstants, MAX_DYNAMIC_CONSTANTS_BYTES_PER_DISPATCH},
dynamic_constants::{
DynamicConstants, MAX_DYNAMIC_CONSTANTS_BYTES_PER_DISPATCH,
MAX_DYNAMIC_CONSTANTS_STORAGE_BUFFER_BYTES,
},
vulkan::{
device::{CommandBuffer, Device},
image::*,
Expand Down Expand Up @@ -253,7 +256,7 @@ impl<'a, 'exec_params, 'constants> RenderPassApi<'a, 'exec_params, 'constants> {
DescriptorSetBinding::DynamicStorageBuffer {
buffer: vk::DescriptorBufferInfo::builder()
.buffer(self.resources.dynamic_constants.buffer.raw)
.range(vk::WHOLE_SIZE)
.range(MAX_DYNAMIC_CONSTANTS_STORAGE_BUFFER_BYTES as u64)
.build(),
offset: *offset,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/lib/kajiya-rg/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl Renderer {
.build();
let storage_buffer_info = vk::DescriptorBufferInfo::builder()
.buffer(dynamic_constants.raw)
.range(vk::WHOLE_SIZE)
.range(MAX_DYNAMIC_CONSTANTS_STORAGE_BUFFER_BYTES as u64)
.build();

let descriptor_set_writes = [
Expand Down
3 changes: 2 additions & 1 deletion crates/lib/kajiya/src/world_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ impl WorldRenderer {
usage: vk::BufferUsageFlags::STORAGE_BUFFER
| vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS
| vk::BufferUsageFlags::INDEX_BUFFER
| vk::BufferUsageFlags::TRANSFER_DST,
| vk::BufferUsageFlags::TRANSFER_DST
| vk::BufferUsageFlags::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR,
mapped: false,
},
None,
Expand Down

0 comments on commit 08b632c

Please sign in to comment.