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

Add sample_bias and gather functions #704

Merged
merged 6 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
target: aarch64-linux-android
runs-on: ${{ matrix.os }}
env:
spirv_tools_version: "20200928"
spirv_tools_version: "20210805"
RUSTUP_UNPACK_RAM: "26214400"
RUSTUP_IO_THREADS: "1"
steps:
Expand All @@ -34,7 +34,7 @@ jobs:
run: |
sudo apt install libwayland-cursor0 libxkbcommon-dev libwayland-dev
mkdir "${HOME}/spirv-tools"
curl -fL https://storage.googleapis.com/spirv-tools/artifacts/prod/graphics_shader_compiler/spirv-tools/linux-clang-release/continuous/1409/20210313-175801/install.tgz | tar -xz -C "${HOME}/spirv-tools"
curl -fL https://storage.googleapis.com/spirv-tools/artifacts/prod/graphics_shader_compiler/spirv-tools/linux-clang-release/continuous/1530/20210805-040049/install.tgz | tar -xz -C "${HOME}/spirv-tools"
echo "${HOME}/spirv-tools/install/bin" >> $GITHUB_PATH
- if: ${{ runner.os == 'macOS' }}
name: Mac - Install spirv-tools
Expand All @@ -47,7 +47,7 @@ jobs:
run: |
tmparch=$(mktemp)
mkdir "${HOME}/spirv-tools"
curl -fL -o "$tmparch" https://storage.googleapis.com/spirv-tools/artifacts/prod/graphics_shader_compiler/spirv-tools/windows-msvc-2017-release/continuous/1391/20210313-183536/install.zip
curl -fL -o "$tmparch" https://storage.googleapis.com/spirv-tools/artifacts/prod/graphics_shader_compiler/spirv-tools/windows-msvc-2017-release/continuous/1517/20210805-040116/install.zip
unzip "$tmparch" -d "${HOME}/spirv-tools"
- if: ${{ runner.os == 'Windows' }}
# Runs separately to add spir-v tools to Powershell's Path.
Expand Down
128 changes: 1 addition & 127 deletions crates/rustc_codegen_spirv/src/builder/spirv_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::spirv_type::SpirvType;
use rspirv::dr;
use rspirv::grammar::{LogicalOperand, OperandKind, OperandQuantifier};
use rspirv::spirv::{
Dim, FPFastMathMode, FragmentShadingRate, FunctionControl, ImageOperands, KernelProfilingInfo,
FPFastMathMode, FragmentShadingRate, FunctionControl, ImageOperands, KernelProfilingInfo,
LoopControl, MemoryAccess, MemorySemantics, Op, RayFlags, SelectionControl, StorageClass, Word,
};
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
Expand Down Expand Up @@ -333,7 +333,6 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
return;
}
_ => {
self.validate_instruction(&inst);
self.emit()
.insert_into_block(dr::InsertPoint::End, inst)
.unwrap();
Expand Down Expand Up @@ -1314,131 +1313,6 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
}
true
}

pub fn validate_instruction(&mut self, inst: &dr::Instruction) {
fn find_image_ty<'cx, 'tcx>(
builder: &mut Builder<'cx, 'tcx>,
inst: &dr::Instruction,
) -> Option<SpirvType> {
// Assumes the image parameter is the first operand
let image_obj = inst.operands[0].unwrap_id_ref();
let emit = builder.emit();
// Assumes the image's value definition is in the current block
let block = &emit.module_ref().functions[emit.selected_function().unwrap()].blocks
[emit.selected_block().unwrap()];
// Loop through the block to find the defining instruction
let defining_inst = match block
.instructions
.iter()
.find(|inst| inst.result_id == Some(image_obj))
{
Some(defining_inst) => defining_inst,
None => {
// Something has gone wrong. All the asm! blocks using these instructions
// should produce the image value in their own basic blocks (usually with
// an OpLoad), so there's probably some typo somewhere with an error
// already emitted, so just skip validation. If there truly is something
// bad going on, spirv-val will catch it.
return None;
}
};
match builder.lookup_type(defining_inst.result_type.unwrap()) {
SpirvType::SampledImage { image_type } => Some(builder.lookup_type(image_type)),
ty => Some(ty),
}
}

fn is_valid_query_size(ty: &SpirvType) -> bool {
match *ty {
SpirvType::Image {
dim,
multisampled,
sampled,
..
} => match dim {
Dim::Dim1D | Dim::Dim2D | Dim::Dim3D | Dim::DimCube => {
multisampled == 1 || sampled == 0 || sampled == 2
}
Dim::DimBuffer | Dim::DimRect => true,
Dim::DimSubpassData => false,
},
_ => true,
}
}

fn is_valid_query_size_lod(ty: &SpirvType) -> bool {
match *ty {
SpirvType::Image {
dim, multisampled, ..
} => match dim {
Dim::Dim1D | Dim::Dim2D | Dim::Dim3D | Dim::DimCube => multisampled == 0,
_ => false,
},
_ => true,
}
}

match inst.class.opcode {
Op::ImageQueryLevels | Op::ImageQueryLod => {
let image_ty = match find_image_ty(self, inst) {
Some(ty) => ty,
None => return,
};
if let SpirvType::Image { dim, .. } = image_ty {
match dim {
Dim::Dim1D | Dim::Dim2D | Dim::Dim3D | Dim::DimCube => {}
bad => self
.struct_err(&format!(
"Op{}'s image has a dimension of {:?}",
inst.class.opname, bad
))
.note("Allowed dimensions are 1D, 2D, 3D, and Cube")
.emit(),
}
}
// If the type isn't an image, something has gone wrong. The functions in image.rs
// shouldn't allow it, so the user is doing something weird. Let spirv-val handle
// the error later on.
}
Op::ImageQuerySize => {
let image_ty = match find_image_ty(self, inst) {
Some(ty) => ty,
None => return,
};
if !is_valid_query_size(&image_ty) {
let mut err =
self.struct_err("OpImageQuerySize is invalid for this image type");
err.note(
"allowed dimensions are 1D, 2D, 3D, Buffer, Rect, or Cube. \
if dimension is 1D, 2D, 3D, or Cube, it must have either \
multisampled be true, *or* sampled of Unknown or No",
);
if is_valid_query_size_lod(&image_ty) {
err.note("query_size_lod is valid for this image, did you mean to use it instead?");
}
err.emit();
}
}
Op::ImageQuerySizeLod => {
let image_ty = match find_image_ty(self, inst) {
Some(ty) => ty,
None => return,
};
if !is_valid_query_size_lod(&image_ty) {
let mut err =
self.struct_err("OpImageQuerySizeLod is invalid for this image type");
err.note("The image's dimension must be 1D, 2D, 3D, or Cube. Multisampled must be false.");
if is_valid_query_size(&image_ty) {
err.note(
"query_size is valid for this image, did you mean to use it instead?",
);
}
err.emit();
}
}
_ => {}
}
}
}

pub const IMAGE_OPERANDS: &[(&str, ImageOperands)] = &[
Expand Down
Loading