Skip to content

Commit 3f76afc

Browse files
authored
Add minimal as/dis support for TOSA.001000.1 extended instruction set (KhronosGroup#6183)
* Add minimal as/dis support for TOSA.001000.1 extended instruction set Change-Id: Ieefcd9c9a46dc3021c1600c02f9be96c49641aa9 Signed-off-by: Kevin Petit <[email protected]> * pick up headers Change-Id: Ie0d1c5258367774451373f7d81e231e2fc674937 * attempt to fix Bazel builds Change-Id: I34fbf54545ecb58a3bacdf1f711e22547e8b5666 * Revert changes to BUILD.gn This reverts commit d4496b7. * update headers Change-Id: I368598d93f94bc39ff71db56269bf1baeedf37c8 * BUILD.bazel: add dependency on spirv_common_headers when building tests Change-Id: I265b9622ce86f3d86b68a523ccf849a0134b890b * attempt to fix table generation in Bazel builds Change-Id: Ifa2a94af00af09fbd5aa1ae48eeac0603aa5b5f0 * another attempt Change-Id: I411737a0544187c0c01d9628df9a7b556490750e --------- Signed-off-by: Kevin Petit <[email protected]>
1 parent dab29fb commit 3f76afc

File tree

7 files changed

+68
-1
lines changed

7 files changed

+68
-1
lines changed

BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ create_grammar_tables_target(
5252
ExtInst("opencl.std.100", target="spirv_opencl_grammar_unified1"),
5353
ExtInst("opencl.debuginfo.100", prefix="CLDEBUG100_"),
5454
ExtInst("nonsemantic.shader.debuginfo.100", prefix="SHDEBUG100_"),
55+
ExtInst("tosa.001000.1", target="spirv_ext_inst_tosa_001000_1", prefix="TOSA_"),
5556
] + [ExtInst(e) for e in [
5657
"spv-amd-shader-explicit-vertex-parameter",
5758
"spv-amd-shader-trinary-minmax",
@@ -431,6 +432,7 @@ cc_library(
431432
":tools_io",
432433
"@googletest//:gtest",
433434
"@googletest//:gtest_main",
435+
"@spirv_headers//:spirv_common_headers",
434436
],
435437
) for f in glob(
436438
[

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ vars = {
1414

1515
're2_revision': 'c84a140c93352cdabbfb547c531be34515b12228',
1616

17-
'spirv_headers_revision': '50daff941d88609b4d2ad076eae558e727f8e5cd',
17+
'spirv_headers_revision': '2a611a970fdbc41ac2e3e328802aed9985352dca',
1818
}
1919

2020
deps = {

include/spirv-tools/libspirv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ typedef enum spv_ext_inst_type_t {
369369
SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION,
370370
SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100,
371371
SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION,
372+
SPV_EXT_INST_TYPE_TOSA_001000_1,
372373

373374
// Multiple distinct extended instruction set types could return this
374375
// value, if they are prefixed with NonSemantic. and are otherwise

source/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set(EI_amd_ballot "${GRAMMAR_DIR}/extinst.spv-amd-shader-ballot.grammar.json")
3131
set(EI_ns_debuginfo "${GRAMMAR_DIR}/extinst.nonsemantic.shader.debuginfo.100.grammar.json")
3232
set(EI_ns_clspvreflect "${GRAMMAR_DIR}/extinst.nonsemantic.clspvreflection.grammar.json")
3333
set(EI_ns_vkspreflect "${GRAMMAR_DIR}/extinst.nonsemantic.vkspreflection.grammar.json")
34+
set(EI_tosa_001000_1 "${GRAMMAR_DIR}/extinst.tosa.001000.1.grammar.json")
3435

3536
set(CORE_TABLES_BODY_INC_FILE ${spirv-tools_BINARY_DIR}/core_tables_body.inc)
3637
set(CORE_TABLES_HEADER_INC_FILE ${spirv-tools_BINARY_DIR}/core_tables_header.inc)
@@ -50,6 +51,7 @@ add_custom_command(OUTPUT ${CORE_TABLES_BODY_INC_FILE} ${CORE_TABLES_HEADER_INC_
5051
--extinst=,${EI_debuginfo}
5152
--extinst=,${EI_ns_clspvreflect}
5253
--extinst=,${EI_ns_vkspreflect}
54+
--extinst=TOSA_,${EI_tosa_001000_1}
5355
DEPENDS ${GGT_SCRIPT}
5456
${SPIRV_CORE_GRAMMAR_JSON_FILE}
5557
${EI_glsl}
@@ -63,6 +65,7 @@ add_custom_command(OUTPUT ${CORE_TABLES_BODY_INC_FILE} ${CORE_TABLES_HEADER_INC_
6365
${EI_debuginfo}
6466
${EI_ns_clspvreflect}
6567
${EI_ns_vkspreflect}
68+
${EI_tosa_001000_1}
6669
COMMENT "Generate grammar tables")
6770
add_custom_target(spirv-tools-tables DEPENDS ${CORE_TABLES_BODY_INC_FILE} ${CORE_TABLES_HEADER_INC_FILE})
6871

source/ext_inst.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) {
5555
if (!strncmp("NonSemantic.VkspReflection.", name, 27)) {
5656
return SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION;
5757
}
58+
if (!strcmp("TOSA.001000.1", name)) {
59+
return SPV_EXT_INST_TYPE_TOSA_001000_1;
60+
}
5861
// ensure to add any known non-semantic extended instruction sets
5962
// above this point, and update spvExtInstIsNonSemantic()
6063
if (!strncmp("NonSemantic.", name, 12)) {

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ set(TEST_SOURCES
108108
ext_inst.glsl_test.cpp
109109
ext_inst.non_semantic_test.cpp
110110
ext_inst.opencl_test.cpp
111+
ext_inst.tosa_test.cpp
111112
ext_inst_lookup_test.cpp
112113
fix_word_test.cpp
113114
generator_magic_number_test.cpp

test/ext_inst.tosa_test.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) 2024-2025 Arm Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <string>
16+
17+
#include "gmock/gmock.h"
18+
#include "source/util/string_utils.h"
19+
#include "spirv/unified1/TOSA.001000.1.h"
20+
#include "test/test_fixture.h"
21+
#include "test/unit_spirv.h"
22+
23+
namespace spvtools {
24+
namespace {
25+
26+
using spvtest::Concatenate;
27+
using spvtest::MakeInstruction;
28+
using spvtest::TextToBinaryTest;
29+
using testing::Eq;
30+
using utils::MakeVector;
31+
32+
TEST_F(TextToBinaryTest, TOSAImportTest) {
33+
const std::string src = "%1 = OpExtInstImport \"TOSA.001000.1\"";
34+
EXPECT_THAT(CompiledInstructions(src),
35+
Eq(MakeInstruction(spv::Op::OpExtInstImport, {1},
36+
MakeVector("TOSA.001000.1"))));
37+
}
38+
39+
TEST_F(TextToBinaryTest, TOSAInstructionSmokeTest) {
40+
const std::string src =
41+
"%1 = OpExtInstImport \"TOSA.001000.1\"\n"
42+
"%3 = OpExtInst %2 %1 ARGMAX %4 %5 %6\n";
43+
44+
// First make sure it assembles correctly.
45+
EXPECT_THAT(
46+
CompiledInstructions(src),
47+
Eq(Concatenate({MakeInstruction(spv::Op::OpExtInstImport, {1},
48+
MakeVector("TOSA.001000.1")),
49+
MakeInstruction(spv::Op::OpExtInst,
50+
{2, 3, 1, TOSAARGMAX, 4, 5, 6})})))
51+
<< src;
52+
// Now check the round trip through the disassembler.
53+
EXPECT_THAT(EncodeAndDecodeSuccessfully(src), src) << src;
54+
}
55+
56+
} // namespace
57+
} // namespace spvtools

0 commit comments

Comments
 (0)