├── tests ├── drm │ ├── .gitignore │ ├── Makefile.am │ └── vblank.c ├── nvhost │ ├── .gitignore │ ├── Makefile.am │ ├── gr3d.h │ ├── gr2d.h │ ├── gr2d-fill.c │ ├── gr3d-triangle.c │ ├── nvmap.h │ └── nvhost.h ├── grate │ ├── asm │ │ ├── linker_vs_tests.txt │ │ ├── cube2_linker.txt │ │ ├── sky_linker.txt │ │ ├── stencil_test_linker.txt │ │ ├── filter_quad_linker.txt │ │ ├── texture_wrap_linker.txt │ │ ├── vs_mov.txt │ │ ├── cube2_fs.txt │ │ ├── stencil_test_fs.txt │ │ ├── stencil_test_vs.txt │ │ ├── texture_wrap_vs.txt │ │ ├── vs_uniform.txt │ │ ├── filter_quad_fs.txt │ │ ├── vs_constant.txt │ │ ├── fs_vs_tests.txt │ │ ├── texture_wrap_fs.txt │ │ ├── fs_uniform.txt │ │ ├── vs_attribute_relative_addressing.txt │ │ ├── vs_function.txt │ │ ├── vs_constant_relative_addressing.txt │ │ ├── vs_predicate.txt │ │ ├── filter_quad_vs.txt │ │ ├── sky_vs.txt │ │ ├── cube2_vs.txt │ │ ├── sky_fs.txt │ │ ├── vs_stack.txt │ │ ├── fs_mfu_tests.txt │ │ ├── stencil_test_fs2.txt │ │ ├── cube2_grate_fs.txt │ │ ├── vs_branching.txt │ │ └── vs_export_relative_addressing.txt │ ├── .gitignore │ ├── Makefile.am │ ├── meson.build │ ├── clear.c │ └── asm_tests.sh ├── host1x │ ├── .gitignore │ ├── Makefile.am │ ├── meson.build │ └── gr2d-clear.c ├── gles1 │ ├── .gitignore │ ├── meson.build │ ├── Makefile.am │ ├── gles1-info.c │ ├── common.h │ ├── gles-logicop.c │ ├── gles-clip.c │ ├── gles-flatshading.c │ └── gles-tex-combiners.c ├── Makefile.am ├── meson.build └── gles2 │ ├── .gitignore │ ├── meson.build │ ├── Makefile.am │ ├── gles2-info.c │ ├── gles-clear.c │ ├── gles-pbuffer-clear.c │ ├── gles-pbuffer-fill.c │ ├── gles-shader-fill.c │ ├── gles-pbuffer-vertex-offset.c │ ├── egl-clear.c │ └── common.h ├── src ├── libwrap │ ├── .gitignore │ ├── Makefile.am │ ├── syscall.h │ ├── host1x.h │ ├── cdma_parser.h │ ├── meson.build │ ├── disasm.h │ ├── utils.h │ └── recorder.h ├── libgrate │ ├── .gitignore │ ├── libgrate.pc.in │ ├── linker_asm.h │ ├── libgrate-private.h │ ├── meson.build │ ├── matrix.h │ ├── Makefile.am │ ├── linker_asm.l │ ├── grate-2d.c │ ├── profile.c │ ├── asm.h │ ├── display.c │ ├── etc1.h │ ├── grate-3d.h │ └── linker_disasm.c ├── Makefile.am ├── meson.build ├── libcgc │ ├── meson.build │ ├── Makefile.am │ ├── dummy.c │ ├── libcgc-private.h │ └── stream.c └── libhost1x │ ├── Makefile.am │ ├── meson.build │ ├── x11-display.h │ ├── nvhost-gr2d.c │ ├── nvhost-gr3d.c │ ├── nvhost-nvmap.h │ └── nvhost.h ├── include ├── Makefile.am ├── list.h └── record_replay.h ├── data ├── font.png ├── tegra.png ├── checkerboard.png ├── grate │ ├── grate.jpg │ ├── Attribution.txt │ └── Creative Commons Attribution License 3.0.txt ├── miptest │ ├── 16x16.png │ ├── 1x1.png │ ├── 2x2.png │ ├── 32x32.png │ ├── 4x4.png │ ├── 64x64.png │ ├── 8x8.png │ ├── 128x128.png │ ├── 256x256.png │ ├── 512x512.png │ ├── 1024x1024.png │ └── nomipmap.png ├── galaxy-1489300667bhk.jpg ├── blue-sky-and-white-clouds-1457775320B2G.jpg └── font.fnt ├── tools ├── .gitignore ├── hex2float.c ├── fx10.c ├── fp20.c ├── Makefile.am ├── meson.build ├── cgc.c └── reset3d.c ├── shaders ├── vert │ ├── mov-vec4.glsl │ ├── neg-vec4.glsl │ ├── abs-vec4.glsl │ ├── add-vec4.glsl │ ├── atan.glsl │ ├── cos.glsl │ ├── dot4.glsl │ ├── exp2.glsl │ ├── log2.glsl │ ├── mul-vec4.glsl │ ├── rcp.glsl │ ├── dot2.glsl │ ├── floor-vec4.glsl │ ├── mad-vec4.glsl │ ├── rsq.glsl │ ├── dot3.glsl │ ├── sle.glsl │ ├── slt.glsl │ ├── mad-vec4-wwww.glsl │ ├── mad-vec4-xxxx.glsl │ ├── seq.glsl │ ├── sge.glsl │ ├── sne.glsl │ ├── max.glsl │ ├── min.glsl │ ├── dual-ops.glsl │ ├── arl.glsl │ └── pred.glsl └── frag │ ├── cos.glsl │ ├── sin.glsl │ ├── atan.glsl │ ├── exp.glsl │ ├── dfdx.glsl │ ├── fwidth.glsl │ ├── vface.glsl │ ├── cmove.glsl │ ├── sat.glsl │ └── lastfrag.glsl ├── autogen.sh ├── Makefile.am ├── .gitignore ├── meson.build ├── README.md ├── COPYING └── configure.ac /tests/drm/.gitignore: -------------------------------------------------------------------------------- 1 | vblank 2 | -------------------------------------------------------------------------------- /src/libwrap/.gitignore: -------------------------------------------------------------------------------- 1 | libwrap.la 2 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_HEADERS = \ 2 | libcgc.h 3 | -------------------------------------------------------------------------------- /src/libgrate/.gitignore: -------------------------------------------------------------------------------- 1 | lex.*.c 2 | *.tab.c 3 | *.tab.h 4 | -------------------------------------------------------------------------------- /tests/nvhost/.gitignore: -------------------------------------------------------------------------------- 1 | gr2d-fill 2 | gr3d-triangle 3 | libnvhost.la 4 | -------------------------------------------------------------------------------- /data/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/font.png -------------------------------------------------------------------------------- /data/tegra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/tegra.png -------------------------------------------------------------------------------- /tests/grate/asm/linker_vs_tests.txt: -------------------------------------------------------------------------------- 1 | LINK fp20, fp20, fp20, fp20, tram0.yxzw, export1 2 | -------------------------------------------------------------------------------- /tests/host1x/.gitignore: -------------------------------------------------------------------------------- 1 | gr2d-blit 2 | gr2d-clear 3 | gr2d-context 4 | gr3d-triangle 5 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = \ 2 | libhost1x \ 3 | libcgc \ 4 | libgrate \ 5 | libwrap 6 | -------------------------------------------------------------------------------- /tools/.gitignore: -------------------------------------------------------------------------------- 1 | assembler 2 | cgc 3 | fp20 4 | fx10 5 | hex2float 6 | replay 7 | reset3d 8 | -------------------------------------------------------------------------------- /data/checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/checkerboard.png -------------------------------------------------------------------------------- /data/grate/grate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/grate/grate.jpg -------------------------------------------------------------------------------- /data/miptest/16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/16x16.png -------------------------------------------------------------------------------- /data/miptest/1x1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/1x1.png -------------------------------------------------------------------------------- /data/miptest/2x2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/2x2.png -------------------------------------------------------------------------------- /data/miptest/32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/32x32.png -------------------------------------------------------------------------------- /data/miptest/4x4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/4x4.png -------------------------------------------------------------------------------- /data/miptest/64x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/64x64.png -------------------------------------------------------------------------------- /data/miptest/8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/8x8.png -------------------------------------------------------------------------------- /shaders/vert/mov-vec4.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position = u; 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/neg-vec4.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position = -u; 5 | } 6 | -------------------------------------------------------------------------------- /data/miptest/128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/128x128.png -------------------------------------------------------------------------------- /data/miptest/256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/256x256.png -------------------------------------------------------------------------------- /data/miptest/512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/512x512.png -------------------------------------------------------------------------------- /shaders/vert/abs-vec4.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position = abs(u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/add-vec4.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position = u + u; 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/atan.glsl: -------------------------------------------------------------------------------- 1 | attribute float a; 2 | void main() 3 | { 4 | gl_Position.x = atan(a); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/cos.glsl: -------------------------------------------------------------------------------- 1 | uniform float u; 2 | void main() 3 | { 4 | gl_Position.x = cos(u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/dot4.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position.x = dot(u, u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/exp2.glsl: -------------------------------------------------------------------------------- 1 | uniform float u; 2 | void main() 3 | { 4 | gl_Position.x = exp2(u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/log2.glsl: -------------------------------------------------------------------------------- 1 | uniform float u; 2 | void main() 3 | { 4 | gl_Position.x = log2(u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/mul-vec4.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position = u * u; 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/rcp.glsl: -------------------------------------------------------------------------------- 1 | uniform float u; 2 | void main() 3 | { 4 | gl_Position.x = 1.0 / u; 5 | } 6 | -------------------------------------------------------------------------------- /data/miptest/1024x1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/1024x1024.png -------------------------------------------------------------------------------- /data/miptest/nomipmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/miptest/nomipmap.png -------------------------------------------------------------------------------- /shaders/frag/cos.glsl: -------------------------------------------------------------------------------- 1 | uniform mediump float u; 2 | void main() 3 | { 4 | gl_FragColor.x = cos(u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/frag/sin.glsl: -------------------------------------------------------------------------------- 1 | uniform mediump float u; 2 | void main() 3 | { 4 | gl_FragColor.x = sin(u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/dot2.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position.x = dot(u.xy, u.xy); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/floor-vec4.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position = floor(u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/mad-vec4.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position = u * u + u; 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/rsq.glsl: -------------------------------------------------------------------------------- 1 | uniform float u; 2 | void main() 3 | { 4 | gl_Position.x = 1.0 / sqrt(u); 5 | } 6 | -------------------------------------------------------------------------------- /src/meson.build: -------------------------------------------------------------------------------- 1 | subdir('libcgc') 2 | subdir('libhost1x') 3 | subdir('libgrate') 4 | subdir('libwrap') 5 | -------------------------------------------------------------------------------- /data/galaxy-1489300667bhk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/galaxy-1489300667bhk.jpg -------------------------------------------------------------------------------- /shaders/frag/atan.glsl: -------------------------------------------------------------------------------- 1 | uniform mediump float u; 2 | void main() 3 | { 4 | gl_FragColor.x = atan(u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/frag/exp.glsl: -------------------------------------------------------------------------------- 1 | uniform mediump float u; 2 | void main() 3 | { 4 | gl_FragColor.x = exp2(u); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/dot3.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position.x = dot(u.xyz, u.xyz); 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/sle.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position.x = u.x > 0.0 ? 1.0 : 0.0; 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/slt.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position.x = u.x < u.y ? 1.0 : 0.0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/gles1/.gitignore: -------------------------------------------------------------------------------- 1 | gles-clip 2 | gles-flatshading 3 | gles-logicop 4 | gles-tex-combiners 5 | gles1-info 6 | -------------------------------------------------------------------------------- /shaders/vert/mad-vec4-wwww.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position = u * u + u.wwww; 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/mad-vec4-xxxx.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position = u * u + u.xxxx; 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/seq.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position.x = u.x == u.y ? 1.0 : 0.0; 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/sge.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position.x = u.x >= u.y ? 1.0 : 0.0; 5 | } 6 | -------------------------------------------------------------------------------- /shaders/vert/sne.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position.x = u.x != u.y ? 1.0 : 0.0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/drm/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = \ 2 | vblank 3 | 4 | AM_CFLAGS = $(DRM_CFLAGS) 5 | LDADD = $(DRM_LIBS) 6 | -------------------------------------------------------------------------------- /shaders/vert/max.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | attribute vec4 a; 3 | void main() 4 | { 5 | gl_Position = max(u, a); 6 | } 7 | -------------------------------------------------------------------------------- /shaders/vert/min.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | attribute vec4 a; 3 | void main() 4 | { 5 | gl_Position = min(u, a); 6 | } 7 | -------------------------------------------------------------------------------- /shaders/vert/dual-ops.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u; 2 | void main() 3 | { 4 | gl_Position.xyz = normalize(u.xyz); 5 | gl_Position.w = dot(u, u); 6 | } 7 | -------------------------------------------------------------------------------- /data/blue-sky-and-white-clouds-1457775320B2G.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grate-driver/grate/HEAD/data/blue-sky-and-white-clouds-1457775320B2G.jpg -------------------------------------------------------------------------------- /tests/grate/asm/cube2_linker.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Shader linker for /grate/tests/cube-textured2 3 | */ 4 | 5 | LINK fp20, fp20, NOP, NOP, tram0.xyzw, export1 6 | -------------------------------------------------------------------------------- /tests/grate/asm/sky_linker.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Shader linker for /grate/tests/cube-textured3 3 | */ 4 | 5 | LINK fp20, fp20, NOP, NOP, tram0.xyzw, export1 6 | -------------------------------------------------------------------------------- /tests/grate/asm/stencil_test_linker.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Shader linker for /grate/tests/stencil 3 | */ 4 | 5 | LINK fp20, fp20, NOP, NOP, tram0.xyzw, export1 6 | -------------------------------------------------------------------------------- /tests/grate/asm/filter_quad_linker.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Shader linker for /grate/tests/texture-filter 3 | */ 4 | 5 | LINK fp20, fp20, NOP, NOP, tram0.xyzw, export1 6 | -------------------------------------------------------------------------------- /tests/grate/asm/texture_wrap_linker.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Shader linker for /grate/tests/texture-wrap 3 | */ 4 | 5 | LINK fp20, fp20, NOP, NOP, tram0.xyzw, export1 6 | -------------------------------------------------------------------------------- /shaders/frag/dfdx.glsl: -------------------------------------------------------------------------------- 1 | #extension GL_OES_standard_derivatives : enable 2 | 3 | uniform mediump vec4 u; 4 | void main() 5 | { 6 | gl_FragColor.x = dFdx(u.x); 7 | } 8 | -------------------------------------------------------------------------------- /shaders/frag/fwidth.glsl: -------------------------------------------------------------------------------- 1 | #extension GL_OES_standard_derivatives : enable 2 | 3 | uniform mediump vec4 u; 4 | void main() 5 | { 6 | gl_FragColor.x = fwidth(u.x); 7 | } 8 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = drm grate host1x nvhost 2 | 3 | if USE_GLES1 4 | SUBDIRS += gles1 5 | endif 6 | 7 | if USE_GLES2 8 | SUBDIRS += gles2 9 | endif 10 | -------------------------------------------------------------------------------- /data/grate/Attribution.txt: -------------------------------------------------------------------------------- 1 | grate.jpg is under CC BY 3.0, was modified, authored by Amy Nelson. 2 | 3 | Original can be found here: 4 | https://www.flickr.com/photos/amyn-design/5374707134/ 5 | -------------------------------------------------------------------------------- /tests/grate/.gitignore: -------------------------------------------------------------------------------- 1 | clear 2 | cube 3 | cube-textured 4 | cube-textured2 5 | cube-textured3 6 | interactive 7 | quad 8 | stencil 9 | texture-filter 10 | texture-wrap 11 | triangle 12 | triangle-rotate 13 | -------------------------------------------------------------------------------- /tests/meson.build: -------------------------------------------------------------------------------- 1 | subdir('host1x') 2 | subdir('grate') 3 | 4 | if egl.found() and x11.found() 5 | if gles1.found() 6 | subdir('gles1') 7 | endif 8 | 9 | if gles2.found() 10 | subdir('gles2') 11 | endif 12 | endif 13 | -------------------------------------------------------------------------------- /shaders/frag/vface.glsl: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | gl_FragColor.x = float(gl_FrontFacing); 4 | gl_FragColor.y = -float(gl_FrontFacing); 5 | gl_FragColor.z = abs(float(gl_FrontFacing)); 6 | gl_FragColor.w = float(gl_FrontFacing) * 2.0; 7 | } 8 | -------------------------------------------------------------------------------- /shaders/vert/arl.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 u[10]; 2 | attribute vec4 a; 3 | void main() 4 | { 5 | gl_Position.x = u[int(a.x)].x; 6 | gl_Position.y = u[int(a.y)].x; 7 | gl_Position.z = u[int(a.z)].x; 8 | gl_Position.w = u[int(a.w)].x; 9 | } 10 | -------------------------------------------------------------------------------- /shaders/frag/cmove.glsl: -------------------------------------------------------------------------------- 1 | uniform mediump vec4 u; 2 | void main() 3 | { 4 | gl_FragColor.x = u.x == 0.0 ? u.y : u.z; 5 | gl_FragColor.y = u.y != 0.0 ? u.y : u.z; 6 | gl_FragColor.z = u.z <= 0.0 ? u.y : u.z; 7 | gl_FragColor.w = u.w < 0.0 ? u.y : u.z; 8 | } 9 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | srcdir=`dirname $0` 4 | test -z "$srcdir" && srcdir=. 5 | 6 | ORIGDIR=`pwd` 7 | cd $srcdir 8 | 9 | test -d m4 || mkdir m4 10 | autoreconf -v --install || exit 1 11 | cd $ORIGDIR || exit $? 12 | 13 | $srcdir/configure "$@" 14 | -------------------------------------------------------------------------------- /tests/host1x/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = \ 2 | -I$(top_srcdir)/include \ 3 | -I$(top_srcdir)/src/libhost1x 4 | 5 | noinst_PROGRAMS = \ 6 | gr2d-blit \ 7 | gr2d-clear \ 8 | gr2d-context \ 9 | gr3d-triangle 10 | 11 | LDADD = ../../src/libhost1x/libhost1x.la 12 | -------------------------------------------------------------------------------- /src/libcgc/meson.build: -------------------------------------------------------------------------------- 1 | libcgc_sources = files( 2 | 'instruction.c', 3 | 'shader.c', 4 | 'stream.c', 5 | 6 | 'dummy.c' # temp 7 | ) 8 | 9 | libcgc = shared_library('cgc', 10 | libcgc_sources, 11 | include_directories : include_directories('../../include') 12 | ) 13 | -------------------------------------------------------------------------------- /tools/hex2float.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | union { 8 | uint32_t u; 9 | float f; 10 | } value; 11 | 12 | value.u = strtoul(argv[1], NULL, 16); 13 | printf("%f\n", value.f); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/libgrate/libgrate.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libgrate 7 | Description: Open source Tegra 2D/3D user-space 8 | Version: @PACKAGE_VERSION@ 9 | Libs: -L${libdir} -lgrate 10 | Cflags: -I${includedir} -I${includedir}/grate 11 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_mov.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .asm 10 | 11 | EXEC(export[0]=vector) 12 | MOVv r0.xyzw, a[0].xyzw 13 | NOPs 14 | ; 15 | 16 | EXEC(export[7]=vector) 17 | MOVv r0.xyzw, a[1].xyzw 18 | NOPs 19 | ; 20 | -------------------------------------------------------------------------------- /tests/gles1/meson.build: -------------------------------------------------------------------------------- 1 | tests = [ 2 | 'gles-clip', 3 | 'gles-flatshading', 4 | 'gles-logicop', 5 | 'gles-tex-combiners', 6 | 'gles1-info' 7 | ] 8 | 9 | foreach test : tests 10 | src = test + '.c' 11 | executable( 12 | test, 13 | [src, 'common.c'], 14 | dependencies : [egl, x11, gles1, libpng] 15 | ) 16 | endforeach 17 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | grateincludedir = $(includedir)/libgrate 4 | 5 | grateinclude_HEADERS = \ 6 | include/host1x.h \ 7 | include/tgr_3d.xml.h \ 8 | src/libgrate/grate.h \ 9 | src/libgrate/grate-3d-ctx.h \ 10 | src/libgrate/matrix.h 11 | 12 | SUBDIRS = \ 13 | include \ 14 | src \ 15 | tests \ 16 | tools 17 | -------------------------------------------------------------------------------- /shaders/frag/sat.glsl: -------------------------------------------------------------------------------- 1 | varying highp vec4 v0, v1, v2; 2 | void main() 3 | { 4 | gl_FragColor.x = clamp((v0.x + v1.x * v2.x) * 1.0, 0.0, 1.0); 5 | gl_FragColor.y = clamp((v0.y + v1.y * v2.y) * 2.0, 0.0, 1.0); 6 | gl_FragColor.z = clamp((v0.z + v1.z * v2.z) * 4.0, 0.0, 1.0); 7 | gl_FragColor.w = clamp((v0.w + v1.w * v2.w) * 0.5, 0.0, 1.0); 8 | } 9 | -------------------------------------------------------------------------------- /tests/nvhost/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libnvhost.la 2 | 3 | libnvhost_la_SOURCES = \ 4 | gr2d.c \ 5 | gr2d.h \ 6 | gr3d.c \ 7 | gr3d.h \ 8 | nvhost.c \ 9 | nvhost.h \ 10 | nvmap.c \ 11 | nvmap.h 12 | 13 | AM_CFLAGS = $(PNG_CFLAGS) 14 | 15 | noinst_PROGRAMS = \ 16 | gr2d-fill \ 17 | gr3d-triangle 18 | 19 | LDADD = libnvhost.la $(PNG_LIBS) 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | *.la 3 | *.lo 4 | *.o 5 | *.pc 6 | .deps 7 | .libs 8 | aclocal.m4 9 | autom4te.cache 10 | compile 11 | config.guess 12 | config.h 13 | config.h.in 14 | config.log 15 | config.status 16 | config.sub 17 | configure 18 | depcomp 19 | install-sh 20 | libtool 21 | ltmain.sh 22 | m4 23 | Makefile 24 | Makefile.in 25 | missing 26 | stamp-h1 27 | test.png 28 | ylwrap 29 | -------------------------------------------------------------------------------- /tests/grate/asm/cube2_fs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Fragment shader for /grate/tests/cube-textured2 3 | */ 4 | 5 | pseq_to_dw_exec_nb = 1 6 | alu_buffer_size = 1 7 | 8 | .asm 9 | EXEC 10 | MFU: sfu: rcp r4 11 | mul0: bar, sfu, bar0 12 | mul1: bar, sfu, bar1 13 | ipl: t0.fp20, t0.fp20, NOP, NOP 14 | 15 | TEX: tex r2, r3, tex0, r0, r1, r2 16 | 17 | DW: store rt1, r2, r3 18 | ; 19 | -------------------------------------------------------------------------------- /src/libcgc/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = \ 2 | libcgc.la 3 | 4 | noinst_HEADERS = \ 5 | libcgc-private.h 6 | 7 | libcgc_la_CPPFLAGS = \ 8 | -I$(top_srcdir)/include 9 | 10 | libcgc_la_SOURCES = \ 11 | instruction.c \ 12 | shader.c \ 13 | stream.c 14 | 15 | if ENABLE_CGC 16 | libcgc_la_LIBADD = \ 17 | -lcgdrv 18 | else 19 | libcgc_la_SOURCES += \ 20 | dummy.c 21 | endif 22 | -------------------------------------------------------------------------------- /tools/fx10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | uint32_t value; 8 | 9 | value = strtoul(argv[1], NULL, 16); 10 | 11 | value &= 0x3ff; 12 | 13 | if ((value >> 9) & 0x1) 14 | printf("%f\n", -(((value - 1) ^ 0x3ff) / 256.0f)); 15 | else 16 | printf("%f\n", value / 256.0f); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/grate/asm/stencil_test_fs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Fragment shader for /grate/tests/stencil 3 | */ 4 | 5 | pseq_to_dw_exec_nb = 1 6 | alu_buffer_size = 1 7 | 8 | .asm 9 | EXEC 10 | ALU: 11 | ALU0: MAD r3.*h, #1, #0, #0 // Alpha 12 | ALU1: MAD r3.l*, #1, #1, #0 // Blue 13 | ALU2: MAD r2.*h, #1, #0, #0 // Green 14 | ALU3: MAD r2.l*, #1, #0, #0 // Red 15 | 16 | DW: store rt1, r2, r3 17 | ; 18 | -------------------------------------------------------------------------------- /tests/grate/asm/stencil_test_vs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Vertex shader for /grate/tests/stencil 3 | */ 4 | 5 | .exports 6 | [0] = "position"; 7 | [7] = "texcoord"; 8 | 9 | .attributes 10 | [0] = "position"; 11 | [1] = "texcoord"; 12 | 13 | .asm 14 | 15 | /* Position */ 16 | EXEC(export[0]=vector) MOVv r63.xy**, a[0].xyzw; 17 | 18 | /* texcoord export */ 19 | EXEC(export[7]=vector) MOVv r63.xy**, a[1].xyzw; 20 | -------------------------------------------------------------------------------- /tests/host1x/meson.build: -------------------------------------------------------------------------------- 1 | tests = [ 2 | 'gr2d-blit', 3 | 'gr2d-clear', 4 | 'gr2d-context', 5 | 'gr3d-triangle', 6 | ] 7 | 8 | includes = include_directories( 9 | '../../include', 10 | '../../src/libhost1x' 11 | ) 12 | 13 | foreach test : tests 14 | src = test + '.c' 15 | executable( 16 | test, 17 | src, 18 | include_directories : includes, 19 | link_with : libhost1x 20 | ) 21 | endforeach 22 | -------------------------------------------------------------------------------- /shaders/frag/lastfrag.glsl: -------------------------------------------------------------------------------- 1 | // #extension GL_EXT_shader_framebuffer_fetch: require 2 | #extension GL_NV_shader_framebuffer_fetch: require 3 | 4 | // mediump vec4 gl_LastFragData[gl_MaxDrawBuffers]; 5 | 6 | void main() 7 | { 8 | gl_FragColor = gl_LastFragData[0] * 2.0; 9 | gl_FragColor += gl_LastFragData[1] + 1.0; 10 | // gl_FragData[2] = gl_LastFragData[1] * 2.0; 11 | // gl_FragData[3] = gl_LastFragData[0] * 2.0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/gles1/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libcommon.la 2 | 3 | libcommon_la_SOURCES = \ 4 | common.c \ 5 | common.h 6 | 7 | libcommon_la_LIBADD = $(X11_LIBS) $(GLES1_LIBS) $(PNG_LIBS) 8 | 9 | AM_CFLAGS = -I$(top_srcdir)/src/libgrate $(GLES1_CFLAGS) $(PNG_CFLAGS) 10 | LDADD = libcommon.la 11 | 12 | noinst_PROGRAMS = \ 13 | gles-clip \ 14 | gles-flatshading \ 15 | gles-logicop \ 16 | gles-tex-combiners \ 17 | gles1-info 18 | -------------------------------------------------------------------------------- /tests/grate/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = \ 2 | clear \ 3 | cube \ 4 | cube-textured \ 5 | cube-textured2 \ 6 | cube-textured3 \ 7 | interactive \ 8 | quad \ 9 | stencil \ 10 | texture-filter \ 11 | texture-wrap \ 12 | triangle \ 13 | triangle-rotate 14 | 15 | AM_LDFLAGS = -lm 16 | 17 | AM_CPPFLAGS = \ 18 | -I$(top_srcdir)/include \ 19 | -I$(top_srcdir)/src/libgrate 20 | 21 | LDADD = \ 22 | $(top_builddir)/src/libgrate/libgrate.la 23 | -------------------------------------------------------------------------------- /tests/grate/asm/texture_wrap_vs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Vertex shader for /grate/tests/texture-wrap 3 | */ 4 | 5 | .exports 6 | [0] = "position"; 7 | [7] = "texcoord"; 8 | 9 | .attributes 10 | [0] = "position"; 11 | [1] = "texcoord"; 12 | 13 | .uniforms 14 | [0] = "vtx_offset"; 15 | 16 | .asm 17 | 18 | /* Position */ 19 | EXEC(export[0]=vector) ADDv r63.xy**, a[0].xyzw, c[0].xyzw; 20 | 21 | /* texcoord export */ 22 | EXEC(export[7]=vector) MOVv r63.xy**, a[1].xyzw; 23 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_uniform.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .uniforms 10 | [100] = "uniform_100"; 11 | [135] = "uniform_135"; 12 | 13 | .asm 14 | EXEC(export[0]=vector) 15 | MOVv r0.xyzw, a[0].xyzw 16 | NOPs 17 | ; 18 | 19 | EXEC(export[7]=vector) 20 | MOVv r0.xy**, c[100].xyzw 21 | NOPs 22 | ; 23 | 24 | EXEC(export[7]=vector) 25 | MOVv r0.**zw, c[135].xyzw 26 | NOPs 27 | ; 28 | -------------------------------------------------------------------------------- /tests/grate/asm/filter_quad_fs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Fragment shader for /grate/tests/texture-filter 3 | */ 4 | 5 | pseq_to_dw_exec_nb = 1 6 | alu_buffer_size = 1 7 | 8 | .uniforms 9 | [0] = "lod_bias"; 10 | 11 | .asm 12 | EXEC 13 | MFU: sfu: rcp r4 14 | mul0: bar, sfu, bar0 15 | mul1: bar, sfu, bar1 16 | ipl: t0.fp20, t0.fp20, NOP, NOP 17 | 18 | ALU: 19 | ALU0: MAD r3.lh, u0, #1, #0 20 | ; 21 | 22 | EXEC 23 | TEX: txb r2, r3, tex0, r0, r1, r2, r3 24 | 25 | DW: store rt1, r2, r3 26 | ; 27 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_constant.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .constants 10 | [100].x = 0.1; 11 | [100].y = 0.2; 12 | 13 | [135].z = 0.3; 14 | [135].w = 0.4; 15 | 16 | .asm 17 | EXEC(export[0]=vector) 18 | MOVv r0.xyzw, a[0].xyzw 19 | NOPs 20 | ; 21 | 22 | EXEC(export[7]=vector) 23 | MOVv r0.xy**, c[100].xyzw 24 | NOPs 25 | ; 26 | 27 | EXEC(export[7]=vector) 28 | MOVv r0.**zw, c[135].xyzw 29 | NOPs 30 | ; 31 | -------------------------------------------------------------------------------- /shaders/vert/pred.glsl: -------------------------------------------------------------------------------- 1 | // uniform mat4 mvp; 2 | // attribute vec4 vert; 3 | // varying vec3 color; 4 | 5 | uniform vec4 u[10]; 6 | attribute vec4 a0, a1, a2, a3; 7 | varying vec4 v0, v1, v2, v3; 8 | uniform bool ub; 9 | void main() 10 | { 11 | // gl_Position = mvp * vert; 12 | gl_Position = a1; 13 | bvec4 cond = lessThan(a0, u[0]); 14 | if (cond.x) 15 | gl_Position.x = a0.x; 16 | if (cond.y) 17 | gl_Position.y = a0.y; 18 | if (!cond.z) 19 | gl_Position.z = a0.z; 20 | if (!cond.w) 21 | gl_Position.w = a0.w; 22 | } 23 | -------------------------------------------------------------------------------- /tests/grate/asm/fs_vs_tests.txt: -------------------------------------------------------------------------------- 1 | alu_buffer_size = 1 2 | pseq_to_dw_exec_nb = 1 3 | 4 | .asm 5 | EXEC 6 | MFU: sfu: rcp r4 7 | mul0: bar, sfu, bar0 8 | mul1: bar, sfu, bar1 9 | ipl: t0.fp20, t0.fp20, t0.fp20, t0.fp20 10 | TEX: NOP 11 | ALU: 12 | ALU0: MAD r3.*h, r3, #1, #0, #1 13 | ALU1: MAD r3.l*, r2, #1, #0, #1 14 | ALU2: MAD r2.*h, r0, #1, #0, #1 15 | ALU3: MAD r2.l*, r1, #1, #0, #1 16 | DW: store rt1, r2, r3 17 | ; 18 | -------------------------------------------------------------------------------- /tests/grate/asm/texture_wrap_fs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Fragment shader for /grate/tests/texture-wrap 3 | */ 4 | 5 | pseq_to_dw_exec_nb = 1 6 | alu_buffer_size = 1 7 | 8 | .uniforms 9 | [0] = "tex_scale"; 10 | [1] = "tex_offset"; 11 | 12 | .asm 13 | EXEC 14 | MFU: sfu: rcp r4 15 | mul0: bar, sfu, bar0 16 | mul1: bar, sfu, bar1 17 | ipl: t0.fp20, t0.fp20, NOP, NOP 18 | 19 | ALU: 20 | ALU0: MAD r0.lh, r0, u0, u1 21 | ALU1: MAD r1.lh, r1, u0, u1 22 | ; 23 | 24 | EXEC 25 | TEX: tex r2, r3, tex0, r0, r1, r2 26 | 27 | DW: store rt1, r2, r3 28 | ; 29 | -------------------------------------------------------------------------------- /tests/gles2/.gitignore: -------------------------------------------------------------------------------- 1 | egl-clear 2 | egl-triangle 3 | egl-x11-clear 4 | egl-x11-triangle 5 | gles-clear 6 | gles-cube 7 | gles-cube-textured 8 | gles-pbuffer-cgshader 9 | gles-pbuffer-clear 10 | gles-pbuffer-cube 11 | gles-pbuffer-fill 12 | gles-pbuffer-triangle 13 | gles-pbuffer-triangle-rotate 14 | gles-pbuffer-uniforms 15 | gles-pbuffer-uniforms-rg 16 | gles-pbuffer-uniforms-rgb 17 | gles-pbuffer-vertex-offset 18 | gles-quad-textured 19 | gles-quad-textured2 20 | gles-quad-textured3 21 | gles-shader-fill 22 | gles-stencil 23 | gles2-info 24 | libcommon.la 25 | -------------------------------------------------------------------------------- /tests/grate/asm/fs_uniform.txt: -------------------------------------------------------------------------------- 1 | alu_buffer_size = 1 2 | pseq_to_dw_exec_nb = 1 3 | 4 | .uniforms 5 | [0].l = "uniform_0_low"; 6 | [2] = "uniform_2"; 7 | [31].l = "uniform_31_low"; 8 | [31].h = "uniform_31_high"; 9 | 10 | .asm 11 | EXEC 12 | ALU: 13 | ALU0: MAD r3.*h, u0.l, #1, #0, #1 14 | ALU1: MAD r3.l*, u2, #1, #0, #1 15 | ALU2: MAD r2.*h, u31.l, #1, #0, #1 16 | ALU3: MAD r2.l*, u31.h, #1, #0, #1 17 | DW: store rt1, r2, r3 18 | ; 19 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | project('grate', 'c', 'cpp') 2 | 3 | cc = meson.get_compiler('c') 4 | lex = find_program('lex') 5 | yacc = find_program('yacc') 6 | math = cc.find_library('m', required : false) 7 | libdl = cc.find_library('dl') 8 | libdrm = dependency('libdrm') 9 | libpng = dependency('libpng') 10 | devil = dependency('ILU') 11 | 12 | egl = dependency('egl', required : false) 13 | x11 = dependency('x11', required : false) 14 | gles1 = dependency('glesv1_cm', required : false) 15 | gles2 = dependency('glesv2', required : false) 16 | 17 | subdir('src') 18 | subdir('tools') 19 | subdir('tests') 20 | -------------------------------------------------------------------------------- /tests/grate/meson.build: -------------------------------------------------------------------------------- 1 | tests = [ 2 | 'clear', 3 | 'cube', 4 | 'cube-textured', 5 | 'cube-textured2', 6 | 'cube-textured3', 7 | 'interactive', 8 | 'quad', 9 | 'stencil', 10 | 'texture-filter', 11 | 'texture-wrap', 12 | 'triangle', 13 | 'triangle-rotate' 14 | ] 15 | 16 | includes = include_directories( 17 | '../../include', 18 | '../../src/libgrate' 19 | ) 20 | 21 | foreach test : tests 22 | src = test + '.c' 23 | executable( 24 | test, 25 | src, 26 | include_directories : includes, 27 | dependencies : math, 28 | link_with : [libgrate, libhost1x] 29 | ) 30 | endforeach 31 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_attribute_relative_addressing.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .constants 10 | [95].y = 1.3; 11 | [95].z = -14.3; 12 | 13 | .asm 14 | EXEC(export[0]=vector) 15 | MOVv r0.xyzw, a[0].xyzw 16 | NOPs 17 | ; 18 | 19 | EXEC 20 | ARLv A0.x***, c[95].yyyy 21 | NOPs 22 | ; 23 | 24 | EXEC 25 | ARRv A0.***w, c[95].zzzz 26 | NOPs 27 | ; 28 | 29 | EXEC(export[7]=vector) 30 | MOVv r63.xy**, a[A0.x].xyzw 31 | NOPs 32 | ; 33 | 34 | EXEC(export[7]=vector) 35 | MOVv r63.**zw, a[A0.w + 15].xyzw 36 | NOPs 37 | ; 38 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_function.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .constants 10 | [77].x = -1.5; 11 | [77].y = -3.3; 12 | 13 | .asm 14 | 15 | EXEC(eq) 16 | ARLv A0.xy**, c[77].xyzw 17 | CALs 2 18 | ; /* 0 */ 19 | 20 | EXEC_END(export[0]=vector) 21 | MOVv r63.xyzw, a[A0.x + 2].xyzw 22 | ; /* 1 */ 23 | 24 | /***** FUNCTION BEGIN *****/ 25 | 26 | EXEC(export[7]=vector)(eq) 27 | MOVv r63.xyzw, a[A0.y + 5].xyzw 28 | RETs 29 | ; /* 2 */ 30 | 31 | /***** FUNCTION END *****/ 32 | 33 | EXEC_END 34 | NOPv 35 | NOPs 36 | ; /* 3 */ 37 | -------------------------------------------------------------------------------- /tools/fp20.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | uint32_t value, sign, mantissa, exponent; 8 | union { 9 | uint32_t u; 10 | float f; 11 | } bits; 12 | 13 | value = strtoul(argv[1], NULL, 16); 14 | 15 | sign = (value >> 19) & 0x1; 16 | exponent = (value >> 13) & 0x3f; 17 | mantissa = (value >> 0) & 0x1fff; 18 | 19 | if (exponent == 0x3f) 20 | exponent = 0xff; 21 | else 22 | exponent += 127 - 31; 23 | 24 | mantissa = mantissa << (23 - 13); 25 | 26 | bits.u = sign << 31 | (exponent << 23) | mantissa; 27 | 28 | printf("%f\n", bits.f); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_constant_relative_addressing.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .constants 10 | [100].x = 0.1; 11 | [100].y = 0.2; 12 | 13 | [135].z = 0.3; 14 | [135].w = 0.4; 15 | 16 | [211].y = 15.9; 17 | [211].z = -19.7; 18 | 19 | .asm 20 | 21 | EXEC(export[0]=vector) 22 | MOVv r63.xyzw, a[0].xyzw 23 | NOPs 24 | ; 25 | 26 | EXEC 27 | ARLv A0.x***, c[211].yyyy 28 | NOPs 29 | ; 30 | 31 | EXEC 32 | ARRv A0.***w, c[211].zzzz 33 | NOPs 34 | ; 35 | 36 | EXEC(export[7]=vector) 37 | MOVv r63.xy**, c[A0.x + 85].xyzw 38 | NOPs 39 | ; 40 | 41 | EXEC(export[7]=vector) 42 | MOVv r63.**zw, c[A0.w + 155].xyzw 43 | NOPs 44 | ; 45 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_predicate.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .constants 10 | [1].x = 0.1; 11 | [1].y = 0.5; 12 | 13 | [2].x = 0.3; 14 | [2].z = 0.4; 15 | 16 | .asm 17 | 18 | EXEC(export[0]=vector) 19 | MOVv r63.xyzw, a[0].xyzw 20 | MOVs r0.xyzw, c[1].xyzw 21 | ; 22 | 23 | EXEC(export[31]=vector)(cs)(cwr)(cr=0) 24 | SLTv r63.xyzw, r0.xyzw, c[2].xyzw 25 | ; 26 | 27 | EXEC(export[31]=vector)(cs)(cwr)(cr=1) 28 | SEQv r63.xyzw, r0.xyzw, c[2].xyzw 29 | ; 30 | 31 | EXEC(export[7]=vector)(cc)(cr=0)(gt)(p.xyzw) 32 | MOVv r63.xyzw, c[1].yyyy 33 | ; 34 | 35 | EXEC(export[7]=vector)(cc)(cr=1)(gt)(p.xyzw) 36 | MOVv r63.xyzw, c[2].zzzz 37 | ; 38 | -------------------------------------------------------------------------------- /tests/grate/asm/filter_quad_vs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Vertex shader for /grate/tests/texture-filter 3 | */ 4 | 5 | .exports 6 | [0] = "position"; 7 | [7] = "texcoord"; 8 | 9 | .attributes 10 | [0] = "position"; 11 | [1] = "texcoord"; 12 | 13 | .uniforms 14 | [0] = "mvp"; 15 | // [0] = "mvp[0]"; 16 | // [1] = "mvp[1]"; 17 | // [2] = "mvp[2]"; 18 | // [3] = "mvp[3]"; 19 | 20 | .asm 21 | 22 | /* Position */ 23 | EXEC(export[0]=vector) DP4v r63.x***, a[0].xyzw, c[0].xyzw; 24 | EXEC(export[0]=vector) DP4v r63.*y**, a[0].xyzw, c[1].xyzw; 25 | EXEC(export[0]=vector) DP4v r63.**z*, a[0].xyzw, c[2].xyzw; 26 | EXEC(export[0]=vector) DP4v r63.***w, a[0].xyzw, c[3].xyzw; 27 | 28 | /* texcoord export */ 29 | EXEC(export[7]=vector) MOVv r63.xy**, a[1].xyzw; 30 | -------------------------------------------------------------------------------- /tests/grate/asm/sky_vs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Vertex shader for /grate/tests/cube-textured3 3 | */ 4 | 5 | .exports 6 | [0] = "position"; 7 | [7] = "texcoord"; 8 | 9 | .attributes 10 | [0] = "position"; 11 | [1] = "texcoord"; 12 | 13 | .uniforms 14 | [0] = "mvp"; 15 | // [0] = "mvp[0]"; 16 | // [1] = "mvp[1]"; 17 | // [2] = "mvp[2]"; 18 | // [3] = "mvp[3]"; 19 | 20 | .asm 21 | 22 | /* Position x MVP mat4 */ 23 | EXEC(export[0]=vector) DP4v r63.x***, a[0].xyzw, c[0].xyzw; 24 | EXEC(export[0]=vector) DP4v r63.*y**, a[0].xyzw, c[1].xyzw; 25 | EXEC(export[0]=vector) DP4v r63.**z*, a[0].xyzw, c[2].xyzw; 26 | EXEC(export[0]=vector) DP4v r63.***w, a[0].xyzw, c[3].xyzw; 27 | 28 | /* texcoord export */ 29 | EXEC(export[7]=vector) MOVv r63.xy**, a[1].xyzw; 30 | -------------------------------------------------------------------------------- /tests/grate/asm/cube2_vs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Vertex shader for /grate/tests/cube-textured2 3 | */ 4 | 5 | .exports 6 | [0] = "position"; 7 | [7] = "texcoord"; 8 | 9 | .attributes 10 | [0] = "position"; 11 | [1] = "texcoord"; 12 | 13 | .uniforms 14 | [0] = "mvp"; 15 | // [0] = "mvp[0]"; 16 | // [1] = "mvp[1]"; 17 | // [2] = "mvp[2]"; 18 | // [3] = "mvp[3]"; 19 | 20 | .asm 21 | 22 | /* Position x MVP mat4 */ 23 | EXEC(export[0]=vector) DP4v r63.x***, a[0].xyzw, c[0].xyzw; 24 | EXEC(export[0]=vector) DP4v r63.*y**, a[0].xyzw, c[1].xyzw; 25 | EXEC(export[0]=vector) DP4v r63.**z*, a[0].xyzw, c[2].xyzw; 26 | EXEC(export[0]=vector) DP4v r63.***w, a[0].xyzw, c[3].xyzw; 27 | 28 | /* texcoord export */ 29 | EXEC(export[7]=vector) MOVv r63.xy**, a[1].xyzw; 30 | -------------------------------------------------------------------------------- /src/libhost1x/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = \ 2 | libhost1x.la 3 | 4 | libhost1x_la_CPPFLAGS = \ 5 | -I$(top_srcdir)/include 6 | 7 | libhost1x_la_CFLAGS = \ 8 | $(DRM_CFLAGS) \ 9 | $(PNG_CFLAGS) \ 10 | $(XCB_CFLAGS) 11 | 12 | libhost1x_la_SOURCES = \ 13 | dri-display.c \ 14 | host1x.c \ 15 | host1x-drm.c \ 16 | host1x-dummy.c \ 17 | host1x-framebuffer.c \ 18 | host1x-gr2d.c \ 19 | host1x-gr3d.c \ 20 | host1x-nvhost.c \ 21 | host1x-pixelbuffer.c \ 22 | host1x-private.h \ 23 | nvhost.c \ 24 | nvhost-display.c \ 25 | nvhost-gr2d.c \ 26 | nvhost-gr3d.c \ 27 | nvhost.h \ 28 | nvhost-nvmap.c \ 29 | nvhost-nvmap.h \ 30 | nvhost-nvmap.h \ 31 | tegra_dc_ext.h \ 32 | tegra_drm.h \ 33 | x11-display.c \ 34 | x11-display.h 35 | 36 | libhost1x_la_LIBADD = $(XCB_LIBS) $(DRM_LIBS) $(PNG_LIBS) 37 | -------------------------------------------------------------------------------- /data/grate/Creative Commons Attribution License 3.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution 3.0 Unported 2 | (http://creativecommons.org/licenses/by/3.0/) 3 | 4 | You are free: 5 | 6 | to Share — to copy, distribute and transmit the work 7 | to Remix — to adapt the work 8 | 9 | Under the following conditions: 10 | 11 | Attribution. 12 | You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). 13 | 14 | For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page. 15 | 16 | Any of the above conditions can be waived if you get permission from the copyright holder. 17 | 18 | Nothing in this license impairs or restricts the author's moral rights. 19 | -------------------------------------------------------------------------------- /tests/grate/asm/sky_fs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Fragment shader for /grate/tests/cube-textured3 3 | */ 4 | 5 | pseq_to_dw_exec_nb = 2 6 | alu_buffer_size = 1 7 | 8 | .uniforms 9 | [0].l = "day"; 10 | [0].h = "night"; 11 | 12 | .asm 13 | 14 | EXEC 15 | MFU: sfu: rcp r4 16 | mul0: bar, sfu, bar0 17 | mul1: bar, sfu, bar1 18 | ipl: t0.fp20, t0.fp20, NOP, NOP 19 | 20 | TEX: tex r2, r3, tex0, r0, r1, r2 21 | 22 | ALU: 23 | ALU1: MAD r3.l*, r3.l, u0.l, #0 // Blue 24 | ALU2: MAD r2.*h, r2.h, u0.l, #0 // Green 25 | ALU3: MAD r2.l*, r2.l, u0.l, #0 // Red 26 | ; 27 | 28 | EXEC 29 | TEX: tex r0, r1, tex1, r0, r1, r2 30 | 31 | ALU: 32 | ALU1: MAD r3.l*, r1.l, u0.h, r3.l // Blue 33 | ALU2: MAD r2.*h, r0.h, u0.h, r2.h // Green 34 | ALU3: MAD r2.l*, r0.l, u0.h, r2.l // Red 35 | 36 | DW: store rt1, r2, r3 37 | ; 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Grate 2 | Grate is an anagram of "Tegra", actually it is a collection of open source reverse-engineering tools aiming at the NVIDIA Tegra 2/34 2D/3D engines. 3 | 4 | ## Documentation 5 | 6 | We have several useful documents of the Tegra architecture on our [wiki](https://github.com/grate-driver/grate/wiki). In particular: 7 | * [Command Stream](https://github.com/grate-driver/grate/wiki/Command-stream) 8 | * [MMIO Registers](https://github.com/grate-driver/grate/wiki/MMIO-Registers) 9 | * [Vertex Shader ISA](https://github.com/grate-driver/grate/wiki/Vertex-Shader-ISA) 10 | * [Fragment Shader ISA](https://github.com/grate-driver/grate/wiki/Fragment-Shader-ISA) 11 | * [Shader Linking](https://github.com/grate-driver/grate/wiki/Shader-Linking) 12 | * [Geometry Submission](https://github.com/grate-driver/grate/wiki/Geometry-Submission) 13 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_stack.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .constants 10 | [77].x = -1.5; 11 | 12 | [123].y = -3.3; 13 | 14 | .asm 15 | 16 | EXEC 17 | ARLv A0.xy**, c[77].xyzw 18 | ; /* 0 */ 19 | 20 | EXEC 21 | PUSHAv 22 | ; /* 1 */ 23 | 24 | EXEC(eq) 25 | CALs 6 26 | ; /* 2 */ 27 | 28 | EXEC 29 | POPAs 30 | ; /* 3 */ 31 | 32 | EXEC(export[0]=vector) 33 | MOVv r63.xyzw, a[A0.x + 2].xyzw 34 | ; /* 4 */ 35 | 36 | EXEC_END 37 | NOPv 38 | NOPs 39 | ; /* 5 */ 40 | 41 | /***** FUNCTION BEGIN *****/ 42 | 43 | EXEC 44 | ARLv A0.xyzw, c[123].yyyy 45 | ; /* 6 */ 46 | 47 | EXEC(export[7]=vector)(eq) 48 | MOVv r63.xyzw, a[A0.x + 5].xyzw 49 | RETs 50 | ; /* 7 */ 51 | 52 | /***** FUNCTION END *****/ 53 | 54 | EXEC_END 55 | NOPv 56 | NOPs 57 | ; /* 8 */ 58 | -------------------------------------------------------------------------------- /tests/grate/asm/fs_mfu_tests.txt: -------------------------------------------------------------------------------- 1 | alu_buffer_size = 1 2 | pseq_to_dw_exec_nb = 3 3 | 4 | .asm 5 | EXEC 6 | MFU: sfu: rcp r4 7 | mul0: bar, sfu, bar0 8 | mul1: bar, sfu, bar1 9 | ipl: t0.fp20, t0.fp20, t0.fp20, t0.fp20 10 | 11 | ALU: 12 | ALU0: MAD r3.lh, r3, #1, r3 13 | ALU1: MAD r1.lh, r1, #0, imm0 14 | ALU2: MAD r2.lh, r2, #0, imm0 15 | ALU3: imm0 = 0.5 16 | ; 17 | 18 | EXEC 19 | MFU: sfu: rcp r3 20 | MFU: sfu: precos r1 21 | MFU: sfu: preex2 r2 22 | ; 23 | 24 | EXEC 25 | MFU: sfu: cos r1 26 | mul0: r0, r0, r3 27 | MFU: sfu: ex2 r2 28 | 29 | ALU: 30 | ALU0: MAD r3.*h, r3, #1, #0 31 | ALU1: MAD r3.l*, r2, #1, -#1 32 | ALU2: MAD r2.*h, r0, #1, #0 33 | ALU3: MAD r2.l*, r1, #1, #0 34 | 35 | DW: store rt1, r2, r3 36 | ; 37 | -------------------------------------------------------------------------------- /tests/grate/asm/stencil_test_fs2.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Fragment shader for /grate/tests/stencil 3 | */ 4 | 5 | pseq_to_dw_exec_nb = 1 6 | alu_buffer_size = 1 7 | 8 | .constants 9 | [0] = 0.017; // color components threshold 10 | 11 | .asm 12 | 13 | EXEC 14 | MFU: sfu: rcp r4 15 | mul0: bar, sfu, bar0 16 | mul1: bar, sfu, bar1 17 | ipl: t0.fp20, t0.fp20, NOP, NOP 18 | 19 | TEX: tex r2, r3, tex0, r0, r1, r2 20 | 21 | /* 22 | * cr0 = (-frag.r + 0.017) > 0; 23 | * cr1 = (-frag.g + 0.017) > 0; 24 | * cr2 = (-frag.b + 0.017) > 0; 25 | * 26 | * if (cr0 * cr1 * cr2 == 1) 27 | * discard; 28 | */ 29 | ALU: 30 | ALU0: MAD cr0, -r2.l, #1, u0, #1 (gt) 31 | ALU1: MAD cr1, -r2.h, #1, u0, #1 (gt) 32 | ALU2: MAD cr2, -r3.l, #1, u0, #1 (gt) 33 | ALU3: MAD cr0, alu0, alu1, #0 34 | ; 35 | 36 | EXEC 37 | ALU: ALU0: MAD kill, cr0, cr2, #0 38 | DW: store stencil 39 | ; 40 | -------------------------------------------------------------------------------- /tools/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = \ 2 | assembler \ 3 | cgc \ 4 | hex2float \ 5 | fp20 \ 6 | fx10 \ 7 | replay \ 8 | reset3d 9 | 10 | assembler_CPPFLAGS = \ 11 | -I$(top_srcdir)/include \ 12 | -I$(top_srcdir)/src/libgrate 13 | 14 | assembler_LDADD = \ 15 | ../src/libgrate/libgrate.la 16 | 17 | cgc_CPPFLAGS = \ 18 | -I$(top_srcdir)/include 19 | 20 | cgc_LDADD = \ 21 | ../src/libcgc/libcgc.la 22 | 23 | replay_CPPFLAGS = \ 24 | -I$(top_srcdir)/include \ 25 | -I$(top_srcdir)/src/libhost1x \ 26 | -I$(top_srcdir)/src/libgrate 27 | 28 | if ENABLE_ZLIB 29 | replay_CPPFLAGS += -DENABLE_ZLIB 30 | endif 31 | 32 | if ENABLE_LZ4 33 | replay_CPPFLAGS += -DENABLE_LZ4 34 | endif 35 | 36 | replay_CFLAGS = $(ZLIB_CFLAGS) 37 | 38 | replay_LDADD = \ 39 | ../src/libgrate/libgrate.la 40 | if ENABLE_ZLIB 41 | replay_LDADD += -lz 42 | endif 43 | if ENABLE_LZ4 44 | replay_LDADD += -llz4 45 | endif 46 | -------------------------------------------------------------------------------- /tests/grate/asm/cube2_grate_fs.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Fragment shader for /grate/tests/cube-textured2 3 | */ 4 | 5 | pseq_to_dw_exec_nb = 1 6 | alu_buffer_size = 1 7 | 8 | .constants 9 | [0] = 0.017; // color components threshold 10 | 11 | .asm 12 | 13 | EXEC 14 | MFU: sfu: rcp r4 15 | mul0: bar, sfu, bar0 16 | mul1: bar, sfu, bar1 17 | ipl: t0.fp20, t0.fp20, NOP, NOP 18 | 19 | TEX: tex r2, r3, tex11, r0, r1, r2 20 | 21 | /* 22 | * cr0 = (-frag.r + 0.017) > 0; 23 | * cr1 = (-frag.g + 0.017) > 0; 24 | * cr2 = (-frag.b + 0.017) > 0; 25 | * 26 | * if (cr0 * cr1 * cr2 == 1) 27 | * discard; 28 | */ 29 | ALU: 30 | ALU0: MAD cr0, -r2.l, #1, u0, #1 (gt) 31 | ALU1: MAD cr1, -r2.h, #1, u0, #1 (gt) 32 | ALU2: MAD cr2, -r3.l, #1, u0, #1 (gt) 33 | ALU3: MAD cr0, alu0, alu1, #0 34 | ; 35 | 36 | EXEC 37 | ALU: 38 | ALU0: MAD kill, cr0, cr2, #0 39 | 40 | DW: store rt1, r2, r3 41 | ; 42 | -------------------------------------------------------------------------------- /tools/meson.build: -------------------------------------------------------------------------------- 1 | tools = [ 2 | 'assembler', 3 | 'cgc', 4 | 'hex2float', 5 | 'fp20', 6 | 'fx10', 7 | 'replay', 8 | 'reset3d', 9 | ] 10 | 11 | includes = include_directories( 12 | '../../include', 13 | '../../src/libgrate', 14 | '../../src/libhost1x' 15 | ) 16 | 17 | tools_deps = [math] 18 | tools_c_args = [] 19 | 20 | libz = cc.find_library('z', required : false) 21 | if libz.found() and cc.has_header('zlib.h') 22 | tools_deps += [libz] 23 | tools_c_args += ['-DENABLE_ZLIB'] 24 | endif 25 | 26 | liblz4 = cc.find_library('lz4', required : false) 27 | if liblz4.found() and cc.has_header('lz4.h') 28 | tools_deps += [liblz4] 29 | tools_c_args += ['-DENABLE_LZ4'] 30 | endif 31 | 32 | foreach tool : tools 33 | src = tool + '.c' 34 | executable( 35 | tool, 36 | src, 37 | include_directories : includes, 38 | dependencies : tools_deps, 39 | link_with : [libgrate, libhost1x, libcgc], 40 | c_args: tools_c_args, 41 | ) 42 | endforeach 43 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_branching.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .constants 10 | [0].x = 1.0; 11 | [0].y = 1.0; 12 | [0].z = 1.0; 13 | [0].w = 1.0; 14 | 15 | .asm 16 | 17 | EXEC(eq) 18 | BRAs 3 19 | ; /* 0 */ 20 | 21 | EXEC_END 22 | NOPv 23 | NOPs 24 | ; /* 1 */ 25 | 26 | EXEC_END 27 | NOPv 28 | NOPs 29 | ; /* 2 */ 30 | 31 | EXEC(export[0]=vector)(eq) 32 | MOVv r63.xyzw, a[0].xyzw 33 | BRAs 7 34 | ; /* 3 */ 35 | 36 | EXEC_END(export[0]=vector) 37 | MOVv r63.xyzw, c[0].xyzw 38 | NOPs 39 | ; /* 4 */ 40 | 41 | EXEC_END(export[0]=vector) 42 | MOVv r63.xyzw, c[0].xyzw 43 | NOPs 44 | ; /* 5 */ 45 | 46 | EXEC_END(export[0]=vector) 47 | MOVv r63.xyzw, c[0].xyzw 48 | NOPs 49 | ; /* 6 */ 50 | 51 | EXEC_END(export[7]=vector) 52 | MOVv r63.xyzw, a[1].xyzw 53 | ; /* 7 */ 54 | 55 | EXEC(export[0]=vector) 56 | MOVv r63.xyzw, c[0].xyzw 57 | NOPs 58 | ; /* 8 */ 59 | -------------------------------------------------------------------------------- /tests/gles2/meson.build: -------------------------------------------------------------------------------- 1 | tests = [ 2 | 'egl-clear', 3 | 'egl-triangle', 4 | 'egl-x11-clear', 5 | 'egl-x11-triangle', 6 | 'gles-clear', 7 | 'gles-cube', 8 | 'gles-cube-textured', 9 | 'gles-pbuffer-cgshader', 10 | 'gles-pbuffer-clear', 11 | 'gles-pbuffer-cube', 12 | 'gles-pbuffer-fill', 13 | 'gles-pbuffer-triangle', 14 | 'gles-pbuffer-triangle-rotate', 15 | 'gles-pbuffer-uniforms', 16 | 'gles-pbuffer-uniforms-rgb', 17 | 'gles-pbuffer-uniforms-rg', 18 | 'gles-pbuffer-vertex-offset', 19 | 'gles-quad-textured', 20 | 'gles-quad-textured2', 21 | 'gles-quad-textured3', 22 | 'gles-shader-fill', 23 | 'gles-stencil', 24 | 'gles2-info' 25 | ] 26 | 27 | include_dirs = [ 28 | '../../include', 29 | '../../src/libgrate', 30 | ] 31 | 32 | foreach test : tests 33 | src = test + '.c' 34 | executable( 35 | test, 36 | [src, 'common.c'], 37 | include_directories : include_directories(include_dirs), 38 | dependencies : [math, egl, x11, gles2, libpng, devil], 39 | link_with : libgrate 40 | ) 41 | endforeach 42 | -------------------------------------------------------------------------------- /tests/gles2/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libcommon.la 2 | 3 | libcommon_la_SOURCES = \ 4 | common.c \ 5 | common.h 6 | 7 | libcommon_la_LIBADD = $(X11_LIBS) $(GLES2_LIBS) $(PNG_LIBS) $(DevIL_LIBS) -lm 8 | 9 | AM_CFLAGS = $(GLES2_CFLAGS) $(PNG_CFLAGS) 10 | AM_CFLAGS += -I$(top_srcdir)/include 11 | AM_CFLAGS += -I$(top_srcdir)/src/libgrate 12 | LDADD = libcommon.la $(top_builddir)/src/libgrate/libgrate.la 13 | 14 | noinst_PROGRAMS = \ 15 | egl-clear \ 16 | egl-triangle \ 17 | egl-x11-clear \ 18 | egl-x11-triangle \ 19 | gles-clear \ 20 | gles-cube \ 21 | gles-cube-textured \ 22 | gles-pbuffer-cgshader \ 23 | gles-pbuffer-clear \ 24 | gles-pbuffer-cube \ 25 | gles-pbuffer-fill \ 26 | gles-pbuffer-triangle \ 27 | gles-pbuffer-triangle-rotate \ 28 | gles-pbuffer-uniforms \ 29 | gles-pbuffer-uniforms-rgb \ 30 | gles-pbuffer-uniforms-rg \ 31 | gles-pbuffer-vertex-offset \ 32 | gles-quad-textured \ 33 | gles-quad-textured2 \ 34 | gles-quad-textured3 \ 35 | gles-shader-fill \ 36 | gles-stencil \ 37 | gles2-info 38 | -------------------------------------------------------------------------------- /tests/drm/vblank.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | drmVBlank vbl; 12 | int fd, err; 13 | 14 | fd = open(argv[1], O_RDWR); 15 | if (fd < 0) { 16 | fprintf(stderr, "open() failed: %m\n"); 17 | return 1; 18 | } 19 | 20 | while (true) { 21 | memset(&vbl, 0, sizeof(vbl)); 22 | vbl.request.type = DRM_VBLANK_RELATIVE; 23 | vbl.request.sequence = 1; 24 | vbl.request.signal = 0; 25 | 26 | err = drmWaitVBlank(fd, &vbl); 27 | if (err < 0) { 28 | fprintf(stderr, "drmWaitVBlank() failed: %m\n"); 29 | return 1; 30 | } 31 | 32 | fprintf(stdout, "reply:\n"); 33 | fprintf(stdout, " type: %x\n", vbl.reply.type); 34 | fprintf(stdout, " sequence: %u\n", vbl.reply.sequence); 35 | fprintf(stdout, " tval_sec: %ld\n", vbl.reply.tval_sec); 36 | fprintf(stdout, " tval_usec: %ld\n", vbl.reply.tval_usec); 37 | } 38 | 39 | close(fd); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /tests/grate/asm/vs_export_relative_addressing.txt: -------------------------------------------------------------------------------- 1 | .attributes 2 | [0] = "position"; 3 | [1] = "color"; 4 | 5 | .exports 6 | [0] = "gl_Position"; 7 | [7] = "vcolor"; 8 | 9 | .constants 10 | [95].x = 1.5; 11 | [95].y = 3.3; 12 | [95].z = -8.3; 13 | [95].w = 7.3; 14 | 15 | [133].x = 0.4; 16 | [133].z = 0.1; 17 | 18 | .asm 19 | 20 | /* A0 = (3, 0, 1, 0) */ 21 | EXEC(export[0]=scalar) 22 | ARLv A0.x*z*, c[95].yyxy 23 | MOVs r63.xyzw, a[0].xyzw 24 | ; 25 | 26 | /* A0 = (3, 7, 1, -14) */ 27 | EXEC 28 | ARRv A0.*y*w, c[95].zwzz 29 | NOPs 30 | ; 31 | 32 | /* A0.x = A0.x + A0.z = 3 + 1 = 4, so A0.xyzw = (4, 7, 1, -14) */ 33 | EXEC 34 | ARAv A0.x*** 35 | NOPs 36 | ; 37 | 38 | EXEC(export[A0.z + 6]=vector) 39 | MOVv r63.xy**, a[A0.z].xyzw 40 | NOPs 41 | ; 42 | 43 | EXEC(export[A0.w + 15]=vector) 44 | MOVv r63.**z*, a[A0.w + 9].xyzw 45 | NOPs 46 | ; 47 | 48 | EXEC(export[A0.y]=vector) 49 | MOVv r63.x***, c[A0.y + 126].zzzz 50 | NOPs 51 | ; 52 | 53 | EXEC(export[A0.x + 3]=vector) 54 | MOVv r63.***w, c[A0.x + 129].xxxx 55 | NOPs 56 | ; 57 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, 2013 Erik Faye-Lund 2 | Copyright (c) 2013 Avionic Design GmbH 3 | Copyright (c) 2013 Thierry Reding 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/libwrap/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libgrate-wrap.la 2 | 3 | libgrate_wrap_la_CPPFLAGS = \ 4 | -I$(top_srcdir)/include \ 5 | -I$(top_srcdir)/src/libgrate 6 | 7 | if ENABLE_RNN 8 | libgrate_wrap_la_CPPFLAGS += -DENABLE_RNN 9 | endif 10 | 11 | if ENABLE_ZLIB 12 | libgrate_wrap_la_CPPFLAGS += -DENABLE_ZLIB 13 | endif 14 | 15 | if ENABLE_LZ4 16 | libgrate_wrap_la_CPPFLAGS += -DENABLE_LZ4 17 | endif 18 | 19 | libgrate_wrap_la_CFLAGS = -pthread $(ZLIB_CFLAGS) $(LZ4_CFLAGS) 20 | 21 | libgrate_wrap_la_SOURCES = \ 22 | cdma_parser.c \ 23 | cdma_parser.h \ 24 | cgdrv.c \ 25 | disasm.h \ 26 | disasm.c \ 27 | drm.h \ 28 | drm_fourcc.h \ 29 | drm_mode.h \ 30 | host1x.c \ 31 | host1x.h \ 32 | nvhost.c \ 33 | nvhost.h \ 34 | recorder.c \ 35 | recorder.h \ 36 | syscall.c \ 37 | syscall.h \ 38 | tegra_drm.h \ 39 | utils.c \ 40 | utils.h 41 | 42 | AUTOMAKE_OPTIONS = subdir-objects 43 | 44 | libgrate_wrap_la_SOURCES += \ 45 | ../libgrate/asm.h \ 46 | ../libgrate/fragment_asm.h \ 47 | ../libgrate/fragment_disasm.c \ 48 | ../libgrate/linker_asm.h \ 49 | ../libgrate/linker_disasm.c \ 50 | ../libgrate/vertex_disasm.c \ 51 | ../libgrate/vpe_vliw.h 52 | 53 | libgrate_wrap_la_LIBADD = -ldl 54 | if ENABLE_RNN 55 | libgrate_wrap_la_LIBADD += -lrnn -lenvyutil -lxml2 56 | endif 57 | if ENABLE_ZLIB 58 | libgrate_wrap_la_LIBADD += -lz 59 | endif 60 | if ENABLE_LZ4 61 | libgrate_wrap_la_LIBADD += -llz4 62 | endif 63 | -------------------------------------------------------------------------------- /src/libwrap/syscall.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_SYSCALL_H 26 | #define GRATE_SYSCALL_H 1 27 | 28 | void *mmap_orig(void *addr, size_t length, int prot, int flags, 29 | int fd, off_t offset); 30 | 31 | int munmap_orig(void *addr, size_t length); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/libwrap/host1x.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Dmitry Osipenko 3 | * Copyright (c) 2012, 2013 Erik Faye-Lund 4 | * Copyright (c) 2013 Avionic Design GmbH 5 | * Copyright (c) 2013 Thierry Reding 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef GRATE_HOST1X_H 27 | #define GRATE_HOST1X_H 1 28 | 29 | #include 30 | #include 31 | 32 | #include "tegra_drm.h" 33 | #include "utils.h" 34 | 35 | void host1x_register(void); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/libhost1x/meson.build: -------------------------------------------------------------------------------- 1 | libhost1x_sources = files( 2 | 'dri-display.c', 3 | 'host1x.c', 4 | 'host1x-drm.c', 5 | 'host1x-dummy.c', 6 | 'host1x-framebuffer.c', 7 | 'host1x-gr2d.c', 8 | 'host1x-gr3d.c', 9 | 'host1x-nvhost.c', 10 | 'host1x-pixelbuffer.c', 11 | 'host1x-private.h', 12 | 'nvhost.c', 13 | 'nvhost-display.c', 14 | 'nvhost-gr2d.c', 15 | 'nvhost-gr3d.c', 16 | 'nvhost.h', 17 | 'nvhost-nvmap.c', 18 | 'nvhost-nvmap.h', 19 | 'nvhost-nvmap.h', 20 | 'tegra_dc_ext.h', 21 | 'tegra_drm.h', 22 | 'x11-display.c', 23 | 'x11-display.h' 24 | ) 25 | 26 | libhost1x_c_args = [] 27 | libhost1x_deps = [libdrm, libpng] 28 | 29 | if x11.found() and \ 30 | dependency('xcb', required : false).found() and \ 31 | dependency('xcb-image', required : false).found() and \ 32 | dependency('xcb-dri2', required : false).found() and \ 33 | dependency('xcb-icccm', required : false).found() 34 | libhost1x_c_args += '-DHAVE_XCB' 35 | libhost1x_deps += dependency('xcb') 36 | libhost1x_deps += dependency('xcb-image') 37 | libhost1x_deps += dependency('xcb-dri2') 38 | libhost1x_deps += dependency('xcb-icccm') 39 | endif 40 | 41 | cc = meson.get_compiler('c') 42 | 43 | if cc.has_function('drmSetClientCap', 44 | prefix: '#include ', 45 | dependencies : [libdrm]) 46 | libhost1x_c_args += '-DHAVE_LIBDRM_CLIENT_CAP' 47 | endif 48 | 49 | libhost1x = shared_library('host1x', 50 | libhost1x_sources, 51 | include_directories : include_directories('../../include'), 52 | dependencies : [libhost1x_deps], 53 | c_args : [libhost1x_c_args], 54 | ) 55 | -------------------------------------------------------------------------------- /src/libgrate/linker_asm.h: -------------------------------------------------------------------------------- 1 | #ifndef LINKER_ASM_H 2 | #define LINKER_ASM_H 3 | 4 | #include 5 | 6 | #define LINK_SWIZZLE_X 0 7 | #define LINK_SWIZZLE_Y 1 8 | #define LINK_SWIZZLE_Z 2 9 | #define LINK_SWIZZLE_W 3 10 | 11 | #define TRAM_DST_NONE 0 12 | #define TRAM_DST_FX10_LOW 1 13 | #define TRAM_DST_FX10_HIGH 2 14 | #define TRAM_DST_FP20 3 15 | 16 | typedef union shader_linking_instruction { 17 | struct __attribute__((packed)) { 18 | unsigned vec4_select:1; 19 | unsigned __pad1:2; 20 | unsigned vertex_export_index:4; 21 | unsigned __pad2:2; 22 | unsigned tram_row_index:6; 23 | unsigned __pad3:1; 24 | unsigned const_x_across_width:1; 25 | unsigned const_x_across_length:1; 26 | unsigned x_across_point:2; 27 | unsigned const_y_across_width:1; 28 | unsigned const_y_across_length:1; 29 | unsigned y_across_point:2; 30 | unsigned const_z_across_width:1; 31 | unsigned const_z_across_length:1; 32 | unsigned z_across_point:2; 33 | unsigned const_w_across_width:1; 34 | unsigned const_w_across_length:1; 35 | unsigned w_across_point:2; 36 | 37 | unsigned tram_dst_swizzle_x:2; 38 | unsigned tram_dst_type_x:2; 39 | unsigned tram_dst_swizzle_y:2; 40 | unsigned tram_dst_type_y:2; 41 | unsigned tram_dst_swizzle_z:2; 42 | unsigned tram_dst_type_z:2; 43 | unsigned tram_dst_swizzle_w:2; 44 | unsigned tram_dst_type_w:2; 45 | unsigned interpolation_disable_x:1; 46 | unsigned interpolation_disable_y:1; 47 | unsigned interpolation_disable_z:1; 48 | unsigned interpolation_disable_w:1; 49 | }; 50 | 51 | struct __attribute__((packed)) { 52 | uint32_t first; 53 | uint32_t latter; 54 | }; 55 | 56 | uint64_t data; 57 | } link_instr; 58 | 59 | #endif // LINKER_ASM_H 60 | -------------------------------------------------------------------------------- /src/libwrap/cdma_parser.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2012, 2013 Erik Faye-Lund 4 | * Copyright (c) 2013 Avionic Design GmbH 5 | * Copyright (c) 2013 Thierry Reding 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef GRATE_CDMA_PARSE_H 27 | #define GRATE_CDMA_PARSE_H 1 28 | 29 | #include 30 | #include 31 | 32 | typedef void (*cdma_write)(void *opaque, uint32_t host1x_class, 33 | uint32_t offset, uint32_t data); 34 | 35 | void cdma_parse_commands(uint32_t *commands, unsigned int count, 36 | bool print, uint32_t *classid, void *write_arg, 37 | cdma_write write_cb); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/libwrap/meson.build: -------------------------------------------------------------------------------- 1 | libwrap_sources = files( 2 | 'cdma_parser.c', 3 | 'cdma_parser.h', 4 | 'cgdrv.c', 5 | 'disasm.c', 6 | 'disasm.h', 7 | 'drm.h', 8 | 'drm_fourcc.h', 9 | 'drm_mode.h', 10 | 'host1x.c', 11 | 'host1x.h', 12 | 'nvhost.c', 13 | 'nvhost.h', 14 | 'recorder.c', 15 | 'recorder.h', 16 | 'syscall.c', 17 | 'syscall.h', 18 | 'tegra_drm.h', 19 | 'utils.c', 20 | 'utils.h' 21 | ) 22 | 23 | libwrap_sources += files( 24 | '../libgrate/asm.h', 25 | '../libgrate/fragment_asm.h', 26 | '../libgrate/fragment_disasm.c', 27 | '../libgrate/linker_asm.h', 28 | '../libgrate/linker_disasm.c', 29 | '../libgrate/vertex_disasm.c', 30 | '../libgrate/vpe_vliw.h' 31 | ) 32 | 33 | libwrap_includes = include_directories( 34 | '../../include', 35 | '../../src/libgrate' 36 | ) 37 | 38 | libwrap_deps = [libdl, dependency('threads')] 39 | libwrap_c_args = ['-U_FILE_OFFSET_BITS'] 40 | 41 | librnn = cc.find_library('rnn', required : false) 42 | if librnn.found() and cc.has_header('envytools/rnn.h') 43 | libenvyutil = cc.find_library('envyutil') 44 | libxml2 = cc.find_library('xml2') 45 | libwrap_deps += [librnn, libenvyutil, libxml2] 46 | libwrap_c_args += ['-DENABLE_RNN'] 47 | endif 48 | 49 | libz = cc.find_library('z', required : false) 50 | if libz.found() and cc.has_header('zlib.h') 51 | libwrap_deps += [libz] 52 | libwrap_c_args += ['-DENABLE_ZLIB'] 53 | endif 54 | 55 | liblz4 = cc.find_library('lz4', required : false) 56 | if liblz4.found() and cc.has_header('lz4.h') 57 | libwrap_deps += [liblz4] 58 | libwrap_c_args += ['-DENABLE_LZ4'] 59 | endif 60 | 61 | libwrap = shared_library( 62 | 'wrap', 63 | libwrap_sources, 64 | dependencies: libwrap_deps, 65 | include_directories : libwrap_includes, 66 | c_args: libwrap_c_args 67 | ) 68 | -------------------------------------------------------------------------------- /src/libgrate/libgrate-private.h: -------------------------------------------------------------------------------- 1 | #ifndef GRATE_LIBGRATE_PRIVATE_H 2 | #define GRATE_LIBGRATE_PRIVATE_H 1 3 | 4 | #include "grate.h" 5 | #include "libcgc.h" 6 | 7 | struct host1x_pushbuf; 8 | 9 | struct grate_region { 10 | unsigned long start; 11 | unsigned long end; 12 | 13 | struct grate_region *prev, *next; 14 | }; 15 | 16 | struct grate_color { 17 | float r, g, b, a; 18 | }; 19 | 20 | struct grate_framebuffer { 21 | struct host1x_framebuffer *front; 22 | struct host1x_framebuffer *back; 23 | }; 24 | 25 | struct grate { 26 | struct grate_options *options; 27 | struct grate_display *display; 28 | struct grate_overlay *overlay; 29 | struct grate_framebuffer *fb; 30 | struct grate_color clear; 31 | struct host1x_options host1x_options; 32 | struct host1x *host1x; 33 | }; 34 | 35 | struct grate_display *grate_display_open(struct grate *grate); 36 | void grate_display_close(struct grate_display *display); 37 | void grate_display_get_resolution(struct grate_display *display, 38 | unsigned int *width, unsigned int *height); 39 | void grate_display_show(struct grate_display *display, 40 | struct grate_framebuffer *fb, 41 | bool vsync, bool reflect_y); 42 | 43 | struct grate_overlay *grate_overlay_create(struct grate_display *display); 44 | void grate_overlay_free(struct grate_overlay *overlay); 45 | void grate_overlay_show(struct grate_overlay *overlay, 46 | struct grate_framebuffer *fb, unsigned int x, 47 | unsigned int y, unsigned int width, 48 | unsigned int height, bool vsync, bool reflect_y); 49 | 50 | #define grate_error(fmt, args...) \ 51 | fprintf(stderr, "\033[31mERROR: %s: " fmt "\033[0m", \ 52 | __func__, ##args) 53 | 54 | #define grate_info(fmt, args...) \ 55 | fprintf(stdout, "INFO: %s: " fmt, __func__, ##args) 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/libgrate/meson.build: -------------------------------------------------------------------------------- 1 | libgrate_sources = files( 2 | 'display.c', 3 | 'etc1.cpp', 4 | 'etc1.h', 5 | 'fragment_asm.h', 6 | 'grate.c', 7 | 'grate.h', 8 | 'grate-asm.c', 9 | 'grate-font.c', 10 | 'grate-texture.c', 11 | 'grate-2d.c', 12 | 'grate-3d.c', 13 | 'grate-3d.h', 14 | 'grate-3d-ctx.c', 15 | 'grate-3d-ctx.h', 16 | 'libgrate-private.h', 17 | 'linker_asm.h', 18 | 'matrix.c', 19 | 'matrix.h', 20 | 'profile.c', 21 | 'shader-cgc.c', 22 | 'vpe_vliw.h', 23 | 'fragment_disasm.c', 24 | 'vertex_disasm.c', 25 | 'linker_disasm.c' 26 | ) 27 | 28 | parser_gen = generator( 29 | yacc, 30 | output : ['@BASENAME@.tab.c', '@BASENAME@.tab.h'], 31 | arguments : ['-d', '-o', '@OUTPUT0@', '@EXTRA_ARGS@', '@INPUT@'] 32 | ) 33 | 34 | lex_gen = generator( 35 | lex, 36 | output : 'lex.@BASENAME@.c', 37 | arguments : ['@EXTRA_ARGS@', '--nounput', '-o', '@OUTPUT@', '@INPUT@'] 38 | ) 39 | 40 | vertex_asm_parser = parser_gen.process('vertex_asm.y', extra_args : ['-p', 'vertex_asm']) 41 | lex_vertex_asm = lex_gen.process('vertex_asm.l', extra_args : ['-P', 'vertex_asm']) 42 | 43 | fragment_asm_parser = parser_gen.process('fragment_asm.y', extra_args : ['-p', 'fragment_asm']) 44 | lex_fragment_asm = lex_gen.process('fragment_asm.l', extra_args : ['-P', 'fragment_asm']) 45 | 46 | linker_asm_parser = parser_gen.process('linker_asm.y', extra_args : ['-p', 'linker_asm']) 47 | lex_linker_asm = lex_gen.process('linker_asm.l', extra_args : ['-P', 'linker_asm']) 48 | 49 | libgrate = shared_library('grate', 50 | libgrate_sources, 51 | vertex_asm_parser, lex_vertex_asm, 52 | fragment_asm_parser, lex_fragment_asm, 53 | linker_asm_parser, lex_linker_asm, 54 | include_directories : include_directories('../../include'), 55 | dependencies : [math, devil], 56 | link_with : [libcgc, libhost1x] 57 | ) 58 | -------------------------------------------------------------------------------- /src/libcgc/dummy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | #include "libcgc-private.h" 28 | 29 | struct CgDrv *CgDrv_Create(void) 30 | { 31 | fprintf(stderr, "%s: BLOB compiler is unavailable\n", __func__); 32 | return NULL; 33 | } 34 | 35 | void CgDrv_Delete(struct CgDrv *cgdrv) 36 | { 37 | } 38 | 39 | void CgDrv_CleanUp(struct CgDrv *cgdrv) 40 | { 41 | } 42 | 43 | int CgDrv_Compile(struct CgDrv *cgdrv, int unknown, int type, 44 | const char *code, size_t length, int unknown2, int unknown3) 45 | { 46 | return -1; 47 | } 48 | -------------------------------------------------------------------------------- /tests/nvhost/gr3d.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_GR3D_H 26 | #define GRATE_GR3D_H 1 27 | 28 | #include "nvhost.h" 29 | 30 | struct nvhost_gr3d { 31 | struct nvhost_client client; 32 | struct nvmap_handle *attributes; 33 | struct nvmap_handle *buffer; 34 | int fd; 35 | }; 36 | 37 | struct nvhost_gr3d *nvhost_gr3d_open(struct nvmap *nvmap, 38 | struct nvhost_ctrl *ctrl); 39 | void nvhost_gr3d_close(struct nvhost_gr3d *gr3d); 40 | int nvhost_gr3d_triangle(struct nvhost_gr3d *gr3d, 41 | struct nvmap_framebuffer *fb); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /tests/gles1/gles1-info.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2014 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | int main(int argc, char *argv[]) 36 | { 37 | struct window *window; 38 | 39 | window = window_create(0, 0, 640, 480); 40 | if (!window) { 41 | fprintf(stderr, "window_create() failed\n"); 42 | return 1; 43 | } 44 | 45 | printf("GL_EXTENSIONS: %s\n", glGetString(GL_EXTENSIONS)); 46 | 47 | window_close(window); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /tests/gles2/gles2-info.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2014 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | int main(int argc, char *argv[]) 36 | { 37 | struct window *window; 38 | 39 | window = window_create(0, 0, 640, 480); 40 | if (!window) { 41 | fprintf(stderr, "window_create() failed\n"); 42 | return 1; 43 | } 44 | 45 | printf("GL_EXTENSIONS: %s\n", glGetString(GL_EXTENSIONS)); 46 | 47 | window_close(window); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /tests/nvhost/gr2d.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_GR2D_H 26 | #define GRATE_GR2D_H 1 27 | 28 | #include "nvhost.h" 29 | 30 | struct nvhost_gr2d { 31 | struct nvhost_client client; 32 | struct nvmap_handle *buffer; 33 | struct nvmap_handle *scratch; 34 | int fd; 35 | }; 36 | 37 | struct nvhost_gr2d *nvhost_gr2d_open(struct nvmap *nvmap, 38 | struct nvhost_ctrl *ctrl); 39 | void nvhost_gr2d_close(struct nvhost_gr2d *gr2d); 40 | int nvhost_gr2d_clear(struct nvhost_gr2d *gr2d, struct nvmap_framebuffer *fb, 41 | float red, float green, float blue, float alpha); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/libhost1x/x11-display.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Dmitry Osipenko 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef GRATE_HOST1X_X11_DISPLAY_H 24 | #define GRATE_HOST1X_X11_DISPLAY_H 1 25 | 26 | #include "host1x-private.h" 27 | 28 | #ifdef HAVE_XCB 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | struct xcb_stuff { 35 | struct host1x_pixelbuffer *pixbuf; 36 | struct host1x *host1x; 37 | xcb_connection_t *disp; 38 | xcb_gcontext_t gc; 39 | xcb_window_t win; 40 | xcb_image_t *img; 41 | int drm_fd; 42 | }; 43 | 44 | void dri2_display_create(struct xcb_stuff *stuff, struct host1x_display *disp); 45 | #endif 46 | 47 | int x11_display_create(struct host1x *host1x, struct host1x_display *base, 48 | int drm_fd); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /tests/gles2/gles-clear.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | void window_draw(struct window *window) 36 | { 37 | glClearColor(1.0f, 0.0f, 0.0f, 1.0f); 38 | glClear(GL_COLOR_BUFFER_BIT); 39 | 40 | eglSwapBuffers(window->egl.display, window->egl.surface); 41 | } 42 | 43 | int main(int argc, char *argv[]) 44 | { 45 | struct window *window; 46 | 47 | window = window_create(0, 0, 640, 480); 48 | if (!window) { 49 | fprintf(stderr, "window_create() failed\n"); 50 | return 1; 51 | } 52 | 53 | window_show(window); 54 | window_draw(window); 55 | 56 | sleep(1); 57 | 58 | window_close(window); 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /tests/grate/clear.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include "grate.h" 26 | 27 | int main(int argc, char *argv[]) 28 | { 29 | struct grate_framebuffer *fb; 30 | struct grate_options options; 31 | struct grate *grate; 32 | 33 | if (!grate_parse_command_line(&options, argc, argv)) 34 | return 1; 35 | 36 | grate = grate_init(&options); 37 | if (!grate) 38 | return 1; 39 | 40 | fb = grate_framebuffer_create(grate, options.width, options.height, 41 | PIX_BUF_FMT_RGBA8888, 42 | PIX_BUF_LAYOUT_TILED_16x16, 43 | GRATE_DOUBLE_BUFFERED); 44 | if (!fb) 45 | return 1; 46 | 47 | grate_clear_color(grate, 1.0f, 0.0f, 1.0f, 1.0f); 48 | grate_bind_framebuffer(grate, fb); 49 | grate_clear(grate); 50 | 51 | grate_swap_buffers(grate); 52 | grate_wait_for_key(grate); 53 | 54 | grate_exit(grate); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /src/libgrate/matrix.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_NVHOST_MATRIX_H 26 | #define GRATE_NVHOST_MATRIX_H 1 27 | 28 | struct mat4 { 29 | float xx, xy, xz, xw; 30 | float yx, yy, yz, yw; 31 | float zx, zy, zz, zw; 32 | float wx, wy, wz, ww; 33 | }; 34 | 35 | void mat4_multiply(struct mat4 *result, const struct mat4 *a, 36 | const struct mat4 *b); 37 | void mat4_zero(struct mat4 *m); 38 | void mat4_identity(struct mat4 *m); 39 | void mat4_translate(struct mat4 *m, float x, float y, float z); 40 | void mat4_scale(struct mat4 *m, float x, float y, float z); 41 | void mat4_rotate_x(struct mat4 *m, float angle); 42 | void mat4_rotate_y(struct mat4 *m, float angle); 43 | void mat4_rotate_z(struct mat4 *m, float angle); 44 | 45 | void mat4_perspective(struct mat4 *m, float fov, float aspect, 46 | float near, float far); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /tests/gles2/gles-pbuffer-clear.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | void pbuffer_draw(struct pbuffer *pbuffer) 36 | { 37 | printf("=== calling glViewport()\n"); 38 | glViewport(0, 0, pbuffer->width, pbuffer->height); 39 | glFlush(); 40 | printf("=== calling glClearColor()\n"); 41 | glClearColor(1.0f, 0.0f, 0.0f, 1.0f); 42 | glFlush(); 43 | printf("=== calling glClear()\n"); 44 | glClear(GL_COLOR_BUFFER_BIT); 45 | glFlush(); 46 | } 47 | 48 | int main(int argc, char *argv[]) 49 | { 50 | struct pbuffer *pbuffer; 51 | 52 | pbuffer = pbuffer_create(32, 32); 53 | if (!pbuffer) { 54 | fprintf(stderr, "pbuffer_create() failed\n"); 55 | return 1; 56 | } 57 | 58 | pbuffer_draw(pbuffer); 59 | pbuffer_save(pbuffer, "test.png"); 60 | pbuffer_free(pbuffer); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /tests/grate/asm_tests.sh: -------------------------------------------------------------------------------- 1 | DIR=$(dirname $0) 2 | 3 | $DIR/../../tools/assembler --vs $DIR/asm/vs_mov.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0xFF01FF00 --testonly \ 4 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_constant.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0x664D331A --testonly \ 5 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_branching.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0xFF01FF00 --testonly \ 6 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_function.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0xFF01FF00 --testonly \ 7 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_stack.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0xFF01FF00 --testonly \ 8 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_predicate.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0x667F007F --testonly \ 9 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_constant_relative_addressing.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0x664D331A --testonly \ 10 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_attribute_relative_addressing.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0xFF01FF00 --testonly \ 11 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_export_relative_addressing.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0x6601FF1A --testonly \ 12 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_uniform.txt --fs $DIR/asm/fs_vs_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0x664D331A --vs_uniform '["uniform_100"]=(0.1,0.2,0.0,0.0)' --vs_uniform '["uniform_135"]=(0.0,0.0,0.3,0.4)' --testonly \ 13 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_mov.txt --fs $DIR/asm/fs_uniform.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0x19334C66 --fs_uniform '["uniform_0_low"]=0.1' --fs_uniform '["uniform_2"]=0.2' --fs_uniform '["uniform_31_low"]=0.3' --fs_uniform '["uniform_31_high"]=0.4' --testonly \ 14 | && $DIR/../../tools/assembler --vs $DIR/asm/vs_mov.txt --fs $DIR/asm/fs_mfu_tests.txt --lnk $DIR/asm/linker_vs_tests.txt --expected 0x7F6A7FE0 --testonly \ 15 | && echo "All tests passed" 16 | -------------------------------------------------------------------------------- /src/libgrate/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libgrate.la 2 | 3 | libgrate_la_CPPFLAGS = \ 4 | -I$(top_srcdir)/include 5 | 6 | libgrate_la_CFLAGS = \ 7 | $(PNG_CFLAGS) 8 | 9 | libgrate_la_SOURCES = \ 10 | display.c \ 11 | etc1.cpp \ 12 | etc1.h \ 13 | fragment_asm.h \ 14 | grate.c \ 15 | grate.h \ 16 | grate-asm.c \ 17 | grate-font.c \ 18 | grate-texture.c \ 19 | grate-2d.c \ 20 | grate-3d.c \ 21 | grate-3d.h \ 22 | grate-3d-ctx.c \ 23 | grate-3d-ctx.h \ 24 | libgrate-private.h \ 25 | linker_asm.h \ 26 | matrix.c \ 27 | matrix.h \ 28 | profile.c \ 29 | shader-cgc.c \ 30 | vpe_vliw.h 31 | 32 | libgrate_la_DEPENDENCIES = \ 33 | ../libcgc/libcgc.la \ 34 | ../libhost1x/libhost1x.la 35 | 36 | libgrate_la_LIBADD = \ 37 | ../libcgc/libcgc.la \ 38 | ../libhost1x/libhost1x.la \ 39 | $(DevIL_LIBS) \ 40 | $(PNG_LIBS) \ 41 | -lm \ 42 | -lrt 43 | 44 | BUILT_SOURCES = \ 45 | lex.fragment_asm.c \ 46 | lex.linker_asm.c \ 47 | lex.vertex_asm.c \ 48 | fragment_asm.tab.c \ 49 | linker_asm.tab.c \ 50 | vertex_asm.tab.c 51 | 52 | CLEANFILES = \ 53 | fragment_asm.tab.h \ 54 | fragment_asm.tab.c \ 55 | linker_asm.tab.h \ 56 | linker_asm.tab.c \ 57 | vertex_asm.tab.h \ 58 | vertex_asm.tab.c \ 59 | lex.fragment_asm.c \ 60 | lex.linker_asm.c \ 61 | lex.vertex_asm.c 62 | 63 | lex.vertex_asm.c: vertex_asm.l vertex_asm.tab.c 64 | $(LEX) -P vertex_asm --nounput $(srcdir)/vertex_asm.l 65 | 66 | vertex_asm.tab.c: vertex_asm.y 67 | $(YACC) -p vertex_asm -b vertex_asm -d --debug $(srcdir)/vertex_asm.y 68 | 69 | lex.fragment_asm.c: fragment_asm.l fragment_asm.tab.c 70 | $(LEX) -P fragment_asm --nounput $(srcdir)/fragment_asm.l 71 | 72 | fragment_asm.tab.c: fragment_asm.y 73 | $(YACC) -p fragment_asm -b fragment_asm -d --debug $(srcdir)/fragment_asm.y 74 | 75 | lex.linker_asm.c: linker_asm.l linker_asm.tab.c 76 | $(LEX) -P linker_asm --nounput $(srcdir)/linker_asm.l 77 | 78 | linker_asm.tab.c: linker_asm.y 79 | $(YACC) -p linker_asm -b linker_asm -d --debug $(srcdir)/linker_asm.y 80 | 81 | libgrate_la_SOURCES += \ 82 | fragment_asm.tab.c \ 83 | fragment_disasm.c \ 84 | lex.fragment_asm.c \ 85 | lex.linker_asm.c \ 86 | lex.vertex_asm.c \ 87 | linker_asm.tab.c \ 88 | linker_disasm.c \ 89 | vertex_asm.tab.c \ 90 | vertex_disasm.c 91 | 92 | pkgconfigdir = ${libdir}/pkgconfig 93 | pkgconfig_DATA = libgrate.pc 94 | -------------------------------------------------------------------------------- /src/libhost1x/nvhost-gr2d.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Thierry Reding 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "nvhost.h" 30 | 31 | struct nvhost_gr2d *nvhost_gr2d_open(struct nvhost *nvhost) 32 | { 33 | struct nvhost_gr2d *gr2d; 34 | int err, fd; 35 | 36 | gr2d = calloc(1, sizeof(*gr2d)); 37 | if (!gr2d) 38 | return NULL; 39 | 40 | fd = open("/dev/nvhost-gr2d", O_RDWR); 41 | if (fd < 0) { 42 | free(gr2d); 43 | return NULL; 44 | } 45 | 46 | err = nvhost_client_init(&gr2d->client, nvhost->nvmap, nvhost->ctrl, 47 | fd); 48 | if (err < 0) { 49 | close(fd); 50 | free(gr2d); 51 | return NULL; 52 | } 53 | 54 | gr2d->base.client = &gr2d->client.base; 55 | 56 | err = host1x_gr2d_init(&nvhost->base, &gr2d->base); 57 | if (err < 0) { 58 | nvhost_client_exit(&gr2d->client); 59 | free(gr2d); 60 | return NULL; 61 | } 62 | 63 | return gr2d; 64 | } 65 | 66 | void nvhost_gr2d_close(struct nvhost_gr2d *gr2d) 67 | { 68 | if (gr2d) { 69 | nvhost_client_exit(&gr2d->client); 70 | host1x_gr2d_exit(&gr2d->base); 71 | } 72 | 73 | free(gr2d); 74 | } 75 | -------------------------------------------------------------------------------- /src/libhost1x/nvhost-gr3d.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Thierry Reding 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "nvhost.h" 30 | 31 | struct nvhost_gr3d *nvhost_gr3d_open(struct nvhost *nvhost) 32 | { 33 | struct nvhost_gr3d *gr3d; 34 | int err, fd; 35 | 36 | gr3d = calloc(1, sizeof(*gr3d)); 37 | if (!gr3d) 38 | return NULL; 39 | 40 | fd = open("/dev/nvhost-gr3d", O_RDWR); 41 | if (fd < 0) { 42 | free(gr3d); 43 | return NULL; 44 | } 45 | 46 | err = nvhost_client_init(&gr3d->client, nvhost->nvmap, nvhost->ctrl, 47 | fd); 48 | if (err < 0) { 49 | close(fd); 50 | free(gr3d); 51 | return NULL; 52 | } 53 | 54 | gr3d->base.client = &gr3d->client.base; 55 | 56 | err = host1x_gr3d_init(&nvhost->base, &gr3d->base); 57 | if (err < 0) { 58 | nvhost_client_exit(&gr3d->client); 59 | free(gr3d); 60 | return NULL; 61 | } 62 | 63 | return gr3d; 64 | } 65 | 66 | void nvhost_gr3d_close(struct nvhost_gr3d *gr3d) 67 | { 68 | if (gr3d) { 69 | nvhost_client_exit(&gr3d->client); 70 | host1x_gr3d_exit(&gr3d->base); 71 | } 72 | 73 | free(gr3d); 74 | } 75 | -------------------------------------------------------------------------------- /src/libgrate/linker_asm.l: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Dmitry Osipenko 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | %option caseless 24 | 25 | %{ 26 | #include 27 | #include "linker_asm.h" 28 | #include "linker_asm.tab.h" 29 | 30 | #define YY_NO_INPUT 31 | 32 | extern void yyerror(char *); 33 | 34 | int yywrap(void) 35 | { 36 | return 1; 37 | } 38 | %} 39 | 40 | %% 41 | [ \t]+ /* skip */; 42 | "/*"([^*]|(\*+[^*/]))*\*+\/ /* multi line comment */; 43 | "//".* /* single line comment */; 44 | [\n] yylineno++; 45 | "." return '.'; 46 | "(" return '('; 47 | ")" return ')'; 48 | "," return ','; 49 | 50 | export[0-9]{1,2} { 51 | linker_asmlval.u = atoi(yytext + 6); 52 | return T_EXPORT; 53 | } 54 | tram[0-9]{1,2} { 55 | linker_asmlval.u = atoi(yytext + 4); 56 | return T_TRAM_ROW; 57 | } 58 | 59 | link return T_LINK; 60 | 61 | x return T_COMPONENT_X; 62 | y return T_COMPONENT_Y; 63 | z return T_COMPONENT_Z; 64 | w return T_COMPONENT_W; 65 | 66 | "nop" return T_NOP; 67 | 68 | "cw" return T_CONST_ACCROSS_WIDTH; 69 | "cl" return T_CONST_ACCROSS_LENGTH; 70 | "dis" return T_INTERPOLATION_DISABLE; 71 | 72 | "fx10.l" return T_FX10_LOW; 73 | "fx10.h" return T_FX10_HIGH; 74 | 75 | fp20 return T_FP20; 76 | 77 | . return T_SYNTAX_ERROR; 78 | %% 79 | -------------------------------------------------------------------------------- /tests/nvhost/gr2d-fill.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "nvhost.h" 34 | #include "gr2d.h" 35 | 36 | int main(int argc, char *argv[]) 37 | { 38 | struct nvmap_framebuffer *fb; 39 | unsigned int width, height; 40 | struct nvhost_gr2d *gr2d; 41 | struct nvhost_ctrl *ctrl; 42 | struct nvmap *nvmap; 43 | int err; 44 | 45 | width = height = 32; 46 | 47 | nvmap = nvmap_open(); 48 | if (!nvmap) { 49 | return 1; 50 | } 51 | 52 | ctrl = nvhost_ctrl_open(); 53 | if (!ctrl) { 54 | return 1; 55 | } 56 | 57 | fb = nvmap_framebuffer_create(nvmap, width, height, 32); 58 | if (!fb) { 59 | return 1; 60 | } 61 | 62 | gr2d = nvhost_gr2d_open(nvmap, ctrl); 63 | if (!gr2d) { 64 | return 1; 65 | } 66 | 67 | err = nvhost_gr2d_clear(gr2d, fb, 1.0f, 0.0f, 1.0f, 1.0f); 68 | if (err < 0) { 69 | return 1; 70 | } 71 | 72 | nvmap_framebuffer_save(fb, "test.png"); 73 | nvmap_framebuffer_free(fb); 74 | nvhost_gr2d_close(gr2d); 75 | nvhost_ctrl_close(ctrl); 76 | nvmap_close(nvmap); 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /tools/cgc.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | # include "config.h" 3 | #endif 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "libcgc.h" 13 | 14 | struct opts { 15 | enum cgc_shader_type type; 16 | bool help; 17 | }; 18 | 19 | static void usage(FILE *fp, const char *program) 20 | { 21 | fprintf(fp, "usage: %s [options] FILE\n", program); 22 | } 23 | 24 | static int parse_command_line(struct opts *opts, int argc, char *argv[]) 25 | { 26 | static const struct option options[] = { 27 | { "fragment", 0, NULL, 'F' }, 28 | { "help", 0, NULL, 'h' }, 29 | { "vertex", 0, NULL, 'v' }, 30 | { NULL, 0, NULL, 0 } 31 | }; 32 | int opt; 33 | 34 | memset(opts, 0, sizeof(*opts)); 35 | opts->type = CGC_SHADER_FRAGMENT; 36 | 37 | while ((opt = getopt_long(argc, argv, "FhvV", options, NULL)) != -1) { 38 | switch (opt) { 39 | case 'F': 40 | opts->type = CGC_SHADER_FRAGMENT; 41 | break; 42 | 43 | case 'h': 44 | opts->help = true; 45 | break; 46 | 47 | case 'v': 48 | opts->type = CGC_SHADER_VERTEX; 49 | break; 50 | 51 | default: 52 | fprintf(stderr, "invalid option '%c'\n", opt); 53 | return -1; 54 | } 55 | } 56 | 57 | return optind; 58 | } 59 | 60 | /** 61 | * This only works if the code is provided through static storage. Allocating 62 | * memory and passing the pointer into CgDrv_Compile() will segfault. 63 | */ 64 | int main(int argc, char *argv[]) 65 | { 66 | struct cgc_shader *shader; 67 | size_t length; 68 | struct opts opts; 69 | char code[65536]; 70 | FILE *fp; 71 | int err; 72 | 73 | err = parse_command_line(&opts, argc, argv); 74 | if (err < 0) { 75 | return 1; 76 | } 77 | 78 | if (opts.help) { 79 | usage(stdout, argv[0]); 80 | return 0; 81 | } 82 | 83 | if (err < argc) { 84 | fp = fopen(argv[err], "r"); 85 | if (!fp) { 86 | fprintf(stderr, "failed to open `%s': %m\n", argv[1]); 87 | return 1; 88 | } 89 | } else { 90 | printf("reading stdin\n"); 91 | fp = stdin; 92 | } 93 | 94 | length = fread(code, 1, sizeof(code), fp); 95 | if (length == 0) { 96 | } 97 | 98 | code[length] = '\0'; 99 | 100 | fclose(fp); 101 | 102 | shader = cgc_compile(opts.type, code, length); 103 | if (shader) { 104 | cgc_shader_dump(shader, stdout); 105 | cgc_shader_free(shader); 106 | } 107 | 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /tools/reset3d.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define CLK_RST_CONTROLLER_RST_DEV_L 0x004 11 | #define CLK_RST_CONTROLLER_RST_DEV_V 0x058 12 | 13 | #define CLK_RST_CONTROLLER_RST_DEV_L_SET_0 0x300 14 | #define CLK_RST_CONTROLLER_RST_DEV_L_CLR_0 0x304 15 | 16 | #define CLK_RST_CONTROLLER_RST_DEV_V_SET_0 0x430 17 | #define CLK_RST_CONTROLLER_RST_DEV_V_CLR_0 0x434 18 | 19 | #define CAR_3D (1 << 24) 20 | #define CAR_3D2 (1 << 2) 21 | 22 | static int map_mem(void **mem_virt, off_t phys_address, int size) 23 | { 24 | off_t PageOffset, PageAddress; 25 | int PagesSize; 26 | int mem_dev; 27 | 28 | mem_dev = open("/dev/mem", O_RDWR | O_SYNC); 29 | if (mem_dev < 0) 30 | return mem_dev; 31 | 32 | PageOffset = phys_address % getpagesize(); 33 | PageAddress = phys_address - PageOffset; 34 | PagesSize = (((size - 1) / getpagesize()) + 1) * getpagesize(); 35 | 36 | *mem_virt = mmap(NULL, (size_t)PagesSize, PROT_READ | PROT_WRITE, 37 | MAP_SHARED, mem_dev, PageAddress); 38 | 39 | if (*mem_virt == MAP_FAILED) 40 | return -1; 41 | 42 | *mem_virt += PageOffset; 43 | 44 | return 0; 45 | } 46 | 47 | static uint32_t reg_read(void *mem_virt, uint32_t offset) 48 | { 49 | return *(volatile uint32_t*)(mem_virt + offset); 50 | } 51 | 52 | static void reg_write(void *mem_virt, uint32_t offset, uint32_t value) 53 | { 54 | *(volatile uint32_t*)(mem_virt + offset) = value; 55 | } 56 | 57 | int main(int argc, char *argv[]) 58 | { 59 | void *CAR_io_mem_virt; 60 | int err; 61 | 62 | err = map_mem(&CAR_io_mem_virt, 0x60006000, 0x1000); 63 | if (err < 0) { 64 | fprintf(stderr, "mmap failed: %d (%s)\n", 65 | err, strerror(errno)); 66 | return err; 67 | } 68 | 69 | printf("GR3D1 reset = %d\n", 70 | !!(reg_read(CAR_io_mem_virt, CLK_RST_CONTROLLER_RST_DEV_L) & CAR_3D)); 71 | 72 | printf("GR3D2 reset = %d\n", 73 | !!(reg_read(CAR_io_mem_virt, CLK_RST_CONTROLLER_RST_DEV_V) & CAR_3D2)); 74 | 75 | reg_write(CAR_io_mem_virt, 76 | CLK_RST_CONTROLLER_RST_DEV_L_SET_0, CAR_3D); 77 | 78 | reg_write(CAR_io_mem_virt, 79 | CLK_RST_CONTROLLER_RST_DEV_V_SET_0, CAR_3D2); 80 | 81 | usleep(1000); 82 | 83 | reg_write(CAR_io_mem_virt, 84 | CLK_RST_CONTROLLER_RST_DEV_L_CLR_0, CAR_3D); 85 | 86 | reg_write(CAR_io_mem_virt, 87 | CLK_RST_CONTROLLER_RST_DEV_V_CLR_0, CAR_3D2); 88 | 89 | printf("done\n"); 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /src/libwrap/disasm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Dmitry Osipenko 3 | * Copyright (c) Erik Faye-Lund 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef GRATE_DISASM_H 25 | #define GRATE_DISASM_H 1 26 | 27 | #include "asm.h" 28 | 29 | struct disasm_state { 30 | union { 31 | vpe_instr128 vpe_instr[256]; 32 | uint32_t vpe_words[1024]; 33 | }; 34 | unsigned int vpe_words_nb; 35 | 36 | union { 37 | link_instr lnk_instr[32]; 38 | uint32_t linker_words[64]; 39 | }; 40 | unsigned int linker_inst_nb; 41 | 42 | pseq_instr pseq_instructions[64]; 43 | unsigned int pseq_words_nb; 44 | 45 | instr_sched mfu_sched[64]; 46 | unsigned int mfu_sched_words_nb; 47 | 48 | union { 49 | mfu_instr mfu_instructions[64]; 50 | uint32_t mfu_words[128]; 51 | 52 | }; 53 | unsigned int mfu_words_nb; 54 | 55 | tex_instr tex_instructions[64]; 56 | unsigned int tex_words_nb; 57 | 58 | union { 59 | union fragment_alu_instruction alu_instructions[256]; 60 | uint32_t alu_words[512]; 61 | }; 62 | unsigned int alu_words_nb; 63 | 64 | uint32_t alu_complements[64]; 65 | unsigned int alu_complements_nb; 66 | 67 | alu_instr_sched_t114 alu_sched[64]; 68 | unsigned int alu_sched_words_nb; 69 | 70 | dw_instr dw_instructions[64]; 71 | unsigned int dw_words_nb; 72 | }; 73 | 74 | void disasm_reset(struct disasm_state *d); 75 | void disasm_write_reg(void *opaque, uint32_t host1x_class, 76 | uint32_t offset, uint32_t value); 77 | void disasm_dump(struct disasm_state *d); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/libgrate/grate-2d.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include "../libhost1x/host1x-private.h" 26 | #include "libgrate-private.h" 27 | 28 | #include "grate.h" 29 | 30 | void grate_clear_color(struct grate *grate, float red, float green, 31 | float blue, float alpha) 32 | { 33 | grate->clear.r = red; 34 | grate->clear.g = green; 35 | grate->clear.b = blue; 36 | grate->clear.a = alpha; 37 | } 38 | 39 | void grate_clear(struct grate *grate) 40 | { 41 | struct host1x_gr2d *gr2d = host1x_get_gr2d(grate->host1x); 42 | struct host1x_framebuffer *front = grate->fb->front; 43 | struct host1x_framebuffer *back = grate->fb->back; 44 | struct host1x_pixelbuffer *pixbuf; 45 | struct grate_color *clear = &grate->clear; 46 | uint32_t color; 47 | int err; 48 | 49 | if (!grate->fb) { 50 | grate_error("no framebuffer bound to state\n"); 51 | return; 52 | } 53 | 54 | pixbuf = back ? back->pixbuf : front->pixbuf; 55 | 56 | if (PIX_BUF_FORMAT_BITS(pixbuf->format) == 16) { 57 | color = ((uint32_t)(clear->r * 31) << 11) | 58 | ((uint32_t)(clear->g * 63) << 5) | 59 | ((uint32_t)(clear->b * 31) << 0); 60 | } else { 61 | color = ((uint32_t)(clear->a * 255) << 24) | 62 | ((uint32_t)(clear->b * 255) << 16) | 63 | ((uint32_t)(clear->g * 255) << 8) | 64 | ((uint32_t)(clear->r * 255) << 0); 65 | } 66 | 67 | err = host1x_gr2d_clear(gr2d, pixbuf, color); 68 | if (err < 0) 69 | grate_error("host1x_gr2d_clear() failed: %d\n", err); 70 | } 71 | -------------------------------------------------------------------------------- /tests/gles1/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_TESTS_3D_COMMON_H 26 | #define GRATE_TESTS_3D_COMMON_H 1 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 34 | 35 | struct gles_options { 36 | unsigned int width; 37 | unsigned int height; 38 | }; 39 | 40 | int gles_parse_command_line(struct gles_options *options, int argc, 41 | char *argv[]); 42 | 43 | struct window { 44 | struct { 45 | Display *display; 46 | Window window; 47 | } x; 48 | 49 | struct { 50 | EGLDisplay display; 51 | EGLContext context; 52 | EGLSurface surface; 53 | } egl; 54 | 55 | unsigned int width; 56 | unsigned int height; 57 | }; 58 | 59 | struct window *window_create(unsigned int x, unsigned int y, 60 | unsigned int width, unsigned int height); 61 | void window_close(struct window *window); 62 | void window_show(struct window *window); 63 | bool window_event_loop(struct window *window); 64 | 65 | struct pbuffer { 66 | EGLDisplay display; 67 | EGLContext context; 68 | EGLSurface surface; 69 | 70 | unsigned int width; 71 | unsigned int height; 72 | }; 73 | 74 | struct pbuffer *pbuffer_create(unsigned int width, unsigned int height); 75 | void pbuffer_free(struct pbuffer *pbuffer); 76 | bool pbuffer_save(struct pbuffer *pbuffer, const char *filename); 77 | 78 | struct gles_texture { 79 | GLenum format; 80 | GLuint id; 81 | }; 82 | 83 | struct gles_texture *gles_texture_load(const char *filename); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /tests/gles1/gles-logicop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | static const GLfloat vertices[] = { 36 | -0.5f, -0.5f, 0.0f, 1.0f, 37 | 0.5f, -0.5f, 0.0f, 1.0f, 38 | 0.0f, 0.5f, 0.0f, 1.0f, 39 | 40 | -0.5f, 0.5f, 0.0f, 1.0f, 41 | 0.5f, 0.5f, 0.0f, 1.0f, 42 | 0.0f, -0.5f, 0.0f, 1.0f, 43 | }; 44 | 45 | static void window_setup(struct window *window) 46 | { 47 | glEnable(GL_DEPTH_TEST); 48 | glDepthFunc(GL_LEQUAL); 49 | glDisable(GL_CULL_FACE); 50 | 51 | glVertexPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), vertices); 52 | glEnableClientState(GL_VERTEX_ARRAY); 53 | } 54 | 55 | static void window_draw(struct window *window) 56 | { 57 | glViewport(0, 0, window->width, window->height); 58 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 59 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 60 | 61 | glDisable(GL_COLOR_LOGIC_OP); 62 | glDrawArrays(GL_TRIANGLES, 0, 3); 63 | 64 | glEnable(GL_COLOR_LOGIC_OP); 65 | glLogicOp(GL_XOR); 66 | glDrawArrays(GL_TRIANGLES, 3, 3); 67 | 68 | eglSwapBuffers(window->egl.display, window->egl.surface); 69 | } 70 | 71 | int main(int argc, char *argv[]) 72 | { 73 | struct window *window; 74 | 75 | window = window_create(0, 0, 640, 480); 76 | if (!window) { 77 | fprintf(stderr, "window_create() failed\n"); 78 | return 1; 79 | } 80 | 81 | window_setup(window); 82 | window_show(window); 83 | 84 | while (true) { 85 | if (!window_event_loop(window)) 86 | break; 87 | 88 | window_draw(window); 89 | } 90 | 91 | window_close(window); 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /src/libgrate/profile.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Thierry Reding 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | 26 | #include "libgrate-private.h" 27 | 28 | struct grate_profile { 29 | struct timespec start; 30 | struct timespec end; 31 | unsigned int frames; 32 | }; 33 | 34 | static float timespec_diff(const struct timespec *start, 35 | const struct timespec *end) 36 | { 37 | unsigned long seconds = end->tv_sec - start->tv_sec; 38 | long ns = end->tv_nsec - start->tv_nsec; 39 | 40 | if (ns < 0) { 41 | ns += 1000000000; 42 | seconds--; 43 | } 44 | 45 | return seconds + ns / 1000000000.0f; 46 | } 47 | 48 | static void grate_profile_dump(struct grate_profile *profile, FILE *fp) 49 | { 50 | float time = timespec_diff(&profile->start, &profile->end); 51 | 52 | fprintf(fp, "%u frames in %.3f seconds: %.2f fps\n", profile->frames, 53 | time, profile->frames / time); 54 | } 55 | 56 | struct grate_profile *grate_profile_start(struct grate *grate) 57 | { 58 | struct grate_profile *profile; 59 | 60 | profile = calloc(1, sizeof(*profile)); 61 | if (!profile) 62 | return NULL; 63 | 64 | clock_gettime(CLOCK_MONOTONIC, &profile->start); 65 | profile->frames = 0; 66 | 67 | return profile; 68 | } 69 | 70 | void grate_profile_free(struct grate_profile *profile) 71 | { 72 | free(profile); 73 | } 74 | 75 | void grate_profile_sample(struct grate_profile *profile) 76 | { 77 | profile->frames++; 78 | } 79 | 80 | void grate_profile_finish(struct grate_profile *profile) 81 | { 82 | clock_gettime(CLOCK_MONOTONIC, &profile->end); 83 | grate_profile_dump(profile, stdout); 84 | } 85 | 86 | float grate_profile_time_elapsed(struct grate_profile *profile) 87 | { 88 | struct timespec now; 89 | 90 | clock_gettime(CLOCK_MONOTONIC, &now); 91 | 92 | return timespec_diff(&profile->start, &now); 93 | } 94 | -------------------------------------------------------------------------------- /data/font.fnt: -------------------------------------------------------------------------------- 1 | textures: font.png 2 | Arial 33pt 3 | 32 0 0 0 0 12 51 12 51 4 | 97 0 0 20 24 2 18 24 51 5 | 98 21 0 20 32 3 10 25 51 6 | 99 42 0 20 24 2 18 22 51 7 | 100 63 0 20 32 2 10 24 51 8 | 101 84 0 20 24 2 18 24 51 9 | 102 105 0 13 32 1 10 13 51 10 | 103 119 0 20 33 2 18 25 51 11 | 104 140 0 18 32 3 10 24 51 12 | 105 159 0 4 32 3 10 10 51 13 | 106 164 0 9 41 -2 10 10 51 14 | 107 174 0 19 32 3 10 22 51 15 | 108 79 0 4 32 3 10 10 51 16 | 109 194 0 32 24 3 18 38 51 17 | 110 227 0 18 24 3 18 24 51 18 | 111 0 25 20 24 2 18 24 51 19 | 112 42 25 20 33 3 18 25 51 20 | 113 84 25 20 33 2 18 25 51 21 | 114 242 25 13 24 3 18 15 51 22 | 115 223 25 18 24 2 18 22 51 23 | 116 211 25 11 31 1 11 12 51 24 | 117 21 33 18 23 3 19 24 51 25 | 118 189 33 21 23 1 19 23 51 26 | 119 105 34 33 23 0 19 33 51 27 | 120 139 34 22 23 0 19 22 51 28 | 121 162 42 21 32 0 19 21 51 29 | 122 63 33 20 23 1 19 22 51 30 | 65 226 50 29 32 0 10 29 51 31 | 66 184 57 23 32 4 10 29 51 32 | 67 0 57 28 32 2 10 32 51 33 | 68 29 59 26 32 4 10 32 51 34 | 69 56 59 23 32 4 10 29 51 35 | 70 80 59 21 32 4 10 27 51 36 | 71 102 59 29 32 2 10 34 51 37 | 72 132 58 24 32 4 10 32 51 38 | 73 79 0 4 32 4 10 12 51 39 | 74 208 57 17 32 1 10 22 51 40 | 75 157 75 26 32 4 10 29 51 41 | 76 236 83 19 32 4 10 24 51 42 | 77 184 90 29 32 4 10 37 51 43 | 78 0 90 24 32 4 10 32 51 44 | 79 25 92 30 32 2 10 34 51 45 | 80 56 92 23 32 4 10 29 51 46 | 81 80 92 30 34 2 10 34 51 47 | 82 111 92 26 32 4 10 32 51 48 | 83 157 108 25 32 2 10 29 51 49 | 84 231 116 24 32 1 10 26 51 50 | 85 183 123 24 32 4 10 32 51 51 | 86 25 125 29 32 0 10 29 51 52 | 87 111 125 43 32 1 10 44 51 53 | 88 55 127 29 32 0 10 29 51 54 | 89 227 149 28 32 0 10 28 51 55 | 90 85 127 25 32 1 10 27 51 56 | 48 4 123 20 32 2 10 24 51 57 | 49 214 90 11 32 5 10 24 51 58 | 50 157 141 20 32 1 10 24 51 59 | 51 178 156 20 32 2 10 24 51 60 | 52 199 156 21 32 1 10 24 51 61 | 53 0 156 20 32 2 10 24 51 62 | 54 21 158 21 32 1 10 24 51 63 | 55 111 158 20 32 2 10 24 51 64 | 56 132 158 20 32 2 10 24 51 65 | 57 43 160 20 32 2 10 24 51 66 | 46 79 28 4 4 4 38 12 51 67 | 44 246 0 4 11 4 38 12 51 68 | 33 226 83 4 32 5 10 14 51 69 | 63 64 160 20 32 2 10 24 51 70 | 45 92 9 12 4 1 29 15 51 71 | 43 208 123 22 22 2 16 26 51 72 | 92 138 91 12 32 1 10 12 51 73 | 47 85 160 12 32 0 10 12 51 74 | 40 98 160 11 41 3 10 15 51 75 | 41 157 174 11 41 1 10 15 51 76 | 58 251 0 4 23 4 19 12 51 77 | 59 231 83 4 30 4 19 12 51 78 | 37 221 182 34 32 2 10 39 51 79 | 38 169 189 26 32 2 10 29 51 80 | 96 194 25 8 6 2 10 15 51 81 | 39 246 12 4 11 2 10 8 51 82 | 42 196 189 15 13 1 10 17 51 83 | 35 132 191 24 32 0 10 24 51 84 | 36 0 189 20 38 2 8 24 51 85 | 61 21 191 21 13 2 20 26 51 86 | 91 212 189 8 41 3 10 12 51 87 | 93 123 191 8 41 1 10 12 51 88 | 64 43 193 41 41 2 10 45 51 89 | 94 85 202 17 17 1 10 19 51 90 | 123 110 191 12 41 1 10 15 51 91 | 125 196 203 12 41 2 10 15 51 92 | 95 85 155 25 4 -1 47 24 51 93 | 126 233 215 22 8 2 23 26 51 94 | 34 21 205 12 11 2 10 16 51 95 | 62 21 217 21 21 2 16 26 51 96 | 60 85 220 21 21 2 16 26 51 97 | 124 128 191 3 41 4 10 11 51 98 | -------------------------------------------------------------------------------- /src/libcgc/libcgc-private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_LIBCGC_PRIVATE_H 26 | #define GRATE_LIBCGC_PRIVATE_H 1 27 | 28 | #include 29 | 30 | struct CgDrv { 31 | unsigned int unknown00; 32 | const char *error; 33 | const char *log; 34 | size_t length; 35 | void *stream; 36 | unsigned int unknown14; 37 | void *binary; 38 | size_t binary_size; 39 | void *unknown20; 40 | unsigned int unknown24; 41 | unsigned int unknown28; 42 | unsigned int unknown2c; 43 | void *unknown30; 44 | unsigned int unknown34; 45 | unsigned int unknown38; 46 | unsigned int unknown3c; 47 | void *unknown40; 48 | unsigned int unknown44; 49 | unsigned int unknown48; 50 | unsigned int unknown4c; 51 | unsigned int unknown50; 52 | unsigned int unknown54; 53 | }; 54 | 55 | struct CgDrv *CgDrv_Create(void); 56 | void CgDrv_Delete(struct CgDrv *cgdrv); 57 | void CgDrv_CleanUp(struct CgDrv *cgdrv); 58 | int CgDrv_Compile(struct CgDrv *cgdrv, int unknown, int type, 59 | const char *code, size_t length, int unknown2, int unknown3); 60 | 61 | struct instruction; 62 | 63 | struct instruction *instruction_create_from_words(uint32_t *words, 64 | unsigned int count); 65 | void instruction_free(struct instruction *inst); 66 | void instruction_print_raw(struct instruction *inst); 67 | void instruction_print_unknown(struct instruction *inst); 68 | unsigned int instruction_get_bit(struct instruction *inst, unsigned int pos); 69 | uint32_t instruction_extract(struct instruction *inst, unsigned int from, 70 | unsigned int to); 71 | void instruction_set_bit(struct instruction *inst, unsigned int pos, 72 | unsigned int value); 73 | void instruction_insert(struct instruction *inst, unsigned int from, 74 | unsigned int to, uint32_t value); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /tests/gles1/gles-clip.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2014 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | static const GLfloat vertices[] = { 36 | -0.5f, -0.5f, 0.0f, 1.0f, 37 | 0.5f, -0.5f, 0.0f, 1.0f, 38 | 0.0f, 0.5f, 0.0f, 1.0f, 39 | 40 | -0.5f, 0.5f, 0.0f, 1.0f, 41 | 0.5f, 0.5f, 0.0f, 1.0f, 42 | 0.0f, -0.5f, 0.0f, 1.0f, 43 | }; 44 | 45 | static void window_setup(struct window *window) 46 | { 47 | glEnable(GL_DEPTH_TEST); 48 | glDepthFunc(GL_LEQUAL); 49 | glDisable(GL_CULL_FACE); 50 | 51 | glVertexPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), vertices); 52 | glEnableClientState(GL_VERTEX_ARRAY); 53 | } 54 | 55 | static void window_draw(struct window *window) 56 | { 57 | GLfloat eq[4]; 58 | glViewport(0, 0, window->width, window->height); 59 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 60 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 61 | 62 | glDrawArrays(GL_TRIANGLES, 0, 3); 63 | 64 | eq[0] = 1.0f; 65 | eq[1] = 2.0f; 66 | eq[2] = 3.0f; 67 | eq[3] = 4.0f; 68 | glClipPlanef(GL_CLIP_PLANE0, eq); 69 | glEnable(GL_CLIP_PLANE0); 70 | glDrawArrays(GL_TRIANGLES, 3, 3); 71 | 72 | eglSwapBuffers(window->egl.display, window->egl.surface); 73 | } 74 | 75 | int main(int argc, char *argv[]) 76 | { 77 | struct window *window; 78 | 79 | window = window_create(0, 0, 640, 480); 80 | if (!window) { 81 | fprintf(stderr, "window_create() failed\n"); 82 | return 1; 83 | } 84 | 85 | window_setup(window); 86 | window_show(window); 87 | 88 | while (true) { 89 | if (!window_event_loop(window)) 90 | break; 91 | 92 | window_draw(window); 93 | } 94 | 95 | window_close(window); 96 | 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /tests/nvhost/gr3d-triangle.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "nvhost.h" 34 | #include "gr2d.h" 35 | #include "gr3d.h" 36 | 37 | #define ATTRIB_BASE(x) (0x100 + ((x) * 2)) 38 | #define ATTRIB_MODE(x) (0x101 + ((x) * 2)) 39 | 40 | #define INDEX_BASE 0x121 41 | #define DRAW_PARAMS 0x122 42 | #define DRAW_PRIMITIVES 0x123 43 | 44 | #define DEPTH_BASE 0xe00 45 | #define COLOR_BASE 0xe01 46 | 47 | int main(int argc, char *argv[]) 48 | { 49 | struct nvmap_framebuffer *fb; 50 | unsigned int width, height; 51 | struct nvhost_gr2d *gr2d; 52 | struct nvhost_gr3d *gr3d; 53 | struct nvhost_ctrl *ctrl; 54 | struct nvmap *nvmap; 55 | int err; 56 | 57 | width = height = 32; 58 | 59 | nvmap = nvmap_open(); 60 | if (!nvmap) { 61 | return 1; 62 | } 63 | 64 | ctrl = nvhost_ctrl_open(); 65 | if (!ctrl) { 66 | return 1; 67 | } 68 | 69 | fb = nvmap_framebuffer_create(nvmap, width, height, 32); 70 | if (!fb) { 71 | return 1; 72 | } 73 | 74 | gr2d = nvhost_gr2d_open(nvmap, ctrl); 75 | if (!gr2d) { 76 | return 1; 77 | } 78 | 79 | gr3d = nvhost_gr3d_open(nvmap, ctrl); 80 | if (!gr3d) { 81 | return 1; 82 | } 83 | 84 | err = nvhost_gr2d_clear(gr2d, fb, 0.0f, 0.0f, 0.0f, 1.0f); 85 | if (err < 0) { 86 | return 1; 87 | } 88 | 89 | err = nvhost_gr3d_triangle(gr3d, fb); 90 | if (err < 0) { 91 | return 1; 92 | } 93 | 94 | nvmap_framebuffer_save(fb, "test.png"); 95 | nvmap_framebuffer_free(fb); 96 | nvhost_gr3d_close(gr3d); 97 | nvhost_ctrl_close(ctrl); 98 | nvmap_close(nvmap); 99 | 100 | return 0; 101 | } 102 | -------------------------------------------------------------------------------- /tests/gles1/gles-flatshading.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | static const GLfloat vertices[] = { 36 | -0.5f, -0.5f, 0.0f, 1.0f, 37 | 0.5f, -0.5f, 0.0f, 1.0f, 38 | 0.0f, 0.5f, 0.0f, 1.0f, 39 | }; 40 | 41 | static const GLfloat colors[] = { 42 | 1.0f, 0.0f, 0.0f, 1.0f, 43 | 0.0f, 1.0f, 0.0f, 1.0f, 44 | 0.0f, 0.0f, 1.0f, 1.0f, 45 | }; 46 | 47 | 48 | static void window_setup(struct window *window) 49 | { 50 | glEnable(GL_DEPTH_TEST); 51 | glDepthFunc(GL_LEQUAL); 52 | glDisable(GL_CULL_FACE); 53 | 54 | glVertexPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), vertices); 55 | glEnableClientState(GL_VERTEX_ARRAY); 56 | 57 | glColorPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), colors); 58 | glEnableClientState(GL_COLOR_ARRAY); 59 | } 60 | 61 | static void window_draw(struct window *window) 62 | { 63 | glViewport(0, 0, window->width, window->height); 64 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 65 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 66 | 67 | glShadeModel(GL_FLAT); 68 | glDrawArrays(GL_TRIANGLES, 0, 3); 69 | glShadeModel(GL_SMOOTH); 70 | glDrawArrays(GL_TRIANGLES, 0, 3); 71 | 72 | eglSwapBuffers(window->egl.display, window->egl.surface); 73 | } 74 | 75 | int main(int argc, char *argv[]) 76 | { 77 | struct window *window; 78 | 79 | window = window_create(0, 0, 640, 480); 80 | if (!window) { 81 | fprintf(stderr, "window_create() failed\n"); 82 | return 1; 83 | } 84 | 85 | window_setup(window); 86 | window_show(window); 87 | 88 | while (true) { 89 | if (!window_event_loop(window)) 90 | break; 91 | 92 | window_draw(window); 93 | break; 94 | } 95 | 96 | window_close(window); 97 | 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /tests/gles1/gles-tex-combiners.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | static const GLfloat vertices[] = { 36 | -0.5f, -0.5f, 0.0f, 1.0f, 37 | 0.5f, -0.5f, 0.0f, 1.0f, 38 | 0.0f, 0.5f, 0.0f, 1.0f, 39 | }; 40 | /* 41 | static const GLfloat texcoords[3][6] = { 42 | { 43 | 0.0f, 0.0f, 44 | 1.0f, 0.0f, 45 | 0.0f, 1.0f, 46 | }, { 47 | 0.0f, 0.0f, 48 | 2.0f, 0.0f, 49 | 0.0f, 2.0f, 50 | }, { 51 | 0.0f, 0.0f, 52 | 3.0f, 0.0f, 53 | 0.0f, 3.0f, 54 | } 55 | };*/ 56 | 57 | static void window_setup(struct window *window) 58 | { 59 | /* glEnable(GL_DEPTH_TEST); 60 | glDepthFunc(GL_LEQUAL); */ 61 | glDisable(GL_CULL_FACE); 62 | 63 | glVertexPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), vertices); 64 | glEnableClientState(GL_VERTEX_ARRAY); 65 | 66 | /* glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), texcoords[0]); 67 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); */ 68 | } 69 | 70 | static void window_draw(struct window *window) 71 | { 72 | glViewport(0, 0, window->width, window->height); 73 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 74 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 75 | 76 | glDrawArrays(GL_TRIANGLES, 0, 3); 77 | 78 | eglSwapBuffers(window->egl.display, window->egl.surface); 79 | } 80 | 81 | int main(int argc, char *argv[]) 82 | { 83 | struct window *window; 84 | 85 | window = window_create(0, 0, 32, 32); 86 | if (!window) { 87 | fprintf(stderr, "window_create() failed\n"); 88 | return 1; 89 | } 90 | 91 | window_setup(window); 92 | window_show(window); 93 | 94 | while (true) { 95 | if (!window_event_loop(window)) 96 | break; 97 | 98 | window_draw(window); 99 | break; 100 | } 101 | 102 | window_close(window); 103 | 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.59) 2 | AC_INIT([grate], [0.0.0], [thierry.reding@avionic-design.de]) 3 | AC_CONFIG_MACRO_DIR([m4]) 4 | AC_CONFIG_SRCDIR([Makefile.am]) 5 | AC_CONFIG_HEADER([config.h]) 6 | AC_CANONICAL_HOST 7 | 8 | AM_INIT_AUTOMAKE([no-dist-gzip dist-xz foreign]) 9 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 10 | 11 | AC_PROG_LIBTOOL 12 | AC_PROG_CC 13 | AM_PROG_CC_C_O 14 | AC_PROG_CXX 15 | AC_PROG_INSTALL 16 | AM_PROG_LEX 17 | AC_PROG_YACC 18 | PKG_PROG_PKG_CONFIG 19 | 20 | PKG_CHECK_MODULES(DevIL, ILU) 21 | PKG_CHECK_MODULES(PNG, libpng) 22 | PKG_CHECK_MODULES(DRM, libdrm) 23 | 24 | AC_CHECK_LIB([z], [adler32], [enable_zlib=yes], [enable_zlib=no]) 25 | AM_CONDITIONAL([ENABLE_ZLIB], [test "x$enable_zlib" = "xyes"]) 26 | 27 | AC_CHECK_LIB([lz4], [LZ4_compress_default], [enable_lz4=yes], [enable_lz4=no]) 28 | AM_CONDITIONAL([ENABLE_LZ4], [test "x$enable_lz4" = "xyes"]) 29 | 30 | AC_ARG_ENABLE([gles-tests], 31 | [AS_HELP_STRING([--enable-gles-tests], 32 | [Build GLES tests (default: enabled)])], 33 | [enable_gles="$enableval"], 34 | [enable_gles=yes]) 35 | AS_IF([test "x$enable_gles" = "xyes"], [ 36 | PKG_CHECK_MODULES(GLES1, [egl glesv1_cm x11], [HAVE_GLES1=1], [HAVE_GLES1=0]) 37 | AM_CONDITIONAL([USE_GLES1], [test "$HAVE_GLES1" -eq 1]) 38 | PKG_CHECK_MODULES(GLES2, [egl glesv2 x11], [HAVE_GLES2=1], [HAVE_GLES2=0]) 39 | AM_CONDITIONAL([USE_GLES2], [test "$HAVE_GLES2" -eq 1]) 40 | ]) 41 | 42 | AC_ARG_ENABLE([x11-display], 43 | [AS_HELP_STRING([--enable-x11-display], 44 | [Build with X11 display support (default: enabled)])], 45 | [enable_x11="$enableval"], 46 | [enable_x11=yes]) 47 | AS_IF([test "x$enable_x11" = "xyes"], [ 48 | PKG_CHECK_MODULES(XCB, [xcb xcb-image xcb-dri2 xcb-icccm], [AC_DEFINE([HAVE_XCB], [1], [Use XCB])]) 49 | ]) 50 | 51 | CFLAGS="$CFLAGS -Wall" 52 | 53 | AC_ARG_ENABLE([werror], 54 | [AS_HELP_STRING([--enable-werror], 55 | [Treat warnings as errors (default: disabled)])], 56 | [enable_werror="$enableval"], 57 | [enable_werror=no]) 58 | if test "x$enable_werror" = "xyes"; then 59 | CFLAGS="$CFLAGS -Werror" 60 | fi 61 | 62 | AC_CHECK_LIB([cgdrv], [CgDrv_Create], [enable_cgc=yes], [enable_cgc=no]) 63 | AM_CONDITIONAL([ENABLE_CGC], [test "x$enable_cgc" = "xyes"]) 64 | 65 | AC_CHECK_HEADER([envytools/rnn.h], 66 | [AC_CHECK_LIB([rnn], [rnn_init], [enable_rnn=yes], [enable_rnn=no], [-lenvyutil -lxml2])]) 67 | AM_CONDITIONAL([ENABLE_RNN], [test "x$enable_rnn" = "xyes"]) 68 | 69 | SAVE_CPPFLAGS="$CPPFLAGS" 70 | CPPFLAGS="$CPPFLAGS $DRM_CFLAGS" 71 | 72 | AC_CHECK_DECL(drmSetClientCap, 73 | [AC_DEFINE(HAVE_LIBDRM_CLIENT_CAP, 1, 74 | [Have drmSetClientCap API])], [], 75 | [#include ]) 76 | 77 | CPPFLAGS="$SAVE_CPPFLAGS" 78 | 79 | AC_CONFIG_FILES([ 80 | src/libgrate/libgrate.pc 81 | ]) 82 | 83 | AC_OUTPUT([ 84 | Makefile 85 | include/Makefile 86 | src/Makefile 87 | src/libcgc/Makefile 88 | src/libgrate/Makefile 89 | src/libhost1x/Makefile 90 | src/libwrap/Makefile 91 | tests/Makefile 92 | tests/drm/Makefile 93 | tests/gles1/Makefile 94 | tests/gles2/Makefile 95 | tests/grate/Makefile 96 | tests/host1x/Makefile 97 | tests/nvhost/Makefile 98 | tools/Makefile 99 | ]) 100 | -------------------------------------------------------------------------------- /src/libwrap/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_UTILS_H 26 | #define GRATE_UTILS_H 1 27 | 28 | #include 29 | #include 30 | 31 | #include "list.h" 32 | 33 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 34 | 35 | #define PRINTF(...) \ 36 | do { \ 37 | if (libwrap_verbose) \ 38 | fprintf(stderr, __VA_ARGS__); \ 39 | } while (0) 40 | 41 | extern bool libwrap_verbose; 42 | 43 | struct ioctl { 44 | unsigned long request; 45 | const char *name; 46 | }; 47 | 48 | #define IOCTL(request) \ 49 | { request, #request } 50 | 51 | enum { 52 | DUMP_PREFIX_NONE, 53 | DUMP_PREFIX_OFFSET, 54 | DUMP_PREFIX_ADDRESS, 55 | }; 56 | 57 | void print_hexdump(FILE *fp, int prefix_type, const char *prefix, 58 | const void *buffer, size_t size, size_t columns, 59 | bool ascii); 60 | 61 | struct file_ops; 62 | 63 | struct file { 64 | struct list_head list; 65 | char *path; 66 | 67 | int fd; 68 | int dup_fds[8]; 69 | 70 | const struct ioctl *ioctls; 71 | unsigned int num_ioctls; 72 | 73 | const struct file_ops *ops; 74 | }; 75 | 76 | struct file_ops { 77 | int (*enter_ioctl)(struct file *file, unsigned long request, void *arg); 78 | int (*leave_ioctl)(struct file *file, unsigned long request, void *arg); 79 | ssize_t (*write)(struct file *file, const void *buffer, size_t size); 80 | ssize_t (*read)(struct file *file, void *buffer, size_t size); 81 | void (*release)(struct file *file); 82 | }; 83 | 84 | struct file *file_open(const char *path, int fd); 85 | struct file *file_lookup(int fd); 86 | struct file *file_find(const char *path); 87 | void file_close(int fd); 88 | void file_dup(struct file *file, int fd); 89 | 90 | struct file_table { 91 | const char *path; 92 | struct file *(*open)(const char *path, int fd); 93 | }; 94 | 95 | void file_table_register(const struct file_table *table, unsigned int count); 96 | 97 | enum chip_id { 98 | TEGRA_INVALID, 99 | TEGRA_UNKNOWN, 100 | TEGRA20, 101 | TEGRA30, 102 | TEGRA114, 103 | }; 104 | 105 | enum chip_id tegra_chip_id(void); 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /include/list.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_LIST_H 26 | #define GRATE_LIST_H 1 27 | 28 | #include 29 | 30 | #define container_of(ptr, type, member) ({ \ 31 | const typeof(((type *)0)->member) *__mptr = (ptr); \ 32 | (type *)((char *)__mptr - offsetof(type, member)); \ 33 | }) 34 | 35 | struct list_head { 36 | struct list_head *prev; 37 | struct list_head *next; 38 | }; 39 | 40 | #define LIST_HEAD_INIT(name) { (&name), (&name) } 41 | 42 | #define LIST_HEAD(name) \ 43 | struct list_head name = LIST_HEAD_INIT(name) 44 | 45 | static inline void INIT_LIST_HEAD(struct list_head *list) 46 | { 47 | list->prev = list; 48 | list->next = list; 49 | } 50 | 51 | static inline void __list_add(struct list_head *new, struct list_head *prev, 52 | struct list_head *next) 53 | { 54 | next->prev = new; 55 | new->next = next; 56 | new->prev = prev; 57 | prev->next = new; 58 | } 59 | 60 | static inline void list_add(struct list_head *new, struct list_head *head) 61 | { 62 | __list_add(new, head, head->next); 63 | } 64 | 65 | static inline void list_add_tail(struct list_head *new, struct list_head *head) 66 | { 67 | __list_add(new, head->prev, head); 68 | } 69 | 70 | static inline void __list_del(struct list_head *prev, struct list_head *next) 71 | { 72 | next->prev = prev; 73 | prev->next = next; 74 | } 75 | 76 | static inline void list_del(struct list_head *entry) 77 | { 78 | __list_del(entry->prev, entry->next); 79 | } 80 | 81 | #define list_entry(ptr, type, member) \ 82 | container_of(ptr, type, member) 83 | 84 | #define list_for_each(pos, head) \ 85 | for (pos = (head)->next; pos != (head); pos = pos->next) 86 | 87 | #define list_for_each_entry(pos, head, member) \ 88 | for (pos = list_entry((head)->next, typeof(*pos), member); \ 89 | &pos->member != (head); \ 90 | pos = list_entry(pos->member.next, typeof(*pos), member)) 91 | 92 | #define list_for_each_entry_safe(pos, n, head, member) \ 93 | for (pos = list_entry(head, typeof(*pos), member), \ 94 | n = list_entry(pos->member.next, typeof(*pos), member); \ 95 | &pos->member != (head); \ 96 | pos = n, n = list_entry(n->member.next, typeof(*pos), member)) 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/libwrap/recorder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Dmitry Osipenko 3 | * Copyright (c) Erik Faye-Lund 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef GRATE_RECORDER_H 25 | #define GRATE_RECORDER_H 1 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "record_replay.h" 37 | 38 | struct rec_ctx { 39 | unsigned int id; 40 | }; 41 | 42 | struct bo_page { 43 | uint8_t data[4096]; 44 | }; 45 | 46 | struct rec_page_meta { 47 | unsigned long chksum; 48 | }; 49 | 50 | struct bo_rec { 51 | struct rec_page_meta *page_meta; 52 | struct bo_page *page_data; 53 | struct rec_ctx *ctx; 54 | unsigned int num_pages; 55 | unsigned int id; 56 | bool captured; 57 | unsigned int width; 58 | unsigned int height; 59 | unsigned int pitch; 60 | uint32_t format; 61 | uint32_t flags; 62 | bool is_framebuffer; 63 | unsigned int fb_id; 64 | }; 65 | 66 | struct job_ctx_rec { 67 | unsigned int id; 68 | bool gr2d; 69 | }; 70 | 71 | struct job_rec { 72 | unsigned int num_syncpt_incrs; 73 | 74 | struct record_gather *gathers; 75 | unsigned int num_gathers; 76 | 77 | struct record_reloc *relocs; 78 | unsigned int num_relocs; 79 | 80 | struct job_ctx_rec *ctx; 81 | }; 82 | 83 | #define REC_VER 0x0004 84 | 85 | struct recorder { 86 | bool inited; 87 | bool enabled; 88 | 89 | FILE *fout; 90 | unsigned int ctx_cnt; 91 | unsigned int bos_cnt; 92 | unsigned int job_ctx_cnt; 93 | unsigned long zeroed_page_chksum; 94 | }; 95 | 96 | bool recorder_enabled(void); 97 | struct rec_ctx *record_create_ctx(void); 98 | void record_destroy_ctx(struct rec_ctx *ctx); 99 | struct bo_rec *record_create_bo(struct rec_ctx *ctx, size_t size, 100 | uint32_t flags); 101 | void record_set_bo_data(struct bo_rec *bo, void *data); 102 | void record_destroy_bo(struct bo_rec *bo); 103 | void record_capture_bo_data(struct bo_rec *bo, bool force); 104 | void record_set_bo_flags(struct bo_rec *bo, uint32_t flags); 105 | void record_add_framebuffer(struct bo_rec *bo, uint32_t flags); 106 | void record_del_framebuffer(struct bo_rec *bo); 107 | void record_display_framebuffer(struct bo_rec *bo); 108 | struct job_ctx_rec *record_job_ctx_create(bool gr2d); 109 | void record_job_ctx_destroy(struct job_ctx_rec *ctx); 110 | void record_job_submit(struct job_rec *job); 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /src/libgrate/asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Dmitry Osipenko 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 | * for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along 15 | * with this program; if not, see . 16 | */ 17 | 18 | #ifndef GRATE_ASM_H 19 | #define GRATE_ASM_H 20 | 21 | #include "fragment_asm.h" 22 | #include "linker_asm.h" 23 | #include "vpe_vliw.h" 24 | 25 | struct yy_buffer_state; 26 | 27 | extern struct yy_buffer_state *vertex_asm_scan_string(const char *); 28 | extern int vertex_asmparse(void); 29 | extern int vertex_asmlex_destroy(void); 30 | 31 | struct asm_vec_component { 32 | uint32_t value; 33 | int dirty; 34 | }; 35 | 36 | typedef struct asm_vec4 { 37 | struct asm_vec_component x; 38 | struct asm_vec_component y; 39 | struct asm_vec_component z; 40 | struct asm_vec_component w; 41 | } asm_vec4; 42 | 43 | typedef struct asm_const { 44 | asm_vec4 vector; 45 | int used; 46 | } asm_const; 47 | 48 | typedef struct asm_in_out { 49 | char name[256]; 50 | union { 51 | int used; 52 | int type; 53 | }; 54 | } asm_in_out; 55 | 56 | extern vpe_instr128 asm_vs_instructions[256]; 57 | extern asm_const asm_vs_constants[256]; 58 | extern asm_in_out asm_vs_attributes[16]; 59 | extern asm_in_out asm_vs_exports[16]; 60 | extern asm_in_out asm_vs_uniforms[256]; 61 | extern int asm_vs_instructions_nb; 62 | 63 | const char * vpe_vliw_disassemble(const vpe_instr128 *ins); 64 | 65 | extern struct yy_buffer_state *fragment_asm_scan_string(const char *); 66 | extern int fragment_asmparse(void); 67 | extern int fragment_asmlex_destroy(void); 68 | 69 | extern pseq_instr asm_pseq_instructions[64]; 70 | extern mfu_instr asm_mfu_instructions[64]; 71 | extern tex_instr asm_tex_instructions[64]; 72 | extern alu_instr asm_alu_instructions[64]; 73 | extern dw_instr asm_dw_instructions[64]; 74 | 75 | extern instr_sched asm_mfu_sched[64]; 76 | extern instr_sched asm_alu_sched[64]; 77 | 78 | extern uint32_t asm_fs_constants[32]; 79 | 80 | #define FS_UNIFORM_FX10_LOW 1 81 | #define FS_UNIFORM_FX10_HIGH 2 82 | #define FS_UNIFORM_FP20 3 83 | 84 | extern asm_in_out asm_fs_uniforms[32 * 2]; 85 | 86 | extern unsigned asm_fs_instructions_nb; 87 | extern unsigned asm_mfu_instructions_nb; 88 | extern unsigned asm_alu_instructions_nb; 89 | 90 | extern unsigned asm_alu_buffer_size; 91 | extern unsigned asm_pseq_to_dw_exec_nb; 92 | 93 | const char * fragment_pipeline_disassemble( 94 | const pseq_instr *pseq, 95 | const mfu_instr *mfu, unsigned mfu_nb, 96 | const tex_instr *tex, 97 | const alu_instr *alu, unsigned alu_nb, 98 | const dw_instr *dw); 99 | 100 | extern int asm_discards_fragment; 101 | 102 | extern struct yy_buffer_state *linker_asm_scan_string(const char *); 103 | extern int linker_asmparse(void); 104 | extern int linker_asmlex_destroy(void); 105 | 106 | extern link_instr asm_linker_instructions[32]; 107 | 108 | extern unsigned asm_linker_instructions_nb; 109 | extern unsigned asm_linker_used_tram_rows_nb; 110 | 111 | const char * linker_instruction_disassemble(const link_instr *instr); 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /src/libgrate/display.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include "../libhost1x/host1x-private.h" 26 | #include "libgrate-private.h" 27 | 28 | struct grate_display { 29 | struct host1x_display *base; 30 | }; 31 | 32 | struct grate_overlay { 33 | struct host1x_overlay *base; 34 | }; 35 | 36 | struct grate_display *grate_display_open(struct grate *grate) 37 | { 38 | struct grate_display *display; 39 | 40 | display = calloc(1, sizeof(*display)); 41 | if (!display) 42 | return NULL; 43 | 44 | display->base = host1x_get_display(grate->host1x); 45 | 46 | if (!display->base) { 47 | free(display); 48 | return NULL; 49 | } 50 | 51 | if (display->base->needs_explicit_vsync) 52 | grate->options->vsync = true; 53 | 54 | return display; 55 | } 56 | 57 | void grate_display_close(struct grate_display *display) 58 | { 59 | free(display); 60 | } 61 | 62 | void grate_display_get_resolution(struct grate_display *display, 63 | unsigned int *width, unsigned int *height) 64 | { 65 | host1x_display_get_resolution(display->base, width, height); 66 | } 67 | 68 | void grate_display_show(struct grate_display *display, 69 | struct grate_framebuffer *fb, 70 | bool vsync, bool reflect_y) 71 | { 72 | host1x_display_set(display->base, fb->front, vsync, reflect_y); 73 | } 74 | 75 | struct grate_overlay *grate_overlay_create(struct grate_display *display) 76 | { 77 | struct grate_overlay *overlay; 78 | int err; 79 | 80 | overlay = calloc(1, sizeof(*overlay)); 81 | if (!overlay) 82 | return NULL; 83 | 84 | err = host1x_overlay_create(&overlay->base, display->base); 85 | if (err < 0) { 86 | grate_error("host1x_overlay_create() failed: %d\n", err); 87 | free(overlay); 88 | return NULL; 89 | } 90 | 91 | return overlay; 92 | } 93 | 94 | void grate_overlay_free(struct grate_overlay *overlay) 95 | { 96 | if (overlay) 97 | host1x_overlay_close(overlay->base); 98 | 99 | free(overlay); 100 | } 101 | 102 | void grate_overlay_show(struct grate_overlay *overlay, 103 | struct grate_framebuffer *fb, unsigned int x, 104 | unsigned int y, unsigned int width, 105 | unsigned int height, bool vsync, bool reflect_y) 106 | { 107 | int err; 108 | 109 | err = host1x_overlay_set(overlay->base, fb->front, x, y, width, 110 | height, vsync, reflect_y); 111 | if (err < 0) 112 | grate_error("host1x_overlay_set() failed: %d\n", err); 113 | } 114 | -------------------------------------------------------------------------------- /tests/gles2/gles-pbuffer-fill.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | static const GLchar *vertex_shader[] = { 36 | "attribute vec4 position;\n", 37 | "\n", 38 | "void main()\n", 39 | "{\n", 40 | " gl_Position = position;\n", 41 | "}" 42 | }; 43 | 44 | static const GLchar *fragment_shader[] = { 45 | "void main()\n", 46 | "{\n", 47 | " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n", 48 | "}" 49 | }; 50 | 51 | void pbuffer_draw(struct pbuffer *pbuffer) 52 | { 53 | static const GLfloat vertices[] = { 54 | -1.0f, 1.0f, 55 | 1.0f, 1.0f, 56 | -1.0f, -1.0f, 57 | 1.0f, -1.0f, 58 | }; 59 | static const GLushort indices[] = { 60 | 0, 1, 2, 61 | 2, 3, 1, 62 | }; 63 | GLuint vs, fs, program; 64 | GLint position; 65 | 66 | printf("=== compiling shaders\n"); 67 | vs = glsl_shader_load(GL_VERTEX_SHADER, vertex_shader, 68 | ARRAY_SIZE(vertex_shader)); 69 | fs = glsl_shader_load(GL_FRAGMENT_SHADER, fragment_shader, 70 | ARRAY_SIZE(fragment_shader)); 71 | glFlush(); 72 | printf("=== linking program\n"); 73 | program = glsl_program_create(vs, fs); 74 | glsl_program_link(program); 75 | glFlush(); 76 | printf("=== using program\n"); 77 | glUseProgram(program); 78 | glFlush(); 79 | 80 | position = glGetAttribLocation(program, "position"); 81 | 82 | printf("=== clearing buffer\n"); 83 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 84 | glClear(GL_COLOR_BUFFER_BIT); 85 | glFlush(); 86 | 87 | printf("=== setting vertex attribute\n"); 88 | glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 89 | 2 * sizeof(GLfloat), vertices); 90 | glFlush(); 91 | printf("=== enabling vertex attribute\n"); 92 | glEnableVertexAttribArray(position); 93 | glFlush(); 94 | 95 | printf("=== drawing triangles\n"); 96 | glDrawElements(GL_TRIANGLES, ARRAY_SIZE(indices), GL_UNSIGNED_SHORT, 97 | indices); 98 | glFlush(); 99 | printf("=== done\n"); 100 | } 101 | 102 | int main(int argc, char *argv[]) 103 | { 104 | struct pbuffer *pbuffer; 105 | 106 | pbuffer = pbuffer_create(32, 32); 107 | if (!pbuffer) { 108 | fprintf(stderr, "pbuffer_create() failed\n"); 109 | return 1; 110 | } 111 | 112 | pbuffer_draw(pbuffer); 113 | pbuffer_save(pbuffer, "test.png"); 114 | pbuffer_free(pbuffer); 115 | 116 | return 0; 117 | } 118 | -------------------------------------------------------------------------------- /src/libgrate/etc1.h: -------------------------------------------------------------------------------- 1 | // Copyright 2009 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef __etc1_h__ 15 | #define __etc1_h__ 16 | #define ETC1_ENCODED_BLOCK_SIZE 8 17 | #define ETC1_DECODED_BLOCK_SIZE 48 18 | #ifndef ETC1_RGB8_OES 19 | #define ETC1_RGB8_OES 0x8D64 20 | #endif 21 | typedef unsigned char etc1_byte; 22 | typedef int etc1_bool; 23 | typedef unsigned int etc1_uint32; 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | // Encode a block of pixels. 28 | // 29 | // pIn is a pointer to a ETC_DECODED_BLOCK_SIZE array of bytes that represent a 30 | // 4 x 4 square of 3-byte pixels in form R, G, B. Byte (3 * (x + 4 * y) is the R 31 | // value of pixel (x, y). 32 | // 33 | // validPixelMask is a 16-bit mask where bit (1 << (x + y * 4)) indicates whether 34 | // the corresponding (x,y) pixel is valid. Invalid pixel color values are ignored when compressing. 35 | // 36 | // pOut is an ETC1 compressed version of the data. 37 | void etc1_encode_block(const etc1_byte* pIn, etc1_uint32 validPixelMask, etc1_byte* pOut); 38 | // Decode a block of pixels. 39 | // 40 | // pIn is an ETC1 compressed version of the data. 41 | // 42 | // pOut is a pointer to a ETC_DECODED_BLOCK_SIZE array of bytes that represent a 43 | // 4 x 4 square of 3-byte pixels in form R, G, B. Byte (3 * (x + 4 * y) is the R 44 | // value of pixel (x, y). 45 | void etc1_decode_block(const etc1_byte* pIn, etc1_byte* pOut); 46 | // Return the size of the encoded image data (does not include size of PKM header). 47 | etc1_uint32 etc1_get_encoded_data_size(etc1_uint32 width, etc1_uint32 height); 48 | // Encode an entire image. 49 | // pIn - pointer to the image data. Formatted such that 50 | // pixel (x,y) is at pIn + pixelSize * x + stride * y; 51 | // pOut - pointer to encoded data. Must be large enough to store entire encoded image. 52 | // pixelSize can be 2 or 3. 2 is an GL_UNSIGNED_SHORT_5_6_5 image, 3 is a GL_BYTE RGB image. 53 | // returns non-zero if there is an error. 54 | int etc1_encode_image(const etc1_byte* pIn, etc1_uint32 width, etc1_uint32 height, 55 | etc1_uint32 pixelSize, etc1_uint32 stride, etc1_byte* pOut); 56 | // Decode an entire image. 57 | // pIn - pointer to encoded data. 58 | // pOut - pointer to the image data. Will be written such that 59 | // pixel (x,y) is at pIn + pixelSize * x + stride * y. Must be 60 | // large enough to store entire image. 61 | // pixelSize can be 2 or 3. 2 is an GL_UNSIGNED_SHORT_5_6_5 image, 3 is a GL_BYTE RGB image. 62 | // returns non-zero if there is an error. 63 | int etc1_decode_image(const etc1_byte* pIn, etc1_byte* pOut, 64 | etc1_uint32 width, etc1_uint32 height, 65 | etc1_uint32 pixelSize, etc1_uint32 stride); 66 | // Size of a PKM header, in bytes. 67 | #define ETC_PKM_HEADER_SIZE 16 68 | // Format a PKM header 69 | void etc1_pkm_format_header(etc1_byte* pHeader, etc1_uint32 width, etc1_uint32 height); 70 | // Check if a PKM header is correctly formatted. 71 | etc1_bool etc1_pkm_is_valid(const etc1_byte* pHeader); 72 | // Read the image width from a PKM header 73 | etc1_uint32 etc1_pkm_get_width(const etc1_byte* pHeader); 74 | // Read the image height from a PKM header 75 | etc1_uint32 etc1_pkm_get_height(const etc1_byte* pHeader); 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | #endif 80 | -------------------------------------------------------------------------------- /src/libgrate/grate-3d.h: -------------------------------------------------------------------------------- 1 | #ifndef GRATE_LIBGRATE_3D_H 2 | #define GRATE_LIBGRATE_3D_H 1 3 | 4 | #include 5 | 6 | #define log2_size(s) (31 - __builtin_clz(s)) 7 | 8 | struct host1x_bo; 9 | struct cgc_shader; 10 | 11 | struct grate_attribute { 12 | int position; 13 | const char *name; 14 | }; 15 | 16 | struct grate_uniform { 17 | int position; 18 | const char *name; 19 | }; 20 | 21 | struct grate_shader { 22 | struct cgc_shader *cgc; 23 | unsigned num_words; 24 | uint32_t *words; 25 | 26 | union { 27 | struct { 28 | unsigned alu_buf_size; 29 | unsigned pseq_inst_nb; 30 | unsigned pseq_to_dw_nb; 31 | bool discards_fragment; 32 | }; 33 | 34 | struct { 35 | unsigned used_tram_rows_nb; 36 | unsigned linker_inst_nb; 37 | }; 38 | }; 39 | }; 40 | 41 | struct grate_program { 42 | struct grate_shader *vs; 43 | struct grate_shader *fs; 44 | struct grate_shader *linker; 45 | 46 | struct grate_attribute *attributes; 47 | unsigned num_attributes; 48 | uint32_t attributes_use_mask; 49 | 50 | struct grate_uniform *vs_uniforms; 51 | unsigned num_vs_uniforms; 52 | 53 | struct grate_uniform *fs_uniforms; 54 | unsigned num_fs_uniforms; 55 | 56 | uint32_t vs_constants[256 * 4]; 57 | uint32_t fs_constants[32]; 58 | }; 59 | 60 | struct grate_render_target { 61 | struct host1x_pixelbuffer *pixbuf; 62 | bool dither_enabled; 63 | }; 64 | 65 | struct grate_vtx_attribute { 66 | struct host1x_bo *bo; 67 | unsigned long stride; 68 | unsigned size; 69 | unsigned type; 70 | }; 71 | 72 | struct grate_texture { 73 | struct host1x_pixelbuffer *pixbuf; 74 | struct host1x_pixelbuffer *mipmap_pixbuf; 75 | bool wrap_t_clamp_to_edge; 76 | bool wrap_s_clamp_to_edge; 77 | bool wrap_t_mirrored_repeat; 78 | bool wrap_s_mirrored_repeat; 79 | unsigned max_lod; 80 | bool mag_filter_enabled; 81 | bool min_filter_enabled; 82 | bool mip_filter_enabled; 83 | bool mipmap_enabled; 84 | }; 85 | 86 | struct grate_3d_ctx { 87 | uint32_t vs_uniforms[256 * 4]; 88 | uint32_t fs_uniforms[32]; 89 | 90 | struct grate *grate; 91 | struct grate_program *program; 92 | 93 | struct grate_render_target render_targets[16]; 94 | struct grate_vtx_attribute *vtx_attributes[16]; 95 | struct grate_texture *textures[16]; 96 | 97 | float depth_range_near; 98 | float depth_range_far; 99 | float point_size; 100 | float point_coord_range_min_s; 101 | float point_coord_range_min_t; 102 | float point_coord_range_max_s; 103 | float point_coord_range_max_t; 104 | float line_width; 105 | float viewport_x_bias; 106 | float viewport_y_bias; 107 | float viewport_z_bias; 108 | float viewport_x_scale; 109 | float viewport_y_scale; 110 | float viewport_z_scale; 111 | float polygon_offset_units; 112 | float polygon_offset_factor; 113 | bool guarband_enabled; 114 | bool provoking_vtx_last; 115 | bool tri_face_front_cw; 116 | bool depth_test; 117 | bool depth_write; 118 | bool stencil_test; 119 | unsigned cull_face; 120 | unsigned depth_func; 121 | unsigned stencil_func_front; 122 | unsigned stencil_fail_op_front; 123 | unsigned stencil_zfail_op_front; 124 | unsigned stencil_zpass_op_front; 125 | unsigned stencil_func_back; 126 | unsigned stencil_fail_op_back; 127 | unsigned stencil_zfail_op_back; 128 | unsigned stencil_zpass_op_back; 129 | uint32_t dither_unk; 130 | uint32_t point_params; 131 | uint32_t line_params; 132 | uint16_t scissor_x; 133 | uint16_t scissor_y; 134 | uint16_t scissor_width; 135 | uint16_t scissor_heigth; 136 | 137 | uint16_t attributes_enable_mask; 138 | uint16_t render_targets_enable_mask; 139 | 140 | uint8_t stencil_ref_front; 141 | uint8_t stencil_ref_back; 142 | uint8_t stencil_mask_front; 143 | uint8_t stencil_mask_back; 144 | }; 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /src/libhost1x/nvhost-nvmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Thierry Reding 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef GRATE_HOST1X_NVHOST_NVMAP_H 25 | #define GRATE_HOST1X_NVHOST_NVMAP_H 1 26 | 27 | #include 28 | #include 29 | 30 | struct nvmap { 31 | int fd; 32 | }; 33 | 34 | struct nvmap *nvmap_open(void); 35 | void nvmap_close(struct nvmap *nvmap); 36 | 37 | struct nvmap_handle { 38 | size_t size; 39 | uint32_t id; 40 | void *ptr; 41 | }; 42 | 43 | static inline unsigned long 44 | nvmap_handle_get_offset(struct nvmap_handle *handle, void *ptr) 45 | { 46 | return (unsigned long)ptr - (unsigned long)handle->ptr; 47 | } 48 | 49 | #define NVMAP_HEAP_SYSTEM (1ul << 31) 50 | #define NVMAP_HEAP_IOVMM (1ul << 30) 51 | #define NVMAP_HEAP_CARVEOUT_IRAM (1ul << 29) 52 | #define NVMAP_HEAP_CARVEOUT_GENERIC (1ul << 0) 53 | 54 | #define NVMAP_HANDLE_UNREACHABLE (0x0ul << 0) 55 | #define NVMAP_HANDLE_WRITE_COMBINE (0x1ul << 0) 56 | #define NVMAP_HANDLE_INNER_CACHEABLE (0x2ul << 0) 57 | #define NVMAP_HANDLE_CACHEABLE (0x3ul << 0) 58 | #define NVMAP_HANDLE_CACHE_FLAG (0x3ul << 0) 59 | 60 | #define NVMAP_HANDLE_SECURE (0x1ul << 2) 61 | #define NVMAP_HANDLE_KIND_SPECIFIED (0x1ul << 3) 62 | #define NVMAP_HANDLE_COMPR_SPECIFIED (0x1ul << 4) 63 | #define NVMAP_HANDLE_ZEROED_PAGES (0x1ul << 5) 64 | 65 | struct nvmap_handle *nvmap_handle_create(struct nvmap *nvmap, size_t size); 66 | void nvmap_handle_free(struct nvmap *nvmap, struct nvmap_handle *handle); 67 | int nvmap_handle_alloc(struct nvmap *nvmap, struct nvmap_handle *handle, 68 | unsigned long heap_mask, unsigned long flags, 69 | unsigned long align); 70 | int nvmap_handle_mmap(struct nvmap *nvmap, struct nvmap_handle *handle); 71 | int nvmap_handle_invalidate(struct nvmap *nvmap, struct nvmap_handle *handle, 72 | unsigned long offset, unsigned long length); 73 | int nvmap_handle_writeback_invalidate(struct nvmap *nvmap, 74 | struct nvmap_handle *handle, 75 | unsigned long offset, 76 | unsigned long length); 77 | 78 | struct nvmap_framebuffer { 79 | unsigned short width; 80 | unsigned short height; 81 | unsigned short depth; 82 | unsigned short pitch; 83 | 84 | struct nvmap_handle *handle; 85 | struct nvmap *nvmap; 86 | }; 87 | 88 | struct nvmap_framebuffer *nvmap_framebuffer_create(struct nvmap *nvmap, 89 | unsigned short width, 90 | unsigned short height, 91 | unsigned short depth); 92 | void nvmap_framebuffer_free(struct nvmap_framebuffer *fb); 93 | int nvmap_framebuffer_save(struct nvmap_framebuffer *fb, const char *filename); 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /tests/nvhost/nvmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_NVMAP_H 26 | #define GRATE_NVMAP_H 1 27 | 28 | #include 29 | #include 30 | 31 | struct nvmap { 32 | int fd; 33 | }; 34 | 35 | struct nvmap *nvmap_open(void); 36 | void nvmap_close(struct nvmap *nvmap); 37 | 38 | struct nvmap_handle { 39 | size_t size; 40 | uint32_t id; 41 | void *ptr; 42 | }; 43 | 44 | static inline unsigned long 45 | nvmap_handle_get_offset(struct nvmap_handle *handle, void *ptr) 46 | { 47 | return (unsigned long)ptr - (unsigned long)handle->ptr; 48 | } 49 | 50 | #define NVMAP_HEAP_SYSTEM (1ul << 31) 51 | #define NVMAP_HEAP_IOVMM (1ul << 30) 52 | #define NVMAP_HEAP_CARVEOUT_IRAM (1ul << 29) 53 | #define NVMAP_HEAP_CARVEOUT_GENERIC (1ul << 0) 54 | 55 | #define NVMAP_HANDLE_UNREACHABLE (0x0ul << 0) 56 | #define NVMAP_HANDLE_WRITE_COMBINE (0x1ul << 0) 57 | #define NVMAP_HANDLE_INNER_CACHEABLE (0x2ul << 0) 58 | #define NVMAP_HANDLE_CACHEABLE (0x3ul << 0) 59 | #define NVMAP_HANDLE_CACHE_FLAG (0x3ul << 0) 60 | 61 | #define NVMAP_HANDLE_SECURE (0x1ul << 2) 62 | #define NVMAP_HANDLE_KIND_SPECIFIED (0x1ul << 3) 63 | #define NVMAP_HANDLE_COMPR_SPECIFIED (0x1ul << 4) 64 | #define NVMAP_HANDLE_ZEROED_PAGES (0x1ul << 5) 65 | 66 | struct nvmap_handle *nvmap_handle_create(struct nvmap *nvmap, size_t size); 67 | void nvmap_handle_free(struct nvmap *nvmap, struct nvmap_handle *handle); 68 | int nvmap_handle_alloc(struct nvmap *nvmap, struct nvmap_handle *handle, 69 | unsigned long heap_mask, unsigned long flags, 70 | unsigned long align); 71 | int nvmap_handle_mmap(struct nvmap *nvmap, struct nvmap_handle *handle); 72 | int nvmap_handle_invalidate(struct nvmap *nvmap, struct nvmap_handle *handle, 73 | unsigned long offset, unsigned long length); 74 | int nvmap_handle_writeback_invalidate(struct nvmap *nvmap, 75 | struct nvmap_handle *handle, 76 | unsigned long offset, 77 | unsigned long length); 78 | 79 | struct nvmap_framebuffer { 80 | unsigned short width; 81 | unsigned short height; 82 | unsigned short depth; 83 | unsigned short pitch; 84 | 85 | struct nvmap_handle *handle; 86 | struct nvmap *nvmap; 87 | }; 88 | 89 | struct nvmap_framebuffer *nvmap_framebuffer_create(struct nvmap *nvmap, 90 | unsigned short width, 91 | unsigned short height, 92 | unsigned short depth); 93 | void nvmap_framebuffer_free(struct nvmap_framebuffer *fb); 94 | int nvmap_framebuffer_save(struct nvmap_framebuffer *fb, const char *filename); 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /tests/gles2/gles-shader-fill.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | static const GLchar *vertex_shader[] = { 36 | "attribute vec4 position;\n", 37 | //"attribute vec2 texcoord;\n", 38 | //"varying vec2 uv;\n", 39 | "\n", 40 | "void main()\n", 41 | "{\n", 42 | " gl_Position = position;\n", 43 | //" uv = texcoord;\n", 44 | "}" 45 | }; 46 | 47 | static const GLchar *fragment_shader[] = { 48 | "void main()\n", 49 | "{\n", 50 | " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n", 51 | "}" 52 | }; 53 | 54 | void window_draw(struct window *window) 55 | { 56 | static const GLfloat vertices[] = { 57 | -1.0f, 1.0f, 58 | 1.0f, 1.0f, 59 | -1.0f, -1.0f, 60 | 1.0f, -1.0f, 61 | }; 62 | static const GLfloat uv[] = { 63 | 0.0f, 0.0f, 64 | 1.0f, 0.0f, 65 | 0.0f, 1.0f, 66 | 1.0f, 1.0f, 67 | }; 68 | static const GLushort indices[] = { 69 | 0, 1, 2, 70 | 2, 3, 1, 71 | }; 72 | GLint position, texcoord; 73 | GLuint vs, fs, program; 74 | 75 | vs = glsl_shader_load(GL_VERTEX_SHADER, vertex_shader, 76 | ARRAY_SIZE(vertex_shader)); 77 | fs = glsl_shader_load(GL_FRAGMENT_SHADER, fragment_shader, 78 | ARRAY_SIZE(fragment_shader)); 79 | program = glsl_program_create(vs, fs); 80 | glsl_program_link(program); 81 | glUseProgram(program); 82 | 83 | position = glGetAttribLocation(program, "position"); 84 | texcoord = glGetAttribLocation(program, "texcoord"); 85 | 86 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 87 | glClear(GL_COLOR_BUFFER_BIT); 88 | 89 | glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 90 | 2 * sizeof(GLfloat), vertices); 91 | glEnableVertexAttribArray(position); 92 | 93 | glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 94 | 2 * sizeof(GLfloat), uv); 95 | glEnableVertexAttribArray(texcoord); 96 | 97 | glDrawElements(GL_TRIANGLES, ARRAY_SIZE(indices), GL_UNSIGNED_SHORT, 98 | indices); 99 | 100 | eglSwapBuffers(window->egl.display, window->egl.surface); 101 | } 102 | 103 | int main(int argc, char *argv[]) 104 | { 105 | struct window *window; 106 | 107 | window = window_create(0, 0, 640, 480); 108 | if (!window) { 109 | fprintf(stderr, "window_create() failed\n"); 110 | return 1; 111 | } 112 | 113 | window_show(window); 114 | window_draw(window); 115 | 116 | sleep(1); 117 | 118 | window_close(window); 119 | return 0; 120 | } 121 | -------------------------------------------------------------------------------- /tests/gles2/gles-pbuffer-vertex-offset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "common.h" 34 | 35 | static const GLchar *vertex_shader[] = { 36 | "attribute vec4 position;\n", 37 | "uniform float z;\n", 38 | "\n", 39 | "void main()\n", 40 | "{\n", 41 | " gl_Position = position + vec4(1.0, 0.5, 0.25, z);\n", 42 | "}" 43 | }; 44 | 45 | static const GLchar *fragment_shader[] = { 46 | "precision mediump float;\n", 47 | "\n", 48 | "void main()\n", 49 | "{\n", 50 | " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n", 51 | "}" 52 | }; 53 | 54 | void pbuffer_draw(struct pbuffer *pbuffer) 55 | { 56 | static const GLfloat vertices[] = { 57 | 0.0f, 0.5f, 0.0f, 1.0f, 58 | -0.5f, -0.5f, 0.0f, 1.0f, 59 | 0.5f, -0.5f, 0.0f, 1.0f, 60 | }; 61 | static const GLushort indices[] = { 62 | 0, 1, 2, 63 | }; 64 | GLuint vs, fs, program; 65 | GLint position, z; 66 | 67 | printf("=== compiling shaders\n"); 68 | vs = glsl_shader_load(GL_VERTEX_SHADER, vertex_shader, 69 | ARRAY_SIZE(vertex_shader)); 70 | fs = glsl_shader_load(GL_FRAGMENT_SHADER, fragment_shader, 71 | ARRAY_SIZE(fragment_shader)); 72 | glFlush(); 73 | printf("=== linking program\n"); 74 | program = glsl_program_create(vs, fs); 75 | glsl_program_link(program); 76 | glFlush(); 77 | printf("=== using program\n"); 78 | glUseProgram(program); 79 | glFlush(); 80 | 81 | position = glGetAttribLocation(program, "position"); 82 | z = glGetUniformLocation(program, "z"); 83 | 84 | printf("=== clearing buffer\n"); 85 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 86 | glClear(GL_COLOR_BUFFER_BIT); 87 | glFlush(); 88 | 89 | printf("=== setting vertex attribute\n"); 90 | glVertexAttribPointer(position, 4, GL_FLOAT, GL_FALSE, 91 | 4 * sizeof(GLfloat), vertices); 92 | glFlush(); 93 | printf("=== enabling vertex attribute\n"); 94 | glEnableVertexAttribArray(position); 95 | glFlush(); 96 | 97 | glUniform1f(z, 0.125f); 98 | 99 | printf("=== drawing triangles\n"); 100 | glDrawElements(GL_TRIANGLES, ARRAY_SIZE(indices), GL_UNSIGNED_SHORT, 101 | indices); 102 | glFlush(); 103 | printf("=== done\n"); 104 | } 105 | 106 | int main(int argc, char *argv[]) 107 | { 108 | struct pbuffer *pbuffer; 109 | 110 | pbuffer = pbuffer_create(32, 32); 111 | if (!pbuffer) { 112 | fprintf(stderr, "pbuffer_create() failed\n"); 113 | return 1; 114 | } 115 | 116 | pbuffer_draw(pbuffer); 117 | pbuffer_save(pbuffer, "test.png"); 118 | pbuffer_free(pbuffer); 119 | 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /src/libhost1x/nvhost.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Thierry Reding 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef GRATE_HOST1X_NVHOST_H 25 | #define GRATE_HOST1X_NVHOST_H 1 26 | 27 | #include "host1x.h" 28 | #include "host1x-private.h" 29 | 30 | #include "nvhost-nvmap.h" 31 | 32 | struct nvhost_ctrl { 33 | int fd; 34 | }; 35 | 36 | struct nvhost_ctrl *nvhost_ctrl_open(void); 37 | void nvhost_ctrl_close(struct nvhost_ctrl *ctrl); 38 | 39 | int nvhost_ctrl_read_syncpt(struct nvhost_ctrl *ctrl, uint32_t syncpt, 40 | uint32_t *value); 41 | 42 | int nvhost_ctrl_wait_syncpt(struct nvhost_ctrl *ctrl, uint32_t syncpt, 43 | uint32_t thresh, uint32_t timeout); 44 | 45 | struct nvhost_pushbuf_reloc { 46 | unsigned long source_offset; 47 | unsigned long target_handle; 48 | unsigned long target_offset; 49 | unsigned long shift; 50 | }; 51 | 52 | struct nvhost_client { 53 | struct host1x_client base; 54 | struct nvhost_ctrl *ctrl; 55 | struct nvmap *nvmap; 56 | int fd; 57 | }; 58 | 59 | static inline struct nvhost_client *to_nvhost_client(struct host1x_client *client) 60 | { 61 | return container_of(client, struct nvhost_client, base); 62 | } 63 | 64 | int nvhost_client_init(struct nvhost_client *client, struct nvmap *nvmap, 65 | struct nvhost_ctrl *ctrl, int fd); 66 | void nvhost_client_exit(struct nvhost_client *client); 67 | 68 | struct nvhost_bo { 69 | struct host1x_bo base; 70 | struct nvmap *nvmap; 71 | struct nvmap_handle *handle; 72 | }; 73 | 74 | static inline struct nvhost_bo *to_nvhost_bo(struct host1x_bo *bo) 75 | { 76 | return container_of(bo, struct nvhost_bo, base); 77 | } 78 | 79 | struct nvhost_display { 80 | struct host1x_display base; 81 | struct host1x_overlay overlay; 82 | struct nvhost *nvhost; 83 | uint32_t vblank_syncpt; 84 | int plane; 85 | int fd; 86 | }; 87 | 88 | struct nvhost_gr2d { 89 | struct nvhost_client client; 90 | struct host1x_gr2d base; 91 | }; 92 | 93 | struct nvhost_gr3d { 94 | struct nvhost_client client; 95 | struct host1x_gr3d base; 96 | }; 97 | 98 | struct nvhost { 99 | struct host1x base; 100 | 101 | struct nvhost_ctrl *ctrl; 102 | struct nvhost_display *display; 103 | struct nvhost_gr2d *gr2d; 104 | struct nvhost_gr3d *gr3d; 105 | struct nvmap *nvmap; 106 | }; 107 | 108 | static inline struct nvhost *to_nvhost(struct host1x *host1x) 109 | { 110 | return container_of(host1x, struct nvhost, base); 111 | } 112 | 113 | struct nvhost_display * nvhost_display_create(struct nvhost *nvhost); 114 | void nvhost_display_close(struct nvhost_display *display); 115 | 116 | struct nvhost_gr2d *nvhost_gr2d_open(struct nvhost *nvhost); 117 | void nvhost_gr2d_close(struct nvhost_gr2d *gr2d); 118 | 119 | struct nvhost_gr3d *nvhost_gr3d_open(struct nvhost *nvhost); 120 | void nvhost_gr3d_close(struct nvhost_gr3d *gr3d); 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /tests/nvhost/nvhost.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_NVHOST_H 26 | #define GRATE_NVHOST_H 1 27 | 28 | #include "nvmap.h" 29 | 30 | #define NVHOST_OPCODE_SETCL(offset, classid, mask) \ 31 | ((0x0 << 28) | (((offset) & 0xfff) << 16) | (((classid) & 0x3ff) << 6) | ((mask) & 0x3f)) 32 | #define NVHOST_OPCODE_INCR(offset, count) \ 33 | ((0x1 << 28) | (((offset) & 0xfff) << 16) | ((count) & 0xffff)) 34 | #define NVHOST_OPCODE_NONINCR(offset, count) \ 35 | ((0x2 << 28) | (((offset) & 0xfff) << 16) | ((count) & 0xffff)) 36 | #define NVHOST_OPCODE_MASK(offset, mask) \ 37 | ((0x3 << 28) | (((offset) & 0xfff) << 16) | ((mask) & 0xffff)) 38 | #define NVHOST_OPCODE_IMM(offset, data) \ 39 | ((0x4 << 28) | (((offset) & 0xfff) << 16) | ((data) & 0xffff)) 40 | #define NVHOST_OPCODE_EXTEND(subop, value) \ 41 | ((0xe << 28) | (((subop) & 0xf) << 24) | ((value) & 0xffffff)) 42 | 43 | struct nvhost_ctrl { 44 | int fd; 45 | }; 46 | 47 | struct nvhost_ctrl *nvhost_ctrl_open(void); 48 | void nvhost_ctrl_close(struct nvhost_ctrl *ctrl); 49 | 50 | struct nvhost_pushbuf_reloc { 51 | unsigned long source_offset; 52 | unsigned long target_handle; 53 | unsigned long target_offset; 54 | unsigned long shift; 55 | }; 56 | 57 | struct nvhost_pushbuf { 58 | struct nvmap_handle *handle; 59 | unsigned long offset; 60 | unsigned long length; 61 | 62 | struct nvhost_pushbuf_reloc *relocs; 63 | unsigned long num_relocs; 64 | 65 | uint32_t *ptr; 66 | }; 67 | 68 | struct nvhost_job { 69 | uint32_t syncpt; 70 | uint32_t syncpt_incrs; 71 | 72 | struct nvhost_pushbuf *pushbufs; 73 | unsigned int num_pushbufs; 74 | }; 75 | 76 | struct nvhost_job *nvhost_job_create(uint32_t syncpt, uint32_t increments); 77 | void nvhost_job_free(struct nvhost_job *job); 78 | struct nvhost_pushbuf *nvhost_job_append(struct nvhost_job *job, 79 | struct nvmap_handle *handle, 80 | unsigned long offset); 81 | int nvhost_pushbuf_push(struct nvhost_pushbuf *pb, uint32_t word); 82 | int nvhost_pushbuf_relocate(struct nvhost_pushbuf *pb, 83 | struct nvmap_handle *target, unsigned long offset, 84 | unsigned long shift); 85 | 86 | struct nvhost_client { 87 | struct nvhost_ctrl *ctrl; 88 | struct nvmap *nvmap; 89 | uint32_t syncpt; 90 | int fd; 91 | }; 92 | 93 | int nvhost_client_init(struct nvhost_client *client, struct nvmap *nvmap, 94 | struct nvhost_ctrl *ctrl, uint32_t syncpt, int fd); 95 | void nvhost_client_exit(struct nvhost_client *client); 96 | int nvhost_client_submit(struct nvhost_client *client, struct nvhost_job *job); 97 | int nvhost_client_flush(struct nvhost_client *client, uint32_t *fencep); 98 | int nvhost_client_wait(struct nvhost_client *client, uint32_t fence, 99 | uint32_t timeout); 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /tests/host1x/gr2d-clear.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "host1x.h" 34 | 35 | int main(int argc, char *argv[]) 36 | { 37 | struct host1x_display *display = NULL; 38 | struct host1x_overlay *overlay = NULL; 39 | struct host1x_options options = {}; 40 | struct host1x_framebuffer *fb; 41 | unsigned int width = 256; 42 | unsigned int height = 256; 43 | struct host1x_gr2d *gr2d; 44 | struct host1x *host1x; 45 | int err; 46 | 47 | options.open_display = true; 48 | options.display_id = -1; 49 | options.fd = -1; 50 | 51 | host1x = host1x_open(&options); 52 | if (!host1x) { 53 | fprintf(stderr, "host1x_open() failed\n"); 54 | return 1; 55 | } 56 | 57 | display = host1x_get_display(host1x); 58 | if (display) { 59 | err = host1x_overlay_create(&overlay, display); 60 | if (err < 0) { 61 | fprintf(stderr, "overlay support missing\n"); 62 | 63 | /* 64 | * If overlay support is missing but we still have 65 | * on-screen display support, make the framebuffer 66 | * the same resolution as the display to make sure 67 | * it can be properly displayed. 68 | */ 69 | 70 | err = host1x_display_get_resolution(display, &width, 71 | &height); 72 | if (err < 0) { 73 | fprintf(stderr, "host1x_display_get_resolution() failed: %d\n", err); 74 | return 1; 75 | } 76 | } 77 | } 78 | 79 | gr2d = host1x_get_gr2d(host1x); 80 | if (!gr2d) { 81 | fprintf(stderr, "host1x_get_gr2d() failed\n"); 82 | return 1; 83 | } 84 | 85 | fb = host1x_framebuffer_create(host1x, width, height, 86 | PIX_BUF_FMT_RGBA8888, 87 | PIX_BUF_LAYOUT_TILED_16x16, 0); 88 | if (!fb) { 89 | fprintf(stderr, "host1x_framebuffer_create() failed\n"); 90 | return 1; 91 | } 92 | 93 | err = host1x_gr2d_clear(gr2d, fb->pixbuf, 0xFFFF00FF); 94 | if (err < 0) { 95 | fprintf(stderr, "host1x_gr2d_clear() failed: %d\n", err); 96 | return 1; 97 | } 98 | 99 | if (display) { 100 | if (overlay) { 101 | err = host1x_overlay_set(overlay, fb, 0, 0, width, height, false, true); 102 | if (err < 0) 103 | fprintf(stderr, "host1x_overlay_set() failed: %d\n", err); 104 | else 105 | sleep(5); 106 | 107 | host1x_overlay_close(overlay); 108 | } else { 109 | err = host1x_display_set(display, fb, false, true); 110 | if (err < 0) 111 | fprintf(stderr, "host1x_display_set() failed: %d\n", err); 112 | else 113 | sleep(5); 114 | } 115 | } else { 116 | host1x_framebuffer_save(host1x, fb, "test.png"); 117 | } 118 | 119 | host1x_framebuffer_free(fb); 120 | host1x_close(host1x); 121 | 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /tests/gles2/egl-clear.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | EGLint major, minor; 33 | EGLDisplay display; 34 | EGLContext context; 35 | EGLSurface surface; 36 | EGLint num_config; 37 | EGLConfig config; 38 | GLint height; 39 | GLint width; 40 | 41 | static EGLint const config_attrs[] = { 42 | EGL_RED_SIZE, 8, 43 | EGL_GREEN_SIZE, 8, 44 | EGL_BLUE_SIZE, 8, 45 | EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 46 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 47 | EGL_DEPTH_SIZE, 8, 48 | EGL_NONE 49 | }; 50 | 51 | static EGLint const context_attrs[] = { 52 | EGL_CONTEXT_CLIENT_VERSION, 2, 53 | EGL_NONE 54 | }; 55 | 56 | static EGLint const pbuffer_attrs[] = { 57 | EGL_WIDTH, 640, 58 | EGL_HEIGHT, 480, 59 | EGL_LARGEST_PBUFFER, EGL_TRUE, 60 | EGL_NONE 61 | }; 62 | 63 | display = eglGetDisplay(EGL_DEFAULT_DISPLAY); 64 | if (display == EGL_NO_DISPLAY) { 65 | fprintf(stderr, "no display found\n"); 66 | return 1; 67 | } 68 | 69 | if (!eglInitialize(display, &major, &minor)) { 70 | fprintf(stderr, "failed to initialize EGL\n"); 71 | return 1; 72 | } 73 | 74 | printf("EGL: %d.%d\n", major, minor); 75 | 76 | if (!eglChooseConfig(display, config_attrs, &config, 1, &num_config)) { 77 | fprintf(stderr, "failed to choose configuration\n"); 78 | return 1; 79 | } 80 | 81 | printf("config:%p num_config:%d\n", config, num_config); 82 | 83 | context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attrs); 84 | if (context == EGL_NO_CONTEXT) { 85 | fprintf(stderr, "failed to create context\n"); 86 | return 1; 87 | } 88 | 89 | surface = eglCreatePbufferSurface(display, config, pbuffer_attrs); 90 | if (surface == EGL_NO_SURFACE) { 91 | fprintf(stderr, "failed to create surface\n"); 92 | return 1; 93 | } 94 | 95 | if (!eglQuerySurface(display, surface, EGL_WIDTH, &width)) { 96 | fprintf(stderr, "failed to query surface width\n"); 97 | return 1; 98 | } 99 | 100 | if (!eglQuerySurface(display, surface, EGL_HEIGHT, &height)) { 101 | fprintf(stderr, "failed to query surface height\n"); 102 | return 1; 103 | } 104 | 105 | printf("PBuffer: %dx%d\n", width, height); 106 | 107 | if (!eglMakeCurrent(display, surface, surface, context)) { 108 | fprintf(stderr, "failed to activate context\n"); 109 | return 1; 110 | } 111 | 112 | printf("=== Calling glClearColor()\n"); 113 | glClearColor(0.0, 0.0, 0.0, 1.0); 114 | glFlush(); 115 | printf("=== Calling glClear()\n"); 116 | glClear(GL_COLOR_BUFFER_BIT); 117 | glFlush(); 118 | 119 | printf("=== Calling eglSwapBuffers()\n"); 120 | eglSwapBuffers(display, surface); 121 | eglDestroySurface(display, surface); 122 | eglTerminate(display); 123 | 124 | return 0; 125 | } 126 | -------------------------------------------------------------------------------- /include/record_replay.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Dmitry Osipenko 3 | * Copyright (c) Erik Faye-Lund 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the "Software"), 7 | * to deal in the Software without restriction, including without limitation 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | * and/or sell copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in 13 | * all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | * DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #ifndef GRATE_RECORD_REPLAY_H 25 | #define GRATE_RECORD_REPLAY_H 1 26 | 27 | #include 28 | 29 | #define REC_MAGIC "grateREC" 30 | 31 | enum record_action { 32 | REC_START, 33 | REC_INFO, 34 | REC_CTX_CREATE, 35 | REC_CTX_DESTROY, 36 | REC_BO_CREATE, 37 | REC_BO_DESTROY, 38 | REC_BO_LOAD_DATA, 39 | REC_BO_SET_FLAGS, 40 | REC_ADD_FRAMEBUFFER, 41 | REC_DEL_FRAMEBUFFER, 42 | REC_DISP_FRAMEBUFFER, 43 | REC_JOB_CTX_CREATE, 44 | REC_JOB_CTX_DESTROY, 45 | REC_JOB_SUBMIT, 46 | }; 47 | 48 | struct __attribute__((packed)) record_gather { 49 | uint16_t id; 50 | uint16_t ctx_id; 51 | uint32_t offset; 52 | uint16_t num_words; 53 | }; 54 | 55 | struct __attribute__((packed)) record_reloc { 56 | uint16_t id; 57 | uint16_t ctx_id; 58 | uint16_t gather_id; 59 | uint32_t offset; 60 | uint32_t patch_offset; 61 | }; 62 | 63 | enum record_compression { 64 | REC_UNCOMPRESSED, 65 | REC_ZLIB, 66 | REC_LZ4, 67 | }; 68 | 69 | struct __attribute__((packed)) record_act { 70 | uint32_t act; 71 | 72 | union { 73 | struct header { 74 | char magic[8]; 75 | uint16_t version; 76 | uint16_t reserved[32]; 77 | } header; 78 | 79 | struct record_info { 80 | uint16_t drm; 81 | uint16_t compression; 82 | uint16_t reserved[32]; 83 | } record_info; 84 | 85 | struct ctx_create { 86 | uint16_t id; 87 | } ctx_create; 88 | 89 | struct ctx_destroy { 90 | uint16_t id; 91 | } ctx_destroy; 92 | 93 | struct bo_create { 94 | uint16_t id; 95 | uint16_t ctx_id; 96 | uint32_t num_pages; 97 | uint32_t flags; 98 | } bo_create; 99 | 100 | struct bo_destroy { 101 | uint16_t id; 102 | uint16_t ctx_id; 103 | } bo_destroy; 104 | 105 | struct bo_load { 106 | uint16_t id; 107 | uint16_t ctx_id; 108 | uint32_t page_id; 109 | uint16_t data_size; 110 | } bo_load; 111 | 112 | struct bo_set_flags { 113 | uint16_t id; 114 | uint16_t ctx_id; 115 | uint32_t flags; 116 | } bo_set_flags; 117 | 118 | struct add_framebuffer { 119 | uint16_t bo_id; 120 | uint16_t ctx_id; 121 | uint16_t width; 122 | uint16_t height; 123 | uint16_t pitch; 124 | uint32_t format; 125 | uint32_t flags; 126 | } add_framebuffer; 127 | 128 | struct del_framebuffer { 129 | uint16_t bo_id; 130 | uint16_t ctx_id; 131 | } del_framebuffer; 132 | 133 | struct disp_framebuffer { 134 | uint16_t bo_id; 135 | uint16_t ctx_id; 136 | } disp_framebuffer; 137 | 138 | struct job_ctx_create { 139 | uint16_t id; 140 | uint16_t gr2d; 141 | } job_ctx_create; 142 | 143 | struct job_ctx_destroy { 144 | uint16_t id; 145 | } job_ctx_destroy; 146 | 147 | struct job_submit { 148 | uint16_t job_ctx_id; 149 | uint16_t num_gathers; 150 | uint16_t num_relocs; 151 | uint16_t num_syncpt_incrs; 152 | } job_submit; 153 | } data; 154 | }; 155 | 156 | #endif 157 | -------------------------------------------------------------------------------- /tests/gles2/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef GRATE_TESTS_3D_COMMON_H 26 | #define GRATE_TESTS_3D_COMMON_H 1 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include "etc1.h" 34 | #include "grate.h" 35 | 36 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 37 | 38 | struct gles_options { 39 | unsigned int width; 40 | unsigned int height; 41 | }; 42 | 43 | int gles_parse_command_line(struct gles_options *options, int argc, 44 | char *argv[]); 45 | 46 | struct window { 47 | struct { 48 | Display *display; 49 | Window window; 50 | } x; 51 | 52 | struct { 53 | EGLDisplay display; 54 | EGLContext context; 55 | EGLSurface surface; 56 | } egl; 57 | 58 | unsigned int width; 59 | unsigned int height; 60 | }; 61 | 62 | struct window *window_create(unsigned int x, unsigned int y, 63 | unsigned int width, unsigned int height); 64 | void window_close(struct window *window); 65 | void window_show(struct window *window); 66 | bool window_event_loop(struct window *window); 67 | 68 | struct pbuffer { 69 | EGLDisplay display; 70 | EGLContext context; 71 | EGLSurface surface; 72 | 73 | unsigned int width; 74 | unsigned int height; 75 | }; 76 | 77 | struct pbuffer *pbuffer_create(unsigned int width, unsigned int height); 78 | void pbuffer_free(struct pbuffer *pbuffer); 79 | bool pbuffer_save(struct pbuffer *pbuffer, const char *filename); 80 | 81 | GLuint glsl_shader_load(GLenum type, const GLchar *lines[], size_t count); 82 | GLuint glsl_program_create(GLuint vertex, GLuint fragment); 83 | void glsl_program_link(GLuint program); 84 | 85 | struct framebuffer { 86 | unsigned int width; 87 | unsigned int height; 88 | GLuint texture; 89 | GLenum format; 90 | GLuint id; 91 | }; 92 | 93 | struct framebuffer *framebuffer_create(unsigned int width, unsigned int height, 94 | GLenum format); 95 | struct framebuffer *display_create(unsigned int width, unsigned int height); 96 | void framebuffer_free(struct framebuffer *framebuffer); 97 | void framebuffer_bind(struct framebuffer *framebuffer); 98 | bool framebuffer_save(struct framebuffer *framebuffer, const char *filename); 99 | 100 | struct gles_texture { 101 | GLenum format; 102 | GLuint id; 103 | }; 104 | 105 | #ifndef GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 106 | #define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1 107 | #endif 108 | #ifndef GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 109 | #define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2 110 | #endif 111 | #ifndef GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 112 | #define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 113 | #endif 114 | 115 | struct gles_texture *gles_texture_load(const char *filename); 116 | struct gles_texture *gles_texture_load2(const char *filename, 117 | unsigned width, unsigned height); 118 | struct gles_texture *gles_texture_load3(const char *filename, 119 | unsigned width, unsigned height, 120 | unsigned gl_format); 121 | void gles_texture_free(struct gles_texture *texture); 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /src/libgrate/linker_disasm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Dmitry Osipenko 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 | * DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "linker_asm.h" 29 | 30 | const char * tram_component(const link_instr *instr, unsigned id) 31 | { 32 | static char ret[4][16]; 33 | char *buf = ret[id]; 34 | unsigned interpolation_disable; 35 | unsigned const_across_length; 36 | unsigned const_across_width; 37 | unsigned tram_dst_type; 38 | 39 | switch (id) { 40 | case 0: 41 | interpolation_disable = instr->interpolation_disable_x; 42 | const_across_length = instr->const_x_across_length; 43 | const_across_width = instr->const_x_across_width; 44 | tram_dst_type = instr->tram_dst_type_x; 45 | break; 46 | case 1: 47 | interpolation_disable = instr->interpolation_disable_y; 48 | const_across_length = instr->const_y_across_length; 49 | const_across_width = instr->const_y_across_width; 50 | tram_dst_type = instr->tram_dst_type_y; 51 | break; 52 | case 2: 53 | interpolation_disable = instr->interpolation_disable_z; 54 | const_across_length = instr->const_z_across_length; 55 | const_across_width = instr->const_z_across_width; 56 | tram_dst_type = instr->tram_dst_type_z; 57 | break; 58 | case 3: 59 | interpolation_disable = instr->interpolation_disable_w; 60 | const_across_length = instr->const_w_across_length; 61 | const_across_width = instr->const_w_across_width; 62 | tram_dst_type = instr->tram_dst_type_w; 63 | break; 64 | default: 65 | return "invalid id"; 66 | } 67 | 68 | switch (tram_dst_type) { 69 | case TRAM_DST_NONE: 70 | buf += sprintf(buf, "NOP"); 71 | break; 72 | case TRAM_DST_FX10_LOW: 73 | buf += sprintf(buf, "fx10.l"); 74 | break; 75 | case TRAM_DST_FX10_HIGH: 76 | buf += sprintf(buf, "fx10.h"); 77 | break; 78 | case TRAM_DST_FP20: 79 | buf += sprintf(buf, "fp20"); 80 | break; 81 | default: 82 | buf += sprintf(buf, "Invalid type!"); 83 | break; 84 | } 85 | 86 | if (interpolation_disable) { 87 | buf += sprintf(buf, "(dis)"); 88 | } 89 | 90 | if (const_across_length) { 91 | buf += sprintf(buf, "(cl)"); 92 | } 93 | 94 | if (const_across_width) { 95 | sprintf(buf, "(cw)"); 96 | } 97 | 98 | return ret[id]; 99 | } 100 | 101 | static char tram_swizzle(unsigned swzl) 102 | { 103 | switch (swzl) { 104 | case LINK_SWIZZLE_X: 105 | return 'x'; 106 | case LINK_SWIZZLE_Y: 107 | return 'y'; 108 | case LINK_SWIZZLE_Z: 109 | return 'z'; 110 | case LINK_SWIZZLE_W: 111 | return 'w'; 112 | } 113 | 114 | return '!'; 115 | } 116 | 117 | const char * linker_instruction_disassemble(const link_instr *instr) 118 | { 119 | static char ret[128]; 120 | char *buf = ret; 121 | 122 | sprintf(buf, "LINK %s, %s, %s, %s, tram%d.%c%c%c%c, export%d %s", 123 | tram_component(instr, 0), 124 | tram_component(instr, 1), 125 | tram_component(instr, 2), 126 | tram_component(instr, 3), 127 | instr->tram_row_index, 128 | tram_swizzle(instr->tram_dst_swizzle_x), 129 | tram_swizzle(instr->tram_dst_swizzle_y), 130 | tram_swizzle(instr->tram_dst_swizzle_z), 131 | tram_swizzle(instr->tram_dst_swizzle_w), 132 | instr->vertex_export_index, 133 | instr->vec4_select ? "(z)" : ""); 134 | 135 | return ret; 136 | } 137 | -------------------------------------------------------------------------------- /src/libcgc/stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012, 2013 Erik Faye-Lund 3 | * Copyright (c) 2013 Avionic Design GmbH 4 | * Copyright (c) 2013 Thierry Reding 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a 7 | * copy of this software and associated documentation files (the "Software"), 8 | * to deal in the Software without restriction, including without limitation 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the 11 | * Software is furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | * DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include "host1x.h" 26 | 27 | enum host1x_opcode { 28 | HOST1X_OPCODE_SETCL, 29 | HOST1X_OPCODE_INCR, 30 | HOST1X_OPCODE_NONINCR, 31 | HOST1X_OPCODE_MASK, 32 | HOST1X_OPCODE_IMM, 33 | HOST1X_OPCODE_RESTART, 34 | HOST1X_OPCODE_GATHER, 35 | HOST1X_OPCODE_EXTEND = 14, 36 | HOST1X_OPCODE_CHDONE = 15, 37 | }; 38 | 39 | void host1x_stream_init(struct host1x_stream *stream, const void *buffer, 40 | size_t size) 41 | { 42 | stream->words = stream->ptr = buffer; 43 | stream->end = buffer + size; 44 | } 45 | 46 | void host1x_stream_interpret(struct host1x_stream *stream) 47 | { 48 | while (stream->ptr < stream->end) { 49 | uint32_t instr = *stream->ptr++; 50 | uint32_t opcode = (instr >> 28) & 0xf; 51 | uint16_t offset, classid, count, mask, value, i; 52 | 53 | switch (opcode) { 54 | case HOST1X_OPCODE_SETCL: 55 | offset = (instr >> 16) & 0xfff; 56 | classid = (instr >> 6) & 0x3ff; 57 | mask = instr & 0x3f; 58 | 59 | stream->classid = classid; 60 | 61 | for (i = 0; i < 16; i++) 62 | if (mask & BIT(i)) 63 | stream->write_word(stream->user, 64 | stream->classid, 65 | offset + i, 66 | *stream->ptr++); 67 | 68 | break; 69 | 70 | case HOST1X_OPCODE_INCR: 71 | offset = (instr >> 16) & 0xfff; 72 | count = instr & 0xffff; 73 | 74 | for (i = 0; i < count; i++) 75 | stream->write_word(stream->user, 76 | stream->classid, 77 | offset + i, 78 | *stream->ptr++); 79 | 80 | break; 81 | 82 | case HOST1X_OPCODE_NONINCR: 83 | offset = (instr >> 16) & 0xfff; 84 | count = instr & 0xffff; 85 | 86 | for (i = 0; i < count; i++) 87 | stream->write_word(stream->user, 88 | stream->classid, 89 | offset, 90 | *stream->ptr++); 91 | 92 | break; 93 | 94 | case HOST1X_OPCODE_MASK: 95 | offset = (instr >> 16) & 0xfff; 96 | mask = instr & 0xffff; 97 | 98 | for (i = 0; i < 16; i++) 99 | if (mask & BIT(i)) 100 | stream->write_word(stream->user, 101 | stream->classid, 102 | offset + i, 103 | *stream->ptr++); 104 | 105 | break; 106 | 107 | case HOST1X_OPCODE_IMM: 108 | offset = (instr >> 16) & 0xfff; 109 | value = instr & 0xffff; 110 | 111 | stream->write_word(stream->user, 112 | stream->classid, 113 | offset, 114 | value); 115 | 116 | break; 117 | 118 | case HOST1X_OPCODE_RESTART: 119 | fprintf(stderr, "HOST1X_OPCODE_RESTART\n"); 120 | break; 121 | 122 | case HOST1X_OPCODE_GATHER: 123 | fprintf(stderr, "HOST1X_OPCODE_GATHER\n"); 124 | break; 125 | 126 | case HOST1X_OPCODE_EXTEND: 127 | fprintf(stderr, "HOST1X_OPCODE_EXTEND\n"); 128 | break; 129 | 130 | case HOST1X_OPCODE_CHDONE: 131 | fprintf(stderr, "HOST1X_OPCODE_CHDONE\n"); 132 | break; 133 | 134 | default: 135 | fprintf(stderr, "UNKNOWN: 0x%08x\n", instr); 136 | return; 137 | } 138 | } 139 | } 140 | --------------------------------------------------------------------------------