From: Chad Versace Date: Wed, 27 May 2015 23:09:26 +0000 (-0700) Subject: vk/glsl_scraper: Indent large text blocks X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fd8b5e0df2b07a1404cd4d94429663871024ff12;p=mesa.git vk/glsl_scraper: Indent large text blocks Indent them to the same level as if the text was code. No changes in entrypoints.{c,h} after a clean build. --- diff --git a/src/vulkan/glsl_scraper.py b/src/vulkan/glsl_scraper.py index d476b3c0947..c2f0495d4bc 100644 --- a/src/vulkan/glsl_scraper.py +++ b/src/vulkan/glsl_scraper.py @@ -8,21 +8,22 @@ import struct import subprocess import sys import tempfile +from textwrap import dedent def print_usage(err): - print """\ -glsl_scraper.py [options] file + print(dedent("""\ + glsl_scraper.py [options] file -This program scrapes a C file for any instance of the GLSL_VK_SHADER macro, -grabs the GLSL source code, compiles it to SPIR-V. The resulting SPIR-V -code is written to another C file as an array of 32-bit words. + This program scrapes a C file for any instance of the GLSL_VK_SHADER macro, + grabs the GLSL source code, compiles it to SPIR-V. The resulting SPIR-V + code is written to another C file as an array of 32-bit words. -If '-' is passed as the input file or output file, stdin or stdout will be -used instead of a file on disc. + If '-' is passed as the input file or output file, stdin or stdout will be + used instead of a file on disc. -Options: - -o outfile Output to the given file (default: stdout) - --with-glslang=PATH Full path to the glslangValidator program""" + Options: + -o outfile Output to the given file (default: stdout) + --with-glslang=PATH Full path to the glslangValidator program""")) exit(err) class Shader: @@ -245,36 +246,36 @@ if not glsl_only: shutil.rmtree(tmpdir) with open_file(outfname, 'w') as outfile: - outfile.write("""\ -/* =========================== DO NOT EDIT! =========================== - * This file is autogenerated by glsl_scraper.py. - */ - -#include - -#define _ANV_SPIRV_MAGIC "\\x03\\x02\\x23\\x07\\0\\0\\0\\0" - -#define _ANV_SPIRV_VERTEX _ANV_SPIRV_MAGIC "\\0\\0\\0\\0" -#define _ANV_SPIRV_TESS_CONTROL _ANV_SPIRV_MAGIC "\\1\\0\\0\\0" -#define _ANV_SPIRV_TESS_EVALUATION _ANV_SPIRV_MAGIC "\\2\\0\\0\\0" -#define _ANV_SPIRV_GEOMETRY _ANV_SPIRV_MAGIC "\\3\\0\\0\\0" -#define _ANV_SPIRV_FRAGMENT _ANV_SPIRV_MAGIC "\\4\\0\\0\\0" -#define _ANV_SPIRV_COMPUTE _ANV_SPIRV_MAGIC "\\5\\0\\0\\0" - -#define _ANV_GLSL_SRC_VAR2(_line) _glsl_helpers_shader ## _line ## _glsl_src -#define _ANV_GLSL_SRC_VAR(_line) _ANV_GLSL_SRC_VAR2(_line) - -#define GLSL_VK_SHADER(device, stage, ...) ({ \\ - VkShader __shader; \\ - VkShaderCreateInfo __shader_create_info = { \\ - .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO, \\ - .codeSize = sizeof(_ANV_GLSL_SRC_VAR(__LINE__)), \\ - .pCode = _ANV_GLSL_SRC_VAR(__LINE__), \\ - }; \\ - vkCreateShader((VkDevice) device, &__shader_create_info, &__shader); \\ - __shader; \\ -}) -""") + outfile.write(dedent("""\ + /* =========================== DO NOT EDIT! =========================== + * This file is autogenerated by glsl_scraper.py. + */ + + #include + + #define _ANV_SPIRV_MAGIC "\\x03\\x02\\x23\\x07\\0\\0\\0\\0" + + #define _ANV_SPIRV_VERTEX _ANV_SPIRV_MAGIC "\\0\\0\\0\\0" + #define _ANV_SPIRV_TESS_CONTROL _ANV_SPIRV_MAGIC "\\1\\0\\0\\0" + #define _ANV_SPIRV_TESS_EVALUATION _ANV_SPIRV_MAGIC "\\2\\0\\0\\0" + #define _ANV_SPIRV_GEOMETRY _ANV_SPIRV_MAGIC "\\3\\0\\0\\0" + #define _ANV_SPIRV_FRAGMENT _ANV_SPIRV_MAGIC "\\4\\0\\0\\0" + #define _ANV_SPIRV_COMPUTE _ANV_SPIRV_MAGIC "\\5\\0\\0\\0" + + #define _ANV_GLSL_SRC_VAR2(_line) _glsl_helpers_shader ## _line ## _glsl_src + #define _ANV_GLSL_SRC_VAR(_line) _ANV_GLSL_SRC_VAR2(_line) + + #define GLSL_VK_SHADER(device, stage, ...) ({ \\ + VkShader __shader; \\ + VkShaderCreateInfo __shader_create_info = { \\ + .sType = VK_STRUCTURE_TYPE_SHADER_CREATE_INFO, \\ + .codeSize = sizeof(_ANV_GLSL_SRC_VAR(__LINE__)), \\ + .pCode = _ANV_GLSL_SRC_VAR(__LINE__), \\ + }; \\ + vkCreateShader((VkDevice) device, &__shader_create_info, &__shader); \\ + __shader; \\ + }) + """)) for shader in parser.shaders: shader.dump_c_code(outfile, glsl_only)