Giter Club home page Giter Club logo

pyshaderc's Introduction

PyShaderc

Build Status

Table of Contents

What is it ?

This module allow you to compile glsl to Spir-V in Python. It leverages power of the great shaderc library to compile glsl.

API

def set_include_paths(paths):
    """Set include paths

    This function allows you to update the include paths.
    Include paths are used with #include <file>.

    Args:
        paths (list[str]): List of paths
    """

def compile_file_into_spirv(filepath, stage, optimization='size',
                            warnings_as_errors=False):
    """Compile shader file into Spir-V binary.

    This function uses shaderc to compile your glsl file code into Spir-V
    code.

    Args:
        filepath (str): Absolute path to your shader file
        stage (str): Pipeline stage in ['vert', 'tesc', 'tese', 'geom',
                     'frag', 'comp']
        optimization (str): 'zero' (no optimization) or 'size' (reduce size)
        warnings_as_errors (bool): Turn warnings into errors

    Returns:
        bytes: Compiled Spir-V binary.

    Raises:
        CompilationError: If compilation fails.
    """

def compile_into_spirv(raw, stage, filepath, language="glsl",
                       optimization='size', suppress_warnings=False,
                       warnings_as_errors=False):
    """Compile shader code into Spir-V binary.

    This function uses shaderc to compile your glsl or hlsl code into Spir-V
    code. You can refer to the shaderc documentation.

    Args:
        raw (bytes): glsl or hlsl code (bytes format, not str)
        stage (str): Pipeline stage in ['vert', 'tesc', 'tese', 'geom',
                     'frag', 'comp']
        filepath (str): Absolute path of the file (needed for #include)
        language (str): 'glsl' or 'hlsl'
        optimization (str): 'zero' (no optimization) or 'size' (reduce size)
        suppress_warnings (bool): True to suppress warnings
        warnings_as_errors (bool): Turn warnings into errors

    Returns:
        bytes: Compiled Spir-V binary.

    Raises:
        CompilationError: If compilation fails.
    """

Installation

Note (Linux): You need cmake and make

Note (Windows): You need cmake and Visual C++ 2015 Build Tools. Set environment configuration with Visual C++ 2015 x64 Native Build Tools Command Prompt in the start menu.

pip install pyshaderc

Or if you want the latest version:

git clone https://github.com/realitix/pyshaderc.git
cd pyshaderc
python setup.py build
python setup.py install

How to use it

Getting started

So simple !

import pyshaderc
spirv = pyshaderc.compile_file_into_spirv('/tmp/myshader.vs.glsl', 'vert')

If you want more control, you can use the lower-level function compile_into_spirv.

Include support

Pyshaderc supports #include preprocessor thanks to shaderc. There are two ways to use it:

#include "myfile"

Include file relatively, it's intuitive.

#include <myfile>

Like in C, you can include from a list of paths. To use this way to include, you must call set_include_paths with a list of directories to search for before compiling your glsl code.

How to update shaderc

Download the last shaderc version on github, put the third party libs in it and just zip it. Then update the build script with the new zip name.

Community

You can checkout my blog, I speak about PyShaderc: Blog

Supported By

PyShaderc is supported by helpful 3rd parties via code contributions, test devices and so forth. Make our supporters happy and visit their sites!

linagora

pyshaderc's People

Contributors

greenboxal avatar realitix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pyshaderc's Issues

Fails to build in VS2017/Python3.6 64bit

Hi,

I am probably being an idiot somehow, but I get this error when I try to build with pip install pyshaderc from the Python 3.6 command prompt, launched from VS2017.

LINK : fatal error LNK1181: cannot open input file 'shaderc_combined.lib'

I have the 2015 build tools installed too, but cmake seems to pick up the 2017 ones (i am doing all this from 2017 after all). It appears to me from the log that all the preceeding builds succeed, and its just the link step that fails.

Cheers!

Fails to build in Windows (Microsoft Build Engine version 16.7.0+b89cb5fde)

Currently trying to install pyshaderc in windows, it seems it fails with the error:

CMake Error at cmake/setup_build.cmake:48 (find_program):
    Could not find ECHO_EXE using the following names: echo

The full stack trace is:

  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\axsau\scoop\apps\python\3.8.3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\axsau\\AppData\\Local\\Temp\\pip-install-2wo03s8
f\\pyshaderc\\setup.py'"'"'; __file__='"'"'C:\\Users\\axsau\\AppData\\Local\\Temp\\pip-install-2wo03s8f\\pyshaderc\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);c
ode=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\axsau\AppData\Local\Temp\pip-wheel-kczr9lyi' --pyt
hon-tag cp38
       cwd: C:\Users\axsau\AppData\Local\Temp\pip-install-2wo03s8f\pyshaderc\
  Complete output (53 lines):
  running bdist_wheel
  running build
  -- Building for: Visual Studio 16 2019
  -- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
  -- The C compiler identification is MSVC 19.27.29111.0
  -- The CXX compiler identification is MSVC 19.27.29111.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Shaderc: build type is "Release".
  -- Configuring Shaderc to avoid building tests.
  -- nosetests was not found - python code will not be tested
  -- asciidoctor was not found - no documentation will be generated
  CMake Error at cmake/setup_build.cmake:48 (find_program):
    Could not find ECHO_EXE using the following names: echo
  Call Stack (most recent call first):
    CMakeLists.txt:17 (include)


  -- Configuring incomplete, errors occurred!
  See also "C:/Users/axsau/AppData/Local/Temp/pip-install-2wo03s8f/pyshaderc/_cffi_build/shaderc_build/CMakeFiles/CMakeOutput.log".
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\axsau\AppData\Local\Temp\pip-install-2wo03s8f\pyshaderc\setup.py", line 13, in <module>
      setup(
    File "C:\Users\axsau\AppData\Roaming\Python\Python38\site-packages\setuptools\__init__.py", line 153, in setup
      return distutils.core.setup(**attrs)
    File "C:\Users\axsau\scoop\apps\python\3.8.3\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "C:\Users\axsau\scoop\apps\python\3.8.3\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "C:\Users\axsau\scoop\apps\python\3.8.3\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\axsau\AppData\Roaming\Python\Python38\site-packages\wheel\bdist_wheel.py", line 290, in run
      self.run_command('build')
    File "C:\Users\axsau\scoop\apps\python\3.8.3\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\axsau\scoop\apps\python\3.8.3\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\axsau\AppData\Local\Temp\pip-install-2wo03s8f\pyshaderc\setup.py", line 9, in run
      shaderc_build.build()
    File "C:\Users\axsau\AppData\Local\Temp\pip-install-2wo03s8f\pyshaderc\_cffi_build\shaderc_build.py", line 49, in build
      subprocess.check_call(call, stderr=subprocess.STDOUT, shell=windows)
    File "C:\Users\axsau\scoop\apps\python\3.8.3\lib\subprocess.py", line 364, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', '-BC:\\Users\\axsau\\AppData\\Local\\Temp\\pip-install-2wo03s8f\\pyshaderc\\_cffi_build\\shaderc_build', '-HC:\\Users\\axsau\\AppDa
ta\\Local\\Temp\\pip-install-2wo03s8f\\pyshaderc\\_cffi_build\\shaderc', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_POSITION_INDEPENDENT_CODE=ON', '-DSPIRV_SKIP_EXECUTABLES=ON', '-DSHADER
C_SKIP_TESTS=ON', '-DCMAKE_C_FLAGS=/nologo /EHsc /MD', '-DCMAKE_CXX_FLAGS=/nologo /EHsc /MD', '-DCMAKE_C_FLAGS_RELEASE=/nologo /EHsc /MD', '-DCMAKE_CXX_FLAGS_RELEASE=/nologo /EHsc /MD
', '-DSHADERC_ENABLE_SHARED_CRT=ON']' returned non-zero exit status 1.
  ----------------------------------------
  ERROR: Failed building wheel for pyshaderc

What would be the best way to amend, it seems the main issue (so far) is he echo error, but I can see there is another issue #2 which outlines a compile issue on Windows, do you know what could be a fix for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.