GithubHelp home page GithubHelp logo

Validator about rspirv HOT 3 OPEN

gfx-rs avatar gfx-rs commented on July 18, 2024 2
Validator

from rspirv.

Comments (3)

caitp avatar caitp commented on July 18, 2024 1

I had a few ideas for this. The premise of these ideas is, the validator would be built as a part of the rspirv library (Possibly behind a feature), and the package would also include an application which consumes the validator API (providing nearly the same experience as SPIRV-Tools' validator).

Being in a library could allow a developer to add additional scrutiny before allowing Vulkan or GL APIs to run their module --- Diagnostic messages could be localized, or possibly easier to understand than errors produced by their graphics or compute API --- But the primary use would still be the validator application.

What do you think?

In addition to the above premise, there are a few areas where I'm a bit unsure of how I want this API to look/to be consumed. These are mostly cosmetic, but a few have significant effects on how the library would need to be developed.

API entrypoints (and their use)

  • Consume binary from start to finish, similar to SPIRV-Tools. This grants the opportunity to perform additional checks on the layout of a module that the rspirv::mr::Loader does not do, and do a better job of recording debug information for diagnostic messages..The main downside is, this would duplicate some of the work Loader is already doing. If a program wanted to do anything with a Module other than validation, it would be necessary to consume the binary again.
pub fn validate_bytes<T: AsRef<[u8]>>(binary: T) -> Result<()>;
pub fn validate_words<T: AsRef<[u32]>>(binary: T) -> Result<()>;
  • Consume an already decoded mr::Module, and assume that the module is in a valid layout. This is simpler, but could fail to report that the Module has an invalid Layout, in some cases (the Loader doesn't appear to reject all per-spec invalid forms, and does appear to reject OpLine/OpNoLine outside of a BasicBlock --- does not reject if a Phi's instruction's block operands are valid, etc). It's also possible that diagnostics could be reported out of order, and it may be difficult to produce good diagnostic messages using the debug opcodes.
pub fn validate_module(module: &mr::Module) -> Result<()>;
  • Making internal ValidationState structure public, and the validation entrypoints become methods of
    that class (Optionally, still have top-level entrtypoints which construct a ValidationState without
    returning it.
pub struct ValidationState {
    // ...
}

impl ValidationState {
    pub fn new(module: &mr::Module) -> ValidationState {
        // ...
    }
    pub fn validate() -> Result<()> {
        // ...
    }

    // ...
}

Error reporting:

  • Single diagnostic message reported via Result()
  • Diagnostics passed to caller through delegation, similar to binary::Consumer (e.g. DiagnosticConsumer)
trait DiagnosticConsumer {
    fn message(severity: Severity, message: Message) -> Action;

    // Or, if building diagnostic messages is the responsibility of the API consumer:
    fn message(severity: Severity, message: Message, line: Option(mr::Instruction) -> Action;
}

Optionally relaxing checks or imposing strict limits, as in SPIRV-Tools:

-pub fn validate_module(module: &mr::Module) -> Result<()>;
+pub fn validate_module(module: &mr::Module, options: Options) -> Result<()>;

Where Options is:

pub struct Options {
    // Same universal limits options as SPIRV-Tools' validator

    // Same lint-relaxing options as SPIRV-Tools' Validator
}

impl Default for Options {
    pub fn default() -> Options {
        Options {
            // Universal limits default to their per-spec values

            // Relaxing options default to false
        }
    }
}

Are Options fields publicly visible? Is Options constructed with a Builder? If so, is it OptionsBuilder or ValidatorBuilder, or what have you? If the API can consume both binary and fully constructed mr::Modules (in which case, we likely have a Builder API), do Options deserve a Builder as well?

from rspirv.

Danielmelody avatar Danielmelody commented on July 18, 2024

It is 2021, any efforts remained?

from rspirv.

grovesNL avatar grovesNL commented on July 18, 2024

@Danielmelody not in rspirv, but it's pretty easy to use spirv-val from Rust now, which is able to validate SPIR-V. spirv-tools-rs contains bindings for spirv-val and some of the other tools from SPIR-V Tools.

from rspirv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.