Skip to content

Commit

Permalink
Merge pull request #868 from AmbientRun/fix-windows-rendering
Browse files Browse the repository at this point in the history
Fix windows rendering
  • Loading branch information
ten3roberts authored Sep 15, 2023
2 parents 521ac7f + 33d8c0c commit f9f8b7f
Show file tree
Hide file tree
Showing 19 changed files with 263 additions and 169 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
}
},
"env": {
"RUST_LOG": "info,wgpu=warn,naga=warn,quinn=warn,sentry=debug,sentry-anyhow=debug,sentry-core=debug,fbxcel=error",
"RUST_LOG": "info,wgpu=warn,naga=warn,quinn=warn,sentry=debug,sentry-anyhow=debug,sentry-core=debug,fbxcel=error,ambient_gpu=info",
"AMBIENT_DISABLE_TIMEOUT": "true",
"AMBIENT_DEBUGGER": "true"
},
"args": [
"run",
"guest/rust/examples/controllers/first_person_camera",
"guest/rust/examples/basics/primitives",
],
"cwd": "${workspaceFolder}",
"sourceLanguages": [
Expand Down Expand Up @@ -865,4 +865,4 @@
]
}
]
}
}
15 changes: 8 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"editor.detectIndentation": false,
"editor.tabSize": 4,
"files.trimTrailingWhitespace": true,
"[toml]": {
"editor.formatOnSave": false
}
}
"editor.detectIndentation": false,
"editor.tabSize": 4,
"files.trimTrailingWhitespace": true,
"[toml]": {
"editor.formatOnSave": false
},
"rust-analyzer.showUnlinkedFileNotification": false
}
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions crates/gpu/src/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,29 @@ impl Gpu {
std::env::set_var("DISABLE_LAYER_NV_OPTIMUS_1", "1");
}

#[cfg(target_os = "windows")]
let backend = wgpu::Backends::VULKAN;

#[cfg(all(not(target_os = "windows"), not(target_os = "unknown")))]
let backend = wgpu::Backends::PRIMARY;
let backends = if cfg!(target_os = "windows") {
wgpu::Backends::VULKAN
} else if cfg!(target_os = "macos") {
wgpu::Backends::PRIMARY
} else if cfg!(target_os = "unknown") {
wgpu::Backends::BROWSER_WEBGPU
} else {
wgpu::Backends::all()
};

#[cfg(target_os = "unknown")]
let backend = wgpu::Backends::all();
tracing::info!("Configured backends: {backends:?}");

let instance = wgpu::Instance::new(InstanceDescriptor {
backends: backend,
// TODO upgrade to Dxc ?
backends,
// TODO: upgrade to Dxc? This requires us to ship additionall dll files, which may be
// possible using an installer. Nevertheless, we are currently using Vulkan on windows
// due to `base_instance` being broken on windows.
// https://docs.rs/wgpu/latest/wgpu/enum.Dx12Compiler.html
dx12_shader_compiler: wgpu::Dx12Compiler::Fxc,
// dx12_shader_compiler: wgpu::Dx12Compiler::Dxc {
// dxil_path: Some("./dxil.dll".into()),
// dxc_path: Some("./dxcompiler.dll".into()),
// },
});

let surface = window.map(|window| unsafe { instance.create_surface(window).unwrap() });
Expand Down
12 changes: 11 additions & 1 deletion crates/network/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum ServerPush {

/// Miscellaneous information about the server that needs to be sent to the client during the handshake.
/// Note: This has to deserialize correctly between versions of the server and client for us to be able to show a nice error message.
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
#[derive(serde::Serialize, serde::Deserialize, Clone)]
pub struct ServerInfo {
/// The name of the main package. Used by the client to figure out what to title its window. Defaults to "Ambient".
pub main_package_name: String,
Expand All @@ -42,6 +42,16 @@ pub struct ServerInfo {
pub external_components: FailableDeserialization<Vec<ExternalComponentDesc>>,
}

impl std::fmt::Debug for ServerInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ServerInfo")
.field("main_package_name", &self.main_package_name)
.field("content_base_url", &self.content_base_url)
.field("version", &self.version)
.finish_non_exhaustive()
}
}

impl ServerInfo {
pub fn new(state: &mut crate::server::ServerState, content_base_url: AbsAssetUrl) -> Self {
let instance = state
Expand Down
4 changes: 2 additions & 2 deletions crates/network/src/web/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ async fn resolve_hosted_server(assets: &AssetCache, url: Url) -> anyhow::Result<
let client = ReqwestClientKey.get(assets);

let res = client
.get(url)
.get(url.clone())
.send()
.await
.context("Failed to resolve hosted server")?
Expand All @@ -446,6 +446,6 @@ async fn resolve_hosted_server(assets: &AssetCache, url: Url) -> anyhow::Result<
.context("Failed to get result for request")?;

Url::parse(&format!("https://{}", res.trim())).with_context(|| {
format!("Expected a valid URL for host resolution, but was unable to resolve \"{res}\"")
format!("Expected a valid Url resolving host, but was unable to resolve {res}")
})
}
9 changes: 3 additions & 6 deletions crates/renderer/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use ambient_native_std::{
asset_cache::{AssetCache, SyncAssetKey, SyncAssetKeyExt},
include_file,
};
use ambient_settings::RenderMode;
use glam::{uvec2, UVec2, UVec3};
use parking_lot::Mutex;
use wgpu::{
Expand Down Expand Up @@ -84,7 +85,6 @@ pub(crate) struct RendererCollectState {
pub params: TypedBuffer<RendererCollectParams>,
pub commands: TypedBuffer<DrawIndexedIndirect>,
pub counts: TypedBuffer<u32>,
#[cfg(any(target_os = "macos", target_os = "unknown"))]
/// Multi draw indexed indirect is not supported on macOS
pub(crate) counts_cpu: Arc<Mutex<DrawCountState>>,
pub tick: u64,
Expand Down Expand Up @@ -119,7 +119,6 @@ impl RendererCollectState {
| wgpu::BufferUsages::COPY_SRC
| wgpu::BufferUsages::INDIRECT,
),
#[cfg(any(target_os = "macos", target_os = "unknown"))]
counts_cpu: Arc::new(Default::default()),
material_layouts: TypedBuffer::new(
gpu,
Expand Down Expand Up @@ -287,6 +286,7 @@ impl RendererCollect {
input_primitives: &TypedMultiBuffer<CollectPrimitive>,
output: &mut RendererCollectState,
primitives_count: u32,
render_mode: RenderMode,
) {
output.commands.set_len(gpu, primitives_count as usize);

Expand Down Expand Up @@ -343,8 +343,7 @@ impl RendererCollect {
cpass.dispatch_workgroups(x, 1, 1);
}

#[cfg(any(target_os = "macos", target_os = "unknown"))]
{
if render_mode == RenderMode::Indirect {
use ambient_core::RuntimeKey;

let buffs = CollectCountStagingBuffersKey.get(assets);
Expand Down Expand Up @@ -400,7 +399,6 @@ impl CollectCountStagingBuffers {
}
}

#[cfg(any(target_os = "macos", target_os = "unknown"))]
fn take_buffer(&self, gpu: &Gpu, size: usize) -> TypedBuffer<u32> {
match self.buffers.lock().pop() {
Some(mut buffer) => {
Expand All @@ -416,7 +414,6 @@ impl CollectCountStagingBuffers {
}
}

#[cfg(any(target_os = "macos", target_os = "unknown"))]
fn return_buffer(&self, buffer: TypedBuffer<u32>) {
self.buffers.lock().push(buffer)
}
Expand Down
3 changes: 0 additions & 3 deletions crates/renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ where
/// No bind groups
pub fn get_defs_module() -> Arc<ShaderModule> {
let iter = [("PI", PI)].iter();
#[cfg(not(target_os = "unknown"))]
let iter = iter.map(|(k, v)| format!("const {k}: f32 = {v};\n"));
#[cfg(target_os = "unknown")]
let iter = iter.map(|(k, v)| format!("const {k}: f32 = {v};\n"));

let iter = iter
Expand Down
6 changes: 4 additions & 2 deletions crates/renderer/src/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ambient_native_std::{
asset_cache::{AssetCache, SyncAssetKeyExt},
include_file,
};
use ambient_settings::SettingsKey;
use ambient_settings::{RenderMode, SettingsKey};
use wgpu::{BindGroupLayoutEntry, BindingType, PrimitiveTopology, ShaderStages};

use super::{
Expand Down Expand Up @@ -115,7 +115,9 @@ impl Outlines {
depth_stencil: false,
cull_mode: Some(wgpu::Face::Back),
depth_bias: Default::default(),
render_mode: settings.render_mode,
render_mode: settings
.render_mode
.unwrap_or_else(RenderMode::instrinsic_render_mode),
software_culling: settings.software_culling,
},
),
Expand Down
6 changes: 4 additions & 2 deletions crates/renderer/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use ambient_native_std::{
asset_cache::{AssetCache, SyncAssetKey, SyncAssetKeyExt},
color::Color,
};
use ambient_settings::SettingsKey;
use ambient_settings::{RenderMode, SettingsKey};
use glam::uvec2;
use std::sync::Arc;
use tracing::debug_span;
Expand Down Expand Up @@ -238,7 +238,9 @@ impl Renderer {
depth_stencil: true,
cull_mode: Some(wgpu::Face::Back),
depth_bias: Default::default(),
render_mode: settings.render_mode,
render_mode: settings
.render_mode
.unwrap_or_else(RenderMode::instrinsic_render_mode),
software_culling: settings.software_culling,
},
))
Expand Down
6 changes: 4 additions & 2 deletions crates/renderer/src/shadow_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ambient_gpu::{
texture::{Texture, TextureView},
};
use ambient_native_std::asset_cache::{AssetCache, SyncAssetKeyExt};
use ambient_settings::SettingsKey;
use ambient_settings::{RenderMode, SettingsKey};
use bytemuck::{Pod, Zeroable};
use glam::{Mat4, Vec3};
use itertools::Itertools;
Expand Down Expand Up @@ -93,7 +93,9 @@ impl ShadowsRenderer {
slope_scale: -1.5,
clamp: 0.0,
},
render_mode: settings.render_mode,
render_mode: settings
.render_mode
.unwrap_or_else(RenderMode::instrinsic_render_mode),
software_culling: settings.software_culling,
},
),
Expand Down
Loading

0 comments on commit f9f8b7f

Please sign in to comment.