GL_EXT_spirv_intrinsics - Port extensions
Add mechanism to use GL_EXT_spirv_intrinsics headers in glslang. Ported GL_EXT_shader_realtime_clock as an example.
This commit is contained in:
parent
b9ba4c5743
commit
035a3bbc4a
14
BUILD.bazel
14
BUILD.bazel
@ -49,6 +49,11 @@ py_binary(
|
|||||||
srcs = ["build_info.py"],
|
srcs = ["build_info.py"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
py_binary(
|
||||||
|
name = "gen_extension_headers",
|
||||||
|
srcs = ["gen_extension_headers.py"],
|
||||||
|
)
|
||||||
|
|
||||||
genrule(
|
genrule(
|
||||||
name = "gen_build_info_h",
|
name = "gen_build_info_h",
|
||||||
srcs = ["CHANGES.md", "build_info.h.tmpl"],
|
srcs = ["CHANGES.md", "build_info.h.tmpl"],
|
||||||
@ -58,6 +63,14 @@ genrule(
|
|||||||
tools = [":build_info"],
|
tools = [":build_info"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
genrule(
|
||||||
|
name = "gen_extension_headers_h",
|
||||||
|
srcs = ["glslang/ExtensionHeaders", "gen_extension_headers.py"],
|
||||||
|
outs = ["glslang/glsl_intrinsic_header.h"],
|
||||||
|
cmd_bash = "$(location gen_extension_headers) -i $(location glslang/ExtensionHeaders) -o $(location glslang/glsl_intrinsic_header.h)",
|
||||||
|
tools = [":gen_extension_headers"],
|
||||||
|
)
|
||||||
|
|
||||||
COMMON_COPTS = select({
|
COMMON_COPTS = select({
|
||||||
"@bazel_tools//src/conditions:windows": [""],
|
"@bazel_tools//src/conditions:windows": [""],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
@ -206,6 +219,7 @@ cc_binary(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"StandAlone/StandAlone.cpp",
|
"StandAlone/StandAlone.cpp",
|
||||||
"StandAlone/Worklist.h",
|
"StandAlone/Worklist.h",
|
||||||
|
":glslang/glsl_intrinsic_header.h"
|
||||||
],
|
],
|
||||||
copts = COMMON_COPTS,
|
copts = COMMON_COPTS,
|
||||||
deps = [
|
deps = [
|
||||||
|
18
BUILD.gn
18
BUILD.gn
@ -69,6 +69,23 @@ action("glslang_build_info") {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
action("glslang_extension_headers") {
|
||||||
|
script = "gen_extension_headers.py"
|
||||||
|
|
||||||
|
out_file = "${target_gen_dir}/include/glslang/glsl_intrinsic_header.h"
|
||||||
|
|
||||||
|
inputs = [
|
||||||
|
script
|
||||||
|
]
|
||||||
|
outputs = [ out_file ]
|
||||||
|
args = [
|
||||||
|
"-i",
|
||||||
|
rebase_path("glslang/ExtensionHeaders", root_build_dir),
|
||||||
|
"-o",
|
||||||
|
rebase_path(out_file, root_build_dir),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
spirv_tools_dir = glslang_spirv_tools_dir
|
spirv_tools_dir = glslang_spirv_tools_dir
|
||||||
if (!defined(glslang_angle)) {
|
if (!defined(glslang_angle)) {
|
||||||
glslang_angle = false
|
glslang_angle = false
|
||||||
@ -302,6 +319,7 @@ executable("glslang_validator") {
|
|||||||
":glslang_build_info",
|
":glslang_build_info",
|
||||||
":glslang_default_resource_limits_sources",
|
":glslang_default_resource_limits_sources",
|
||||||
":glslang_sources",
|
":glslang_sources",
|
||||||
|
":glslang_extension_headers",
|
||||||
]
|
]
|
||||||
public_configs = [ ":glslang_hlsl" ]
|
public_configs = [ ":glslang_hlsl" ]
|
||||||
|
|
||||||
|
@ -31,6 +31,22 @@
|
|||||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
find_host_package(PythonInterp 3 REQUIRED)
|
||||||
|
|
||||||
|
set(GLSLANG_INTRINSIC_H "${GLSLANG_GENERATED_INCLUDEDIR}/glslang/glsl_intrinsic_header.h")
|
||||||
|
set(GLSLANG_INTRINSIC_PY "${CMAKE_SOURCE_DIR}/gen_extension_headers.py")
|
||||||
|
set(GLSLANG_INTRINSIC_HEADER_DIR "${CMAKE_SOURCE_DIR}/glslang/ExtensionHeaders")
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${GLSLANG_INTRINSIC_H}
|
||||||
|
COMMAND ${PYTHON_EXECUTABLE} "${GLSLANG_INTRINSIC_PY}"
|
||||||
|
"-i" ${GLSLANG_INTRINSIC_HEADER_DIR}
|
||||||
|
"-o" ${GLSLANG_INTRINSIC_H}
|
||||||
|
DEPENDS ${GLSLANG_INTRINSIC_PY}
|
||||||
|
COMMENT "Generating ${GLSLANG_INTRINSIC_H}")
|
||||||
|
|
||||||
|
#add_custom_target(glslangValidator DEPENDS ${GLSLANG_INTRINSIC_H})
|
||||||
|
|
||||||
add_library(glslang-default-resource-limits
|
add_library(glslang-default-resource-limits
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/ResourceLimits.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/ResourceLimits.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/resource_limits_c.cpp)
|
${CMAKE_CURRENT_SOURCE_DIR}/resource_limits_c.cpp)
|
||||||
@ -41,7 +57,7 @@ target_include_directories(glslang-default-resource-limits
|
|||||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||||
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>)
|
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>)
|
||||||
|
|
||||||
set(SOURCES StandAlone.cpp DirStackFileIncluder.h)
|
set(SOURCES StandAlone.cpp DirStackFileIncluder.h ${GLSLANG_INTRINSIC_H})
|
||||||
|
|
||||||
add_executable(glslangValidator ${SOURCES})
|
add_executable(glslangValidator ${SOURCES})
|
||||||
set_property(TARGET glslangValidator PROPERTY FOLDER tools)
|
set_property(TARGET glslangValidator PROPERTY FOLDER tools)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
// Copyright (C) 2013-2016 LunarG, Inc.
|
// Copyright (C) 2013-2016 LunarG, Inc.
|
||||||
// Copyright (C) 2016-2020 Google, Inc.
|
// Copyright (C) 2016-2020 Google, Inc.
|
||||||
|
// Modifications Copyright(C) 2021 Advanced Micro Devices, Inc.All rights reserved.
|
||||||
//
|
//
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
@ -65,6 +66,8 @@
|
|||||||
// Build-time generated includes
|
// Build-time generated includes
|
||||||
#include "glslang/build_info.h"
|
#include "glslang/build_info.h"
|
||||||
|
|
||||||
|
#include "glslang/glsl_intrinsic_header.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
GLSLANG_EXPORT void ShOutputHtml();
|
GLSLANG_EXPORT void ShOutputHtml();
|
||||||
}
|
}
|
||||||
@ -263,6 +266,7 @@ protected:
|
|||||||
|
|
||||||
// Track the user's #define and #undef from the command line.
|
// Track the user's #define and #undef from the command line.
|
||||||
TPreamble UserPreamble;
|
TPreamble UserPreamble;
|
||||||
|
std::string PreambleString;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create the default name for saving a binary if -o is not provided.
|
// Create the default name for saving a binary if -o is not provided.
|
||||||
@ -1204,8 +1208,17 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
|
|||||||
"Use '-e <name>'.\n");
|
"Use '-e <name>'.\n");
|
||||||
shader->setSourceEntryPoint(sourceEntryPointName);
|
shader->setSourceEntryPoint(sourceEntryPointName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string intrinsicString = getIntrinsic(compUnit.text, compUnit.count);
|
||||||
|
|
||||||
|
PreambleString = "";
|
||||||
if (UserPreamble.isSet())
|
if (UserPreamble.isSet())
|
||||||
shader->setPreamble(UserPreamble.get());
|
PreambleString.append(UserPreamble.get());
|
||||||
|
|
||||||
|
if (!intrinsicString.empty())
|
||||||
|
PreambleString.append(intrinsicString);
|
||||||
|
|
||||||
|
shader->setPreamble(PreambleString.c_str());
|
||||||
shader->addProcesses(Processes);
|
shader->addProcesses(Processes);
|
||||||
|
|
||||||
#ifndef GLSLANG_WEB
|
#ifndef GLSLANG_WEB
|
||||||
|
98
gen_extension_headers.py
Normal file
98
gen_extension_headers.py
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Copyright (c) 2020 Google Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import glob
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
def generate_main(glsl_files, output_header_file):
|
||||||
|
# Write commit ID to output header file
|
||||||
|
with open(output_header_file, "w") as header_file:
|
||||||
|
# Copyright Notice
|
||||||
|
header_string = '/***************************************************************************\n'
|
||||||
|
header_string += ' *\n'
|
||||||
|
header_string += ' * Copyright (c) 2015-2021 The Khronos Group Inc.\n'
|
||||||
|
header_string += ' * Copyright (c) 2015-2021 Valve Corporation\n'
|
||||||
|
header_string += ' * Copyright (c) 2015-2021 LunarG, Inc.\n'
|
||||||
|
header_string += ' * Copyright (c) 2015-2021 Google Inc.\n'
|
||||||
|
header_string += ' * Copyright (c) 2021 Advanced Micro Devices, Inc.All rights reserved.\n'
|
||||||
|
header_string += ' *\n'
|
||||||
|
header_string += ' ****************************************************************************/\n'
|
||||||
|
header_string += '#pragma once\n\n'
|
||||||
|
header_string += '#ifndef _INTRINSIC_EXTENSION_HEADER_H_\n'
|
||||||
|
header_string += '#define _INTRINSIC_EXTENSION_HEADER_H_\n\n'
|
||||||
|
header_file.write(header_string)
|
||||||
|
|
||||||
|
symbol_name_list = []
|
||||||
|
|
||||||
|
for i in glsl_files:
|
||||||
|
glsl_contents = open(i,"r").read()
|
||||||
|
|
||||||
|
filename = os.path.basename(i)
|
||||||
|
symbol_name = filename.split(".")[0]
|
||||||
|
symbol_name_list.append(symbol_name)
|
||||||
|
header_name = symbol_name + ".h"
|
||||||
|
header_str = 'std::string %s_GLSL = R"(\n%s\n)";\n' % (symbol_name, glsl_contents)
|
||||||
|
header_str += '\n'
|
||||||
|
header_file.write(header_str)
|
||||||
|
|
||||||
|
contents = ''
|
||||||
|
contents += '\n'
|
||||||
|
contents += 'std::string getIntrinsic(const char* const* shaders, int n) {\n'
|
||||||
|
contents += '\tstd::string shaderString = "";\n';
|
||||||
|
|
||||||
|
contents += '\tfor (int i = 0; i < n; i++) {\n'
|
||||||
|
|
||||||
|
for symbol_name in symbol_name_list:
|
||||||
|
contents += '\t\tif (strstr(shaders[i], "%s") != NULL) {\n' % (symbol_name)
|
||||||
|
contents += '\t\t shaderString.append(%s_GLSL);\n' % (symbol_name)
|
||||||
|
contents += '\t\t}\n'
|
||||||
|
|
||||||
|
contents += '\t}\n'
|
||||||
|
contents += '\treturn shaderString;\n';
|
||||||
|
contents += '}\n'
|
||||||
|
|
||||||
|
contents += '\n#endif\n'
|
||||||
|
header_file.write(contents)
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
raise Exception("Invalid number of arguments")
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while i < len(sys.argv):
|
||||||
|
opt = sys.argv[i]
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
if opt == "-i" or opt == "-o":
|
||||||
|
if i == len(sys.argv):
|
||||||
|
raise Exception("Expected path after {}".format(opt))
|
||||||
|
val = sys.argv[i]
|
||||||
|
i = i + 1
|
||||||
|
if (opt == "-i"):
|
||||||
|
input_dir = val
|
||||||
|
elif (opt == "-o"):
|
||||||
|
output_file = val
|
||||||
|
else:
|
||||||
|
raise Exception("Unknown flag {}".format(opt))
|
||||||
|
|
||||||
|
glsl_files = glob.glob(input_dir + '/*.glsl')
|
||||||
|
|
||||||
|
# Generate main header
|
||||||
|
generate_main(glsl_files, output_file)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
54
glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl
Normal file
54
glslang/ExtensionHeaders/GL_EXT_shader_realtime_clock.glsl
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
|
||||||
|
// Copyright (C) 2013-2016 LunarG, Inc.
|
||||||
|
// Copyright (C) 2016-2020 Google, Inc.
|
||||||
|
// Modifications Copyright(C) 2021 Advanced Micro Devices, Inc.All rights reserved.
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without
|
||||||
|
// modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// Redistributions of source code must retain the above copyright
|
||||||
|
// notice, this list of conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// Redistributions in binary form must reproduce the above
|
||||||
|
// copyright notice, this list of conditions and the following
|
||||||
|
// disclaimer in the documentation and/or other materials provided
|
||||||
|
// with the distribution.
|
||||||
|
//
|
||||||
|
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived
|
||||||
|
// from this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
|
||||||
|
#extension GL_EXT_spirv_intrinsics : enable
|
||||||
|
#extension GL_ARB_gpu_shader_int64 : enable
|
||||||
|
|
||||||
|
uvec2 clockRealtime2x32EXT(void) {
|
||||||
|
spirv_instruction (extensions = ["SPV_KHR_shader_clock"], capabilities = [5055], id = 5056)
|
||||||
|
uvec2 clockRealtime2x32EXT_internal(uint scope);
|
||||||
|
|
||||||
|
return clockRealtime2x32EXT_internal(1 /*Device scope*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t clockRealtimeEXT(void) {
|
||||||
|
spirv_instruction (extensions = ["SPV_KHR_shader_clock"], capabilities = [5055], id = 5056)
|
||||||
|
uint64_t clockRealtimeEXT_internal(uint scope);
|
||||||
|
|
||||||
|
return clockRealtimeEXT_internal(1 /*Device scope*/);
|
||||||
|
}
|
@ -3,7 +3,7 @@
|
|||||||
// Copyright (C) 2012-2016 LunarG, Inc.
|
// Copyright (C) 2012-2016 LunarG, Inc.
|
||||||
// Copyright (C) 2015-2020 Google, Inc.
|
// Copyright (C) 2015-2020 Google, Inc.
|
||||||
// Copyright (C) 2017 ARM Limited.
|
// Copyright (C) 2017 ARM Limited.
|
||||||
// Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
|
// Modifications Copyright (C) 2020-2021 Advanced Micro Devices, Inc. All rights reserved.
|
||||||
//
|
//
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
@ -4653,13 +4653,11 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
|
|||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// GL_ARB_shader_clock & GL_EXT_shader_realtime_clock
|
// GL_ARB_shader_clock
|
||||||
if (profile != EEsProfile && version >= 450) {
|
if (profile != EEsProfile && version >= 450) {
|
||||||
commonBuiltins.append(
|
commonBuiltins.append(
|
||||||
"uvec2 clock2x32ARB();"
|
"uvec2 clock2x32ARB();"
|
||||||
"uint64_t clockARB();"
|
"uint64_t clockARB();"
|
||||||
"uvec2 clockRealtime2x32EXT();"
|
|
||||||
"uint64_t clockRealtimeEXT();"
|
|
||||||
"\n");
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8408,9 +8406,6 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
|
|||||||
symbolTable.setFunctionExtensions("clockARB", 1, &E_GL_ARB_shader_clock);
|
symbolTable.setFunctionExtensions("clockARB", 1, &E_GL_ARB_shader_clock);
|
||||||
symbolTable.setFunctionExtensions("clock2x32ARB", 1, &E_GL_ARB_shader_clock);
|
symbolTable.setFunctionExtensions("clock2x32ARB", 1, &E_GL_ARB_shader_clock);
|
||||||
|
|
||||||
symbolTable.setFunctionExtensions("clockRealtimeEXT", 1, &E_GL_EXT_shader_realtime_clock);
|
|
||||||
symbolTable.setFunctionExtensions("clockRealtime2x32EXT", 1, &E_GL_EXT_shader_realtime_clock);
|
|
||||||
|
|
||||||
if (profile == EEsProfile && version < 320) {
|
if (profile == EEsProfile && version < 320) {
|
||||||
symbolTable.setVariableExtensions("gl_PrimitiveID", Num_AEP_geometry_shader, AEP_geometry_shader);
|
symbolTable.setVariableExtensions("gl_PrimitiveID", Num_AEP_geometry_shader, AEP_geometry_shader);
|
||||||
symbolTable.setVariableExtensions("gl_Layer", Num_AEP_geometry_shader, AEP_geometry_shader);
|
symbolTable.setVariableExtensions("gl_Layer", Num_AEP_geometry_shader, AEP_geometry_shader);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user