Rewrite genshaders.sh as a Python script that uses a manifest. (bug 1365859 part 1, r=bas)

--HG--
extra : rebase_source : a5b60ab1c5531c7e911fc6c6e522d4e7b8cc2497
This commit is contained in:
David Anderson 2017-05-19 12:32:13 -07:00
Родитель ac4efab30b
Коммит 8894231cd7
5 изменённых файлов: 143 добавлений и 59 удалений

Просмотреть файл

@ -13,11 +13,11 @@
#include <d3d11.h>
#include <dxgi1_2.h>
struct ShaderBytes;
namespace mozilla {
namespace layers {
struct ShaderBytes;
class DeviceAttachmentsD3D11
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DeviceAttachmentsD3D11);

Просмотреть файл

@ -0,0 +1,108 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import argparse
import codecs
import subprocess
import sys
import tempfile
import yaml
def shell_main():
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--output', type=str, required=True,
help='Output file')
parser.add_argument('manifest', type=str,
help='Manifest source file')
args = parser.parse_args()
with open(args.output, 'w') as out_file:
process_manifest(out_file, args.manifest)
def main(output_fp, input_filename):
process_manifest(output_fp, input_filename)
HEADER = """// AUTOGENERATED - DO NOT EDIT
namespace mozilla {
namespace layers {
struct ShaderBytes { const void* mData; size_t mLength; };
"""
FOOTER = """
} // namespace layers
} // namespace mozilla"""
def process_manifest(output_fp, manifest_filename):
with codecs.open(manifest_filename, 'r', 'UTF-8') as in_fp:
manifest = yaml.load(in_fp)
shader_folder, _ = os.path.split(manifest_filename)
output_fp.write(HEADER)
for block in manifest:
if 'type' not in block:
raise Exception("Expected 'type' key with shader mode")
if 'file' not in block:
raise Exception("Expected 'file' key with shader file")
if 'shaders' not in block:
raise Exception("Expected 'shaders' key with shader name list")
shader_model = block['type']
shader_file = os.path.join(shader_folder, block['file'])
for shader_name in block['shaders']:
run_fxc(
shader_model = shader_model,
shader_file = shader_file,
shader_name = shader_name,
output_fp = output_fp)
output_fp.write(FOOTER)
def run_fxc(shader_model,
shader_file,
shader_name,
output_fp):
argv = [
'fxc',
'-nologo',
'-T{0}'.format(shader_model),
shader_file,
'-E{0}'.format(shader_name),
'-Vn{0}'.format(shader_name),
]
if shader_model.startswith('vs_'):
argv += ['-DVERTEX_SHADER']
elif shader_model.startswith('ps_'):
argv += ['-DPIXEL_SHADER']
with ScopedTempFilename() as temp_filename:
argv += ['-Fh{0}'.format(temp_filename)]
sys.stdout.write('{0}\n'.format(' '.join(argv)))
subprocess.check_call(argv)
with open(temp_filename, 'r') as temp_fp:
output_fp.write(temp_fp.read())
output_fp.write("ShaderBytes s{0} = {{ {0}, sizeof({0}) }};\n".format(
shader_name))
# Allocate a temporary file name and delete it when done. We need an extra
# wrapper for this since TemporaryNamedFile holds the file open.
class ScopedTempFilename(object):
def __init__(self):
self.name = None
def __enter__(self):
with tempfile.NamedTemporaryFile(delete = False) as tmp:
self.name = tmp.name
return self.name
def __exit__(self, type, value, traceback):
if not self.name:
return
try:
os.unlink(self.name)
except:
pass
if __name__ == '__main__':
shell_main()

Просмотреть файл

@ -1,56 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
tempfile=tmpShaderHeader
FXC_DEBUG_FLAGS="-Zi -Fd shaders.pdb"
FXC_FLAGS=""
# If DEBUG is in the environment, then rebuild with debug info
if [ "$DEBUG" != "" ] ; then
FXC_FLAGS="$FXC_DEBUG_FLAGS"
fi
makeShaderVS() {
fxc -nologo $FXC_FLAGS -Tvs_4_0_level_9_3 $SRC -E$1 -Vn$1 -Fh$tempfile
echo "ShaderBytes s$1 = { $1, sizeof($1) };" >> $tempfile;
cat $tempfile >> $DEST
}
makeShaderPS() {
fxc -nologo $FXC_FLAGS -Tps_4_0_level_9_3 $SRC -E$1 -Vn$1 -Fh$tempfile
echo "ShaderBytes s$1 = { $1, sizeof($1) };" >> $tempfile;
cat $tempfile >> $DEST
}
SRC=CompositorD3D11.hlsl
DEST=CompositorD3D11Shaders.h
rm -f $DEST
echo "struct ShaderBytes { const void* mData; size_t mLength; };" >> $DEST;
makeShaderVS LayerQuadVS
makeShaderVS LayerDynamicVS
makeShaderPS SolidColorShader
makeShaderPS RGBShader
makeShaderPS RGBAShader
makeShaderPS ComponentAlphaShader
makeShaderPS YCbCrShader
makeShaderPS NV12Shader
makeShaderVS LayerQuadMaskVS
makeShaderVS LayerDynamicMaskVS
makeShaderPS SolidColorShaderMask
makeShaderPS RGBShaderMask
makeShaderPS RGBAShaderMask
makeShaderPS YCbCrShaderMask
makeShaderPS NV12ShaderMask
makeShaderPS ComponentAlphaShaderMask
# Mix-blend shaders
makeShaderVS LayerQuadBlendVS
makeShaderVS LayerQuadBlendMaskVS
makeShaderVS LayerDynamicBlendVS
makeShaderVS LayerDynamicBlendMaskVS
makeShaderPS BlendShader
rm $tempfile

Просмотреть файл

@ -0,0 +1,28 @@
- type: vs_4_0_level_9_3
file: CompositorD3D11.hlsl
shaders:
- LayerQuadVS
- LayerDynamicVS
- LayerQuadMaskVS
- LayerDynamicMaskVS
- LayerQuadBlendVS
- LayerQuadBlendMaskVS
- LayerDynamicBlendVS
- LayerDynamicBlendMaskVS
- type: ps_4_0_level_9_3
file: CompositorD3D11.hlsl
shaders:
- SolidColorShader
- RGBShader
- RGBAShader
- ComponentAlphaShader
- YCbCrShader
- NV12Shader
- SolidColorShaderMask
- RGBShaderMask
- RGBAShaderMask
- YCbCrShaderMask
- NV12ShaderMask
- ComponentAlphaShaderMask
- BlendShader

Просмотреть файл

@ -42,9 +42,13 @@
*/
// See CompositorD3D11Shaders.h
namespace mozilla {
namespace layers {
struct ShaderBytes { const void* mData; size_t mLength; };
extern ShaderBytes sRGBShader;
extern ShaderBytes sLayerQuadVS;
} // namespace layers
} // namespace mozilla
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
@ -1504,4 +1508,4 @@ VRSystemManagerOculus::RemoveControllers()
mOculusController.Clear();
mControllerCount = 0;
}
}