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

Example from docs doesn't validate #95

Closed
jrmuizel opened this issue Aug 18, 2019 · 1 comment · Fixed by #98
Closed

Example from docs doesn't validate #95

jrmuizel opened this issue Aug 18, 2019 · 1 comment · Fixed by #98
Labels

Comments

@jrmuizel
Copy link

extern crate rspirv;
extern crate spirv_headers as spirv;

use rspirv::binary::Assemble;
use rspirv::binary::Disassemble;

fn main() {
    // Building
    let mut b = rspirv::mr::Builder::new();
    b.memory_model(spirv::AddressingModel::Logical, spirv::MemoryModel::GLSL450);
    let void = b.type_void();
    let voidf = b.type_function(void, vec![void]);
    b.begin_function(void,
                     None,
                     (spirv::FunctionControl::DONT_INLINE |
                      spirv::FunctionControl::CONST),
                     voidf)
     .unwrap();
    b.begin_basic_block(None).unwrap();
    b.ret().unwrap();
    b.end_function().unwrap();
    let module = b.module();

    // Assembling
    let code = module.assemble();
    assert!(code.len() > 20);  // Module header contains 5 words
    assert_eq!(spirv::MAGIC_NUMBER, code[0]);

    // Parsing
    let mut loader = rspirv::mr::Loader::new();
    rspirv::binary::parse_words(&code, &mut loader).unwrap();
    let module = loader.module();
    use std::io::Write;
    let mut f = std::fs::File::create("out.frag").unwrap();
    let len = code[..].len() * 4;
    let buf = unsafe { std::slice::from_raw_parts(code[..].as_ptr() as *const u8, len) };
    f.write(buf);
}

gives the following error when spirv-val out.frag is run.

error: line 1: Operand 2 of MemoryModel requires one of these capabilities: Shader
  OpMemoryModel Logical GLSL450
@jrmuizel
Copy link
Author

It seems like adding b.capability(spirv::Capability::Shader); should fix this.

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

Successfully merging a pull request may close this issue.

2 participants