Support Android app-specific extensions in shaders

This commit is contained in:
Brad Davis 2019-02-15 14:16:58 -08:00
parent 578bc4fc89
commit 51884155ee
8 changed files with 52 additions and 14 deletions

View file

@ -270,6 +270,16 @@ macro(AUTOSCRIBE_SHADER_LIBS)
set(AUTOSCRIBE_SHADERGEN_COMMANDS_FILE ${CMAKE_CURRENT_BINARY_DIR}/shadergen.txt)
file(WRITE ${AUTOSCRIBE_SHADERGEN_COMMANDS_FILE} "${AUTOSCRIBE_SHADERGEN_COMMANDS}")
if (HIFI_ANDROID)
if (
(${HIFI_ANDROID_APP} STREQUAL "questInterface") OR
(${HIFI_ANDROID_APP} STREQUAL "questFramePlayer") OR
(${HIFI_ANDROID_APP} STREQUAL "framePlayer")
)
set(EXTRA_SHADERGEN_ARGS "--extensions EXT_clip_cull_distance")
endif()
endif()
# A custom python script which will generate all our shader artifacts
add_custom_command(
OUTPUT ${SCRIBED_SHADERS} ${SPIRV_SHADERS} ${REFLECTED_SHADERS}
@ -279,6 +289,7 @@ macro(AUTOSCRIBE_SHADER_LIBS)
--tools-dir ${VCPKG_TOOLS_DIR}
--build-dir ${CMAKE_CURRENT_BINARY_DIR}
--source-dir ${CMAKE_SOURCE_DIR}
${EXTRA_SHADERGEN_ARGS}
DEPENDS ${AUTOSCRIBE_SHADER_HEADERS} ${CMAKE_SOURCE_DIR}/tools/shadergen.py ${ALL_SCRIBE_SHADERS})
add_custom_target(shadergen DEPENDS ${SCRIBED_SHADERS} ${SPIRV_SHADERS} ${REFLECTED_SHADERS})

View file

@ -1,6 +1,3 @@
#version 310 es
#define GPU_GLES
#define GPU_GLES_310
#define BITFIELD highp int
#define LAYOUT(X) layout(X)
#define LAYOUT_STD140(X) layout(std140, X)
@ -9,7 +6,7 @@
#define gl_VertexID gl_VertexIndex
#endif
#extension GL_EXT_texture_buffer : enable
#ifndef VULKAN
#if defined(HAVE_EXT_clip_cull_distance) && !defined(VULKAN)
#extension GL_EXT_clip_cull_distance : enable
#endif
precision highp float;

View file

@ -0,0 +1,3 @@
#version 310 es
#define GPU_GLES
#define GPU_GLES_310

View file

@ -1,5 +1,3 @@
#version 410 core
#define GPU_GL410
#define BITFIELD int
#if defined(VULKAN)
#extension GL_ARB_shading_language_420pack : require

View file

@ -0,0 +1,2 @@
#version 410 core
#define GPU_GL410

View file

@ -1,5 +1,3 @@
#version 450 core
#define GPU_GL450
#define GPU_SSBO_TRANSFORM_OBJECT
#define BITFIELD int
#define LAYOUT(X) layout(X)

View file

@ -0,0 +1,2 @@
#version 450 core
#define GPU_GL450

View file

@ -49,11 +49,36 @@ def getCommonScribeArgs(scribefile, includeLibs):
scribeArgs.append(scribefile)
return scribeArgs
def getDialectAndVariantHeaders(dialect, variant):
extensionsHeaderMutex = Lock()
def getExtensionsHeader(dialect, variant, extensions):
extensionHeader = '{}/extensions_{}_{}.glsl'.format(args.build_dir, dialect, variant)
global extensionsHeaderMutex
extensionsHeaderMutex.acquire()
if not os.path.exists(extensionHeader):
extensionsDefines = []
for extension in extensions:
extensionsDefines.append('#define HAVE_{}'.format(extension))
# make sure we end with a line feed
extensionsDefines.append("\r\n")
with open(extensionHeader, "w") as f:
f.write('\r\n'.join(extensionsDefines))
extensionsHeaderMutex.release()
return extensionHeader
def getDialectAndVariantHeaders(dialect, variant, extensions=None):
result = []
headerPath = args.source_dir + '/libraries/shaders/headers/'
variantHeader = headerPath + ('stereo.glsl' if (variant == 'stereo') else 'mono.glsl')
versionHeader = headerPath + dialect + '/version.glsl'
result.append(versionHeader)
if extensions is not None:
result.append(getExtensionsHeader(dialect, variant, extensions))
dialectHeader = headerPath + dialect + '/header.glsl'
return [dialectHeader, variantHeader]
result.append(dialectHeader)
variantHeader = headerPath + ('stereo.glsl' if (variant == 'stereo') else 'mono.glsl')
result.append(variantHeader)
return result
class ScribeDependenciesCache:
cache = {}
@ -170,7 +195,7 @@ def processCommand(line):
scribeDepCache.gen(scribeFile, libs, dialect, variant)
scribeArgs = getCommonScribeArgs(scribeFile, libs)
for header in getDialectAndVariantHeaders(dialect, variant):
for header in getDialectAndVariantHeaders(dialect, variant, args.extensions):
scribeArgs.extend(['-H', header])
scribeArgs.extend(['-o', unoptGlslFile])
executeSubprocess(scribeArgs)
@ -218,6 +243,7 @@ def main():
parser = ArgumentParser(description='Generate shader artifacts.')
parser.add_argument('--extensions', type=str, nargs='*', help='Available extensions for the shaders')
parser.add_argument('--commands', type=argparse.FileType('r'), help='list of commands to execute')
parser.add_argument('--tools-dir', type=str, help='location of the host compatible binaries')
parser.add_argument('--build-dir', type=str, help='The build directory base path')
@ -230,8 +256,8 @@ args = None
if len(sys.argv) == 1:
# for debugging
sourceDir = expanduser('~/git/hifi')
toolsDir = os.path.join(expanduser('~/git/vcpkg'), 'installed', 'x64-windows', 'tools')
buildPath = sourceDir + '/build'
toolsDir = 'd:/hifi/vcpkg/android/fd82f0a8/installed/x64-windows/tools'
buildPath = sourceDir + '/build_android'
commandsPath = buildPath + '/libraries/shaders/shadergen.txt'
shaderDir = buildPath + '/libraries/shaders'
testArgs = '--commands {} --tools-dir {} --build-dir {} --source-dir {}'.format(
@ -239,6 +265,7 @@ if len(sys.argv) == 1:
).split()
testArgs.append('--debug')
testArgs.append('--force')
testArgs.extend('--extensions EXT_clip_cull_distance'.split())
#testArgs.append('--dry-run')
args = parser.parse_args(testArgs)
else: