Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dawn update #27

Merged
merged 38 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
da8690d
Add build argument for Dawn path
Dec 6, 2023
c4fa966
Add placeholder for dawn src dir
Dec 6, 2023
ff719ea
Fix typo in dawn src dir
Dec 6, 2023
148f2e7
Update location of flatten bidings header
Dec 6, 2023
c277c4e
Update dawn::native syntax
Dec 6, 2023
79bda01
Update namespaces
Dec 6, 2023
d73f8b9
Update tint header locations
Dec 7, 2023
97f967e
Update DiscoverDefaultAdapter due to deprecation
Dec 8, 2023
a67759c
Pass options to EnumerateAdapters()
Dec 11, 2023
5e963eb
Update Manager::Run
Dec 11, 2023
11473dd
Update calls to Program::IsValid
Dec 11, 2023
68eed62
Update function params from *Program to &Program
Dec 11, 2023
16f5d71
Update Generate return type
Dec 11, 2023
8ddfc76
Update Result structs for HLSL and MSL
Dec 11, 2023
667bc74
Update bindings for structs
Dec 12, 2023
6ad3228
Remove comment
Dec 13, 2023
80a4359
Use WGPUBool instead of u32
Dec 13, 2023
a1695b7
Update linked libraries to read relevant libs from dawn lib directory
Dec 14, 2023
71af7ef
Tint takes updated shader attribute syntax
Dec 14, 2023
4de6537
Pass Dawn source folder to build as env variable
Dec 21, 2023
866635f
Merge remote-tracking branch 'origin/main' into dawn_update
hasali19 Jan 3, 2024
ca5232f
Merge branch 'main' into dawn_update
hasali19 Jan 3, 2024
cd94c37
Bump Dawn submodule commit
Jan 4, 2024
a0c00ac
Remove config file since not necessary
Jan 4, 2024
4f3987f
Update dawn path arg for stylistic consistency
ambergorzynski Jan 4, 2024
31857f4
Change unwrap to ?
ambergorzynski Jan 4, 2024
9113d53
Remove concise_stage_attrs throughout since tint no longer supports this
Jan 4, 2024
78c2d8b
Adapt Dawn lib path according to target
Jan 4, 2024
5f8a645
Remove commented code
Jan 4, 2024
863ce50
Update unwrap to ?
ambergorzynski Jan 4, 2024
3516330
Move variable inside braces
ambergorzynski Jan 4, 2024
7f52fc5
Remove commented code
Jan 4, 2024
cd02710
Update Dawn build for workflow
Jan 5, 2024
261bddc
Update formatting
Jan 5, 2024
5d2fb91
Remove mut from shader since current options no longer mutate shader
Jan 5, 2024
c3331bf
Update MacOS deployment target in CI
Jan 9, 2024
4c57af2
Revert "Update MacOS deployment target in CI"
Jan 9, 2024
8c7d760
Disable macOS build
hasali19 Jan 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependency_versions.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dawn: autobuild-2023-01-31-12-46
dawn: autobuild-2024-01-04-21-29
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ jobs:
matrix:
target:
- win64
- macos64
# - macos64
- linux64
include:
- target: win64
os: ubuntu-latest
rust-target: x86_64-pc-windows-msvc
exe_suffix: .exe
- target: macos64
os: macos-latest
rust-target: x86_64-apple-darwin
exe_suffix: ""
# - target: macos64
# os: macos-latest
# rust-target: x86_64-apple-darwin
# exe_suffix: ""
- target: linux64
os: ubuntu-latest
rust-target: x86_64-unknown-linux-gnu
Expand Down
20 changes: 11 additions & 9 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def parse_args():
parser.add_argument("--install-prefix")
parser.add_argument("--no-reducer", action="store_true")
parser.add_argument("--no-harness", action="store_true")
parser.add_argument("--dawn-path", default="external/dawn")
return parser.parse_args()


Expand All @@ -33,6 +34,8 @@ def get_cargo_host_target():
build_target = args.target if args.target is not None else host_target
is_cross = args.target is not None and host_target != args.target

dawn_src_dir = Path(args.dawn_path)
dawn_build_dir = Path(f"build/dawn/{build_target}")

def get_commit(git_dir):
output = subprocess.check_output(["git", "--git-dir", git_dir, "rev-parse", "HEAD"])
Expand Down Expand Up @@ -84,30 +87,28 @@ def cargo_build(package, target=None, cwd=None, features=[]):
cmd += ["--target", target]
if len(features) > 0:
cmd += ["--features", ",".join(features)]

cmd += ["--config",f'env.DAWN_SRC_DIR="{dawn_src_dir}"']
print(f">> {' '.join(cmd)}")
subprocess.run(cmd, cwd=cwd).check_returncode()


def bootstrap_gclient_config():
gclient_config = Path("external/dawn/.gclient")
gclient_config_tmpl = Path("external/dawn/scripts/standalone.gclient")
gclient_config = Path(f'{dawn_src_dir}/.gclient')
gclient_config_tmpl = Path(f'{dawn_src_dir}/scripts/standalone.gclient')
if not gclient_config.exists():
shutil.copyfile(gclient_config_tmpl, gclient_config)


def gclient_sync():
dawn_commit = get_commit("external/dawn/.git")
dawn_commit = get_commit(f'{dawn_src_dir}/.git')
print(f'dawn commit is: {dawn_commit}')
gclient_sync_hash = read_gclient_sync_hash()
if gclient_sync_hash != dawn_commit:
print("> dawn commit has changed, rerunning gclient sync")
subprocess.run(["gclient", "sync"], cwd="external/dawn").check_returncode()
subprocess.run(["gclient", "sync"], cwd=dawn_src_dir).check_returncode()
write_gclient_sync_hash(dawn_commit)


dawn_src_dir = Path("external/dawn")
dawn_build_dir = Path(f"build/dawn/{build_target}")


def dawn_gen_cmake():
if is_cross and build_target != "x86_64-pc-windows-msvc":
print(f"cannot build dawn for target '{build_target}' (host={host_target})")
Expand Down Expand Up @@ -197,3 +198,4 @@ def build_harness():

for task in tasks:
task()

8 changes: 1 addition & 7 deletions crates/ast/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub struct Writer {

#[derive(Default)]
pub struct Options {
pub concise_stage_attrs: bool,
pub module_scope_constants: bool,
}

Expand Down Expand Up @@ -98,12 +97,7 @@ impl Writer {
for attr in &func.attrs {
match attr {
FnAttr::Stage(stage) => {
// TODO: Tint doesn't currently support the new stage attribute syntax - update when implemented
if self.options.concise_stage_attrs {
ambergorzynski marked this conversation as resolved.
Show resolved Hide resolved
writeln!(f, "@{stage}")?;
} else {
writeln!(f, "@stage({stage})")?;
}
writeln!(f, "@{stage}")?;
}
_ => self.write_attr(f, attr)?,
}
Expand Down
40 changes: 12 additions & 28 deletions crates/dawn/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;
use std::error::Error;
use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;

Expand All @@ -25,55 +26,38 @@ fn main() -> Result<(), Box<dyn Error>> {

println!("cargo:rustc-link-search=native={}", dawn_lib_dir.display());

let common_libs = [
"absl_base",
"absl_int128",
"absl_log_severity",
"absl_raw_logging_internal",
"absl_spinlock_wait",
"absl_str_format_internal",
"absl_strings_internal",
"absl_strings",
"absl_throw_delegate",
"dawn_common",
"dawn_headers",
"dawn_native",
"dawn_platform",
"dawn_proc",
"dawncpp_headers",
"SPIRV-Tools-opt",
"SPIRV-Tools",
"tint_diagnostic_utils",
"tint",
];
let common_libs = fs::read_dir(dawn_lib_dir)?
.filter_map(|e| e.ok())
.map(|e| e.path())
.filter(|e| e.is_file())
.collect::<Vec<_>>();

let target_os = env::var("CARGO_CFG_TARGET_OS")?;
let target_family = env::var("CARGO_CFG_TARGET_FAMILY")?;

for lib in common_libs {
let lib_name = lib.file_stem().unwrap().to_str().unwrap();
let lib_name = if target_family == "windows" {
format!("{lib}.lib")
lib_name
} else if target_family == "unix" {
format!("lib{lib}.a")
&lib_name[3..]
} else {
panic!("unsupported target_family '{target_family}'");
};

let path = dawn_lib_dir.join(lib_name);

if target_os == "linux"
&& !Command::new("ar")
.arg("d")
.arg(&path)
.arg(&lib)
.arg("Placeholder.cpp.o")
.status()?
.success()
{
panic!("ar command failed");
}

println!("cargo:rerun-if-changed={}", path.display());
println!("cargo:rustc-link-lib=static={lib}");
println!("cargo:rerun-if-changed={}", lib.display());
println!("cargo:rustc-link-lib=static={lib_name}");
}

// Additional platform-specific libraries we need to link
Expand Down
4 changes: 2 additions & 2 deletions crates/dawn/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Device {
sType: WGPUSType_WGPUSType_ShaderModuleWGSLDescriptor,
..zeroed()
},
source: source.as_ptr() as _,
code: source.as_ptr() as _,
};

let descriptor = WGPUShaderModuleDescriptor {
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Device {

pub fn create_buffer(
&self,
mapped: bool,
mapped: crate::webgpu::WGPUBool,
size: usize,
usage: DeviceBufferUsage,
) -> DeviceBuffer {
Expand Down
25 changes: 14 additions & 11 deletions crates/dawn/src/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,35 @@
#include <dawn/webgpu_cpp.h>
#include <dawn/native/DawnNative.h>

extern "C" dawn_native::Instance* new_instance() {
extern "C" dawn::native::Instance* new_instance() {
// Initialize WebGPU proc table
dawnProcSetProcs(&dawn_native::GetProcs());
dawnProcSetProcs(&dawn::native::GetProcs());

auto instance = new dawn_native::Instance;
auto instance = new dawn::native::Instance;

// This makes things slow
// instance->EnableBackendValidation(true);
// instance->SetBackendValidationLevel(dawn_native::BackendValidationLevel::Full);
// instance->SetBackendValidationLevel(dawn::native::BackendValidationLevel::Full);

instance->DiscoverDefaultAdapters();
WGPURequestAdapterOptions options = {};
instance->EnumerateAdapters(&options);

return instance;
}

extern "C" void delete_instance(dawn_native::Instance* instance) {
extern "C" void delete_instance(dawn::native::Instance* instance) {
delete instance;
}

extern "C" void enumerate_adapters(
const dawn_native::Instance* instance,
const dawn::native::Instance* instance,
void(*callback)(const WGPUAdapterProperties*, void*),
void* userdata
) {
if (callback == nullptr) return;

auto adapters = instance->GetAdapters();
WGPURequestAdapterOptions options = {};
auto adapters = instance->EnumerateAdapters(&options);

for (auto& adapter : adapters) {
WGPUAdapterProperties properties = {};
Expand All @@ -42,13 +44,14 @@ extern "C" void enumerate_adapters(
}

extern "C" WGPUDevice create_device(
const dawn_native::Instance* instance,
const dawn::native::Instance* instance,
WGPUBackendType backendType,
uint32_t deviceID
) {
auto adapters = instance->GetAdapters();
WGPURequestAdapterOptions options = {};
auto adapters = instance->EnumerateAdapters(&options);

dawn_native::Adapter *selectedAdapter = nullptr;
dawn::native::Adapter *selectedAdapter = nullptr;
for (auto& adapter : adapters) {
WGPUAdapterProperties properties = {};
adapter.GetProperties(&properties);
Expand Down
12 changes: 8 additions & 4 deletions crates/harness/src/dawn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use color_eyre::eyre::eyre;
use dawn::webgpu::{
WGPUBackendType_WGPUBackendType_D3D12, WGPUBackendType_WGPUBackendType_Metal,
WGPUBackendType_WGPUBackendType_Vulkan,
WGPUBackendType_WGPUBackendType_Vulkan, WGPUBool,
};
use dawn::*;
use reflection::{PipelineDescription, ResourceKind};
Expand Down Expand Up @@ -63,18 +63,20 @@ pub async fn run(

let mut buffer_sets = vec![];

let mapped: WGPUBool = 0;

for resource in &meta.resources {
let size = resource.size as usize;
match resource.kind {
ResourceKind::StorageBuffer => {
let storage = device.create_buffer(
false,
mapped,
size,
DeviceBufferUsage::STORAGE | DeviceBufferUsage::COPY_SRC,
);

let read = device.create_buffer(
false,
mapped,
size,
DeviceBufferUsage::COPY_DST | DeviceBufferUsage::MAP_READ,
);
Expand All @@ -87,7 +89,9 @@ pub async fn run(
});
}
ResourceKind::UniformBuffer => {
let mut buffer = device.create_buffer(true, size, DeviceBufferUsage::UNIFORM);
let mapped: WGPUBool = 1;

let mut buffer = device.create_buffer(mapped, size, DeviceBufferUsage::UNIFORM);

if let Some(init) = resource.init.as_deref() {
buffer.get_mapped_range(size).copy_from_slice(init);
Expand Down
1 change: 0 additions & 1 deletion crates/harness/src/wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub async fn run(
let (device, queue) = adapter.request_device(&device_descriptor, None).await?;

let preprocessor_opts = preprocessor::Options {
concise_stage_attrs: true,
module_scope_constants: false,
};

Expand Down
6 changes: 1 addition & 5 deletions crates/preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
pub use ast::writer::Options;

pub fn preprocess(options: Options, mut shader: String) -> String {
if options.concise_stage_attrs {
shader = shader.replace("@stage(compute)", "@compute");
}

pub fn preprocess(options: Options, shader: String) -> String {
if options.module_scope_constants {
panic!("module scope constants are not supported yet");
}
Expand Down
20 changes: 13 additions & 7 deletions crates/tint/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;
use std::error::Error;
use std::fs;
use std::path::{Path, PathBuf};

fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -23,23 +24,28 @@ fn main() -> Result<(), Box<dyn Error>> {

println!("cargo:rustc-link-search=native={}", dawn_lib_dir.display());

let libs = ["tint_diagnostic_utils", "tint"];
let libs = fs::read_dir(dawn_lib_dir)?
.filter_map(|e| e.ok())
.map(|e| e.path())
.filter(|e| e.is_file())
.filter(|e| e.to_str().unwrap().contains("tint"))
.collect::<Vec<_>>();

let target_family = env::var("CARGO_CFG_TARGET_FAMILY")?;

for lib in libs {
let lib_name = lib.file_stem().unwrap().to_str().unwrap();

let lib_name = if target_family == "windows" {
format!("{lib}.lib")
lib_name
} else if target_family == "unix" {
format!("lib{lib}.a")
&lib_name[3..]
} else {
panic!("unsupported target_family '{target_family}'");
};

let path = dawn_lib_dir.join(lib_name);

println!("cargo:rerun-if-changed={}", path.display());
println!("cargo:rustc-link-lib=static={lib}");
println!("cargo:rerun-if-changed={}", lib.display());
println!("cargo:rustc-link-lib=static={}", lib_name);
}

let mut build = cxx_build::bridge("src/lib.rs");
Expand Down
Loading
Loading