GithubHelp home page GithubHelp logo

eebackend / llpc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gpuopen-drivers/llpc

0.0 1.0 0.0 3.55 MB

LLVM-Based Pipeline Compiler

License: MIT License

CMake 0.20% C++ 29.27% C 59.32% LLVM 6.42% Python 0.98% GLSL 3.80% JavaScript 0.02%

llpc's Introduction

LLVM-Based Pipeline Compiler (LLPC)

LLPC builds on LLVM's existing shader compilation infrastructure for AMD GPUs to generate code objects compatible with PAL's pipeline ABI. It consists of three components:

LLPC Architecture Diagram

  • SPIR-V translator is based on Khronos SPIRV-LLVM translator. It translates SPIR-V binary to LLVM IR with rich metadata.

  • Lower translates all LLVM compiler unsupported LLVM IR and metadata to function calls.

Both SPIR-V translator and Lower are machine independent.

  • Patcher replaces all external function calls with LLVM compiler compatible LLVM IR according to the pipeline information. It calls LLVM and reorganizes LLVM compiler's output with PAL Pipeline ABI.

Standalone Compiler

LLPC could be built into a standalone offline compiler (amdllpc). It supports GLSL, SPIR-V binary and SPIR-V assemble file as input and output GPU ISA code and related register settings.

Build Instruction

Please refer to the Build Instructions of amdvlk. By default, amdllpc is built together with Vulkan driver. You can use "make amdllpc" to build amdllpc only.

Usage

export LD_LIBRARY_PATH=<path_to_spvgen>:$LD_LIBRARY_PATH
amdllpc [<options>...] [<files>...]

Options

  • Basic options
Option Name Description Default Value
-help Print detail help, include all LLVM options
-gfxip=<major.minor.step> Graphics IP version 8.0.0
-o=<filename> Output ELF binary file
-entry-target=<entryname> Name string of entry target in SPIRV main
-val Validate input SPIR-V binary or text
-verify-ir Verify LLVM IR after each pass false
  • Dump options
Option Name Description Default Value
-enable-errs Enable error message output (to stdout or external file)
-enable-outs Enable LLPC-specific debug dump output (to stdout or external false
file)
-v Alias for -enable-outs false
-enable-time-profiler Enable time profiler for various compilation phases
-log-file-dbgs=<filename> Name of the file to log info from dbgs() "" (meaning stderr)
-log-file-outs=<filename> Name of the file to log info from LLPC_OUTS() and LLPC_ERRS()
-enable-pipeline-dump Enable pipeline info dump
-pipeline-dump-dir=<directory> Directory where pipeline shader info are dumped
  • Debug & Performance tunning options
Option Name Description Default Value
-enable-errs Enable error message output (to stdout or external file)
-enable-si-scheduler Enable target option si-scheduler
-disable-gs-onchip Disable geometry shader on-chip mode
-enable-tess-offchip Enable tessellation off-chip mode
-disable-fp32-denormals Disable target option fp32-denormals
-disable-llvm-patch Disable the patch for LLVM back-end issues
-disable-lower-opt Disable optimization for SPIR-V lowering
-ignore-color-attachment-formats Ignore color attachment formats
-lower-dyn-index Lower SPIR-V dynamic (non-constant) index in access chain
-vgpr-limit=<uint> Maximum VGPR limit for this shader 0
-sgpr-limit=<uint> Maximum SGPR limit for this shader 0
-waves-per-eu=<minVal,maxVal> The range of waves per EU for this shader empty
-shader-cache-mode=<uint> Shader cache mode
0 - disable
1 - runtime cache
2 - cache to disk
1
-shader-replace-dir=<dir> Directory to store the files used in shader replacement
-shader-replace-mode=<uint> Shader replacement mode
0 - disable
1 - replacement based on shader hash
2 - replacement based on both shader hash and pipeline hash
0
-shader-replace-pipeline-hashes=<hashes with comma as separator> A collection of pipeline hashes, specifying shader replacement is operated on which pipelines
-enable-shadow-desc Enable shadow descriptor table
-shadow-desc-table-ptr-high=<uint> High part of VA for shadow descriptor table pointer 2

Note: amdllpc overwrites following native options in LLVM:

-pragma-unroll-threshold=4096 -unroll-allow-partial -simplifycfg-sink-common=false -amdgpu-vgpr-index-mode -filetype=obj

File formats

<file>.vert     GLSL source text file for a vertex shader

<file>.tesc     GLSL source text file for a tessellation control shader

<file>.tese     GLSL source text file for a tessellation evaluation shader

<file>.geom     GLSL source text file for a tessellation geometry shader

<file>.frag     GLSL source text file for a tessellation fragment shader

<file>.comp     GLSL source text file for a tessellation compute shader

<file>.spv      SPIR-V binary file

<file>.spvas    SPIR-V text file

<file>.pipe     Pipeline info file

Note: To compile a GLSL source text file or a SPIR-V text (assembly) file, or a Pipeline info file that contains or points to either of those, amdllpc needs to call spvgen. The directory of the spvgen library needs to be added to the environment variable LD_LIBRARY_PATH. Compiling SPIR-V binary or a Pipeline info file that contains or points to SPIR-V binary does not require spvgen.

Examples

  • Compile single fragment shader "a.frag" on Vega10
amdllpc -auto-layout-desc -gfxip=9.0.0 a.frag
  • Compile full pipeline file "b.pipe" on Ellesmere and output to c.elf
amdllpc -gfxip=8.0.3 -o=c.elf b.pipe

Test with SHADERDB

You can use shaderdb to test llpc with standalone compiler and spvgen:

By integrating with lit, the test will check the correctness of shader compilation result with the pattern specified in test files.

First, enable LLVM utils build when you build Vulkan driver and amdllpc:

cd <vulkandriver_path>/drivers/xgl
cmake -H. -Bbuilds/Release64 -DLLVM_BUILD_UTILS=ON -DLLVM_INCLUDE_UTILS=ON
cd builds/Release64
make -j$(nproc)

Now, the tests can be run in the same directory using:

make -j$(nproc) check-amdllpc

That command (re)builds amdllpc and spvgen.so if necessary. If the spvgen.so build fails with an error like this:

drivers/spvgen/source/spvgen.cpp:51:10: fatal error: doc.h: No such file or directory

then you need to fetch the external sources (glslang and SPIRV-Tools) used by SPVGEN:

(cd ../../../spvgen/external && python fetch_external_sources.py)

and then retry the check-amdllpc.

When you need to investigate a test failure, run a single test from that same build directory like this example:

llvm/bin/llvm-lit -v llpc/test/shaderdb/OpAtomicIIncrement_TestVariablePointer_lit.spvas

Third Party Software

LLPC contains code written by third parties:

  • SPIRV-LLVM translator is distributed under the terms of University of Illinois/NCSA Open Source License. See translator/LICENSE.TXT.
  • SPIRV-Tools is distributed under the terms of Apache License version 2.0. See translator/hex_float.h and bitutils.h.
  • Metrohash is distributed under the terms of MIT License. See imported/metrohash/metrohash-license.
  • CWPack is distributed under the terms of MITLicense. See imported/cwpack/cwpack-license.

llpc's People

Contributors

alan-baker avatar amdrexu avatar anzhonghuang avatar davidmaoamd avatar dnovillo avatar jacobheamd avatar jiaolu avatar jinjianrong avatar linqun avatar s-perron avatar trenouf avatar yjaelex avatar zhicaigfx avatar

Watchers

 avatar

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.