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

spv_parsed_instruction_t cleanup #21

Closed
wants to merge 2 commits into from

Conversation

dneto0
Copy link
Collaborator

@dneto0 dneto0 commented Nov 20, 2015

Add members:

  • words: a pointer to an array of words in the instruction,
    in host native endianness.
  • num_words: sizes the words member

Remove member:

  • offset

This simplifies clients of spvBinaryParse, because they don't
have to handle endianness translation.

Also, it makes the binary parse API more composable, allowing
for easy chaining of binary parse clients. A binary parse client
is handed the array of words directly instead of having to reference
some external array of all the words in the SPIR-V binary. It also
allows a binary parse client to mutate the instruction stream before
handing off to a downstream consumer.

TODO(dneto): Still need to write the unit tests for spvBinaryParse

Fixes: #1

Add members:
 - words: a pointer to an array of words in the instruction,
   in host native endianness.
 - num_words: sizes the words member

Remove member:
 - offset

This simplifies clients of spvBinaryParse, because they don't
have to handle endianness translation.

Also, it makes the binary parse API more composable, allowing
for easy chaining of binary parse clients.  A binary parse client
is handed the array of words directly instead of having to reference
some external array of all the words in the SPIR-V binary.  It also
allows a binary parse client to mutate the instruction stream before
handing off to a downstream consumer.

TODO(dneto): Still need to write the unit tests for spvBinaryParse

Fixes: KhronosGroup#1
spv_result_t parseOperand(spv_parsed_instruction_t* inst,
// Parses an instruction operand with the given type, for an instruction
// starting at inst_offset words into the SPIR-V binary. Appends, to the
// words parameter, the endian-translated words for the operand, but only if
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a simpler interface for this? I'm finding it hard to follow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This becomes a fairly complicated interface...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tipping point on the complexity of this is caused by the fact that the method behaves differently based on whether endian conversion must be done or not. If no endian conversion is required, then the endian_converted_inst_words parameter is ignored. Life would be simpler if we didn't mind copying the underlying data in that case. We save on allocations and copying time in that very common case. I think it's worth keeping that optimization.

Maybe I worded it poorly. How about replacing the sentence from "Appends....from host" with:

If the SPIR-V binary is the same endianness as the host, then the endian_converted_inst_words parameter is ignored. Otherwise, this method appends the words for this operand, converted to host native endianness, to the end of endian_converted_inst_words.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. I like the later version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to new version

@antiagainst
Copy link
Contributor

+2

@dneto0
Copy link
Collaborator Author

dneto0 commented Nov 23, 2015

Rebased, squashed, and pushed onto master

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

Successfully merging this pull request may close these issues.

3 participants