Skip to content

Commit

Permalink
add passes for vulkan-shader-profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
rjodinchr committed Feb 22, 2024
1 parent 1b643ea commit 0f44668
Show file tree
Hide file tree
Showing 18 changed files with 1,102 additions and 17 deletions.
7 changes: 7 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ SPVTOOLS_OUT_PATH=$(if $(call host-path-is-absolute,$(TARGET_OUT)),$(TARGET_OUT)
ifeq ($(SPVHEADERS_LOCAL_PATH),)
SPVHEADERS_LOCAL_PATH := $(LOCAL_PATH)/external/spirv-headers
endif
ifeq ($(VKHEADERS_LOCAL_PATH),)
VKHEADERS_LOCAL_PATH := $(LOCAL_PATH)/external/vulkan-headers
endif

SPVTOOLS_SRC_FILES := \
source/assembly_grammar.cpp \
Expand Down Expand Up @@ -192,6 +195,8 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/upgrade_memory_model.cpp \
source/opt/value_number_table.cpp \
source/opt/vector_dce.cpp \
source/opt/vksp_passes.cpp \
source/opt/vksp_passes.h \
source/opt/workaround1209.cpp \
source/opt/wrap_opkill.cpp

Expand Down Expand Up @@ -289,6 +294,7 @@ $(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-bal
$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-explicit-vertex-parameter,""))
$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),spv-amd-shader-trinary-minmax,""))
$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),nonsemantic.clspvreflection,""))
$(eval $(call gen_spvtools_vendor_tables,$(SPVTOOLS_OUT_PATH),nonsemantic.vkspreflection,""))

define gen_spvtools_enum_string_mapping
$(call generate-file-dir,$(1)/extension_enum.inc.inc)
Expand Down Expand Up @@ -354,6 +360,7 @@ LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/source \
$(SPVHEADERS_LOCAL_PATH)/include \
$(VKHEADERS_LOCAL_PATH)/include \
$(SPVTOOLS_OUT_PATH)
LOCAL_CXXFLAGS:=-std=c++17 -fno-exceptions -fno-rtti -Werror
LOCAL_STATIC_LIBRARIES:=SPIRV-Tools
Expand Down
4 changes: 4 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ generate_vendor_tables(extension = "debuginfo")

generate_vendor_tables(extension = "nonsemantic.clspvreflection")

generate_vendor_tables(extension = "nonsemantic.vkspreflection")

generate_vendor_tables(
extension = "opencl.debuginfo.100",
operand_kind_prefix = "CLDEBUG100_",
Expand Down Expand Up @@ -147,6 +149,7 @@ cc_library(
":gen_vendor_tables_debuginfo",
":gen_vendor_tables_nonsemantic_clspvreflection",
":gen_vendor_tables_nonsemantic_shader_debuginfo_100",
":gen_vendor_tables_nonsemantic_vkspreflection",
":gen_vendor_tables_opencl_debuginfo_100",
":gen_vendor_tables_spv_amd_gcn_shader",
":gen_vendor_tables_spv_amd_shader_ballot",
Expand Down Expand Up @@ -201,6 +204,7 @@ cc_library(
deps = [
":spirv_tools_internal",
"@spirv_headers//:spirv_common_headers",
"@vulkan_headers//:vulkan_headers_config",
],
)

Expand Down
8 changes: 8 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if (defined(is_fuchsia_tree) && is_fuchsia_tree) {
spvtools_build_executables = true
}

vulkan_headers = spirv_tools_vulkan_headers_dir
spirv_headers = spirv_tools_spirv_headers_dir
spirv_is_winuwp = is_win && target_os == "winuwp"

Expand Down Expand Up @@ -331,6 +332,10 @@ spvtools_vendor_tables = [
"nonsemantic.shader.debuginfo.100",
"SHDEBUG100_",
],
[
"nonsemantic.vkspreflection",
"...nil...",
],
]

foreach(table_def, spvtools_vendor_tables) {
Expand Down Expand Up @@ -810,6 +815,8 @@ static_library("spvtools_opt") {
"source/opt/value_number_table.h",
"source/opt/vector_dce.cpp",
"source/opt/vector_dce.h",
"source/opt/vksp_passes.cpp",
"source/opt/vksp_passes.h",
"source/opt/workaround1209.cpp",
"source/opt/workaround1209.h",
"source/opt/wrap_opkill.cpp",
Expand All @@ -825,6 +832,7 @@ static_library("spvtools_opt") {
":spvtools_headers",
":spvtools_language_header_cldebuginfo100",
":spvtools_language_header_vkdebuginfo100",
"${vulkan_headers}:vulkan_headers"
]

if (build_with_chromium) {
Expand Down
5 changes: 5 additions & 0 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ vars = {

're2_revision': 'ed9fc269e2fdb299afe59e912928d31ad3fdcf7d',
'spirv_headers_revision': '05cc486580771e4fa7ddc89f5c9ee1e97382689a',
'vulkan_headers_revision': '217e93c664ec6704ec2d8c36fa116c1a4a1e2d40',
}

deps = {
Expand All @@ -35,5 +36,9 @@ deps = {
'external/spirv-headers':
Var('github') + '/KhronosGroup/SPIRV-Headers.git@' +
Var('spirv_headers_revision'),

'external/vulkan-headers':
Var('github') + '/KhronosGroup/Vulkan-Headers.git@' +
Var('vulkan_headers_revision'),
}

28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ Some versions of SPIRV-Tools are tagged as stable releases (see
[tags](https://github.com/KhronosGroup/SPIRV-Tools/tags) on github).
These versions undergo extra testing.
Releases are not directly related to releases (or versions) of
[SPIRV-Headers][spirv-headers].
Releases of SPIRV-Tools are tested against the version of SPIRV-Headers listed
in the [DEPS](DEPS) file.
[SPIRV-Headers][spirv-headers] and [Vulkan-Headers][vulkan-headers].
Releases of SPIRV-Tools are tested against the version of SPIRV-Headers and
Vulkan-Headers listed in the [DEPS](DEPS) file.
The release generally uses the most recent compatible version of SPIRV-Headers
available at the time of release.
No version of SPIRV-Headers other than the one listed in the DEPS file is
guaranteed to work with the SPIRV-Tools release.
and Vulkan-Headers available at the time of release.
No version of SPIRV-Headers and Vulkan-Headers other than the one listed in the
DEPS file is guaranteed to work with the SPIRV-Tools release.

## Supported features

### Assembler, binary parser, and disassembler

* Support for SPIR-V 1.0, through 1.5
* Based on SPIR-V syntax described by JSON grammar files in the
[SPIRV-Headers](https://github.com/KhronosGroup/SPIRV-Headers) repository.
[SPIRV-Headers][spirv-headers] repository.
* Usually, support for a new version of SPIR-V is ready within days after
publication.
* Support for extended instruction sets:
Expand Down Expand Up @@ -289,11 +289,12 @@ Example of getting sources, assuming SPIRV-Tools is configured as a standalone p

For some kinds of development, you may need the latest sources from the third-party projects:

git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-tools/external/spirv-headers
git clone https://github.com/google/googletest.git spirv-tools/external/googletest
git clone https://github.com/google/effcee.git spirv-tools/external/effcee
git clone https://github.com/google/re2.git spirv-tools/external/re2
git clone https://github.com/abseil/abseil-cpp.git spirv-tools/external/abseil_cpp
git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-tools/external/spirv-headers
git clone https://github.com/KhronosGroup/Vulkan-Headers.git spirv-tools/external/vulkan-headers
git clone https://github.com/google/googletest.git spirv-tools/external/googletest
git clone https://github.com/google/effcee.git spirv-tools/external/effcee
git clone https://github.com/google/re2.git spirv-tools/external/re2
git clone https://github.com/abseil/abseil-cpp.git spirv-tools/external/abseil_cpp

#### Dependency on Effcee

Expand Down Expand Up @@ -322,6 +323,8 @@ Effcee itself depends on [RE2][re2], and RE2 depends on [Abseil][abseil-cpp].
* `include/`: API clients should add this directory to the include search path
* `external/spirv-headers`: Intended location for
[SPIR-V headers][spirv-headers], not provided
* `external/vulkan-headers`: Intended location for
[Vulkan headers][vulkan-headers], not provided
* `include/spirv-tools/libspirv.h`: C API public interface
* `source/`: API implementation
* `test/`: Tests, using the [googletest][googletest] framework
Expand Down Expand Up @@ -792,6 +795,7 @@ limitations under the License.
[spirv-tools-mailing-list]: https://www.khronos.org/spir/spirv-tools-mailing-list
[spirv-registry]: https://www.khronos.org/registry/spir-v/
[spirv-headers]: https://github.com/KhronosGroup/SPIRV-Headers
[vulkan-headers]: https://github.com/KhronosGroup/Vulkan-Headers
[googletest]: https://github.com/google/googletest
[googletest-pull-612]: https://github.com/google/googletest/pull/612
[googletest-issue-610]: https://github.com/google/googletest/issues/610
Expand Down
1 change: 1 addition & 0 deletions build_overrides/spirv_tools.gni
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ spirv_tools_standalone = true
# The path to SPIRV-Tools' dependencies
spirv_tools_googletest_dir = "//external/googletest"
spirv_tools_spirv_headers_dir = "//external/spirv-headers"
spirv_tools_vulkan_headers_dir = "//external/vulkan-headers"
4 changes: 4 additions & 0 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ else()
"SPIRV-Headers was not found - please checkout a copy under external/.")
endif()

if (NOT DEFINED VULKAN_HEADER_INCLUDE_DIR)
set(VULKAN_HEADER_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vulkan-headers)
endif()

if (NOT ${SPIRV_SKIP_TESTS})
# Find gmock if we can. If it's not already configured, then try finding
# it in external/googletest.
Expand Down
1 change: 1 addition & 0 deletions include/spirv-tools/libspirv.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ typedef enum spv_ext_inst_type_t {
SPV_EXT_INST_TYPE_OPENCL_DEBUGINFO_100,
SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION,
SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100,
SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION,

// Multiple distinct extended instruction set types could return this
// value, if they are prefixed with NonSemantic. and are otherwise
Expand Down
135 changes: 135 additions & 0 deletions include/spirv-tools/optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,141 @@ Optimizer::PassToken CreateInvocationInterlockPlacementPass();
// Creates a pass to add/remove maximal reconvergence execution mode.
// This pass either adds or removes maximal reconvergence from all entry points.
Optimizer::PassToken CreateModifyMaximalReconvergencePass(bool add);

struct vksp_push_constant {
uint32_t offset;
uint32_t size;
uint32_t stageFlags;
const char* pValues;
};

#define VKSP_DESCRIPTOR_TYPE_STORAGE_BUFFER_COUNTER_BITS (0xf0000000)
#define VKSP_DESCRIPTOR_TYPE_STORAGE_BUFFER_COUNTER_MASK \
(~VKSP_DESCRIPTOR_TYPE_STORAGE_BUFFER_COUNTER_BITS)
#define VKSP_DESCRIPTOR_TYPE_STORAGE_BUFFER_COUNTER \
(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER | \
VKSP_DESCRIPTOR_TYPE_STORAGE_BUFFER_COUNTER_BITS)
struct vksp_descriptor_set {
uint32_t ds;
uint32_t binding;
uint32_t type;
union {
struct {
uint32_t flags;
uint32_t queueFamilyIndexCount;
uint32_t sharingMode;
uint32_t size;
uint32_t usage;
uint32_t range;
uint32_t offset;
uint32_t memorySize;
uint32_t memoryType;
uint32_t bindOffset;
} buffer;
struct {
uint32_t imageLayout;
uint32_t imageFlags;
uint32_t imageType;
uint32_t format;
uint32_t width;
uint32_t height;
uint32_t depth;
uint32_t mipLevels;
uint32_t arrayLayers;
uint32_t samples;
uint32_t tiling;
uint32_t usage;
uint32_t sharingMode;
uint32_t queueFamilyIndexCount;
uint32_t initialLayout;
uint32_t aspectMask;
uint32_t baseMipLevel;
uint32_t levelCount;
uint32_t baseArrayLayer;
uint32_t layerCount;
uint32_t viewFlags;
uint32_t viewType;
uint32_t viewFormat;
uint32_t component_a;
uint32_t component_b;
uint32_t component_g;
uint32_t component_r;
uint32_t memorySize;
uint32_t memoryType;
uint32_t bindOffset;
} image;
struct {
uint32_t flags;
uint32_t magFilter;
uint32_t minFilter;
uint32_t mipmapMode;
uint32_t addressModeU;
uint32_t addressModeV;
uint32_t addressModeW;
union {
float fMipLodBias;
uint32_t uMipLodBias;
};
uint32_t anisotropyEnable;
union {
float fMaxAnisotropy;
uint32_t uMaxAnisotropy;
};
uint32_t compareEnable;
uint32_t compareOp;
union {
float fMinLod;
uint32_t uMinLod;
};
union {
float fMaxLod;
uint32_t uMaxLod;
};
uint32_t borderColor;
uint32_t unnormalizedCoordinates;
} sampler;
};
};

struct vksp_configuration {
const char* enabledExtensionNames;
uint32_t specializationInfoDataSize;
const char* specializationInfoData;
const char* shaderName;
const char* entryPoint;
uint32_t groupCountX;
uint32_t groupCountY;
uint32_t groupCountZ;
};

struct vksp_specialization_map_entry {
uint32_t constantID;
uint32_t offset;
uint32_t size;
};

struct vksp_counter {
uint32_t index;
const char* name;
};

// Creates a vksp insert reflection info pass.
// This pass inserts vksp non semantic instructions representing the different
// vksp structures passed in argument in the module.
Optimizer::PassToken CreateInsertVkspReflectInfoPass(
std::vector<vksp_push_constant>* pc, std::vector<vksp_descriptor_set>* ds,
std::vector<vksp_specialization_map_entry>* me, vksp_configuration* config);

// Creates a vksp extract reflection info pass.
// This pass extracts the vksp information into the different vksp structures
// from the vksp non semantic instructions present in the module.
// It also adds a global counter for the whole module as well as replacing all
// `StartCounter` and `StopCounter` non semantic instructions by a real counter.
Optimizer::PassToken CreateExtractVkspReflectInfoPass(
std::vector<vksp_push_constant>* pc, std::vector<vksp_descriptor_set>* ds,
std::vector<vksp_specialization_map_entry>* me,
std::vector<vksp_counter>* counters, vksp_configuration* config);

} // namespace spvtools

#endif // INCLUDE_SPIRV_TOOLS_OPTIMIZER_HPP_
1 change: 1 addition & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ spvtools_vendor_tables("debuginfo" "debuginfo" "")
spvtools_vendor_tables("opencl.debuginfo.100" "cldi100" "CLDEBUG100_")
spvtools_vendor_tables("nonsemantic.shader.debuginfo.100" "shdi100" "SHDEBUG100_")
spvtools_vendor_tables("nonsemantic.clspvreflection" "clspvreflection" "")
spvtools_vendor_tables("nonsemantic.vkspreflection" "vkspreflection" "")
spvtools_extinst_lang_headers("DebugInfo" ${DEBUGINFO_GRAMMAR_JSON_FILE})
spvtools_extinst_lang_headers("OpenCLDebugInfo100" ${CLDEBUGINFO100_GRAMMAR_JSON_FILE})
spvtools_extinst_lang_headers("NonSemanticShaderDebugInfo100" ${VKDEBUGINFO100_GRAMMAR_JSON_FILE})
Expand Down
10 changes: 9 additions & 1 deletion source/ext_inst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "glsl.std.450.insts.inc"
#include "nonsemantic.clspvreflection.insts.inc"
#include "nonsemantic.shader.debuginfo.100.insts.inc"
#include "nonsemantic.vkspreflection.insts.inc"
#include "opencl.debuginfo.100.insts.inc"
#include "opencl.std.insts.inc"

Expand Down Expand Up @@ -62,6 +63,9 @@ static const spv_ext_inst_group_t kGroups_1_0[] = {
{SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION,
ARRAY_SIZE(nonsemantic_clspvreflection_entries),
nonsemantic_clspvreflection_entries},
{SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION,
ARRAY_SIZE(nonsemantic_vkspreflection_entries),
nonsemantic_vkspreflection_entries},
};

static const spv_ext_inst_table_t kTable_1_0 = {ARRAY_SIZE(kGroups_1_0),
Expand Down Expand Up @@ -138,6 +142,9 @@ spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) {
if (!strncmp("NonSemantic.ClspvReflection.", name, 28)) {
return SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION;
}
if (!strncmp("NonSemantic.VkspReflection.", name, 27)) {
return SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION;
}
// ensure to add any known non-semantic extended instruction sets
// above this point, and update spvExtInstIsNonSemantic()
if (!strncmp("NonSemantic.", name, 12)) {
Expand All @@ -149,7 +156,8 @@ spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) {
bool spvExtInstIsNonSemantic(const spv_ext_inst_type_t type) {
if (type == SPV_EXT_INST_TYPE_NONSEMANTIC_UNKNOWN ||
type == SPV_EXT_INST_TYPE_NONSEMANTIC_SHADER_DEBUGINFO_100 ||
type == SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION) {
type == SPV_EXT_INST_TYPE_NONSEMANTIC_CLSPVREFLECTION ||
type == SPV_EXT_INST_TYPE_NONSEMANTIC_VKSPREFLECTION) {
return true;
}
return false;
Expand Down

0 comments on commit 0f44668

Please sign in to comment.