dfranx / SPIRV-VM

Virtual machine for executing SPIR-V
MIT License
294 stars 27 forks source link

fnLocation passed into spvm_state_prepare is not valid. #1

Closed Danielmelody closed 4 years ago

Danielmelody commented 4 years ago

Both in README.md and example.c, I found this code strange:

    spvm_source fnMain = spvm_state_get_result(state, "main");
    spvm_state_prepare(state, fnMain);

where fnMain is a pointer, but spvm_state_prepare declares as

void spvm_state_prepare(spvm_state_t state, spvm_word fnLocation)
{
    state->code_current = state->results[fnLocation].source_location;
    state->current_function = &state->results[fnLocation];

which makes state->results[fnLocation] accessed an invalid memory.

If I change the call to

spvm_state_prepare(state, *fnMain);

I got

0.00 0.00 0.00 0.00
discarded: 0

However from the source examples/shader.glsl, this is incorrect.

What did I do wrong? or there is a bug here?

dfranx commented 4 years ago

I've changed how spvm_state_prepare works and forgot to update README and example.c... It should now be:

spvm_word fnMain = spvm_state_get_result_location(state, "main");
spvm_state_prepare(state, fnMain);

Thanks for reporting!

Danielmelody commented 4 years ago

BTW, any plans for unit tests?

I 'm interesting on using your project, but I 'm not sure it is still in an early stage or full featured.

dfranx commented 4 years ago

Honestly, unit tests aren't on my TODO list right now but SPIRV-VM has most of the instructions implemented (except some OpImage* and compute shader related instructions). You can check the list of instructions that don't have an implementation here: OPCODES.txt.

BTW, may I know what you would use SPIRV-VM for? Just curious 😊

Danielmelody commented 4 years ago

Well, I 'm developing a DSL targeting SPIR-V, and I 'm interesting on debugging and validating my compiler by this vm. I 've googled an found this is the only SPIR-V vm in the world. I 'd be very appreciate if you can make this project more serious, like, for example, well tested.