Skip to content

Commit 054ed82

Browse files
committed
rewrite: Initial codegen
1 parent 8eb9094 commit 054ed82

File tree

267 files changed

+2433
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

267 files changed

+2433
-18
lines changed

analysis/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ edition = "2021"
66
[dependencies]
77
roxmltree = "0.19"
88
tracing = "0.1"
9+
indexmap = "2"

analysis/src/cdecl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct UnsupportedCTok<'a>(&'a str);
3333
impl<'a> CTok<'a> {
3434
pub const SUPPORTED_KEYWORDS: &'static [&'static str] = &["const", "struct", "typedef", "void"];
3535

36-
pub fn lex_into(
36+
pub(crate) fn lex_into(
3737
s: &'a str,
3838
out: &mut impl Extend<CTok<'a>>,
3939
) -> Result<(), UnsupportedCTok<'a>> {
@@ -143,7 +143,7 @@ pub enum CDeclParseErrorKind<'a> {
143143

144144
impl<'a> CDecl<'a> {
145145
// HACK(eddyb) this split is literally just to simplify error tracking.
146-
pub fn parse<'b>(
146+
pub(crate) fn parse<'b>(
147147
mode: CDeclMode,
148148
tokens: &'b [CTok<'a>],
149149
) -> Result<CDecl<'a>, CDeclParseError<'a, 'b>> {

analysis/src/items/mod.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use self::structures::Structure;
2+
use crate::{xml::UnwrapBorrowed, Library, LibraryId};
3+
use indexmap::IndexMap;
4+
use std::collections::HashMap;
5+
6+
pub mod structures;
7+
8+
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
9+
pub struct Origin {
10+
pub library_id: LibraryId,
11+
pub required_by: RequiredBy,
12+
}
13+
14+
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
15+
pub enum RequiredBy {
16+
Feature { major: u32, minor: u32 },
17+
Extension { name: &'static str },
18+
}
19+
20+
#[derive(Default, Debug)]
21+
pub struct Items {
22+
pub structures: IndexMap<&'static str, Structure>,
23+
}
24+
25+
impl Items {
26+
pub(super) fn collect(
27+
&mut self,
28+
library: &Library,
29+
types_require_map: HashMap<&str, RequiredBy>,
30+
) {
31+
for structure in &library.xml.structs {
32+
let name = structure.name.unwrap_borrowed();
33+
let Some(&required_by) = types_require_map.get(name) else {
34+
continue;
35+
};
36+
37+
let origin = Origin {
38+
library_id: library.id,
39+
required_by,
40+
};
41+
42+
let structure = Structure::new(origin, structure);
43+
assert!(self.structures.insert(name, structure).is_none());
44+
}
45+
}
46+
}

analysis/src/items/structures.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use super::Origin;
2+
use crate::xml::{self, UnwrapBorrowed};
3+
4+
#[derive(Debug)]
5+
pub struct Structure {
6+
pub origin: Origin,
7+
pub name: &'static str,
8+
}
9+
10+
impl Structure {
11+
pub fn new(origin: Origin, xml: &xml::Structure) -> Structure {
12+
Structure {
13+
origin,
14+
name: xml.name.unwrap_borrowed(),
15+
}
16+
}
17+
}

analysis/src/lib.rs

Lines changed: 104 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,129 @@
1-
mod xml;
1+
pub mod cdecl;
2+
pub mod items;
3+
pub mod xml;
24

3-
use std::{fs, path::Path};
5+
use items::{Items, RequiredBy};
6+
use std::{
7+
collections::HashMap,
8+
fmt::{self, Display},
9+
fs,
10+
path::{Path, PathBuf},
11+
};
412
use tracing::{debug, error_span};
13+
use xml::UnwrapBorrowed;
514

615
#[derive(Debug)]
716
pub struct Analysis {
8-
pub vk: Library,
9-
pub video: Library,
17+
vk: Library,
18+
video: Library,
19+
items: Items,
1020
}
1121

1222
impl Analysis {
1323
pub fn new(vulkan_headers_path: impl AsRef<Path>) -> Analysis {
24+
let vk = Library::new(LibraryId::Vk, &vulkan_headers_path);
25+
let video = Library::new(LibraryId::Video, &vulkan_headers_path);
26+
27+
let mut items = Items::default();
28+
vk.collect_into(&mut items);
29+
video.collect_into(&mut items);
30+
31+
Analysis { vk, video, items }
32+
}
33+
34+
pub fn vk_xml(&self) -> &xml::Registry {
35+
&self.vk.xml
36+
}
37+
38+
pub fn video_xml(&self) -> &xml::Registry {
39+
&self.video.xml
40+
}
41+
42+
pub fn items(&self) -> &Items {
43+
&self.items
44+
}
45+
}
46+
47+
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
48+
pub enum LibraryId {
49+
Vk,
50+
Video,
51+
}
52+
53+
impl LibraryId {
54+
fn xml_path(&self, vulkan_headers_path: impl AsRef<Path>) -> PathBuf {
1455
let vulkan_headers_path = vulkan_headers_path.as_ref();
15-
Analysis {
16-
vk: Library::new(vulkan_headers_path.join("registry/vk.xml")),
17-
video: Library::new(vulkan_headers_path.join("registry/video.xml")),
56+
match self {
57+
LibraryId::Vk => vulkan_headers_path.join("registry/vk.xml"),
58+
LibraryId::Video => vulkan_headers_path.join("registry/video.xml"),
1859
}
1960
}
2061
}
2162

63+
impl Display for LibraryId {
64+
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
65+
formatter.write_str(match self {
66+
LibraryId::Vk => "vk",
67+
LibraryId::Video => "video",
68+
})
69+
}
70+
}
71+
2272
#[derive(Debug)]
2373
pub struct Library {
24-
_xml: xml::Registry,
74+
id: LibraryId,
75+
xml: xml::Registry,
2576
}
2677

2778
impl Library {
28-
fn new(xml_path: impl AsRef<Path>) -> Library {
29-
let xml = error_span!("xml", path = %xml_path.as_ref().display()).in_scope(|| {
79+
fn new(id: LibraryId, vulkan_headers_path: impl AsRef<Path>) -> Library {
80+
let xml = error_span!("xml", library_id = %id).in_scope(|| {
81+
let path = id.xml_path(vulkan_headers_path);
3082
// We leak the input string here for convenience, to avoid explicit lifetimes.
31-
let xml_input = Box::leak(fs::read_to_string(xml_path).unwrap().into_boxed_str());
83+
let input = Box::leak(fs::read_to_string(path).unwrap().into_boxed_str());
3284
debug!("parsing xml");
33-
xml::Registry::parse(xml_input, "vulkan")
85+
xml::Registry::parse(input, "vulkan")
3486
});
3587

36-
Library { _xml: xml }
88+
Library { id, xml }
89+
}
90+
91+
pub fn id(&self) -> LibraryId {
92+
self.id
93+
}
94+
95+
pub fn xml(&self) -> &xml::Registry {
96+
&self.xml
97+
}
98+
99+
fn collect_into(&self, items: &mut Items) {
100+
let mut types_require_map = HashMap::new();
101+
102+
for feature in &self.xml.features {
103+
let required_by = RequiredBy::Feature {
104+
major: feature.major,
105+
minor: feature.minor,
106+
};
107+
108+
for require in &feature.requires {
109+
for require_type in &require.types {
110+
types_require_map.insert(require_type.name.unwrap_borrowed(), required_by);
111+
}
112+
}
113+
}
114+
115+
for extension in &self.xml.extensions {
116+
let required_by = RequiredBy::Extension {
117+
name: extension.name.unwrap_borrowed(),
118+
};
119+
120+
for require in &extension.requires {
121+
for require_type in &require.types {
122+
types_require_map.insert(require_type.name.unwrap_borrowed(), required_by);
123+
}
124+
}
125+
}
126+
127+
items.collect(self, types_require_map);
37128
}
38129
}

analysis/src/xml.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,26 @@ type Node<'a> = roxmltree::Node<'a, 'static>;
99
///
1010
/// A `&'static str` is not used directly because sometimes string allocation is
1111
/// needed, for example when replacing `&quot;` with normal quotes.
12-
type XmlStr = Cow<'static, str>;
12+
pub type XmlStr = Cow<'static, str>;
13+
14+
pub trait UnwrapBorrowed<'a, B>
15+
where
16+
B: ToOwned + ?Sized,
17+
{
18+
fn unwrap_borrowed(&self) -> &'a B;
19+
}
20+
21+
impl<'a, B> UnwrapBorrowed<'a, B> for Cow<'a, B>
22+
where
23+
B: ToOwned + ?Sized,
24+
{
25+
fn unwrap_borrowed(&self) -> &'a B {
26+
match self {
27+
Cow::Borrowed(b) => b,
28+
Cow::Owned(_) => panic!("Called `unwrap_borrowed` on `Owned` value"),
29+
}
30+
}
31+
}
1332

1433
/// Retrieves the value of the `node`'s attribute named `name`.
1534
fn attribute(node: Node, name: &str) -> Option<XmlStr> {

ash-rewrite/src/generated/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub mod video;
3+
pub mod vk;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoH264SpsVuiFlags;
3+
pub struct StdVideoH264HrdParameters;
4+
pub struct StdVideoH264SequenceParameterSetVui;
5+
pub struct StdVideoH264SpsFlags;
6+
pub struct StdVideoH264ScalingLists;
7+
pub struct StdVideoH264SequenceParameterSet;
8+
pub struct StdVideoH264PpsFlags;
9+
pub struct StdVideoH264PictureParameterSet;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoDecodeH264PictureInfoFlags;
3+
pub struct StdVideoDecodeH264PictureInfo;
4+
pub struct StdVideoDecodeH264ReferenceInfoFlags;
5+
pub struct StdVideoDecodeH264ReferenceInfo;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoEncodeH264WeightTableFlags;
3+
pub struct StdVideoEncodeH264WeightTable;
4+
pub struct StdVideoEncodeH264SliceHeaderFlags;
5+
pub struct StdVideoEncodeH264PictureInfoFlags;
6+
pub struct StdVideoEncodeH264ReferenceInfoFlags;
7+
pub struct StdVideoEncodeH264ReferenceListsInfoFlags;
8+
pub struct StdVideoEncodeH264RefListModEntry;
9+
pub struct StdVideoEncodeH264RefPicMarkingEntry;
10+
pub struct StdVideoEncodeH264ReferenceListsInfo;
11+
pub struct StdVideoEncodeH264PictureInfo;
12+
pub struct StdVideoEncodeH264ReferenceInfo;
13+
pub struct StdVideoEncodeH264SliceHeader;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoH265ProfileTierLevelFlags;
3+
pub struct StdVideoH265ProfileTierLevel;
4+
pub struct StdVideoH265DecPicBufMgr;
5+
pub struct StdVideoH265SubLayerHrdParameters;
6+
pub struct StdVideoH265HrdFlags;
7+
pub struct StdVideoH265HrdParameters;
8+
pub struct StdVideoH265VpsFlags;
9+
pub struct StdVideoH265VideoParameterSet;
10+
pub struct StdVideoH265ScalingLists;
11+
pub struct StdVideoH265ShortTermRefPicSetFlags;
12+
pub struct StdVideoH265ShortTermRefPicSet;
13+
pub struct StdVideoH265LongTermRefPicsSps;
14+
pub struct StdVideoH265SpsVuiFlags;
15+
pub struct StdVideoH265SequenceParameterSetVui;
16+
pub struct StdVideoH265PredictorPaletteEntries;
17+
pub struct StdVideoH265SpsFlags;
18+
pub struct StdVideoH265SequenceParameterSet;
19+
pub struct StdVideoH265PpsFlags;
20+
pub struct StdVideoH265PictureParameterSet;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoDecodeH265PictureInfoFlags;
3+
pub struct StdVideoDecodeH265PictureInfo;
4+
pub struct StdVideoDecodeH265ReferenceInfoFlags;
5+
pub struct StdVideoDecodeH265ReferenceInfo;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct StdVideoEncodeH265WeightTableFlags;
3+
pub struct StdVideoEncodeH265WeightTable;
4+
pub struct StdVideoEncodeH265LongTermRefPics;
5+
pub struct StdVideoEncodeH265SliceSegmentHeaderFlags;
6+
pub struct StdVideoEncodeH265SliceSegmentHeader;
7+
pub struct StdVideoEncodeH265ReferenceListsInfoFlags;
8+
pub struct StdVideoEncodeH265ReferenceListsInfo;
9+
pub struct StdVideoEncodeH265PictureInfoFlags;
10+
pub struct StdVideoEncodeH265PictureInfo;
11+
pub struct StdVideoEncodeH265ReferenceInfoFlags;
12+
pub struct StdVideoEncodeH265ReferenceInfo;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub mod codec_h264std;
3+
pub mod codec_h264std_decode;
4+
pub mod codec_h264std_encode;
5+
pub mod codec_h265std;
6+
pub mod codec_h265std_decode;
7+
pub mod codec_h265std_encode;
8+
#[doc(no_inline)]
9+
pub use codec_h264std::*;
10+
#[doc(no_inline)]
11+
pub use codec_h264std_decode::*;
12+
#[doc(no_inline)]
13+
pub use codec_h264std_encode::*;
14+
#[doc(no_inline)]
15+
pub use codec_h265std::*;
16+
#[doc(no_inline)]
17+
pub use codec_h265std_decode::*;
18+
#[doc(no_inline)]
19+
pub use codec_h265std_encode::*;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub mod extension;
3+
#[doc(no_inline)]
4+
pub use extension::*;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkPhysicalDeviceCoherentMemoryFeaturesAMD;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkDisplayNativeHdrSurfaceCapabilitiesAMD;
3+
pub struct VkSwapchainDisplayNativeHdrCreateInfoAMD;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkDeviceMemoryOverallocationCreateInfoAMD;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkPipelineCompilerControlCreateInfoAMD;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkPipelineRasterizationStateRasterizationOrderAMD;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkPhysicalDeviceShaderCorePropertiesAMD;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkPhysicalDeviceShaderCoreProperties2AMD;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkPhysicalDeviceShaderEarlyAndLateFragmentTestsFeaturesAMD;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkShaderResourceUsageAMD;
3+
pub struct VkShaderStatisticsInfoAMD;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkTextureLODGatherFormatPropertiesAMD;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// DO NOT EDIT: @generated by ash generator-rewrite 2.0.0
2+
pub struct VkPhysicalDeviceShaderEnqueuePropertiesAMDX;
3+
pub struct VkPhysicalDeviceShaderEnqueueFeaturesAMDX;
4+
pub struct VkExecutionGraphPipelineCreateInfoAMDX;
5+
pub struct VkPipelineShaderStageNodeCreateInfoAMDX;
6+
pub struct VkExecutionGraphPipelineScratchSizeAMDX;
7+
pub struct VkDispatchGraphInfoAMDX;
8+
pub struct VkDispatchGraphCountInfoAMDX;

0 commit comments

Comments
 (0)