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

Parsing with parse_bytes fails but shader runs with opengl #176

Closed
Boscop opened this issue Dec 14, 2020 · 2 comments
Closed

Parsing with parse_bytes fails but shader runs with opengl #176

Boscop opened this issue Dec 14, 2020 · 2 comments

Comments

@Boscop
Copy link

Boscop commented Dec 14, 2020

I'm trying to get a list of entry points of the shader like this:

use rspirv::{
	binary::parse_bytes,
	dr::{self, Loader, Module, Operand},
	grammar,
	spirv::{ExecutionModel, Op},
};

let mut loader = Loader::new();
parse_bytes(binary, &mut loader).expect("parsing SPIRV-V failed");
let module = loader.module();
let entry_points = module
	.entry_points
	.iter()
	.filter_map(|ep| {
		match_map!(ep,
			dr::Instruction { class: &grammar::Instruction { opname: "EntryPoint", opcode: Op::EntryPoint, .. }, operands, ..
		} if operands.iter().any(|o| matches!(o, Operand::ExecutionModel(ExecutionModel::Fragment))) => {
			let ep = operands.iter().find_map(|o| match_map!(o, Operand::LiteralString(s) => s))?;
			ep.as_str()
		})
	})
	.collect_vec();

But it fails with

thread 'main' panicked at 'parsing SPIRV-V failed: OperandExceeded(647492, 5251)'

When I use spirv-dis to get the entry points:

let spirv_dis = cmd!("spirv-dis", "-")
	.stdin_bytes(binary.clone())
	.read()
	.context("can't determine SPIR-V entry points")?;
let entry_points = regex!(r#"OpEntryPoint Fragment %\w+ "(\w+)""#)
	.captures_iter(&spirv_dis)
	.map(|cap| cap.get(1).map(|m| m.as_str()).expect("entry point"))
	.collect_vec();

it works and the shader runs (with opengl/glium).

(Although the shader doesn't render what it should, I'm not sure if it's related.)

minimal_vr.spv.zip

@khyperia
Copy link
Collaborator

This panics with your error on 0.7.0, but runs successfully on master. Please use master until a new version is released.

@khyperia
Copy link
Collaborator

khyperia commented Dec 14, 2020

Just checked, the problem is an OpConstant for an 8 bit integer, which was fixed in #163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants