Skip to content

Commit a93d6e0

Browse files
authored
Add sample_bias and gather functions (#704)
* Add sample_bias function * Update line numbers * Add gather function * Update spirv-tools CI was failing on "Capability SampledRect is not allowed by Vulkan 1.1 specification (or requires extension)", except locally it was fine, and I have more up to date spirv-tools than CI, so try bumping the CI version to see if it's just an out-of-date spirv-val * Fix gather() in vulkan * Convert compiler valication into marker traits
1 parent bca7656 commit a93d6e0

File tree

11 files changed

+762
-210
lines changed

11 files changed

+762
-210
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
target: aarch64-linux-android
2323
runs-on: ${{ matrix.os }}
2424
env:
25-
spirv_tools_version: "20200928"
25+
spirv_tools_version: "20210805"
2626
RUSTUP_UNPACK_RAM: "26214400"
2727
RUSTUP_IO_THREADS: "1"
2828
steps:
@@ -34,7 +34,7 @@ jobs:
3434
run: |
3535
sudo apt install libwayland-cursor0 libxkbcommon-dev libwayland-dev
3636
mkdir "${HOME}/spirv-tools"
37-
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"
37+
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"
3838
echo "${HOME}/spirv-tools/install/bin" >> $GITHUB_PATH
3939
- if: ${{ runner.os == 'macOS' }}
4040
name: Mac - Install spirv-tools
@@ -47,7 +47,7 @@ jobs:
4747
run: |
4848
tmparch=$(mktemp)
4949
mkdir "${HOME}/spirv-tools"
50-
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
50+
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
5151
unzip "$tmparch" -d "${HOME}/spirv-tools"
5252
- if: ${{ runner.os == 'Windows' }}
5353
# Runs separately to add spir-v tools to Powershell's Path.

crates/rustc_codegen_spirv/src/builder/spirv_asm.rs

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::spirv_type::SpirvType;
55
use rspirv::dr;
66
use rspirv::grammar::{LogicalOperand, OperandKind, OperandQuantifier};
77
use rspirv::spirv::{
8-
Dim, FPFastMathMode, FragmentShadingRate, FunctionControl, ImageOperands, KernelProfilingInfo,
8+
FPFastMathMode, FragmentShadingRate, FunctionControl, ImageOperands, KernelProfilingInfo,
99
LoopControl, MemoryAccess, MemorySemantics, Op, RayFlags, SelectionControl, StorageClass, Word,
1010
};
1111
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
@@ -333,7 +333,6 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
333333
return;
334334
}
335335
_ => {
336-
self.validate_instruction(&inst);
337336
self.emit()
338337
.insert_into_block(dr::InsertPoint::End, inst)
339338
.unwrap();
@@ -1314,131 +1313,6 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
13141313
}
13151314
true
13161315
}
1317-
1318-
pub fn validate_instruction(&mut self, inst: &dr::Instruction) {
1319-
fn find_image_ty<'cx, 'tcx>(
1320-
builder: &mut Builder<'cx, 'tcx>,
1321-
inst: &dr::Instruction,
1322-
) -> Option<SpirvType> {
1323-
// Assumes the image parameter is the first operand
1324-
let image_obj = inst.operands[0].unwrap_id_ref();
1325-
let emit = builder.emit();
1326-
// Assumes the image's value definition is in the current block
1327-
let block = &emit.module_ref().functions[emit.selected_function().unwrap()].blocks
1328-
[emit.selected_block().unwrap()];
1329-
// Loop through the block to find the defining instruction
1330-
let defining_inst = match block
1331-
.instructions
1332-
.iter()
1333-
.find(|inst| inst.result_id == Some(image_obj))
1334-
{
1335-
Some(defining_inst) => defining_inst,
1336-
None => {
1337-
// Something has gone wrong. All the asm! blocks using these instructions
1338-
// should produce the image value in their own basic blocks (usually with
1339-
// an OpLoad), so there's probably some typo somewhere with an error
1340-
// already emitted, so just skip validation. If there truly is something
1341-
// bad going on, spirv-val will catch it.
1342-
return None;
1343-
}
1344-
};
1345-
match builder.lookup_type(defining_inst.result_type.unwrap()) {
1346-
SpirvType::SampledImage { image_type } => Some(builder.lookup_type(image_type)),
1347-
ty => Some(ty),
1348-
}
1349-
}
1350-
1351-
fn is_valid_query_size(ty: &SpirvType) -> bool {
1352-
match *ty {
1353-
SpirvType::Image {
1354-
dim,
1355-
multisampled,
1356-
sampled,
1357-
..
1358-
} => match dim {
1359-
Dim::Dim1D | Dim::Dim2D | Dim::Dim3D | Dim::DimCube => {
1360-
multisampled == 1 || sampled == 0 || sampled == 2
1361-
}
1362-
Dim::DimBuffer | Dim::DimRect => true,
1363-
Dim::DimSubpassData => false,
1364-
},
1365-
_ => true,
1366-
}
1367-
}
1368-
1369-
fn is_valid_query_size_lod(ty: &SpirvType) -> bool {
1370-
match *ty {
1371-
SpirvType::Image {
1372-
dim, multisampled, ..
1373-
} => match dim {
1374-
Dim::Dim1D | Dim::Dim2D | Dim::Dim3D | Dim::DimCube => multisampled == 0,
1375-
_ => false,
1376-
},
1377-
_ => true,
1378-
}
1379-
}
1380-
1381-
match inst.class.opcode {
1382-
Op::ImageQueryLevels | Op::ImageQueryLod => {
1383-
let image_ty = match find_image_ty(self, inst) {
1384-
Some(ty) => ty,
1385-
None => return,
1386-
};
1387-
if let SpirvType::Image { dim, .. } = image_ty {
1388-
match dim {
1389-
Dim::Dim1D | Dim::Dim2D | Dim::Dim3D | Dim::DimCube => {}
1390-
bad => self
1391-
.struct_err(&format!(
1392-
"Op{}'s image has a dimension of {:?}",
1393-
inst.class.opname, bad
1394-
))
1395-
.note("Allowed dimensions are 1D, 2D, 3D, and Cube")
1396-
.emit(),
1397-
}
1398-
}
1399-
// If the type isn't an image, something has gone wrong. The functions in image.rs
1400-
// shouldn't allow it, so the user is doing something weird. Let spirv-val handle
1401-
// the error later on.
1402-
}
1403-
Op::ImageQuerySize => {
1404-
let image_ty = match find_image_ty(self, inst) {
1405-
Some(ty) => ty,
1406-
None => return,
1407-
};
1408-
if !is_valid_query_size(&image_ty) {
1409-
let mut err =
1410-
self.struct_err("OpImageQuerySize is invalid for this image type");
1411-
err.note(
1412-
"allowed dimensions are 1D, 2D, 3D, Buffer, Rect, or Cube. \
1413-
if dimension is 1D, 2D, 3D, or Cube, it must have either \
1414-
multisampled be true, *or* sampled of Unknown or No",
1415-
);
1416-
if is_valid_query_size_lod(&image_ty) {
1417-
err.note("query_size_lod is valid for this image, did you mean to use it instead?");
1418-
}
1419-
err.emit();
1420-
}
1421-
}
1422-
Op::ImageQuerySizeLod => {
1423-
let image_ty = match find_image_ty(self, inst) {
1424-
Some(ty) => ty,
1425-
None => return,
1426-
};
1427-
if !is_valid_query_size_lod(&image_ty) {
1428-
let mut err =
1429-
self.struct_err("OpImageQuerySizeLod is invalid for this image type");
1430-
err.note("The image's dimension must be 1D, 2D, 3D, or Cube. Multisampled must be false.");
1431-
if is_valid_query_size(&image_ty) {
1432-
err.note(
1433-
"query_size is valid for this image, did you mean to use it instead?",
1434-
);
1435-
}
1436-
err.emit();
1437-
}
1438-
}
1439-
_ => {}
1440-
}
1441-
}
14421316
}
14431317

14441318
pub const IMAGE_OPERANDS: &[(&str, ImageOperands)] = &[

0 commit comments

Comments
 (0)