Commit Graph

4066 Commits

Author SHA1 Message Date
David Neto
66f649d501 Use static_cast instead of constructor for uint32_t 2015-12-01 16:19:44 -05:00
David Neto
39fa148234 OpDecorate should not accept any number of literal operands.
This is a grammar fix.  The Decoration operand of OpDecorate (and
OpMemberDecorate) determines the remaining operands.  Don't just
allow any number of literal numbers as operands.

(The OperandVariableLiterals operand class as the last member
of the OpDecorate and OpMemberDecorate entries in in opcode.inc is
an artifact of how the spec generates the opcode descriptions. It's
not suitable for parsing those instructions.)

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/34
2015-12-01 15:38:32 -05:00
David Neto
36909c05a5 binary parse test: extra words after string literal
Covers the case where the string literal is the
last operand.

TODO: Case where one more operand is expected after
the string literal.  Occurs only for the LinkageAttributes
decoration.  To test that, we need to update the grammar
as well.
2015-12-01 15:38:32 -05:00
David Neto
292acb5b41 Don't add -frtti for tests. Use newer googletest.
Using -frtti caused link failures when both of the following are
in effect:
	-DDISABLE_EXCEPTIONS=ON
	-DDISABLE_RTTI=ON

The correct fix is to use tip-of-tree googletest.
Specifically, we need a version of googletest with the fix in
https://github.com/google/googletest/pull/612
In particular, it must be later than googletest 1.7.0.
2015-12-01 12:19:09 -05:00
David Neto
bdc50b5d62 Add -frtti for tests that use mocking
The tests now use mocked methods.  This requires runtime type
information for those test classes.
https://github.com/google/googletest/issues/610

This has been fixed recently upstream in googletest.  Until we pick
up that fix, add -frtti for the the test executable only.
2015-12-01 10:01:33 -05:00
Dejan Mircevski
15aebef8a0 Merge PR #32.
Simplify binary parser tests using GoogleMock.
2015-11-30 18:06:33 -05:00
Dejan Mircevski
7a3a459af5 Mention that ParsedInstruction owns its components.
Also close a parenthesis in ParsedInstruction printout.
2015-11-30 14:12:04 -05:00
David Neto
d9ad050a95 spvBinaryParse: fix overruns, handle image format
Add unit tests for all diagnostics issued by spvBinaryParse.

Handle image format operands in the binary parser and the
disassembler.

Document that the callback function pointers can be null,
in which case they are ignored.

Detect exhaustion of input when parsing an operand,
to avoid buffer overruns on some invalid input cases.

Fix the description strings for some operand types.
Make the diagnostic messages for those operand types
consistent between the assembler and binary parser.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/29
2015-11-30 10:44:23 -05:00
David Neto
ee8a007810 Clarify the non-SPV_SUCCESS case parser callbacks.
When a callback returns something other than SPV_SUCCESS,
then no futher callbacks are issued (parsing terminates early),
and no additional diagnostics are emitted.

The unit tests already check this behaviour.
2015-11-30 10:36:42 -05:00
David Neto
750f205b63 Several unit tests for spvBinaryParse
Add a non-zero spv_result_t value SPV_REQUESTED_TERMINATION
which should be used to signal an ok result, but signals
early termination for a process, such as binary parsing.

Tests include:
 - correct contents sent to header and instruction callbacks
 - non-zero status from a callback should terminate parsing,
   but the parser should not generate its own diagnostic.

TODO: Check diagnostics generated by the parser itself.
2015-11-27 10:19:06 -05:00
David Neto
c9e0845c7f Aliasing through a union member is valid.
Take back my previous TODO.
2015-11-23 15:35:00 -05:00
David Neto
15afbf9372 Fix compilation of an assert.
The asserts check the length of the endian-converted words
vector with the reported number of words in the instruction.
2015-11-23 14:25:40 -05:00
David Neto
7bff3eb6f9 spv_parsed_instruction_t cleanup
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: https://github.com/KhronosGroup/SPIRV-Tools/issues/1
2015-11-23 09:52:38 -05:00
Ben Vanik
01c8d7a8fb Merge pull request #23.
Fixing some C++ conversion errors.
* Implicit conversion from int to bool.
* Implicit conversion from size_t to uint32_t.
* Implicit conversion from char* to uint8_t.

Adding no-op color operators so unhandled platforms can still link.
2015-11-23 01:42:46 -05:00
David Neto
01656363a7 Put DiagnosticStream and clr exports in libspirv namespace
Each exported functions either has an "spv" prefix, or is inthe libspirv
namespace.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/18
2015-11-20 10:46:42 -05:00
Lei Zhang
9e53117061 Fix paths for binaries to match changes in CMake configuration. 2015-11-20 09:44:13 -05:00
Lei Zhang
39a83291fc Use test fixture for a test. 2015-11-19 11:39:11 -05:00
Andrew Woloszyn
5b9fff7175 Removed executable flag from HexFloat.cpp. 2015-11-19 10:12:44 -05:00
David Neto
3958c90277 Updated spirv.h header. Fixes SPV_VERSION macro
The SPV_VERSION macro value was updated to be 0x10000.
Previously it was missing the "0x" prefix, which caused
confusion.

The value of the const unsigned int SpvVersion has always
been 0x00010000.  That's what should appear as the version
word in the SPIR-V header.

The SPV_VERSION symbol is to be used in preprocessor directives.
2015-11-19 09:56:35 -05:00
Andrew Woloszyn
3a4bc7e61a Turned warnings-as-errors on by default.
Fixed a few warnings that appear in builds on VS2013 and VS2015.
2015-11-19 09:46:59 -05:00
Lei Zhang
8bd75d650e Clean up CMake configuration and address compiler warnings.
- Removed dead configuration in CMakeLists.txt.
- Used target_compile_options() instead of CMAKE_{C|CXX}_FLAGS.
- Turned on warnings on tests.
- Fixed various warnings for comparing signed with unsigned values.
- Removed dead code exposed by compiler warnings.
2015-11-18 16:32:41 -05:00
David Neto
64a9be97ca Remove old names for enums: memory semantics, scope ID 2015-11-18 15:56:38 -05:00
David Neto
8ddd4ec102 Bottom byte of version header word should be 0
The assembler should always make it 0.
The disassembler should ignore it.

Remove the macro support for supplying a value for it.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/6
2015-11-18 15:19:43 -05:00
Pierre Moreau
01a3b9ce36 CMake: Respect user-defined install path 2015-11-18 10:04:04 -05:00
David Neto
748d585a9a Object files should depend on spirv.h and friends
Don't use SYSTEM attribute on include_directories directive
for the SPIR-V standard header files.  When you do, object files
are not considered dependent on those headers.

Checked by looking at the dependency file source/disassemble.cpp.o.d,
and by trying to compile after a trivial edit to spirv.h

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/7

Also, use "" inclusion instead of <> inclusion for standard SPIR-V
headers.
2015-11-17 18:04:12 -05:00
Lei Zhang
aa50c45e3b Fix test: version number has changed. 2015-11-17 16:46:55 -05:00
Lei Zhang
62fcaf1a74 Update external headers.
Now use the headers published at
https://www.khronos.org/registry/spir-v/api/1.0/.
2015-11-17 16:02:44 -05:00
Lei Zhang
af9906e4e5 Use Google comment style and fix typos. 2015-11-16 17:25:43 -05:00
David Neto
287cfc1dd7 Fix grammar: "The SPIR-V Tools project provides" 2015-11-14 08:24:59 -06:00
David Neto
2266ba1061 Register Glslang tool 2015-11-13 12:35:47 -06:00
Lei Zhang
acf7287c42 Fix many typos. 2015-11-13 12:35:43 -06:00
David Neto
56fb3f016b Revamp the README for public release.
Reorganize the README, and update its contents to more accurately
reflect the public release.
Remove the incremental "Changes" section.

Rename readme.md to README.md
Rename license.txt to LICENSE

Update the assembler tool to support -h, and make its help look
more consistent with the disassembler.

Change the target and library name to SPIRV-Tools.  To better
match the GitHub repo name.  Also, it's not SHOUTING.
2015-11-13 12:35:39 -06:00
David Neto
3d348a8440 The version header word has 3 byte-size components.
Bits 24-31: 0
Bits 16-23: SPIR-V major number (1)
Bits  8-15: SPIR-V minor number (0)
Bits   0-7: SPIR-V minor number (2)

The assembler will construct the word appropriately,
and the disassemble will print it in major.minor.revision form.
2015-11-13 12:35:34 -06:00
David Neto
14b93e49ed Generator word now has two 16-bit components
The high 16-bits are a registered generator tool.
These are registered at
https://www.khronos.org/registry/spir-v/api/spir-v.xml

The low 16-bits are tool-specific.  It might be a version number,
for example, but is not constrained by the spec or by the registration
process.

The disassembler prints the tool name when we know it.
If we don't, print "Unknown" and then the numeric tool number
in parentheses.
In all cases, the disassembler prints lower 16-bit number on the
same line but after the tool name.

Also add newly registered generators:
  6: Khronos LLVM/SPIR-V Translator
  7: Khronos SPIR-V Tools Assembler
2015-11-13 12:35:29 -06:00
David Neto
5f7ed91e18 Support capabilities StorageImageReadWithoutFormat
Also add capability StorageImageWriteWithoutFormat.

They only affect validation rules.
2015-11-12 16:27:51 -05:00
David Neto
df3ea3c5de Disassembler can read the binary from stdin.
Read from stdin if:
 - no input filename specified
 - the input filename is "-"

Also, output goes to stdout if the output filename (argument to -o)
is "-".
2015-11-12 16:27:51 -05:00
David Neto
12511c8a4f Add GeometryStreams capability
Decoration Stream depends on it.
GeometryStreams depends on Geometry capability.

Spot check dependence of OpEmitStreamVertex on GeometryStreams.
(Opcode dependencies on capabilities are automatically generated from
opcode.inc)
2015-11-12 16:27:51 -05:00
David Neto
0c6cf8cdff Support OpImage
It's already in the syntax table.  Just test it.
2015-11-12 16:27:51 -05:00
Lei Zhang
972788bf23 Use opaque context object to hold SPIR-V info tables.
Previously the opcode table is declared as an global array and we
have spvOpcodeTableInitialize() modifying it. That can result in
race condition. Now spvOpcodeTabelGet() copies the whole underlying
array.
2015-11-12 16:27:51 -05:00
Lei Zhang
321c3e206b Remove an obselete and redundant text. 2015-11-12 16:27:51 -05:00
David Neto
e7c426ac8d Disassembler tool indents to 15 by default
The assigned-to result Id appears to the left of the 15th column.

Add --no-indent option.

The API form of the disassembler does not indent by default.
2015-11-12 16:27:50 -05:00
David Neto
9a5ac08bcf spirv-dis prints to stdout by default.
Color printing is enabled only for printing to stdout.
Add --no-color to turn off color printing.
2015-11-12 16:27:50 -05:00
Lei Zhang
39b01b9988 Simplify some tests 2015-11-12 16:27:46 -05:00
Lei Zhang
4ac601a2c3 libspirv.h doesn't depend on spirv_operands.hpp anymore.
Also change spirv_operands.hpp to a C header since we only have
an enum inside it, and move it to source/.
2015-11-12 09:43:26 -05:00
Lei Zhang
a23a73671a Moves parser interface to libspirv.h. 2015-11-12 09:43:23 -05:00
Lei Zhang
8984f6f31f Move internal macros/structs for SPIR-V to a separate header. 2015-11-12 09:43:20 -05:00
David Neto
d02f68ae79 Update to 1.0 Rev 2 work-in-progress headers
Updated readme.

Note: The header advertises itself as Rev 1, but contains
many (all?) the updates intended for Rev 2.  We might need
to update one more time before SPIR-V 1.0 Rev2 is published.

Regenerated syntax tables for 1.0.

Changed names:
  InputTriangles -> Triangles
  InputQuads -> Quads
  InputIsolines -> Isolines
  WorkgroupLocal -> Workgroup
  WorkgroupGlobal -> CrossWorkgroup
  PrivateGlobal -> Private
  (Dim) InputTarget -> SubpassData
  WorkgroupLocalMemoryMask -> WorkgroupMemoryMask
  WorkgroupGlobalMemoryMask -> CrossWorkgroupMemoryMask
  AsyncGroupCopy -> GroupAsyncCopy
  WaitGroupEvents -> GroupWaitEvents

Remove:
  IndependentForwardProgress capability
  Smooth decoration
  FragColor BuiltIn
  WorkgroupLinearId in favour of LocalInvocationId
  ImageSRGBWrite capability
  Special OpenCL image instructions

Add:
  image channel data type UnormInt101010_2
  AcquireReleaseMask

InputTargetIndex updates:
  InputTargetIndex -> InputAttachmentIndex
  InputAttachmentIndex depends on InputAttachment capability,
  and it takes a literal number argument.

Capability StorageImageExtendedFormats updates:
  Enum value changed from 26 to 49. (Changes position in tables).
  Replaces AdvancedImageFormat capability.

OpenCL source language -> OpenCL_C, OpenCL_CPP
2015-11-12 09:43:12 -05:00
Lei Zhang
aa056cd8c7 Move SPIR-V constants/limits to a separate header. 2015-11-12 09:43:09 -05:00
Lei Zhang
16f3ddfbb8 Use std::string instead of a huge array for storing literal strings. 2015-11-12 09:43:06 -05:00
Lei Zhang
2a0b773b27 Add missing copyright. 2015-11-12 09:43:03 -05:00