Documentation fixes

This commit is contained in:
João Capucho
2021-07-30 19:11:31 +01:00
committed by Dzmitry Malyshau
parent b7a4ee1d2d
commit d39f6780a7
8 changed files with 79 additions and 71 deletions

View File

@@ -134,7 +134,7 @@ fn name(option: &Option<String>) -> &str {
}
}
/// set39 color scheme from https://graphviz.org/doc/info/colors.html
/// set39 color scheme from <https://graphviz.org/doc/info/colors.html>
const COLORS: &[&str] = &[
"white", // pattern starts at 1
"#8dd3c7", "#ffffb3", "#bebada", "#fb8072", "#80b1d3", "#fdb462", "#b3de69", "#fccde5",

View File

@@ -647,7 +647,8 @@ impl<'a, W: Write> Writer<'a, W> {
/// # Panics
/// - If type is either a image, a sampler, a pointer, or a struct
/// - If it's an Array with a [`ArraySize::Constant`](crate::ArraySize::Constant) with a
/// constant that isn't [`Uint`](crate::ConstantInner::Uint)
/// constant that isn't a [`Scalar`](crate::ConstantInner::Scalar) or if the
/// scalar value isn't an [`Sint`](crate::ScalarValue::Sint) or [`Uint`](crate::ScalarValue::Uint)
fn write_value_type(&mut self, inner: &TypeInner) -> BackendResult {
match *inner {
// Scalars are simple we just get the full name from `glsl_scalar`
@@ -712,7 +713,8 @@ impl<'a, W: Write> Writer<'a, W> {
/// # Panics
/// - If type is either a image or sampler
/// - If it's an Array with a [`ArraySize::Constant`](crate::ArraySize::Constant) with a
/// constant that isn't [`Uint`](crate::ConstantInner::Uint)
/// constant that isn't a [`Scalar`](crate::ConstantInner::Scalar) or if the
/// scalar value isn't an [`Sint`](crate::ScalarValue::Sint) or [`Uint`](crate::ScalarValue::Uint)
fn write_type(&mut self, ty: Handle<crate::Type>) -> BackendResult {
match self.module.types[ty].inner {
// glsl has no pointer types so just write types as normal and loads are skipped

View File

@@ -11,7 +11,8 @@ impl crate::ScalarKind {
}
/// Helper function that returns scalar related strings
/// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-scalar
///
/// <https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-scalar>
pub(super) fn to_hlsl_str(self, width: crate::Bytes) -> Result<&'static str, Error> {
match self {
Self::Sint => Ok("int"),

View File

@@ -1,25 +1,28 @@
// Important note about `Expression::ImageQuery`/`Expression::ArrayLength` and hlsl backend:
// Due to implementation of `GetDimensions` function in hlsl (https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-getdimensions)
// backend can't work with it as an expression.
// Instead, it generates a unique wrapped function per `Expression::ImageQuery`, based on texure info and query function.
// See `WrappedImageQuery` struct that represents a unique function and will be generated before writing all statements and expressions.
// This allowed to works with `Expression::ImageQuery` as expression and write wrapped function.
//
// For example:
// ```wgsl
// let dim_1d = textureDimensions(image_1d);
// ```
//
// ```hlsl
// int NagaDimensions1D(Texture1D<float4>)
// {
// uint4 ret;
// image_1d.GetDimensions(ret.x);
// return ret.x;
// }
//
// int dim_1d = NagaDimensions1D(image_1d);
// ```
//! Helpers for the hlsl backend
//!
//! Important note about `Expression::ImageQuery`/`Expression::ArrayLength` and hlsl backend:
//!
//! Due to implementation of `GetDimensions` function in hlsl (<https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-getdimensions>)
//! backend can't work with it as an expression.
//! Instead, it generates a unique wrapped function per `Expression::ImageQuery`, based on texure info and query function.
//! See `WrappedImageQuery` struct that represents a unique function and will be generated before writing all statements and expressions.
//! This allowed to works with `Expression::ImageQuery` as expression and write wrapped function.
//!
//! For example:
//! ```wgsl
//! let dim_1d = textureDimensions(image_1d);
//! ```
//!
//! ```hlsl
//! int NagaDimensions1D(Texture1D<float4>)
//! {
//! uint4 ret;
//! image_1d.GetDimensions(ret.x);
//! return ret.x;
//! }
//!
//! int dim_1d = NagaDimensions1D(image_1d);
//! ```
use super::{super::FunctionCtx, BackendResult};
use crate::arena::Handle;
@@ -38,37 +41,37 @@ pub(super) struct WrappedImageQuery {
pub(super) query: ImageQuery,
}
// HLSL backend requires its own `ImageQuery` enum.
// It is used inside `WrappedImageQuery` and should be unique per ImageQuery function.
// IR version can't be unique per function, because it's store mipmap level as an expression.
//
// For example:
// ```wgsl
// let dim_cube_array_lod = textureDimensions(image_cube_array, 1);
// let dim_cube_array_lod2 = textureDimensions(image_cube_array, 1);
// ```
//
// ```ir
// ImageQuery {
// image: [1],
// query: Size {
// level: Some(
// [1],
// ),
// },
// },
// ImageQuery {
// image: [1],
// query: Size {
// level: Some(
// [2],
// ),
// },
// },
// ```
//
// HLSL should generate only 1 function for this case.
//
/// HLSL backend requires its own `ImageQuery` enum.
///
/// It is used inside `WrappedImageQuery` and should be unique per ImageQuery function.
/// IR version can't be unique per function, because it's store mipmap level as an expression.
///
/// For example:
/// ```wgsl
/// let dim_cube_array_lod = textureDimensions(image_cube_array, 1);
/// let dim_cube_array_lod2 = textureDimensions(image_cube_array, 1);
/// ```
///
/// ```ir
/// ImageQuery {
/// image: [1],
/// query: Size {
/// level: Some(
/// [1],
/// ),
/// },
/// },
/// ImageQuery {
/// image: [1],
/// query: Size {
/// level: Some(
/// [2],
/// ),
/// },
/// },
/// ```
///
/// HLSL should generate only 1 function for this case.
#[derive(Clone, Copy, Debug, Hash, Eq, Ord, PartialEq, PartialOrd)]
pub(super) enum ImageQuery {
Size,
@@ -141,7 +144,8 @@ impl<'a, W: Write> super::Writer<'a, W> {
}
/// Helper function that write wrapped function for `Expression::ArrayLength`
/// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwbyteaddressbuffer-getdimensions
///
/// <https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwbyteaddressbuffer-getdimensions>
pub(super) fn write_wrapped_array_length_function(
&mut self,
module: &crate::Module,
@@ -221,7 +225,8 @@ impl<'a, W: Write> super::Writer<'a, W> {
}
/// Helper function that write wrapped function for `Expression::ImageQuery`
/// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-getdimensions
///
/// <https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-getdimensions>
pub(super) fn write_wrapped_image_query_function(
&mut self,
module: &crate::Module,
@@ -338,7 +343,8 @@ impl<'a, W: Write> super::Writer<'a, W> {
}
/// Helper function that write wrapped function for `Expression::ImageQuery` and `Expression::ArrayLength`
/// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-getdimensions
///
/// <https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-getdimensions>
pub(super) fn write_wrapped_functions(
&mut self,
module: &crate::Module,

View File

@@ -1,6 +1,6 @@
/// HLSL Reserved Words
/// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords
/// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-reserved-words
//! HLSL Reserved Words
//! - <https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords>
//! - <https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-reserved-words>
pub const RESERVED: &[&str] = &[
"AppendStructuredBuffer",
"asm",

View File

@@ -1734,7 +1734,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
Ok(())
}
/// Helper method used to write [`ScalarValue`](ScalarValue)
/// Helper method used to write [`ScalarValue`](crate::ScalarValue)
///
/// # Notes
/// Adds no trailing or leading whitespace

View File

@@ -268,7 +268,7 @@ enum Dimension {
Matrix,
}
/// A map from evaluated [`Expression`s] to their SPIR-V ids.
/// A map from evaluated [`Expression`](crate::Expression)s to their SPIR-V ids.
///
/// When we emit code to evaluate a given `Expression`, we record the
/// SPIR-V id of its value here, under its `Handle<Expression>` index.
@@ -343,7 +343,7 @@ struct BlockContext<'w> {
/// [`ir_function`](BlockContext::ir_function).
fun_info: &'w crate::valid::FunctionInfo,
/// The [`back::spv::Function`] to which we are contributing SPIR-V instructions.
/// The [`spv::Function`](Function) to which we are contributing SPIR-V instructions.
function: &'w mut Function,
/// SPIR-V ids for expressions we've evaluated.

View File

@@ -9,8 +9,7 @@ use std::fmt::Write;
/// Shorthand result used internally by the backend
type BackendResult = Result<(), Error>;
/// WGSL attribute
/// https://gpuweb.github.io/gpuweb/wgsl/#attributes
/// WGSL [attribute](https://gpuweb.github.io/gpuweb/wgsl/#attributes)
enum Attribute {
Binding(u32),
Block,
@@ -137,7 +136,7 @@ impl<W: Write> Writer<W> {
Ok(())
}
/// Helper method used to write [`ScalarValue`](ScalarValue)
/// Helper method used to write [`ScalarValue`](crate::ScalarValue)
///
/// # Notes
/// Adds no trailing or leading whitespace
@@ -179,8 +178,8 @@ impl<W: Write> Writer<W> {
Ok(())
}
/// Helper method used to write structs
/// https://gpuweb.github.io/gpuweb/wgsl/#functions
/// Helper method used to write
/// [functions](https://gpuweb.github.io/gpuweb/wgsl/#functions)
///
/// # Notes
/// Ends in a newline