Update readme about the "<result-id> = <opcode> <operand>..." format.

This commit is contained in:
Lei Zhang 2015-08-24 14:07:37 -04:00 committed by David Neto
parent 8a37520908
commit 902e5a8a52

View File

@ -95,16 +95,34 @@ text names from that specification. Here is an example.
``` ```
OpCapability Shader OpCapability Shader
OpMemoryModel Logical Simple OpMemoryModel Logical Simple
OpEntryPoint GLCompute $3 "main" OpEntryPoint GLCompute %3 "main"
OpExecutionMode $3 LocalSize 64 64 1 OpExecutionMode %3 LocalSize 64 64 1
OpTypeVoid %1 OpTypeVoid %1
OpTypeFunction %2 $1 OpTypeFunction %2 %1
OpFunction $1 %3 None $2 OpFunction %1 %3 None %2
OpLabel %4 OpLabel %4
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
``` ```
In order to improve the text's readability, the `<result-id>` generated by an
instruction can be moved to the beginning of that instruction and followed by
an `=` sign. This allows us to distinguish between variable defs and uses and
locate variable defs more easily. So, the above example can also be written as:
```
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint GLCompute %3 "main"
OpExecutionMode %3 LocalSize 64 64 1
%1 = OpTypeVoid
%2 = OpTypeFunction %1
%3 = OpFunction %1 None %2
%4 = OpLabel
OpReturn
OpFunctionEnd
```
Each line encapsulates one and only one instruction, or an OpCode and all of its Each line encapsulates one and only one instruction, or an OpCode and all of its
operands. OpCodes use the names provided in section 3.28 Instructions of the operands. OpCodes use the names provided in section 3.28 Instructions of the
SPIR-V specification, immediate values such as Addressing Model, Memory Model, SPIR-V specification, immediate values such as Addressing Model, Memory Model,
@ -114,11 +132,9 @@ Capability of the SPIR-V specification. Literals strings are enclosed in quotes
##### ID Definitions & Usage ##### ID Definitions & Usage
An ID definition pertains to the `Result <id>` of an OpCode, and ID usage is any An ID definition pertains to the `<result-id>` of an OpCode, and ID usage is any
input to an OpCode. To differentiate between definitions and uses, all ID input to an OpCode. All IDs are prefixed with `%`. To differentiate between
definitions are prefixed with `%` and take the form `%<id>`, meanwhile all ID defs and uses, we suggest using the second format shown in the above.
uses are prefixed with `$` and take the form `$<id>`. See the above example to
see this in action.
##### Named IDs ##### Named IDs
@ -130,12 +146,12 @@ following example will result in identical SPIR-V binary as the example above.
``` ```
OpCapability Shader OpCapability Shader
OpMemoryModel Logical Simple OpMemoryModel Logical Simple
OpEntryPoint GLCompute $main "main" OpEntryPoint GLCompute %main "main"
OpExecutionMode $main LocalSize 64 64 1 OpExecutionMode %main LocalSize 64 64 1
OpTypeVoid %void %void = OpTypeVoid
OpTypeFunction %fnMain $void %fnMain = OpTypeFunction %void
OpFunction $void %main None $fnMain %main = OpFunction %void None %fnMain
OpLabel %lbMain %lbMain = OpLabel
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
``` ```