Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5562 → Rev 5563

/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/SConscript
0,0 → 1,43
Import('*')
 
env = env.Clone()
 
env.Prepend(LIBS = [gallium])
 
env.Prepend(LIBPATH = [graw.dir])
env.Prepend(LIBS = ['graw'])
 
if env['platform'] in ('freebsd8', 'sunos'):
env.Append(LIBS = ['m'])
 
if env['platform'] == 'freebsd8':
env.Append(LIBS = ['pthread'])
 
progs = [
'clear',
'disasm',
'fs-fragcoord',
'fs-frontface',
'fs-test',
'fs-write-z',
'gs-test',
'occlusion-query',
'quad-sample',
'quad-tex',
'shader-leak',
'tex-srgb',
'tex-swizzle',
'tri',
'tri-gs',
'tri-instanced',
'vs-test',
]
 
for name in progs:
program = env.Program(
target = name,
source = name + '.c',
)
#env.Depends(program, graw)
env.Alias('graw-progs', program)
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/clear.c
0,0 → 1,121
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
 
#include <stdio.h>
#include "state_tracker/graw.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
 
enum pipe_format formats[] = {
PIPE_FORMAT_RGBA8888_UNORM,
PIPE_FORMAT_BGRA8888_UNORM,
PIPE_FORMAT_NONE
};
 
static const int WIDTH = 300;
static const int HEIGHT = 300;
 
struct pipe_screen *screen;
struct pipe_context *ctx;
struct pipe_surface *surf;
struct pipe_resource *tex;
static void *window = NULL;
 
static void draw( void )
{
union pipe_color_union clear_color = { {1, 0, 1, 1} };
 
ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
ctx->flush(ctx, NULL, 0);
 
graw_save_surface_to_file(ctx, surf, NULL);
 
screen->flush_frontbuffer(screen, tex, 0, 0, window);
}
 
static void init( void )
{
struct pipe_framebuffer_state fb;
struct pipe_resource templat;
struct pipe_surface surf_tmpl;
int i;
 
/* It's hard to say whether window or screen should be created
* first. Different environments would prefer one or the other.
*
* Also, no easy way of querying supported formats if the screen
* cannot be created first.
*/
for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
screen = graw_create_window_and_screen(0, 0, 300, 300,
formats[i],
&window);
if (window && screen)
break;
}
if (!screen || !window) {
fprintf(stderr, "Unable to create window\n");
exit(1);
}
ctx = screen->context_create(screen, NULL);
if (ctx == NULL)
exit(3);
 
templat.target = PIPE_TEXTURE_2D;
templat.format = formats[i];
templat.width0 = WIDTH;
templat.height0 = HEIGHT;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DISPLAY_TARGET);
tex = screen->resource_create(screen,
&templat);
if (tex == NULL)
exit(4);
 
surf_tmpl.format = templat.format;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
surf = ctx->create_surface(ctx, tex, &surf_tmpl);
if (surf == NULL)
exit(5);
 
memset(&fb, 0, sizeof fb);
fb.nr_cbufs = 1;
fb.width = WIDTH;
fb.height = HEIGHT;
fb.cbufs[0] = surf;
 
ctx->set_framebuffer_state(ctx, &fb);
}
 
static void args(int argc, char *argv[])
{
int i;
 
for (i = 1; i < argc;) {
if (graw_parse_args(&i, argc, argv)) {
continue;
}
exit(1);
}
}
 
int main( int argc, char *argv[] )
{
args(argc, argv);
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/disasm.c
0,0 → 1,90
/**************************************************************************
*
* Copyright 2013 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL THE AUTHOR AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
 
 
/*
* Small utility to disassemble a memory dump of TGSI tokens.
*
* Dump can be easily obtained from gdb through the tgsi_dump.gdb helper:
*
* (gdb) source tgsi_dump.gdb
* (gdb) tgsi_dump state->tokens
*
* which will generate a tgsi_dump.bin file in the current directory.
*/
 
 
#include <stdio.h>
#include <stdlib.h>
 
#include "pipe/p_shader_tokens.h"
#include "tgsi/tgsi_dump.h"
 
 
static void
usage(const char *arg0)
{
fprintf(stderr, "usage: %s [ options ] <tgsi_dump.bin> ...\n", arg0);
}
 
 
static void
disasm(const char *filename)
{
FILE *fp;
const size_t max_tokens = 1024*1024;
struct tgsi_token *tokens;
 
fp = fopen(filename, "rb");
if (!fp) {
exit(1);
}
tokens = malloc(max_tokens * sizeof *tokens);
fread(tokens, sizeof *tokens, max_tokens, fp);
 
tgsi_dump(tokens, 0);
 
free(tokens);
fclose(fp);
}
 
 
int main( int argc, char *argv[] )
{
int i;
 
if (argc < 2) {
usage(argv[0]);
return 0;
}
 
for (i = 1; i < argc; ++i) {
disasm(argv[i]);
}
 
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-abs.sh
0,0 → 1,13
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { -0.5, -0.4, -0.6, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
ABS OUT[0], TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-add.sh
0,0 → 1,8
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
ADD OUT[0], IN[0], IN[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-cb-1d.sh
0,0 → 1,13
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL CONST[1]
DCL CONST[3]
DCL TEMP[0..1]
 
ADD TEMP[0], IN[0], CONST[1]
RCP TEMP[1], CONST[3].xxxx
MUL OUT[0], TEMP[0], TEMP[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-cb-2d.sh
0,0 → 1,9
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL CONST[1][6]
 
MOV OUT[0], CONST[1][6]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-dp3.sh
0,0 → 1,8
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DP3 OUT[0], IN[0], IN[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-dp4.sh
0,0 → 1,8
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DP4 OUT[0], IN[0].xyzx, IN[0].xyzx
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-dst.sh
0,0 → 1,8
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DST OUT[0], IN[0], IN[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-ex2.sh
0,0 → 1,11
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
EX2 TEMP[0], IN[0].xxxx
MUL OUT[0], TEMP[0], IN[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-face.sh
0,0 → 1,14
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL IN[1], FACE, CONSTANT
DCL OUT[0], COLOR
DCL TEMP[0]
IMM FLT32 { 0.5, 1.0, 0.0, 0.0 }
 
MUL TEMP[0], IN[1].xxxx, IMM[0].xxxx
ADD TEMP[0], TEMP[0], IMM[0].yyyy
 
MOV OUT[0], TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-flr.sh
0,0 → 1,15
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 2.5, 4.0, 2.0, 1.0 }
IMM FLT32 { 0.4, 0.25, 0.5, 1.0 }
 
MUL TEMP[0], IN[0], IMM[0]
FLR TEMP[0], TEMP[0]
MUL OUT[0], TEMP[0], IMM[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-frc.sh
0,0 → 1,13
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 2.7, 3.1, 4.5, 1.0 }
 
MUL TEMP[0], IN[0], IMM[0]
FRC OUT[0], TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-kil.sh
0,0 → 1,18
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 0.6, 0.6, 0.6, 0.0 }
IMM FLT32 { 0.01, 0.0, 0.0, 0.0 }
IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
 
SLT TEMP[0], IN[0], IMM[0]
MUL OUT[0], IN[0], TEMP[0]
MOV OUT[0].w, IMM[2].xxxx
SUB TEMP[0], TEMP[0], IMM[1].xxxy
KIL TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-lg2.sh
0,0 → 1,15
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
IMM FLT32 { 0.5, 0.0, 0.0, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
LG2 TEMP[0].x, TEMP[0].xxxx
ADD OUT[0], TEMP[0], IMM[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-lit.sh
0,0 → 1,8
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
LIT OUT[0], IN[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-lrp.sh
0,0 → 1,11
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
ABS TEMP[0], IN[0]
LRP OUT[0], TEMP[0], IN[0].xxxx, IN[0].yyyy
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-mad-immx.sh
0,0 → 1,10
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL IMMX[0..1] {{ 0.5, 0.4, 0.6, 1.0 },
{ 0.5, 0.4, 0.6, 0.0 }}
 
MAD OUT[0], IN[0], IMMX[0], IMMX[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-mad.sh
0,0 → 1,11
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
IMM FLT32 { 0.5, 0.4, 0.6, 1.0 }
IMM FLT32 { 0.5, 0.4, 0.6, 0.0 }
 
MAD OUT[0], IN[0], IMM[0], IMM[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-max.sh
0,0 → 1,10
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
IMM FLT32 { 0.4, 0.4, 0.4, 0.0 }
 
MAX OUT[0], IN[0], IMM[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-min.sh
0,0 → 1,10
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
IMM FLT32 { 0.6, 0.6, 0.6, 1.0 }
 
MIN OUT[0], IN[0], IMM[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-mov.sh
0,0 → 1,8
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
MOV OUT[0], IN[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-mul.sh
0,0 → 1,10
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
IMM FLT32 { 0.5, 0.6, 0.7, 1.0 }
 
MUL OUT[0], IN[0], IMM[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-rcp.sh
0,0 → 1,15
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
IMM FLT32 { 1.5, 0.0, 0.0, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
RCP TEMP[0].x, TEMP[0].xxxx
SUB OUT[0], TEMP[0], IMM[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-rsq.sh
0,0 → 1,15
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
IMM FLT32 { 1.5, 0.0, 0.0, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
RSQ TEMP[0].x, TEMP[0].xxxx
SUB OUT[0], TEMP[0], IMM[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-sge.sh
0,0 → 1,13
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 0.6, 0.6, 0.6, 0.0 }
 
SGE TEMP[0], IN[0], IMM[0]
MUL OUT[0], IN[0], TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-slt.sh
0,0 → 1,13
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 0.6, 0.6, 0.6, 0.0 }
 
SLT TEMP[0], IN[0], IMM[0]
MUL OUT[0], IN[0], TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-srcmod-abs.sh
0,0 → 1,13
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { -0.3, -0.5, -0.4, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
MOV OUT[0], |TEMP[0]|
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-srcmod-absneg.sh
0,0 → 1,15
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { -0.2, -0.3, -0.4, 0.0 }
IMM FLT32 { -1.0, -1.0, -1.0, -1.0 }
 
ADD TEMP[0], IN[0], IMM[0]
MOV TEMP[0], -|TEMP[0]|
MUL OUT[0], TEMP[0], IMM[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-srcmod-neg.sh
0,0 → 1,11
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMP[0]
 
SUB TEMP[0], IN[0], IN[0].yzxw
MOV OUT[0], -TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-srcmod-swz.sh
0,0 → 1,8
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
MOV OUT[0], IN[0].yxzw
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-sub.sh
0,0 → 1,8
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
SUB OUT[0], IN[0], IN[0].yzxw
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-tempx.sh
0,0 → 1,14
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
DCL TEMPX[0][0..1]
 
IMM FLT32 { -0.5, -0.4, -0.6, 0.0 }
 
ADD TEMPX[0][0], IN[0], IMM[0]
ADD TEMPX[0][1], IN[0], IMM[0]
ABS OUT[0], TEMPX[0][1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-ucmp.sh
0,0 → 1,11
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL TEMP[0]
IMM[0] FLT32 { 10.0000, 1.0000, 0.0000, 0.0000}
IMM[1] UINT32 {1, 0, 0, 0}
0: MUL TEMP[0].x, IN[0].xxxx, IMM[0].xxxx
1: F2U TEMP[0].x, TEMP[0].xxxx
2: AND TEMP[0].x, TEMP[0].xxxx, IMM[1].xxxx
3: UCMP OUT[0], TEMP[0].xxxx, IMM[0].yzzz, IMM[0].yyyz
4: END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fragment-shader/frag-xpd.sh
0,0 → 1,8
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
XPD OUT[0], IN[0], IN[0].yzxw
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fs-fragcoord.c
0,0 → 1,261
/* Test the TGSI_SEMANTIC_POSITION fragment shader input.
* Plus properties for upper-left vs. lower-left origin and
* center integer vs. half-integer;
*/
 
#include <stdio.h>
 
#include "graw_util.h"
 
 
static int width = 300;
static int height = 300;
 
static struct graw_info info;
 
struct vertex {
float position[4];
float color[4];
};
 
/* Note: the upper-left vertex is pushed to the left a bit to
* make sure we can spot upside-down rendering.
*/
static struct vertex vertices[] =
{
{
{-0.95, -0.95, 0.5, 1.0 },
{ 0, 0, 0, 1 }
},
 
{
{ 0.85, -0.95, 0.5, 1.0 },
{ 0, 0, 0, 1 }
},
 
{
{ 0.95, 0.95, 0.5, 1.0 },
{ 0, 0, 0, 1 }
},
 
{
{-0.95, 0.95, 0.5, 1.0 },
{ 0, 0, 0, 1 }
}
};
 
#define NUM_VERTS (sizeof(vertices) / sizeof(vertices[0]))
 
 
static void
set_vertices(void)
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve);
info.ctx->bind_vertex_elements_state(info.ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof(struct vertex);
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
info.ctx->set_vertex_buffers(info.ctx, 0, 1, &vbuf);
}
 
 
static void
set_vertex_shader(void)
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], GENERIC[0]\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: MOV OUT[1], IN[1]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(info.ctx, text);
info.ctx->bind_vs_state(info.ctx, handle);
}
 
 
static void
set_fragment_shader(int mode)
{
void *handle;
 
const char *origin_upper_left_text =
"FRAG\n"
"PROPERTY FS_COORD_ORIGIN UPPER_LEFT\n" /* upper-left = black corner */
"DCL IN[0], POSITION, LINEAR\n"
"DCL OUT[0], COLOR\n"
"DCL TEMP[0]\n"
"IMM FLT32 { 0.003333, 0.003333, 1.0, 1.0 }\n"
"IMM FLT32 { 0.0, 300.0, 0.0, 0.0 }\n"
" 0: MOV TEMP[0], IN[0] \n"
" 1: MOV TEMP[0].zw, IMM[1].xxxx \n"
" 2: MUL OUT[0], TEMP[0], IMM[0] \n"
" 3: END\n";
 
const char *origin_lower_left_text =
"FRAG\n"
"PROPERTY FS_COORD_ORIGIN LOWER_LEFT\n" /* lower-left = black corner */
"DCL IN[0], POSITION, LINEAR\n"
"DCL OUT[0], COLOR\n"
"DCL TEMP[0]\n"
"IMM FLT32 { 0.003333, 0.003333, 1.0, 1.0 }\n"
"IMM FLT32 { 0.0, 300.0, 0.0, 0.0 }\n"
" 0: MOV TEMP[0], IN[0] \n"
" 1: MOV TEMP[0].zw, IMM[1].xxxx \n"
" 2: MUL OUT[0], TEMP[0], IMM[0] \n"
" 3: END\n";
 
/* Test fragcoord center integer vs. half integer */
const char *center_integer_text =
"FRAG\n"
"PROPERTY FS_COORD_PIXEL_CENTER INTEGER \n" /* pixels are black */
"DCL IN[0], POSITION, LINEAR \n"
"DCL OUT[0], COLOR \n"
"DCL TEMP[0] \n"
"IMM FLT32 { 0.003333, 0.003333, 1.0, 1.0 } \n"
"IMM FLT32 { 0.0, 300.0, 0.0, 0.0 } \n"
"0: FRC TEMP[0], IN[0] \n"
"1: MOV TEMP[0].zw, IMM[1].xxxx \n"
"2: MOV OUT[0], TEMP[0] \n"
"3: END \n";
 
const char *center_half_integer_text =
"FRAG\n"
"PROPERTY FS_COORD_PIXEL_CENTER HALF_INTEGER \n" /* pixels are olive colored */
"DCL IN[0], POSITION, LINEAR \n"
"DCL OUT[0], COLOR \n"
"DCL TEMP[0] \n"
"IMM FLT32 { 0.003333, 0.003333, 1.0, 1.0 } \n"
"IMM FLT32 { 0.0, 300.0, 0.0, 0.0 } \n"
"0: FRC TEMP[0], IN[0] \n"
"1: MOV TEMP[0].zw, IMM[1].xxxx \n"
"2: MOV OUT[0], TEMP[0] \n"
"3: END \n";
 
const char *text;
 
if (mode == 0)
text = origin_upper_left_text;
else if (mode == 1)
text = origin_lower_left_text;
else if (mode == 2)
text = center_integer_text;
else
text = center_half_integer_text;
 
handle = graw_parse_fragment_shader(info.ctx, text);
info.ctx->bind_fs_state(info.ctx, handle);
}
 
 
static void
draw(void)
{
union pipe_color_union clear_color;
 
clear_color.f[0] = 0.25;
clear_color.f[1] = 0.25;
clear_color.f[2] = 0.25;
clear_color.f[3] = 1.0;
 
info.ctx->clear(info.ctx,
PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
&clear_color, 1.0, 0);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, NUM_VERTS);
info.ctx->flush(info.ctx, NULL, 0);
 
#if 0
/* At the moment, libgraw leaks out/makes available some of the
* symbols from gallium/auxiliary, including these debug helpers.
* Will eventually want to bless some of these paths, and lock the
* others down so they aren't accessible from test programs.
*
* This currently just happens to work on debug builds - a release
* build will probably fail to link here:
*/
debug_dump_surface_bmp(info.ctx, "result.bmp", surf);
#endif
 
graw_util_flush_front(&info);
}
 
 
#if 0
static void
resize(int w, int h)
{
width = w;
height = h;
 
set_viewport(0, 0, width, height, 30, 1000);
}
#endif
 
 
static void
init(int mode)
{
if (!graw_util_create_window(&info, width, height, 1, TRUE))
exit(1);
 
graw_util_default_state(&info, TRUE);
 
graw_util_viewport(&info, 0, 0, width, height, -1.0, 1.0);
 
set_vertices();
set_vertex_shader();
set_fragment_shader(mode);
}
 
 
int
main(int argc, char *argv[])
{
int mode = argc > 1 ? atoi(argv[1]) : 0;
 
switch (mode) {
default:
case 0:
printf("frag coord origin upper-left (lower-left = black)\n");
break;
case 1:
printf("frag coord origin lower-left (upper-left = black)\n");
break;
case 2:
printf("frag coord center integer (all pixels black)\n");
break;
case 3:
printf("frag coord center half-integer (all pixels olive color)\n");
break;
}
 
init(mode);
 
graw_set_display_func(draw);
/*graw_set_reshape_func(resize);*/
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fs-frontface.c
0,0 → 1,208
/* Test the TGSI_SEMANTIC_FACE fragment shader input.
*/
 
#include <stdio.h>
 
#include "graw_util.h"
 
 
static int width = 300;
static int height = 300;
 
static struct graw_info info;
 
struct vertex {
float position[4];
float color[4];
};
 
#define z0 0.2
#define z01 0.5
#define z1 0.4
 
static struct vertex vertices[] =
{
/* left quad: clock-wise, front-facing, red */
{
{-0.8, -0.9, z0, 1.0 },
{ 0, 0, 0, 1 }
},
 
{
{ -0.2, -0.9, z0, 1.0 },
{ 0, 0, 0, 1 }
},
 
{
{ 0.2, 0.9, z01, 1.0 },
{ 0, 0, 0, 1 }
},
 
{
{-0.9, 0.9, z01, 1.0 },
{ 0, 0, 0, 1 }
},
 
/* right quad : counter-clock-wise, back-facing, green */
{
{ 0.2, -0.9, z1, 1.0 },
{ 1, 1, 1, -1 }
},
 
{
{ -0.2, 0.8, z1, 1.0 },
{ 1, 1, 1, -1 }
},
 
{
{ 0.9, 0.8, z1, 1.0 },
{ 1, 1, 1, -1 }
},
 
{
{ 0.8, -0.9, z1, 1.0 },
{ 1, 1, 1, -1 }
},
};
 
#define NUM_VERTS (sizeof(vertices) / sizeof(vertices[0]))
 
 
 
static void
set_vertices(void)
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve);
info.ctx->bind_vertex_elements_state(info.ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof(struct vertex);
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
info.ctx->set_vertex_buffers(info.ctx, 0, 1, &vbuf);
}
 
 
static void
set_vertex_shader(void)
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], GENERIC[0]\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: MOV OUT[1], IN[1]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(info.ctx, text);
info.ctx->bind_vs_state(info.ctx, handle);
}
 
 
static void
set_fragment_shader(void)
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], FACE, CONSTANT\n"
"DCL IN[1], GENERIC, CONSTANT\n"
"DCL OUT[0], COLOR\n"
"DCL TEMP[0]\n"
"IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }\n"
"IMM FLT32 { 0.0, 1.0, 0.0, 0.0 }\n"
"IMM FLT32 { 0.5, 0.6, 0.0, 0.0 }\n"
" 0: SGT TEMP[0].x, IN[0].xxxx, IMM[1].xxxx\n" /* TMP[0].x = IN[0].x > 0.0 */
" 1: IF TEMP[0].xxxx :4\n"
" 2: MOV OUT[0], IMM[0]\n" /* front-facing: red */
" 3: ELSE :5\n"
" 4: MOV OUT[0], IMM[1]\n" /* back-facing: green */
" 5: ENDIF\n"
" 6: END\n";
 
handle = graw_parse_fragment_shader(info.ctx, text);
info.ctx->bind_fs_state(info.ctx, handle);
}
 
 
static void
draw(void)
{
union pipe_color_union clear_color;
 
clear_color.f[0] = 0.25;
clear_color.f[1] = 0.25;
clear_color.f[2] = 0.25;
clear_color.f[3] = 1.00;
 
info.ctx->clear(info.ctx,
PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
&clear_color, 1.0, 0);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, NUM_VERTS);
info.ctx->flush(info.ctx, NULL, 0);
 
graw_util_flush_front(&info);
}
 
 
#if 0
static void
resize(int w, int h)
{
width = w;
height = h;
 
set_viewport(0, 0, width, height, 30, 1000);
}
#endif
 
 
static void
init(void)
{
if (!graw_util_create_window(&info, width, height, 1, TRUE))
exit(1);
 
graw_util_default_state(&info, TRUE);
 
graw_util_viewport(&info, 0, 0, width, height, -1.0, 1.0);
 
set_vertices();
set_vertex_shader();
set_fragment_shader();
}
 
 
int
main(int argc, char *argv[])
{
init();
 
printf("Left quad: clock-wise, front-facing, red\n");
printf("Right quad: counter clock-wise, back-facing, green\n");
 
graw_set_display_func(draw);
/*graw_set_reshape_func(resize);*/
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fs-test.c
0,0 → 1,514
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
 
#include "state_tracker/graw.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
#include <stdio.h> /* for fread(), etc */
 
#include "util/u_inlines.h"
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
#include "util/u_box.h"
 
static const char *filename = NULL;
unsigned show_fps = 0;
 
 
static void usage(char *name)
{
fprintf(stderr, "usage: %s [ options ] shader_filename\n", name);
#ifndef _WIN32
fprintf(stderr, "\n" );
fprintf(stderr, "options:\n");
fprintf(stderr, " -fps show frames per second\n");
#endif
}
 
 
enum pipe_format formats[] = {
PIPE_FORMAT_RGBA8888_UNORM,
PIPE_FORMAT_BGRA8888_UNORM,
PIPE_FORMAT_NONE
};
 
static const int WIDTH = 250;
static const int HEIGHT = 250;
 
static struct pipe_screen *screen = NULL;
static struct pipe_context *ctx = NULL;
static struct pipe_resource *rttex = NULL;
static struct pipe_surface *surf = NULL;
static struct pipe_sampler_view *sv = NULL;
static void *sampler = NULL;
static void *window = NULL;
static struct pipe_resource *samptex = NULL;
 
struct vertex {
float position[4];
float color[4];
float texcoord[4];
};
 
/* Vertex data matches progs/fp/fp-tri.c, but flipped in Y dimension
* so that the final images are the same.
*/
static struct vertex vertices[] =
{
{ { 0.9, 0.9, 0.0, 1.0 },
{ 0, 0, 1, 1 },
{ 1, 1, 0, 1 } },
 
{ { 0.9, -0.9, 0.0, 1.0 },
{ 1, 0, 0, 1 },
{ 1, -1, 0, 1 } },
 
{ {-0.9, 0.0, 0.0, 1.0 },
{ 0, 1, 0, 1 },
{ -1, 0, 0, 1 } },
};
 
static float constants1[] =
{ 0.4, 0, 0, 1,
1, 1, 1, 1,
2, 2, 2, 2,
4, 8, 16, 32,
 
3, 0, 0, 0,
0, .5, 0, 0,
1, 0, 0, 1,
0, 0, 0, 1,
 
1, 0, 0, 0.5,
0, 1, 0, 0.5,
0, 0, 1, 0,
0, 0, 0, 1,
};
 
 
static float constants2[] =
{ 1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
0, 0, 0, 0,
 
1, 1, 0, 1,
1, .5, 0, 1,
1, 0, 0, 1,
0, 0, 0, 1,
 
1, 0, 0, 0.5,
0, 1, 0, 0.5,
0, 0, 1, 0,
0, 0, 0, 1,
};
 
static void init_fs_constbuf( void )
{
struct pipe_constant_buffer cb1;
struct pipe_constant_buffer cb2;
 
memset(&cb1, 0, sizeof cb1);
cb1.buffer_size = sizeof constants1;
cb1.user_buffer = constants1;
 
ctx->set_constant_buffer(ctx,
PIPE_SHADER_FRAGMENT, 0,
&cb1);
 
memset(&cb2, 0, sizeof cb2);
cb2.buffer_size = sizeof constants2;
cb2.user_buffer = constants2;
 
ctx->set_constant_buffer(ctx,
PIPE_SHADER_FRAGMENT, 1,
&cb2);
}
 
 
static void set_viewport( float x, float y,
float width, float height,
float near, float far)
{
float z = far;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)far - (float)near) / 2.0f;
struct pipe_viewport_state vp;
 
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.scale[3] = 1.0f;
 
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.translate[3] = 0.0f;
 
ctx->set_viewport_states( ctx, 0, 1, &vp );
}
 
static void set_vertices( void )
{
struct pipe_vertex_element ve[3];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[2].src_offset = Offset(struct vertex, texcoord);
ve[2].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = ctx->create_vertex_elements_state(ctx, 3, ve);
ctx->bind_vertex_elements_state(ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof( struct vertex );
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
ctx->set_vertex_buffers(ctx, 0, 1, &vbuf);
}
 
static void set_vertex_shader( void )
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL IN[2]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], COLOR[0]\n"
"DCL OUT[2], GENERIC[0]\n"
" MOV OUT[0], IN[0]\n"
" MOV OUT[1], IN[1]\n"
" MOV OUT[2], IN[2]\n"
" END\n";
 
handle = graw_parse_vertex_shader(ctx, text);
ctx->bind_vs_state(ctx, handle);
}
 
static void set_fragment_shader( const char *filename )
{
FILE *f;
char buf[50000];
void *handle;
int sz;
 
if ((f = fopen(filename, "r")) == NULL) {
fprintf(stderr, "Couldn't open %s\n", filename);
exit(1);
}
 
sz = fread(buf, 1, sizeof(buf), f);
if (!feof(f)) {
printf("file too long\n");
exit(1);
}
printf("%.*s\n", sz, buf);
buf[sz] = 0;
 
handle = graw_parse_fragment_shader(ctx, buf);
ctx->bind_fs_state(ctx, handle);
fclose(f);
}
 
 
static void draw( void )
{
union pipe_color_union clear_color = { {.1,.3,.5,0} };
 
ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3);
ctx->flush(ctx, NULL, 0);
 
graw_save_surface_to_file(ctx, surf, NULL);
 
screen->flush_frontbuffer(screen, rttex, 0, 0, window);
}
 
#define SIZE 16
 
static void init_tex( void )
{
struct pipe_sampler_view sv_template;
struct pipe_sampler_state sampler_desc;
struct pipe_resource templat;
struct pipe_box box;
ubyte tex2d[SIZE][SIZE][4];
int s, t;
 
#if (SIZE != 2)
for (s = 0; s < SIZE; s++) {
for (t = 0; t < SIZE; t++) {
if (0) {
int x = (s ^ t) & 1;
tex2d[t][s][0] = (x) ? 0 : 63;
tex2d[t][s][1] = (x) ? 0 : 128;
tex2d[t][s][2] = 0;
tex2d[t][s][3] = 0xff;
}
else {
int x = ((s ^ t) >> 2) & 1;
tex2d[t][s][0] = s*255/(SIZE-1);
tex2d[t][s][1] = t*255/(SIZE-1);
tex2d[t][s][2] = (x) ? 0 : 128;
tex2d[t][s][3] = 0xff;
}
}
}
#else
tex2d[0][0][0] = 0;
tex2d[0][0][1] = 255;
tex2d[0][0][2] = 255;
tex2d[0][0][3] = 0;
 
tex2d[0][1][0] = 0;
tex2d[0][1][1] = 0;
tex2d[0][1][2] = 255;
tex2d[0][1][3] = 255;
 
tex2d[1][0][0] = 255;
tex2d[1][0][1] = 255;
tex2d[1][0][2] = 0;
tex2d[1][0][3] = 255;
 
tex2d[1][1][0] = 255;
tex2d[1][1][1] = 0;
tex2d[1][1][2] = 0;
tex2d[1][1][3] = 255;
#endif
 
templat.target = PIPE_TEXTURE_2D;
templat.format = PIPE_FORMAT_B8G8R8A8_UNORM;
templat.width0 = SIZE;
templat.height0 = SIZE;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = PIPE_BIND_SAMPLER_VIEW;
 
samptex = screen->resource_create(screen,
&templat);
if (samptex == NULL)
exit(4);
 
u_box_2d(0,0,SIZE,SIZE, &box);
 
ctx->transfer_inline_write(ctx,
samptex,
0,
PIPE_TRANSFER_WRITE,
&box,
tex2d,
sizeof tex2d[0],
sizeof tex2d);
 
/* Possibly read back & compare against original data:
*/
if (0)
{
struct pipe_transfer *t;
uint32_t *ptr;
ptr = pipe_transfer_map(ctx, samptex,
0, 0, /* level, layer */
PIPE_TRANSFER_READ,
0, 0, SIZE, SIZE, &t); /* x, y, width, height */
 
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
 
ctx->transfer_unmap(ctx, t);
}
 
memset(&sv_template, 0, sizeof sv_template);
sv_template.format = samptex->format;
sv_template.texture = samptex;
sv_template.swizzle_r = 0;
sv_template.swizzle_g = 1;
sv_template.swizzle_b = 2;
sv_template.swizzle_a = 3;
sv = ctx->create_sampler_view(ctx, samptex, &sv_template);
if (sv == NULL)
exit(5);
 
ctx->set_fragment_sampler_views(ctx, 1, &sv);
 
memset(&sampler_desc, 0, sizeof sampler_desc);
sampler_desc.wrap_s = PIPE_TEX_WRAP_REPEAT;
sampler_desc.wrap_t = PIPE_TEX_WRAP_REPEAT;
sampler_desc.wrap_r = PIPE_TEX_WRAP_REPEAT;
sampler_desc.min_img_filter = PIPE_TEX_FILTER_NEAREST;
sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
sampler_desc.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE;
sampler_desc.compare_func = 0;
sampler_desc.normalized_coords = 1;
sampler_desc.max_anisotropy = 0;
sampler = ctx->create_sampler_state(ctx, &sampler_desc);
if (sampler == NULL)
exit(6);
 
ctx->bind_fragment_sampler_states(ctx, 1, &sampler);
}
 
static void init( void )
{
struct pipe_framebuffer_state fb;
struct pipe_resource templat;
struct pipe_surface surf_tmpl;
int i;
 
/* It's hard to say whether window or screen should be created
* first. Different environments would prefer one or the other.
*
* Also, no easy way of querying supported formats if the screen
* cannot be created first.
*/
for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
screen = graw_create_window_and_screen(0, 0, 300, 300,
formats[i],
&window);
if (window && screen)
break;
}
if (!screen || !window) {
fprintf(stderr, "Unable to create window\n");
exit(1);
}
 
ctx = screen->context_create(screen, NULL);
if (ctx == NULL)
exit(3);
 
templat.target = PIPE_TEXTURE_2D;
templat.format = formats[i];
templat.width0 = WIDTH;
templat.height0 = HEIGHT;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DISPLAY_TARGET);
rttex = screen->resource_create(screen,
&templat);
if (rttex == NULL)
exit(4);
 
surf_tmpl.format = templat.format;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
surf = ctx->create_surface(ctx, rttex, &surf_tmpl);
if (surf == NULL)
exit(5);
 
memset(&fb, 0, sizeof fb);
fb.nr_cbufs = 1;
fb.width = WIDTH;
fb.height = HEIGHT;
fb.cbufs[0] = surf;
 
ctx->set_framebuffer_state(ctx, &fb);
{
struct pipe_blend_state blend;
void *handle;
memset(&blend, 0, sizeof blend);
blend.rt[0].colormask = PIPE_MASK_RGBA;
handle = ctx->create_blend_state(ctx, &blend);
ctx->bind_blend_state(ctx, handle);
}
 
{
struct pipe_depth_stencil_alpha_state depthstencil;
void *handle;
memset(&depthstencil, 0, sizeof depthstencil);
handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil);
ctx->bind_depth_stencil_alpha_state(ctx, handle);
}
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
rasterizer.depth_clip = 1;
handle = ctx->create_rasterizer_state(ctx, &rasterizer);
ctx->bind_rasterizer_state(ctx, handle);
}
 
set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000);
 
init_tex();
init_fs_constbuf();
 
set_vertices();
set_vertex_shader();
set_fragment_shader(filename);
}
 
static void args(int argc, char *argv[])
{
int i;
 
for (i = 1; i < argc;) {
if (graw_parse_args(&i, argc, argv)) {
continue;
}
if (strcmp(argv[i], "-fps") == 0) {
show_fps = 1;
i++;
}
else if (i == argc - 1) {
filename = argv[i];
i++;
}
else {
usage(argv[0]);
exit(1);
}
}
 
if (!filename) {
usage(argv[0]);
exit(1);
}
}
 
int main( int argc, char *argv[] )
{
args(argc,argv);
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/fs-write-z.c
0,0 → 1,224
/* Test the writing Z in fragment shader.
* The red quad should be entirely in front of the blue quad even
* though the overlap and intersect in Z.
*/
 
#include <stdio.h>
 
#include "graw_util.h"
 
 
static int width = 300;
static int height = 300;
 
static struct graw_info info;
 
 
struct vertex {
float position[4];
float color[4];
};
 
#define z0 0.2
#define z01 0.5
#define z1 0.4
 
 
static struct vertex vertices[] =
{
/* left quad: clock-wise, front-facing, red */
{
{-0.8, -0.9, z0, 1.0 },
{ 1, 0, 0, 1 }
},
 
{
{ -0.2, -0.9, z0, 1.0 },
{ 1, 0, 0, 1 }
},
 
{
{ 0.2, 0.9, z01, 1.0 },
{ 1, 0, 0, 1 }
},
 
{
{-0.9, 0.9, z01, 1.0 },
{ 1, 0, 0, 1 }
},
 
/* right quad : counter-clock-wise, back-facing, green */
{
{ 0.2, -0.9, z1, 1.0 },
{ 0, 0, 1, -1 }
},
 
{
{ -0.2, 0.8, z1, 1.0 },
{ 0, 0, 1, -1 }
},
 
{
{ 0.9, 0.8, z1, 1.0 },
{ 0, 0, 1, -1 }
},
 
{
{ 0.8, -0.9, z1, 1.0 },
{ 0, 0, 1, -1 }
},
};
 
#define NUM_VERTS (sizeof(vertices) / sizeof(vertices[0]))
 
 
 
static void
set_vertices(void)
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve);
info.ctx->bind_vertex_elements_state(info.ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof(struct vertex);
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
info.ctx->set_vertex_buffers(info.ctx, 0, 1, &vbuf);
}
 
 
static void
set_vertex_shader(void)
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], GENERIC[0]\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: MOV OUT[1], IN[1]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(info.ctx, text);
info.ctx->bind_vs_state(info.ctx, handle);
}
 
 
static void
set_fragment_shader(void)
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], GENERIC, CONSTANT\n"
"DCL OUT[0], COLOR\n"
"DCL OUT[1], POSITION\n"
"DCL TEMP[0]\n"
"IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }\n"
"IMM FLT32 { 0.0, 1.0, 0.0, 0.0 }\n"
"IMM FLT32 { 0.5, 0.4, 0.0, 0.0 }\n"
" 0: MOV OUT[0], IN[0]\n" /* front-facing: red */
" 1: IF IN[0].xxxx :3\n"
" 2: MOV OUT[1].z, IMM[2].yyyy\n" /* red: Z = 0.4 */
" 3: ELSE :5\n"
" 4: MOV OUT[1].z, IMM[2].xxxx\n" /* blue: Z = 0.5 */
" 5: ENDIF\n"
" 6: END\n";
 
handle = graw_parse_fragment_shader(info.ctx, text);
info.ctx->bind_fs_state(info.ctx, handle);
}
 
 
 
static void
draw(void)
{
union pipe_color_union clear_color;
 
clear_color.f[0] = 0.25;
clear_color.f[1] = 0.25;
clear_color.f[2] = 0.25;
clear_color.f[3] = 1.00;
 
info.ctx->clear(info.ctx,
PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
&clear_color, 1.0, 0);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, NUM_VERTS);
info.ctx->flush(info.ctx, NULL, 0);
 
#if 0
/* At the moment, libgraw leaks out/makes available some of the
* symbols from gallium/auxiliary, including these debug helpers.
* Will eventually want to bless some of these paths, and lock the
* others down so they aren't accessible from test programs.
*
* This currently just happens to work on debug builds - a release
* build will probably fail to link here:
*/
debug_dump_surface_bmp(info.ctx, "result.bmp", surf);
#endif
 
graw_util_flush_front(&info);
}
 
 
#if 0
static void
resize(int w, int h)
{
width = w;
height = h;
 
graw_util_viewport(&info, 0, 0, width, height, -1.0, 1.0);
}
#endif
 
 
static void
init(void)
{
if (!graw_util_create_window(&info, width, height, 1, TRUE))
exit(1);
 
graw_util_default_state(&info, TRUE);
 
graw_util_viewport(&info, 0, 0, width, height, -1.0, 1.0);
 
set_vertices();
set_vertex_shader();
set_fragment_shader();
}
 
 
int
main(int argc, char *argv[])
{
init();
 
printf("The red quad should be entirely in front of the blue quad.\n");
 
graw_set_display_func(draw);
/*graw_set_reshape_func(resize);*/
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/geometry-shader/add-mix.txt
0,0 → 1,24
GEOM
PROPERTY GS_INPUT_PRIMITIVE TRIANGLES
PROPERTY GS_OUTPUT_PRIMITIVE TRIANGLE_STRIP
PROPERTY GS_MAX_OUTPUT_VERTICES 3
DCL IN[][0], POSITION, CONSTANT
DCL IN[][1], COLOR, CONSTANT
DCL OUT[0], POSITION, CONSTANT
DCL OUT[1], COLOR, CONSTANT
 
MOV OUT[0], IN[0][0]
ADD OUT[1], IN[0][1], IN[1][1]
EMIT
 
MOV OUT[0], IN[1][0]
ADD OUT[1], IN[1][1], IN[2][1]
EMIT
 
MOV OUT[0], IN[2][0]
ADD OUT[1], IN[2][1], IN[0][1]
EMIT
 
ENDPRIM
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/geometry-shader/add.txt
0,0 → 1,24
GEOM
PROPERTY GS_INPUT_PRIMITIVE TRIANGLES
PROPERTY GS_OUTPUT_PRIMITIVE LINE_STRIP
PROPERTY GS_MAX_OUTPUT_VERTICES 3
DCL IN[][0], POSITION, CONSTANT
DCL IN[][1], COLOR, CONSTANT
DCL OUT[0], POSITION, CONSTANT
DCL OUT[1], COLOR, CONSTANT
 
MOV OUT[0], IN[0][0]
ADD OUT[1], IN[0][1], IN[0][1]
EMIT
 
MOV OUT[0], IN[1][0]
ADD OUT[1], IN[1][1], IN[1][1]
EMIT
 
MOV OUT[0], IN[2][0]
ADD OUT[1], IN[2][1], IN[2][1]
EMIT
 
ENDPRIM
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/geometry-shader/line.txt
0,0 → 1,28
GEOM
PROPERTY GS_INPUT_PRIMITIVE TRIANGLES
PROPERTY GS_OUTPUT_PRIMITIVE LINE_STRIP
PROPERTY GS_MAX_OUTPUT_VERTICES 4
DCL IN[][0], POSITION, CONSTANT
DCL IN[][1], COLOR, CONSTANT
DCL OUT[0], POSITION, CONSTANT
DCL OUT[1], COLOR, CONSTANT
 
MOV OUT[0], IN[0][0]
MOV OUT[1], IN[0][1]
EMIT
 
MOV OUT[0], IN[1][0]
MOV OUT[1], IN[0][1]
EMIT
 
MOV OUT[0], IN[2][0]
MOV OUT[1], IN[2][1]
EMIT
 
MOV OUT[0], IN[0][0]
MOV OUT[1], IN[0][1]
EMIT
 
ENDPRIM
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/geometry-shader/mov-cb-2d.txt
0,0 → 1,25
GEOM
PROPERTY GS_INPUT_PRIMITIVE TRIANGLES
PROPERTY GS_OUTPUT_PRIMITIVE TRIANGLE_STRIP
PROPERTY GS_MAX_OUTPUT_VERTICES 3
DCL IN[][0], POSITION, CONSTANT
DCL IN[][1], COLOR, CONSTANT
DCL OUT[0], POSITION, CONSTANT
DCL OUT[1], COLOR, CONSTANT
DCL CONST[1][0..6]
 
MOV OUT[0], IN[0][0]
MOV OUT[1], CONST[1][0]
EMIT
 
MOV OUT[0], IN[1][0]
MOV OUT[1], CONST[1][1]
EMIT
 
MOV OUT[0], IN[2][0]
MOV OUT[1], CONST[1][4]
EMIT
 
ENDPRIM
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/geometry-shader/mov.txt
0,0 → 1,24
GEOM
PROPERTY GS_INPUT_PRIMITIVE TRIANGLES
PROPERTY GS_OUTPUT_PRIMITIVE TRIANGLE_STRIP
PROPERTY GS_MAX_OUTPUT_VERTICES 3
DCL IN[][0], POSITION, CONSTANT
DCL IN[][1], COLOR, CONSTANT
DCL OUT[0], POSITION, CONSTANT
DCL OUT[1], COLOR, CONSTANT
 
MOV OUT[0], IN[0][0]
MOV OUT[1], IN[0][1]
EMIT
 
MOV OUT[0], IN[1][0]
MOV OUT[1], IN[1][1]
EMIT
 
MOV OUT[0], IN[2][0]
MOV OUT[1], IN[2][1]
EMIT
 
ENDPRIM
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/geometry-shader/multi-line.txt
0,0 → 1,42
GEOM
PROPERTY GS_INPUT_PRIMITIVE TRIANGLES
PROPERTY GS_OUTPUT_PRIMITIVE LINE_STRIP
PROPERTY GS_MAX_OUTPUT_VERTICES 8
DCL IN[][0], POSITION, CONSTANT
DCL IN[][1], COLOR, CONSTANT
DCL OUT[0], POSITION, CONSTANT
DCL OUT[1], COLOR, CONSTANT
DCL TEMP[0]
 
MOV TEMP[0], IN[0][0]
ADD TEMP[0].y, IN[0][0], IN[1][0]
 
MOV OUT[0], TEMP[0]
MOV OUT[1], IN[0][1]
EMIT
MOV OUT[0], IN[2][0]
MOV OUT[1], IN[0][1]
EMIT
MOV OUT[0], IN[0][0]
MOV OUT[1], IN[2][1]
EMIT
MOV OUT[0], TEMP[0]
MOV OUT[1], IN[0][1]
EMIT
ENDPRIM
 
MOV OUT[0], TEMP[0]
MOV OUT[1], IN[0][1]
EMIT
MOV OUT[0], IN[2][0]
MOV OUT[1], IN[0][1]
EMIT
MOV OUT[0], IN[1][0]
MOV OUT[1], IN[2][1]
EMIT
MOV OUT[0], TEMP[0]
MOV OUT[1], IN[0][1]
EMIT
ENDPRIM
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/graw_util.h
0,0 → 1,328
 
#include "state_tracker/graw.h"
 
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/p_state.h"
 
#include "util/u_box.h"
#include "util/u_debug.h"
#include "util/u_draw_quad.h"
#include "util/u_format.h"
#include "util/u_inlines.h"
#include "util/u_memory.h"
 
 
struct graw_info
{
struct pipe_screen *screen;
struct pipe_context *ctx;
struct pipe_resource *color_buf[PIPE_MAX_COLOR_BUFS], *zs_buf;
struct pipe_surface *color_surf[PIPE_MAX_COLOR_BUFS], *zs_surf;
void *window;
};
 
 
 
static INLINE boolean
graw_util_create_window(struct graw_info *info,
int width, int height,
int num_cbufs, bool zstencil_buf)
{
static const enum pipe_format formats[] = {
PIPE_FORMAT_RGBA8888_UNORM,
PIPE_FORMAT_BGRA8888_UNORM,
PIPE_FORMAT_NONE
};
enum pipe_format format;
struct pipe_resource resource_temp;
struct pipe_surface surface_temp;
int i;
 
memset(info, 0, sizeof(*info));
 
/* It's hard to say whether window or screen should be created
* first. Different environments would prefer one or the other.
*
* Also, no easy way of querying supported formats if the screen
* cannot be created first.
*/
for (i = 0; info->window == NULL && formats[i] != PIPE_FORMAT_NONE; i++) {
info->screen = graw_create_window_and_screen(0, 0, width, height,
formats[i],
&info->window);
format = formats[i];
}
if (!info->screen || !info->window) {
debug_printf("graw: Failed to create screen/window\n");
return FALSE;
}
info->ctx = info->screen->context_create(info->screen, NULL);
if (info->ctx == NULL) {
debug_printf("graw: Failed to create context\n");
return FALSE;
}
 
for (i = 0; i < num_cbufs; i++) {
/* create color texture */
resource_temp.target = PIPE_TEXTURE_2D;
resource_temp.format = format;
resource_temp.width0 = width;
resource_temp.height0 = height;
resource_temp.depth0 = 1;
resource_temp.array_size = 1;
resource_temp.last_level = 0;
resource_temp.nr_samples = 1;
resource_temp.bind = (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DISPLAY_TARGET);
info->color_buf[i] = info->screen->resource_create(info->screen,
&resource_temp);
if (info->color_buf[i] == NULL) {
debug_printf("graw: Failed to create color texture\n");
return FALSE;
}
 
/* create color surface */
surface_temp.format = resource_temp.format;
surface_temp.u.tex.level = 0;
surface_temp.u.tex.first_layer = 0;
surface_temp.u.tex.last_layer = 0;
info->color_surf[i] = info->ctx->create_surface(info->ctx,
info->color_buf[i],
&surface_temp);
if (info->color_surf[i] == NULL) {
debug_printf("graw: Failed to get color surface\n");
return FALSE;
}
}
 
/* create Z texture (XXX try other Z/S formats if needed) */
resource_temp.target = PIPE_TEXTURE_2D;
resource_temp.format = PIPE_FORMAT_S8_UINT_Z24_UNORM;
resource_temp.width0 = width;
resource_temp.height0 = height;
resource_temp.depth0 = 1;
resource_temp.array_size = 1;
resource_temp.last_level = 0;
resource_temp.nr_samples = 1;
resource_temp.bind = PIPE_BIND_DEPTH_STENCIL;
info->zs_buf = info->screen->resource_create(info->screen, &resource_temp);
if (!info->zs_buf) {
debug_printf("graw: Failed to create Z texture\n");
return FALSE;
}
 
/* create z surface */
surface_temp.format = resource_temp.format;
surface_temp.u.tex.level = 0;
surface_temp.u.tex.first_layer = 0;
surface_temp.u.tex.last_layer = 0;
info->zs_surf = info->ctx->create_surface(info->ctx,
info->zs_buf,
&surface_temp);
if (info->zs_surf == NULL) {
debug_printf("graw: Failed to get Z surface\n");
return FALSE;
}
 
{
struct pipe_framebuffer_state fb;
memset(&fb, 0, sizeof fb);
fb.nr_cbufs = num_cbufs;
fb.width = width;
fb.height = height;
for (i = 0; i < num_cbufs; i++)
fb.cbufs[i] = info->color_surf[i];
fb.zsbuf = info->zs_surf;
info->ctx->set_framebuffer_state(info->ctx, &fb);
}
 
return TRUE;
}
 
 
static INLINE void
graw_util_default_state(struct graw_info *info, boolean depth_test)
{
{
struct pipe_blend_state blend;
void *handle;
memset(&blend, 0, sizeof blend);
blend.rt[0].colormask = PIPE_MASK_RGBA;
handle = info->ctx->create_blend_state(info->ctx, &blend);
info->ctx->bind_blend_state(info->ctx, handle);
}
 
{
struct pipe_depth_stencil_alpha_state depthStencilAlpha;
void *handle;
memset(&depthStencilAlpha, 0, sizeof depthStencilAlpha);
depthStencilAlpha.depth.enabled = depth_test;
depthStencilAlpha.depth.writemask = 1;
depthStencilAlpha.depth.func = PIPE_FUNC_LESS;
handle = info->ctx->create_depth_stencil_alpha_state(info->ctx,
&depthStencilAlpha);
info->ctx->bind_depth_stencil_alpha_state(info->ctx, handle);
}
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
handle = info->ctx->create_rasterizer_state(info->ctx, &rasterizer);
info->ctx->bind_rasterizer_state(info->ctx, handle);
}
}
 
 
static INLINE void
graw_util_viewport(struct graw_info *info,
float x, float y,
float width, float height,
float near, float far)
{
float z = near;
float half_width = width / 2.0f;
float half_height = height / 2.0f;
float half_depth = (far - near) / 2.0f;
struct pipe_viewport_state vp;
 
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.scale[3] = 1.0f;
 
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.translate[3] = 0.0f;
 
info->ctx->set_viewport_states(info->ctx, 0, 1, &vp);
}
 
 
static INLINE void
graw_util_flush_front(const struct graw_info *info)
{
info->screen->flush_frontbuffer(info->screen, info->color_buf[0],
0, 0, info->window);
}
 
 
static INLINE struct pipe_resource *
graw_util_create_tex2d(const struct graw_info *info,
int width, int height, enum pipe_format format,
const void *data)
{
const int row_stride = width * util_format_get_blocksize(format);
const int image_bytes = row_stride * height;
struct pipe_resource temp, *tex;
struct pipe_box box;
 
temp.target = PIPE_TEXTURE_2D;
temp.format = format;
temp.width0 = width;
temp.height0 = height;
temp.depth0 = 1;
temp.last_level = 0;
temp.array_size = 1;
temp.nr_samples = 1;
temp.bind = PIPE_BIND_SAMPLER_VIEW;
tex = info->screen->resource_create(info->screen, &temp);
if (!tex) {
debug_printf("graw: failed to create texture\n");
return NULL;
}
 
u_box_2d(0, 0, width, height, &box);
 
info->ctx->transfer_inline_write(info->ctx,
tex,
0,
PIPE_TRANSFER_WRITE,
&box,
data,
row_stride,
image_bytes);
 
/* Possibly read back & compare against original data:
*/
#if 0
{
struct pipe_transfer *t;
uint32_t *ptr;
t = pipe_transfer_map(info->ctx, samptex,
0, 0, /* level, layer */
PIPE_TRANSFER_READ,
0, 0, SIZE, SIZE); /* x, y, width, height */
 
ptr = info->ctx->transfer_map(info->ctx, t);
 
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
 
info->ctx->transfer_unmap(info->ctx, t);
 
info->ctx->transfer_destroy(info->ctx, t);
}
#endif
 
return tex;
}
 
 
static INLINE void *
graw_util_create_simple_sampler(const struct graw_info *info,
unsigned wrap_mode,
unsigned img_filter)
{
struct pipe_sampler_state sampler_desc;
void *sampler;
 
memset(&sampler_desc, 0, sizeof sampler_desc);
sampler_desc.wrap_s =
sampler_desc.wrap_t =
sampler_desc.wrap_r = wrap_mode;
sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
sampler_desc.min_img_filter =
sampler_desc.mag_img_filter = img_filter;
sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE;
sampler_desc.compare_func = 0;
sampler_desc.normalized_coords = 1;
sampler_desc.max_anisotropy = 0;
sampler = info->ctx->create_sampler_state(info->ctx, &sampler_desc);
 
return sampler;
}
 
 
static INLINE struct pipe_sampler_view *
graw_util_create_simple_sampler_view(const struct graw_info *info,
struct pipe_resource *texture)
{
struct pipe_sampler_view sv_temp;
struct pipe_sampler_view *sv;
 
memset(&sv_temp, 0, sizeof(sv_temp));
sv_temp.format = texture->format;
sv_temp.texture = texture;
sv_temp.swizzle_r = PIPE_SWIZZLE_RED;
sv_temp.swizzle_g = PIPE_SWIZZLE_GREEN;
sv_temp.swizzle_b = PIPE_SWIZZLE_BLUE;
sv_temp.swizzle_a = PIPE_SWIZZLE_ALPHA;
 
sv = info->ctx->create_sampler_view(info->ctx, texture, &sv_temp);
 
return sv;
}
 
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/gs-test.c
0,0 → 1,626
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
 
#include "state_tracker/graw.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
#include <stdio.h> /* for fread(), etc */
 
#include "util/u_inlines.h"
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
#include "util/u_box.h"
 
static const char *filename = NULL;
unsigned show_fps = 0;
unsigned draw_strip = 0;
 
 
static void usage(char *name)
{
fprintf(stderr, "usage: %s [ options ] shader_filename\n", name);
#ifndef _WIN32
fprintf(stderr, "\n" );
fprintf(stderr, "options:\n");
fprintf(stderr, " -fps show frames per second\n");
fprintf(stderr, " -strip renders a triangle strip\n");
#endif
}
 
 
enum pipe_format formats[] = {
PIPE_FORMAT_R8G8B8A8_UNORM,
PIPE_FORMAT_B8G8R8A8_UNORM,
PIPE_FORMAT_NONE
};
 
static const int WIDTH = 250;
static const int HEIGHT = 250;
 
static struct pipe_screen *screen = NULL;
static struct pipe_context *ctx = NULL;
static struct pipe_resource *rttex = NULL;
static struct pipe_resource *constbuf1 = NULL;
static struct pipe_resource *constbuf2 = NULL;
static struct pipe_surface *surf = NULL;
static struct pipe_sampler_view *sv = NULL;
static void *sampler = NULL;
static void *window = NULL;
static struct pipe_resource *samptex = NULL;
 
struct vertex {
float position[4];
float color[4];
float texcoord[4];
float generic[4];
};
 
/* Vertex data matches progs/fp/fp-tri.c, but flipped in Y dimension
* so that the final images are the same.
*/
static struct vertex vertices[] =
{
{ { 0.9, 0.9, 0.0, 1.0 },
{ 0, 0, 1, 1 },
{ 1, 1, 0, 1 },
{ 1, 0, 1, 0 }
},
 
{ { 0.9, -0.9, 0.0, 1.0 },
{ 1, 0, 0, 1 },
{ 1, -1, 0, 1 },
{ 0, 1, 0, 1 }
},
 
{ {-0.9, 0.0, 0.0, 1.0 },
{ 0, 1, 0, 1 },
{ -1, 0, 0, 1 },
{ 0, 0, 1, 1 }
},
};
 
static struct vertex vertices_strip[] =
{
{ { 0.9, 0.9, 0.0, 1.0 },
{ 0, 0, 1, 1 },
{ 1, 1, 0, 1 },
{ 1, 0, 0, 1 }
},
 
{ { 0.9, -0.9, 0.0, 1.0 },
{ 1, 0, 0, 1 },
{ 1, -1, 0, 1 },
{ 0, 1, 0, 1 }
},
 
{ {-0.9, 0.9, 0.0, 1.0 },
{ 0, 1, 0, 1 },
{ -1, 1, 0, 1 },
{ 0, 0, 1, 1 }
},
 
{ {-0.9, -0.9, 0.0, 1.0 },
{ 1, 1, 0, 1 },
{ -1, -1, 0, 1 },
{ 1, 1, 0, 1 }
},
};
 
static float constants1[] =
{ 0.4, 0, 0, 1,
1, 1, 1, 1,
2, 2, 2, 2,
4, 8, 16, 32,
 
3, 0, 0, 0,
0, .5, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
 
1, 0, 0, 0.5,
0, 1, 0, 0.5,
0, 0, 1, 0,
0, 0, 0, 1,
};
 
 
static float constants2[] =
{ 1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
0, 0, 0, 1,
 
1, 1, 0, 1,
1, .5, 0, 1,
0, 1, 1, 1,
1, 0, 1, 1,
 
1, 0, 0, 0.5,
0, 1, 0, 0.5,
0, 0, 1, 0,
0, 0, 0, 1,
};
 
 
static void init_fs_constbuf( void )
{
struct pipe_resource templat;
struct pipe_box box;
 
templat.target = PIPE_BUFFER;
templat.format = PIPE_FORMAT_R8_UNORM;
templat.width0 = sizeof(constants1);
templat.height0 = 1;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = PIPE_BIND_CONSTANT_BUFFER;
 
constbuf1 = screen->resource_create(screen, &templat);
if (constbuf1 == NULL)
exit(4);
constbuf2 = screen->resource_create(screen, &templat);
if (constbuf2 == NULL)
exit(4);
 
{
u_box_2d(0,0,sizeof(constants1),1, &box);
 
ctx->transfer_inline_write(ctx,
constbuf1,
0,
PIPE_TRANSFER_WRITE,
&box,
constants1,
sizeof constants1,
sizeof constants1);
 
 
pipe_set_constant_buffer(ctx,
PIPE_SHADER_GEOMETRY, 0,
constbuf1);
}
{
u_box_2d(0,0,sizeof(constants2),1, &box);
 
ctx->transfer_inline_write(ctx,
constbuf2,
0,
PIPE_TRANSFER_WRITE,
&box,
constants2,
sizeof constants2,
sizeof constants2);
 
 
pipe_set_constant_buffer(ctx,
PIPE_SHADER_GEOMETRY, 1,
constbuf2);
}
}
 
 
static void set_viewport( float x, float y,
float width, float height,
float near, float far)
{
float z = far;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)far - (float)near) / 2.0f;
struct pipe_viewport_state vp;
 
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.scale[3] = 1.0f;
 
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.translate[3] = 0.0f;
 
ctx->set_viewport_states( ctx, 0, 1, &vp );
}
 
static void set_vertices( void )
{
struct pipe_vertex_element ve[4];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[2].src_offset = Offset(struct vertex, texcoord);
ve[2].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[3].src_offset = Offset(struct vertex, generic);
ve[3].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = ctx->create_vertex_elements_state(ctx, 4, ve);
ctx->bind_vertex_elements_state(ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof( struct vertex );
vbuf.buffer_offset = 0;
if (draw_strip) {
vbuf.buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices_strip),
vertices_strip);
} else {
vbuf.buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
}
 
ctx->set_vertex_buffers(ctx, 0, 1, &vbuf);
}
 
static void set_vertex_shader( void )
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL IN[2]\n"
"DCL IN[3]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], COLOR[0]\n"
"DCL OUT[2], GENERIC[0]\n"
"DCL OUT[3], GENERIC[1]\n"
" MOV OUT[0], IN[0]\n"
" MOV OUT[1], IN[1]\n"
" MOV OUT[2], IN[2]\n"
" MOV OUT[3], IN[3]\n"
" END\n";
 
handle = graw_parse_vertex_shader(ctx, text);
ctx->bind_vs_state(ctx, handle);
}
 
static void set_fragment_shader( void )
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], COLOR, LINEAR\n"
"DCL OUT[0], COLOR\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: END\n";
 
handle = graw_parse_fragment_shader(ctx, text);
ctx->bind_fs_state(ctx, handle);
}
 
 
static void set_geometry_shader( void )
{
FILE *f;
char buf[50000];
void *handle;
int sz;
 
if ((f = fopen(filename, "r")) == NULL) {
fprintf(stderr, "Couldn't open %s\n", filename);
exit(1);
}
 
sz = fread(buf, 1, sizeof(buf), f);
if (!feof(f)) {
printf("file too long\n");
exit(1);
}
printf("%.*s\n", sz, buf);
buf[sz] = 0;
 
handle = graw_parse_geometry_shader(ctx, buf);
ctx->bind_gs_state(ctx, handle);
fclose(f);
}
 
 
static void draw( void )
{
union pipe_color_union clear_color = { {.1,.3,.5,0} };
 
ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
if (draw_strip)
util_draw_arrays(ctx, PIPE_PRIM_TRIANGLE_STRIP, 0, 4);
else
util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3);
 
ctx->flush(ctx, NULL, 0);
 
graw_save_surface_to_file(ctx, surf, NULL);
 
screen->flush_frontbuffer(screen, rttex, 0, 0, window);
}
 
#define SIZE 16
 
static void init_tex( void )
{
struct pipe_sampler_view sv_template;
struct pipe_sampler_state sampler_desc;
struct pipe_resource templat;
struct pipe_box box;
ubyte tex2d[SIZE][SIZE][4];
int s, t;
 
#if (SIZE != 2)
for (s = 0; s < SIZE; s++) {
for (t = 0; t < SIZE; t++) {
if (0) {
int x = (s ^ t) & 1;
tex2d[t][s][0] = (x) ? 0 : 63;
tex2d[t][s][1] = (x) ? 0 : 128;
tex2d[t][s][2] = 0;
tex2d[t][s][3] = 0xff;
}
else {
int x = ((s ^ t) >> 2) & 1;
tex2d[t][s][0] = s*255/(SIZE-1);
tex2d[t][s][1] = t*255/(SIZE-1);
tex2d[t][s][2] = (x) ? 0 : 128;
tex2d[t][s][3] = 0xff;
}
}
}
#else
tex2d[0][0][0] = 0;
tex2d[0][0][1] = 255;
tex2d[0][0][2] = 255;
tex2d[0][0][3] = 0;
 
tex2d[0][1][0] = 0;
tex2d[0][1][1] = 0;
tex2d[0][1][2] = 255;
tex2d[0][1][3] = 255;
 
tex2d[1][0][0] = 255;
tex2d[1][0][1] = 255;
tex2d[1][0][2] = 0;
tex2d[1][0][3] = 255;
 
tex2d[1][1][0] = 255;
tex2d[1][1][1] = 0;
tex2d[1][1][2] = 0;
tex2d[1][1][3] = 255;
#endif
 
templat.target = PIPE_TEXTURE_2D;
templat.format = PIPE_FORMAT_B8G8R8A8_UNORM;
templat.width0 = SIZE;
templat.height0 = SIZE;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = PIPE_BIND_SAMPLER_VIEW;
 
samptex = screen->resource_create(screen,
&templat);
if (samptex == NULL)
exit(4);
 
u_box_2d(0,0,SIZE,SIZE, &box);
 
ctx->transfer_inline_write(ctx,
samptex,
0,
PIPE_TRANSFER_WRITE,
&box,
tex2d,
sizeof tex2d[0],
sizeof tex2d);
 
/* Possibly read back & compare against original data:
*/
if (0)
{
struct pipe_transfer *t;
uint32_t *ptr;
ptr = pipe_transfer_map(ctx, samptex,
0, 0, /* level, layer */
PIPE_TRANSFER_READ,
0, 0, SIZE, SIZE, &t); /* x, y, width, height */
 
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
 
ctx->transfer_unmap(ctx, t);
}
 
memset(&sv_template, 0, sizeof sv_template);
sv_template.format = samptex->format;
sv_template.texture = samptex;
sv_template.swizzle_r = 0;
sv_template.swizzle_g = 1;
sv_template.swizzle_b = 2;
sv_template.swizzle_a = 3;
sv = ctx->create_sampler_view(ctx, samptex, &sv_template);
if (sv == NULL)
exit(5);
 
ctx->set_fragment_sampler_views(ctx, 1, &sv);
 
memset(&sampler_desc, 0, sizeof sampler_desc);
sampler_desc.wrap_s = PIPE_TEX_WRAP_REPEAT;
sampler_desc.wrap_t = PIPE_TEX_WRAP_REPEAT;
sampler_desc.wrap_r = PIPE_TEX_WRAP_REPEAT;
sampler_desc.min_img_filter = PIPE_TEX_FILTER_NEAREST;
sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
sampler_desc.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE;
sampler_desc.compare_func = 0;
sampler_desc.normalized_coords = 1;
sampler_desc.max_anisotropy = 0;
sampler = ctx->create_sampler_state(ctx, &sampler_desc);
if (sampler == NULL)
exit(6);
 
ctx->bind_fragment_sampler_states(ctx, 1, &sampler);
}
 
static void init( void )
{
struct pipe_framebuffer_state fb;
struct pipe_resource templat;
struct pipe_surface surf_tmpl;
int i;
 
/* It's hard to say whether window or screen should be created
* first. Different environments would prefer one or the other.
*
* Also, no easy way of querying supported formats if the screen
* cannot be created first.
*/
for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
screen = graw_create_window_and_screen(0, 0, 300, 300,
formats[i],
&window);
if (window && screen)
break;
}
if (!screen || !window) {
fprintf(stderr, "Unable to create window\n");
exit(1);
}
 
ctx = screen->context_create(screen, NULL);
if (ctx == NULL)
exit(3);
 
templat.target = PIPE_TEXTURE_2D;
templat.format = formats[i];
templat.width0 = WIDTH;
templat.height0 = HEIGHT;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DISPLAY_TARGET);
rttex = screen->resource_create(screen,
&templat);
if (rttex == NULL)
exit(4);
 
surf_tmpl.format = templat.format;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
surf = ctx->create_surface(ctx, rttex, &surf_tmpl);
if (surf == NULL)
exit(5);
 
memset(&fb, 0, sizeof fb);
fb.nr_cbufs = 1;
fb.width = WIDTH;
fb.height = HEIGHT;
fb.cbufs[0] = surf;
 
ctx->set_framebuffer_state(ctx, &fb);
{
struct pipe_blend_state blend;
void *handle;
memset(&blend, 0, sizeof blend);
blend.rt[0].colormask = PIPE_MASK_RGBA;
handle = ctx->create_blend_state(ctx, &blend);
ctx->bind_blend_state(ctx, handle);
}
 
{
struct pipe_depth_stencil_alpha_state depthstencil;
void *handle;
memset(&depthstencil, 0, sizeof depthstencil);
handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil);
ctx->bind_depth_stencil_alpha_state(ctx, handle);
}
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
rasterizer.depth_clip = 1;
handle = ctx->create_rasterizer_state(ctx, &rasterizer);
ctx->bind_rasterizer_state(ctx, handle);
}
 
set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000);
 
init_tex();
init_fs_constbuf();
 
set_vertices();
set_vertex_shader();
set_fragment_shader();
set_geometry_shader();
}
 
static void args(int argc, char *argv[])
{
int i;
 
for (i = 1; i < argc;) {
if (graw_parse_args(&i, argc, argv)) {
continue;
}
if (strcmp(argv[i], "-fps") == 0) {
show_fps = 1;
i++;
}
else if (strcmp(argv[i], "-strip") == 0) {
draw_strip = 1;
i++;
}
else if (i == argc - 1) {
filename = argv[i];
i++;
}
else {
usage(argv[0]);
exit(1);
}
}
 
if (!filename) {
usage(argv[0]);
exit(1);
}
}
 
int main( int argc, char *argv[] )
{
args(argc,argv);
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/occlusion-query.c
0,0 → 1,243
/* Test gallium occlusion queries.
*/
 
#include <stdio.h>
 
#include "graw_util.h"
 
 
static int width = 300;
static int height = 300;
 
/* expected results of occlusion test (depndsd on window size) */
static int expected1 = (int) ((300 * 0.9) * (300 * 0.9));
static int expected2 = 420;
 
 
static struct graw_info info;
 
struct vertex {
float position[4];
float color[4];
};
 
#define z0 0.2
#define z1 0.6
 
static struct vertex obj1_vertices[4] =
{
{
{-0.9, -0.9, z0, 1.0 },
{ 1, 0, 0, 1 }
},
 
{
{ 0.9, -0.9, z0, 1.0 },
{ 1, 0, 0, 1 }
},
 
{
{ 0.9, 0.9, z0, 1.0 },
{ 1, 0, 0, 1 }
},
 
{
{-0.9, 0.9, z0, 1.0 },
{ 1, 0, 0, 1 }
}
};
 
static struct vertex obj2_vertices[4] =
{
{
{ -0.2, -0.2, z1, 1.0 },
{ 0, 0, 1, 1 }
},
 
{
{ 0.95, -0.2, z1, 1.0 },
{ 0, 0, 1, 1 }
},
 
{
{ 0.95, 0.2, z1, 1.0 },
{ 0, 0, 1, 1 }
},
 
{
{ -0.2, 0.2, z1, 1.0 },
{ 0, 0, 1, 1 }
},
};
 
#define NUM_VERTS 4
 
 
 
static void
set_vertices(struct vertex *vertices, unsigned bytes)
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve);
info.ctx->bind_vertex_elements_state(info.ctx, handle);
 
 
vbuf.stride = sizeof(struct vertex);
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
bytes,
vertices);
 
info.ctx->set_vertex_buffers(info.ctx, 0, 1, &vbuf);
}
 
 
static void
set_vertex_shader(struct graw_info *info)
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], GENERIC[0]\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: MOV OUT[1], IN[1]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(info->ctx, text);
if (!handle) {
debug_printf("Failed to parse vertex shader\n");
return;
}
info->ctx->bind_vs_state(info->ctx, handle);
}
 
 
static void
set_fragment_shader(struct graw_info *info)
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], GENERIC, LINEAR\n"
"DCL OUT[0], COLOR\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: END\n";
 
handle = graw_parse_fragment_shader(info->ctx, text);
if (!handle) {
debug_printf("Failed to parse fragment shader\n");
return;
}
info->ctx->bind_fs_state(info->ctx, handle);
}
 
 
static void
draw(void)
{
int expected1_min = (int) (expected1 * 0.95);
int expected1_max = (int) (expected1 * 1.05);
int expected2_min = (int) (expected2 * 0.95);
int expected2_max = (int) (expected2 * 1.05);
 
union pipe_color_union clear_color;
 
struct pipe_query *q1, *q2;
union pipe_query_result res1, res2;
 
clear_color.f[0] = 0.25;
clear_color.f[1] = 0.25;
clear_color.f[2] = 0.25;
clear_color.f[3] = 1.00;
 
info.ctx->clear(info.ctx,
PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
&clear_color, 1.0, 0);
 
q1 = info.ctx->create_query(info.ctx, PIPE_QUERY_OCCLUSION_COUNTER);
q2 = info.ctx->create_query(info.ctx, PIPE_QUERY_OCCLUSION_COUNTER);
 
/* draw first, large object */
set_vertices(obj1_vertices, sizeof(obj1_vertices));
info.ctx->begin_query(info.ctx, q1);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, NUM_VERTS);
info.ctx->end_query(info.ctx, q1);
 
/* draw second, small object behind first object */
set_vertices(obj2_vertices, sizeof(obj2_vertices));
info.ctx->begin_query(info.ctx, q2);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, NUM_VERTS);
info.ctx->end_query(info.ctx, q2);
 
info.ctx->get_query_result(info.ctx, q1, TRUE, &res1);
info.ctx->get_query_result(info.ctx, q2, TRUE, &res2);
 
printf("result1 = %lu result2 = %lu\n", res1.u64, res2.u64);
if (res1.u64 < expected1_min || res1.u64 > expected1_max)
printf(" Failure: result1 should be near %d\n", expected1);
if (res2.u64 < expected2_min || res2.u64 > expected2_max)
printf(" Failure: result2 should be near %d\n", expected2);
 
info.ctx->flush(info.ctx, NULL, 0);
 
graw_util_flush_front(&info);
 
info.ctx->destroy_query(info.ctx, q1);
info.ctx->destroy_query(info.ctx, q2);
}
 
 
#if 0
static void
resize(int w, int h)
{
width = w;
height = h;
 
graw_util_viewport(&info, 0, 0, width, height, 30, 1000);
}
#endif
 
 
static void
init(void)
{
if (!graw_util_create_window(&info, width, height, 1, TRUE))
exit(1);
 
graw_util_default_state(&info, TRUE);
 
graw_util_viewport(&info, 0, 0, width, height, -1.0, 1.0);
 
set_vertex_shader(&info);
set_fragment_shader(&info);
}
 
 
int
main(int argc, char *argv[])
{
init();
 
printf("The red quad should mostly occlude the blue quad.\n");
 
graw_set_display_func(draw);
/*graw_set_reshape_func(resize);*/
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/quad-sample.c
0,0 → 1,413
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
 
#include "state_tracker/graw.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
 
#include "util/u_debug.h" /* debug_dump_surface_bmp() */
#include "util/u_inlines.h"
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
#include "util/u_box.h"
 
#include <stdio.h>
 
enum pipe_format formats[] = {
PIPE_FORMAT_RGBA8888_UNORM,
PIPE_FORMAT_BGRA8888_UNORM,
PIPE_FORMAT_NONE
};
 
static const int WIDTH = 300;
static const int HEIGHT = 300;
 
static struct pipe_screen *screen = NULL;
static struct pipe_context *ctx = NULL;
static struct pipe_resource *rttex = NULL;
static struct pipe_resource *samptex = NULL;
static struct pipe_surface *surf = NULL;
static struct pipe_sampler_view *sv = NULL;
static void *sampler = NULL;
static void *window = NULL;
 
struct vertex {
float position[4];
float color[4];
};
 
static struct vertex vertices[] =
{
{ { 0.9, -0.9, 0.0, 1.0 },
{ 1, 0, 0, 1 } },
 
{ { 0.9, 0.9, 0.0, 1.0 },
{ 1, 1, 0, 1 } },
 
{ {-0.9, 0.9, 0.0, 1.0 },
{ 0, 1, 0, 1 } },
 
{ {-0.9, -0.9, 0.0, 1.0 },
{ 0, 0, 0, 1 } },
};
 
 
 
 
static void set_viewport( float x, float y,
float width, float height,
float near, float far)
{
float z = far;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)far - (float)near) / 2.0f;
struct pipe_viewport_state vp;
 
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.scale[3] = 1.0f;
 
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.translate[3] = 0.0f;
 
ctx->set_viewport_states( ctx, 0, 1, &vp );
}
 
static void set_vertices( void )
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = ctx->create_vertex_elements_state(ctx, 2, ve);
ctx->bind_vertex_elements_state(ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof( struct vertex );
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
ctx->set_vertex_buffers(ctx, 0, 1, &vbuf);
}
 
static void set_vertex_shader( void )
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], GENERIC[0]\n"
" 0: MOV OUT[1], IN[1]\n"
" 1: MOV OUT[0], IN[0]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(ctx, text);
ctx->bind_vs_state(ctx, handle);
}
 
static void set_fragment_shader( void )
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], GENERIC[0], PERSPECTIVE\n"
"DCL OUT[0], COLOR\n"
"DCL TEMP[0]\n"
"DCL SAMP[0]\n"
"DCL RES[0], 2D, FLOAT\n"
" 0: SAMPLE TEMP[0], IN[0], RES[0], SAMP[0]\n"
" 1: MOV OUT[0], TEMP[0]\n"
" 2: END\n";
 
handle = graw_parse_fragment_shader(ctx, text);
ctx->bind_fs_state(ctx, handle);
}
 
 
static void draw( void )
{
union pipe_color_union clear_color = { {.5,.5,.5,1} };
 
ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
util_draw_arrays(ctx, PIPE_PRIM_QUADS, 0, 4);
ctx->flush(ctx, NULL, 0);
 
graw_save_surface_to_file(ctx, surf, NULL);
 
screen->flush_frontbuffer(screen, rttex, 0, 0, window);
}
 
#define SIZE 16
 
static void init_tex( void )
{
struct pipe_sampler_view sv_template;
struct pipe_sampler_state sampler_desc;
struct pipe_resource templat;
struct pipe_box box;
ubyte tex2d[SIZE][SIZE][4];
int s, t;
 
#if (SIZE != 2)
for (s = 0; s < SIZE; s++) {
for (t = 0; t < SIZE; t++) {
if (0) {
int x = (s ^ t) & 1;
tex2d[t][s][0] = (x) ? 0 : 63;
tex2d[t][s][1] = (x) ? 0 : 128;
tex2d[t][s][2] = 0;
tex2d[t][s][3] = 0xff;
}
else {
int x = ((s ^ t) >> 2) & 1;
tex2d[t][s][0] = s*255/(SIZE-1);
tex2d[t][s][1] = t*255/(SIZE-1);
tex2d[t][s][2] = (x) ? 0 : 128;
tex2d[t][s][3] = 0xff;
}
}
}
#else
tex2d[0][0][0] = 0;
tex2d[0][0][1] = 255;
tex2d[0][0][2] = 255;
tex2d[0][0][3] = 0;
 
tex2d[0][1][0] = 0;
tex2d[0][1][1] = 0;
tex2d[0][1][2] = 255;
tex2d[0][1][3] = 255;
 
tex2d[1][0][0] = 255;
tex2d[1][0][1] = 255;
tex2d[1][0][2] = 0;
tex2d[1][0][3] = 255;
 
tex2d[1][1][0] = 255;
tex2d[1][1][1] = 0;
tex2d[1][1][2] = 0;
tex2d[1][1][3] = 255;
#endif
 
templat.target = PIPE_TEXTURE_2D;
templat.format = PIPE_FORMAT_B8G8R8A8_UNORM;
templat.width0 = SIZE;
templat.height0 = SIZE;
templat.depth0 = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = PIPE_BIND_SAMPLER_VIEW;
 
samptex = screen->resource_create(screen,
&templat);
if (samptex == NULL)
exit(4);
 
u_box_2d(0,0,SIZE,SIZE, &box);
 
ctx->transfer_inline_write(ctx,
samptex,
0,
PIPE_TRANSFER_WRITE,
&box,
tex2d,
sizeof tex2d[0],
sizeof tex2d);
 
/* Possibly read back & compare against original data:
*/
if (0)
{
struct pipe_transfer *t;
uint32_t *ptr;
ptr = pipe_transfer_map(ctx, samptex,
0, 0, /* level, layer */
PIPE_TRANSFER_READ,
0, 0, SIZE, SIZE, &t); /* x, y, width, height */
 
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
 
ctx->transfer_unmap(ctx, t);
}
 
memset(&sv_template, 0, sizeof sv_template);
sv_template.format = samptex->format;
sv_template.texture = samptex;
sv_template.swizzle_r = 0;
sv_template.swizzle_g = 1;
sv_template.swizzle_b = 2;
sv_template.swizzle_a = 3;
sv = ctx->create_sampler_view(ctx, samptex, &sv_template);
if (sv == NULL)
exit(5);
 
ctx->set_fragment_sampler_views(ctx, 1, &sv);
 
memset(&sampler_desc, 0, sizeof sampler_desc);
sampler_desc.wrap_s = PIPE_TEX_WRAP_REPEAT;
sampler_desc.wrap_t = PIPE_TEX_WRAP_REPEAT;
sampler_desc.wrap_r = PIPE_TEX_WRAP_REPEAT;
sampler_desc.min_img_filter = PIPE_TEX_FILTER_NEAREST;
sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
sampler_desc.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE;
sampler_desc.compare_func = 0;
sampler_desc.normalized_coords = 1;
sampler_desc.max_anisotropy = 0;
sampler = ctx->create_sampler_state(ctx, &sampler_desc);
if (sampler == NULL)
exit(6);
 
ctx->bind_fragment_sampler_states(ctx, 1, &sampler);
}
 
static void init( void )
{
struct pipe_framebuffer_state fb;
struct pipe_resource templat;
struct pipe_surface surf_tmpl;
int i;
 
/* It's hard to say whether window or screen should be created
* first. Different environments would prefer one or the other.
*
* Also, no easy way of querying supported formats if the screen
* cannot be created first.
*/
for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
screen = graw_create_window_and_screen(0, 0, 300, 300,
formats[i],
&window);
if (window && screen)
break;
}
if (!screen || !window) {
fprintf(stderr, "Unable to create window\n");
exit(1);
}
 
ctx = screen->context_create(screen, NULL);
if (ctx == NULL)
exit(3);
 
templat.target = PIPE_TEXTURE_2D;
templat.format = formats[i];
templat.width0 = WIDTH;
templat.height0 = HEIGHT;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DISPLAY_TARGET);
rttex = screen->resource_create(screen,
&templat);
if (rttex == NULL)
exit(4);
 
surf_tmpl.format = templat.format;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
surf = ctx->create_surface(ctx, rttex, &surf_tmpl);
if (surf == NULL)
exit(5);
 
memset(&fb, 0, sizeof fb);
fb.nr_cbufs = 1;
fb.width = WIDTH;
fb.height = HEIGHT;
fb.cbufs[0] = surf;
 
ctx->set_framebuffer_state(ctx, &fb);
{
struct pipe_blend_state blend;
void *handle;
memset(&blend, 0, sizeof blend);
blend.rt[0].colormask = PIPE_MASK_RGBA;
handle = ctx->create_blend_state(ctx, &blend);
ctx->bind_blend_state(ctx, handle);
}
 
{
struct pipe_depth_stencil_alpha_state depthstencil;
void *handle;
memset(&depthstencil, 0, sizeof depthstencil);
handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil);
ctx->bind_depth_stencil_alpha_state(ctx, handle);
}
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
rasterizer.depth_clip = 1;
handle = ctx->create_rasterizer_state(ctx, &rasterizer);
ctx->bind_rasterizer_state(ctx, handle);
}
 
set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000);
 
init_tex();
 
set_vertices();
set_vertex_shader();
set_fragment_shader();
}
 
static void args(int argc, char *argv[])
{
int i;
 
for (i = 1; i < argc;) {
if (graw_parse_args(&i, argc, argv)) {
continue;
}
exit(1);
}
}
 
 
int main( int argc, char *argv[] )
{
args(argc, argv);
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/quad-tex.c
0,0 → 1,228
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
 
#include "graw_util.h"
 
static const int WIDTH = 300;
static const int HEIGHT = 300;
 
static struct graw_info info;
 
 
static struct pipe_resource *texture = NULL;
static struct pipe_sampler_view *sv = NULL;
static void *sampler = NULL;
 
struct vertex {
float position[4];
float color[4];
};
 
static struct vertex vertices[] =
{
{ { 0.9, -0.9, 0.0, 1.0 },
{ 1, 0, 0, 1 } },
 
{ { 0.9, 0.9, 0.0, 1.0 },
{ 1, 1, 0, 1 } },
 
{ {-0.9, 0.9, 0.0, 1.0 },
{ 0, 1, 0, 1 } },
 
{ {-0.9, -0.9, 0.0, 1.0 },
{ 0, 0, 0, 1 } },
};
 
 
 
 
static void set_vertices( void )
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve);
info.ctx->bind_vertex_elements_state(info.ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof( struct vertex );
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
info.ctx->set_vertex_buffers(info.ctx, 0, 1, &vbuf);
}
 
static void set_vertex_shader( void )
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], GENERIC[0]\n"
" 0: MOV OUT[1], IN[1]\n"
" 1: MOV OUT[0], IN[0]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(info.ctx, text);
info.ctx->bind_vs_state(info.ctx, handle);
}
 
static void set_fragment_shader( void )
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], GENERIC[0], PERSPECTIVE\n"
"DCL OUT[0], COLOR\n"
"DCL TEMP[0]\n"
"DCL SAMP[0]\n"
" 0: TXP TEMP[0], IN[0], SAMP[0], 2D\n"
" 1: MOV OUT[0], TEMP[0]\n"
" 2: END\n";
 
handle = graw_parse_fragment_shader(info.ctx, text);
info.ctx->bind_fs_state(info.ctx, handle);
}
 
 
static void draw( void )
{
union pipe_color_union clear_color = { {.5,.5,.5,1} };
 
info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, 4);
info.ctx->flush(info.ctx, NULL, 0);
 
graw_save_surface_to_file(info.ctx, info.color_surf[0], NULL);
 
graw_util_flush_front(&info);
}
 
 
#define SIZE 16
 
static void init_tex( void )
{
ubyte tex2d[SIZE][SIZE][4];
int s, t;
 
#if (SIZE != 2)
for (s = 0; s < SIZE; s++) {
for (t = 0; t < SIZE; t++) {
if (0) {
int x = (s ^ t) & 1;
tex2d[t][s][0] = (x) ? 0 : 63;
tex2d[t][s][1] = (x) ? 0 : 128;
tex2d[t][s][2] = 0;
tex2d[t][s][3] = 0xff;
}
else {
int x = ((s ^ t) >> 2) & 1;
tex2d[t][s][0] = s*255/(SIZE-1);
tex2d[t][s][1] = t*255/(SIZE-1);
tex2d[t][s][2] = (x) ? 0 : 128;
tex2d[t][s][3] = 0xff;
}
}
}
#else
tex2d[0][0][0] = 0;
tex2d[0][0][1] = 255;
tex2d[0][0][2] = 255;
tex2d[0][0][3] = 0;
 
tex2d[0][1][0] = 0;
tex2d[0][1][1] = 0;
tex2d[0][1][2] = 255;
tex2d[0][1][3] = 255;
 
tex2d[1][0][0] = 255;
tex2d[1][0][1] = 255;
tex2d[1][0][2] = 0;
tex2d[1][0][3] = 255;
 
tex2d[1][1][0] = 255;
tex2d[1][1][1] = 0;
tex2d[1][1][2] = 0;
tex2d[1][1][3] = 255;
#endif
 
texture = graw_util_create_tex2d(&info, SIZE, SIZE,
PIPE_FORMAT_B8G8R8A8_UNORM, tex2d);
 
sv = graw_util_create_simple_sampler_view(&info, texture);
info.ctx->set_fragment_sampler_views(info.ctx, 1, &sv);
 
sampler = graw_util_create_simple_sampler(&info,
PIPE_TEX_WRAP_REPEAT,
PIPE_TEX_FILTER_NEAREST);
info.ctx->bind_fragment_sampler_states(info.ctx, 1, &sampler);
}
 
 
static void init( void )
{
if (!graw_util_create_window(&info, WIDTH, HEIGHT, 1, FALSE))
exit(1);
 
graw_util_default_state(&info, FALSE);
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
rasterizer.depth_clip = 1;
handle = info.ctx->create_rasterizer_state(info.ctx, &rasterizer);
info.ctx->bind_rasterizer_state(info.ctx, handle);
}
 
graw_util_viewport(&info, 0, 0, WIDTH, HEIGHT, 30, 1000);
 
init_tex();
 
set_vertices();
set_vertex_shader();
set_fragment_shader();
}
 
 
static void args(int argc, char *argv[])
{
int i;
 
for (i = 1; i < argc;) {
if (graw_parse_args(&i, argc, argv)) {
continue;
}
exit(1);
}
}
 
int main( int argc, char *argv[] )
{
args(argc, argv);
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/shader-leak.c
0,0 → 1,278
/**
* Create shaders in a loop to test memory usage.
*/
 
#include <stdio.h>
#include "state_tracker/graw.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
 
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
#include "util/u_inlines.h"
 
 
static int num_iters = 100;
 
 
enum pipe_format formats[] = {
PIPE_FORMAT_RGBA8888_UNORM,
PIPE_FORMAT_BGRA8888_UNORM,
PIPE_FORMAT_NONE
};
 
static const int WIDTH = 300;
static const int HEIGHT = 300;
 
static struct pipe_screen *screen = NULL;
static struct pipe_context *ctx = NULL;
static struct pipe_surface *surf = NULL;
static struct pipe_resource *tex = NULL;
static void *window = NULL;
 
struct vertex {
float position[4];
float color[4];
};
 
static struct vertex vertices[1] =
{
{
{ 0.0f, -0.9f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 0.0f, 1.0f }
}
};
 
 
 
 
static void set_viewport( float x, float y,
float width, float height,
float near, float far)
{
float z = far;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)far - (float)near) / 2.0f;
struct pipe_viewport_state vp;
 
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.scale[3] = 1.0f;
 
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.translate[3] = 0.0f;
 
ctx->set_viewport_states( ctx, 0, 1, &vp );
}
 
static void set_vertices( void )
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = ctx->create_vertex_elements_state(ctx, 2, ve);
ctx->bind_vertex_elements_state(ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof(struct vertex);
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
ctx->set_vertex_buffers(ctx, 0, 1, &vbuf);
}
 
static void set_vertex_shader( void )
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], COLOR\n"
" 0: MOV OUT[1], IN[1]\n"
" 1: MOV OUT[0], IN[0]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(ctx, text);
ctx->bind_vs_state(ctx, handle);
}
 
 
 
static void *
set_fragment_shader( void )
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], COLOR, LINEAR\n"
"DCL OUT[0], COLOR\n"
"DCL TEMP[0..1]\n"
" 0: MUL TEMP[0], IN[0], IN[0]\n"
" 1: ADD TEMP[1], IN[0], IN[0]\n"
" 2: SUB OUT[0], TEMP[0], TEMP[1]\n"
" 3: END\n";
 
handle = graw_parse_fragment_shader(ctx, text);
return handle;
}
 
 
static void draw( void )
{
union pipe_color_union clear_color = { {0,0,0,1} };
int i;
 
printf("Creating %d shaders\n", num_iters);
 
for (i = 0; i < num_iters; i++) {
void *fs = set_fragment_shader();
 
ctx->bind_fs_state(ctx, fs);
 
ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
util_draw_arrays(ctx, PIPE_PRIM_POINTS, 0, 1);
ctx->flush(ctx, NULL, 0);
 
ctx->bind_fs_state(ctx, NULL);
ctx->delete_fs_state(ctx, fs);
}
 
screen->flush_frontbuffer(screen, tex, 0, 0, window);
ctx->destroy(ctx);
 
exit(0);
}
 
 
static void init( void )
{
struct pipe_framebuffer_state fb;
struct pipe_resource templat;
struct pipe_surface surf_tmpl;
int i;
 
/* It's hard to say whether window or screen should be created
* first. Different environments would prefer one or the other.
*
* Also, no easy way of querying supported formats if the screen
* cannot be created first.
*/
for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
screen = graw_create_window_and_screen(0, 0, 300, 300,
formats[i],
&window);
if (window && screen)
break;
}
if (!screen || !window) {
fprintf(stderr, "Unable to create window\n");
exit(1);
}
 
ctx = screen->context_create(screen, NULL);
if (ctx == NULL)
exit(3);
 
templat.target = PIPE_TEXTURE_2D;
templat.format = formats[i];
templat.width0 = WIDTH;
templat.height0 = HEIGHT;
templat.depth0 = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DISPLAY_TARGET);
tex = screen->resource_create(screen, &templat);
if (tex == NULL) {
fprintf(stderr, "Unable to create screen texture!\n");
exit(4);
}
 
surf_tmpl.format = templat.format;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
surf = ctx->create_surface(ctx, tex, &surf_tmpl);
if (surf == NULL) {
fprintf(stderr, "Unable to create tex surface!\n");
exit(5);
}
 
memset(&fb, 0, sizeof fb);
fb.nr_cbufs = 1;
fb.width = WIDTH;
fb.height = HEIGHT;
fb.cbufs[0] = surf;
 
ctx->set_framebuffer_state(ctx, &fb);
{
struct pipe_blend_state blend;
void *handle;
memset(&blend, 0, sizeof blend);
blend.rt[0].colormask = PIPE_MASK_RGBA;
handle = ctx->create_blend_state(ctx, &blend);
ctx->bind_blend_state(ctx, handle);
}
 
{
struct pipe_depth_stencil_alpha_state depthstencil;
void *handle;
memset(&depthstencil, 0, sizeof depthstencil);
handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil);
ctx->bind_depth_stencil_alpha_state(ctx, handle);
}
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
rasterizer.depth_clip = 1;
handle = ctx->create_rasterizer_state(ctx, &rasterizer);
ctx->bind_rasterizer_state(ctx, handle);
}
 
set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000);
set_vertices();
set_vertex_shader();
if (0)
set_fragment_shader();
}
 
 
int main( int argc, char *argv[] )
{
if (argc > 1)
num_iters = atoi(argv[1]);
 
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/tex-srgb.c
0,0 → 1,226
/* Test sRGB texturing.
*/
 
#include "graw_util.h"
 
 
static const int WIDTH = 600;
static const int HEIGHT = 300;
 
static struct graw_info info;
 
static struct pipe_resource *texture;
static struct pipe_sampler_view *linear_sv, *srgb_sv;
 
 
struct vertex {
float position[4];
float color[4];
};
 
static struct vertex vertices1[] =
{
{ { -0.1, -0.9, 0.0, 1.0 },
{ 1, 1, 0, 1 } },
 
{ { -0.1, 0.9, 0.0, 1.0 },
{ 1, 0, 0, 1 } },
 
{ {-0.9, 0.9, 0.0, 1.0 },
{ 0, 0, 0, 1 } },
 
{ {-0.9, -0.9, 0.0, 1.0 },
{ 0, 1, 0, 1 } },
};
 
 
static struct vertex vertices2[] =
{
{ { 0.9, -0.9, 0.0, 1.0 },
{ 1, 1, 0, 1 } },
 
{ { 0.9, 0.9, 0.0, 1.0 },
{ 1, 0, 0, 1 } },
 
{ { 0.1, 0.9, 0.0, 1.0 },
{ 0, 0, 0, 1 } },
 
{ { 0.1, -0.9, 0.0, 1.0 },
{ 0, 1, 0, 1 } },
};
 
 
 
 
static void
set_vertices(struct vertex *verts, unsigned num_verts)
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve);
info.ctx->bind_vertex_elements_state(info.ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof(struct vertex);
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
num_verts * sizeof(struct vertex),
verts);
 
info.ctx->set_vertex_buffers(info.ctx, 0, 1, &vbuf);
}
 
static void set_vertex_shader( void )
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], GENERIC[0]\n"
" 0: MOV OUT[1], IN[1]\n"
" 1: MOV OUT[0], IN[0]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(info.ctx, text);
info.ctx->bind_vs_state(info.ctx, handle);
}
 
static void set_fragment_shader( void )
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], GENERIC[0], PERSPECTIVE\n"
"DCL OUT[0], COLOR\n"
"DCL TEMP[0]\n"
"DCL SAMP[0]\n"
" 0: TXP TEMP[0], IN[0], SAMP[0], 2D\n"
" 1: MOV OUT[0], TEMP[0]\n"
" 2: END\n";
 
handle = graw_parse_fragment_shader(info.ctx, text);
info.ctx->bind_fs_state(info.ctx, handle);
}
 
 
static void draw( void )
{
union pipe_color_union clear_color;
 
clear_color.f[0] = 0.5;
clear_color.f[1] = 0.5;
clear_color.f[2] = 0.5;
clear_color.f[3] = 1.0;
 
info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
 
info.ctx->set_fragment_sampler_views(info.ctx, 1, &linear_sv);
set_vertices(vertices1, 4);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, 4);
 
info.ctx->set_fragment_sampler_views(info.ctx, 1, &srgb_sv);
set_vertices(vertices2, 4);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, 4);
 
info.ctx->flush(info.ctx, NULL, 0);
 
graw_util_flush_front(&info);
}
 
 
static void init_tex( void )
{
#define SIZE 64
ubyte tex2d[SIZE][SIZE][4];
int s, t;
 
for (s = 0; s < SIZE; s++) {
for (t = 0; t < SIZE; t++) {
tex2d[t][s][0] = 0;
tex2d[t][s][1] = s * 255 / SIZE;
tex2d[t][s][2] = t * 255 / SIZE;
tex2d[t][s][3] = 255;
}
}
 
texture = graw_util_create_tex2d(&info, SIZE, SIZE,
PIPE_FORMAT_B8G8R8A8_UNORM, tex2d);
 
{
void *sampler;
sampler = graw_util_create_simple_sampler(&info,
PIPE_TEX_WRAP_REPEAT,
PIPE_TEX_FILTER_NEAREST);
info.ctx->bind_fragment_sampler_states(info.ctx, 1, &sampler);
}
 
/* linear sampler view */
{
struct pipe_sampler_view sv_temp;
memset(&sv_temp, 0, sizeof sv_temp);
sv_temp.format = PIPE_FORMAT_B8G8R8A8_UNORM;
sv_temp.texture = texture;
sv_temp.swizzle_r = PIPE_SWIZZLE_RED;
sv_temp.swizzle_g = PIPE_SWIZZLE_GREEN;
sv_temp.swizzle_b = PIPE_SWIZZLE_BLUE;
sv_temp.swizzle_a = PIPE_SWIZZLE_ALPHA;
linear_sv = info.ctx->create_sampler_view(info.ctx, texture, &sv_temp);
if (linear_sv == NULL)
exit(0);
}
 
/* srgb sampler view */
{
struct pipe_sampler_view sv_temp;
memset(&sv_temp, 0, sizeof sv_temp);
sv_temp.format = PIPE_FORMAT_B8G8R8A8_SRGB;
sv_temp.texture = texture;
sv_temp.swizzle_r = PIPE_SWIZZLE_RED;
sv_temp.swizzle_g = PIPE_SWIZZLE_GREEN;
sv_temp.swizzle_b = PIPE_SWIZZLE_BLUE;
sv_temp.swizzle_a = PIPE_SWIZZLE_ALPHA;
srgb_sv = info.ctx->create_sampler_view(info.ctx, texture, &sv_temp);
if (srgb_sv == NULL)
exit(0);
}
#undef SIZE
}
 
static void init( void )
{
if (!graw_util_create_window(&info, WIDTH, HEIGHT, 1, FALSE))
exit(1);
 
graw_util_default_state(&info, FALSE);
graw_util_viewport(&info, 0, 0, WIDTH, HEIGHT, 30, 10000);
 
init_tex();
 
set_vertex_shader();
set_fragment_shader();
}
 
 
int main( int argc, char *argv[] )
{
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/tex-swizzle.c
0,0 → 1,228
/* Test texture swizzles */
 
#include <stdio.h>
 
#include "graw_util.h"
 
 
static struct graw_info info;
 
static struct pipe_resource *texture = NULL;
static struct pipe_sampler_view *sv = NULL;
static void *sampler = NULL;
 
static const int WIDTH = 300;
static const int HEIGHT = 300;
 
struct vertex {
float position[4];
float color[4];
};
 
static struct vertex vertices[] =
{
{ { 0.9, -0.9, 0.0, 1.0 },
{ 1, 0, 0, 1 } },
 
{ { 0.9, 0.9, 0.0, 1.0 },
{ 1, 1, 0, 1 } },
 
{ {-0.9, 0.9, 0.0, 1.0 },
{ 0, 1, 0, 1 } },
 
{ {-0.9, -0.9, 0.0, 1.0 },
{ 0, 0, 0, 1 } },
};
 
 
static void set_vertices(void)
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve);
info.ctx->bind_vertex_elements_state(info.ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof(struct vertex);
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
info.ctx->set_vertex_buffers(info.ctx, 0, 1, &vbuf);
}
 
static void set_vertex_shader(void)
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], GENERIC[0]\n"
" 0: MOV OUT[1], IN[1]\n"
" 1: MOV OUT[0], IN[0]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(info.ctx, text);
info.ctx->bind_vs_state(info.ctx, handle);
}
 
static void set_fragment_shader(void)
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], GENERIC[0], PERSPECTIVE\n"
"DCL OUT[0], COLOR\n"
"DCL SAMP[0]\n"
" 0: TXP OUT[0], IN[0], SAMP[0], 2D\n"
" 2: END\n";
 
handle = graw_parse_fragment_shader(info.ctx, text);
info.ctx->bind_fs_state(info.ctx, handle);
}
 
 
static void draw(void)
{
union pipe_color_union clear_color;
 
clear_color.f[0] = 0.5;
clear_color.f[1] = 0.5;
clear_color.f[2] = 0.5;
clear_color.f[3] = 1.0;
 
info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, 4);
info.ctx->flush(info.ctx, NULL, 0);
 
graw_util_flush_front(&info);
}
 
 
 
static void
init_tex(const unsigned swizzle[4])
{
#define SIZE 256
struct pipe_sampler_view sv_template;
ubyte tex2d[SIZE][SIZE][4];
int s, t;
 
for (s = 0; s < SIZE; s++) {
for (t = 0; t < SIZE; t++) {
tex2d[t][s][0] = 0; /*B*/
tex2d[t][s][1] = t; /*G*/
tex2d[t][s][2] = s; /*R*/
tex2d[t][s][3] = 1; /*A*/
}
}
 
texture = graw_util_create_tex2d(&info, SIZE, SIZE,
PIPE_FORMAT_B8G8R8A8_UNORM, tex2d);
 
memset(&sv_template, 0, sizeof sv_template);
sv_template.format = texture->format;
sv_template.texture = texture;
sv_template.swizzle_r = swizzle[0];
sv_template.swizzle_g = swizzle[1];
sv_template.swizzle_b = swizzle[2];
sv_template.swizzle_a = swizzle[3];
sv = info.ctx->create_sampler_view(info.ctx, texture, &sv_template);
if (sv == NULL)
exit(5);
 
info.ctx->set_fragment_sampler_views(info.ctx, 1, &sv);
 
sampler = graw_util_create_simple_sampler(&info,
PIPE_TEX_WRAP_REPEAT,
PIPE_TEX_FILTER_NEAREST);
 
info.ctx->bind_fragment_sampler_states(info.ctx, 1, &sampler);
#undef SIZE
}
 
 
static void
init(const unsigned swizzle[4])
{
if (!graw_util_create_window(&info, WIDTH, HEIGHT, 1, FALSE))
exit(1);
 
graw_util_default_state(&info, FALSE);
graw_util_viewport(&info, 0, 0, WIDTH, HEIGHT, 30, 10000);
 
init_tex(swizzle);
 
set_vertices();
set_vertex_shader();
set_fragment_shader();
}
 
 
static unsigned
char_to_swizzle(char c)
{
switch (c) {
case 'r':
return PIPE_SWIZZLE_RED;
case 'g':
return PIPE_SWIZZLE_GREEN;
case 'b':
return PIPE_SWIZZLE_BLUE;
case 'a':
return PIPE_SWIZZLE_ALPHA;
case '0':
return PIPE_SWIZZLE_ZERO;
case '1':
return PIPE_SWIZZLE_ONE;
default:
return PIPE_SWIZZLE_RED;
}
}
 
 
int main(int argc, char *argv[])
{
const char swizzle_names[] = "rgba01";
uint swizzle[4];
int i;
 
swizzle[0] = PIPE_SWIZZLE_RED;
swizzle[1] = PIPE_SWIZZLE_GREEN;
swizzle[2] = PIPE_SWIZZLE_BLUE;
swizzle[3] = PIPE_SWIZZLE_ALPHA;
 
for (i = 1; i < argc; i++) {
swizzle[i-1] = char_to_swizzle(argv[i][0]);
}
 
printf("Example:\n");
printf(" tex-swizzle r 0 g 1\n");
printf("Current swizzle = ");
for (i = 0; i < 4; i++) {
printf("%c", swizzle_names[swizzle[i]]);
}
printf("\n");
 
init(swizzle);
 
graw_set_display_func(draw);
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/tgsi_dump.gdb
0,0 → 1,6
define tgsi_dump
set $tokens=(const struct tgsi_header *)($arg0)
set $nr_tokens = $tokens->HeaderSize + $tokens->BodySize
set $tokens_end = &$tokens[$nr_tokens]
dump memory tgsi_dump.bin $tokens $tokens_end
end
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/tri-gs.c
0,0 → 1,280
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
 
#include <stdio.h>
#include "state_tracker/graw.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
 
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
#include "util/u_inlines.h"
 
enum pipe_format formats[] = {
PIPE_FORMAT_RGBA8888_UNORM,
PIPE_FORMAT_BGRA8888_UNORM,
PIPE_FORMAT_NONE
};
 
static const int WIDTH = 300;
static const int HEIGHT = 300;
 
static struct pipe_screen *screen = NULL;
static struct pipe_context *ctx = NULL;
static struct pipe_surface *surf = NULL;
static struct pipe_resource *tex = NULL;
static void *window = NULL;
 
struct vertex {
float position[4];
float color[4];
};
 
static struct vertex vertices[4] =
{
{ { 0.0f, -0.9f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 0.0f, 1.0f }
},
{ { -0.9f, 0.9f, 0.0f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 1.0f }
},
{ { 0.9f, 0.9f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 1.0f, 1.0f }
}
};
 
 
 
 
static void set_viewport( float x, float y,
float width, float height,
float near, float far)
{
float z = far;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)far - (float)near) / 2.0f;
struct pipe_viewport_state vp;
 
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.scale[3] = 1.0f;
 
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.translate[3] = 0.0f;
 
ctx->set_viewport_states( ctx, 0, 1, &vp );
}
 
static void set_vertices( void )
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = ctx->create_vertex_elements_state(ctx, 2, ve);
ctx->bind_vertex_elements_state(ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof( struct vertex );
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
ctx->set_vertex_buffers(ctx, 0, 1, &vbuf);
}
 
static void set_vertex_shader( void )
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], COLOR\n"
" 0: MOV OUT[1], IN[1]\n"
" 1: MOV OUT[0], IN[0]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(ctx, text);
ctx->bind_vs_state(ctx, handle);
}
 
static void set_fragment_shader( void )
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], COLOR, LINEAR\n"
"DCL OUT[0], COLOR\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: END\n";
 
handle = graw_parse_fragment_shader(ctx, text);
ctx->bind_fs_state(ctx, handle);
}
 
 
static void set_geometry_shader( void )
{
void *handle;
const char *text =
"GEOM\n"
"PROPERTY GS_INPUT_PRIMITIVE TRIANGLES\n"
"PROPERTY GS_OUTPUT_PRIMITIVE TRIANGLE_STRIP\n"
"DCL IN[][0], POSITION, CONSTANT\n"
"DCL IN[][1], COLOR, CONSTANT\n"
"DCL OUT[0], POSITION, CONSTANT\n"
"DCL OUT[1], COLOR, CONSTANT\n"
"0:MOV OUT[0], IN[0][0]\n"
"1:MOV OUT[1], IN[0][1]\n"
"2:EMIT\n"
"3:MOV OUT[0], IN[1][0]\n"
"4:MOV OUT[1], IN[0][1]\n" /* copy color from input vertex 0 */
"5:EMIT\n"
"6:MOV OUT[0], IN[2][0]\n"
"7:MOV OUT[1], IN[2][1]\n"
"8:EMIT\n"
"9:ENDPRIM\n"
"10:END\n";
 
handle = graw_parse_geometry_shader(ctx, text);
ctx->bind_gs_state(ctx, handle);
}
 
static void draw( void )
{
union pipe_color_union clear_color = { {1,0,1,1} };
 
ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3);
ctx->flush(ctx, NULL, 0);
 
screen->flush_frontbuffer(screen, tex, 0, 0, window);
}
 
 
static void init( void )
{
struct pipe_framebuffer_state fb;
struct pipe_resource templat;
struct pipe_surface surf_tmpl;
int i;
 
/* It's hard to say whether window or screen should be created
* first. Different environments would prefer one or the other.
*
* Also, no easy way of querying supported formats if the screen
* cannot be created first.
*/
for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
screen = graw_create_window_and_screen(0, 0, 300, 300,
formats[i],
&window);
if (window && screen)
break;
}
if (!screen || !window) {
fprintf(stderr, "Unable to create window\n");
exit(1);
}
ctx = screen->context_create(screen, NULL);
if (ctx == NULL)
exit(3);
 
templat.target = PIPE_TEXTURE_2D;
templat.format = formats[i];
templat.width0 = WIDTH;
templat.height0 = HEIGHT;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DISPLAY_TARGET);
tex = screen->resource_create(screen,
&templat);
if (tex == NULL)
exit(4);
 
surf_tmpl.format = templat.format;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
surf = ctx->create_surface(ctx, tex, &surf_tmpl);
if (surf == NULL)
exit(5);
 
memset(&fb, 0, sizeof fb);
fb.nr_cbufs = 1;
fb.width = WIDTH;
fb.height = HEIGHT;
fb.cbufs[0] = surf;
 
ctx->set_framebuffer_state(ctx, &fb);
{
struct pipe_blend_state blend;
void *handle;
memset(&blend, 0, sizeof blend);
blend.rt[0].colormask = PIPE_MASK_RGBA;
handle = ctx->create_blend_state(ctx, &blend);
ctx->bind_blend_state(ctx, handle);
}
 
{
struct pipe_depth_stencil_alpha_state depthstencil;
void *handle;
memset(&depthstencil, 0, sizeof depthstencil);
handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil);
ctx->bind_depth_stencil_alpha_state(ctx, handle);
}
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
rasterizer.depth_clip = 1;
handle = ctx->create_rasterizer_state(ctx, &rasterizer);
ctx->bind_rasterizer_state(ctx, handle);
}
 
set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000);
set_vertices();
set_vertex_shader();
set_fragment_shader();
set_geometry_shader();
}
 
 
int main( int argc, char *argv[] )
{
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/tri-instanced.c
0,0 → 1,355
/*
* Test draw instancing.
*/
 
#include <stdio.h>
#include <string.h>
 
#include "state_tracker/graw.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
 
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
#include "util/u_inlines.h"
 
 
enum pipe_format formats[] = {
PIPE_FORMAT_RGBA8888_UNORM,
PIPE_FORMAT_BGRA8888_UNORM,
PIPE_FORMAT_NONE
};
 
static const int WIDTH = 300;
static const int HEIGHT = 300;
 
static struct pipe_screen *screen = NULL;
static struct pipe_context *ctx = NULL;
static struct pipe_surface *surf = NULL;
static struct pipe_resource *tex = NULL;
static void *window = NULL;
 
struct vertex {
float position[4];
float color[4];
};
 
 
static int draw_elements = 0;
 
 
/**
* Vertex data.
* Each vertex has three attributes: position, color and translation.
* The translation attribute is a per-instance attribute. See
* "instance_divisor" below.
*/
static struct vertex vertices[4] =
{
{
{ 0.0f, -0.3f, 0.0f, 1.0f }, /* pos */
{ 1.0f, 0.0f, 0.0f, 1.0f } /* color */
},
{
{ -0.2f, 0.3f, 0.0f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 1.0f }
},
{
{ 0.2f, 0.3f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 1.0f, 1.0f }
}
};
 
 
#define NUM_INST 5
 
static float inst_data[NUM_INST][4] =
{
{ -0.50f, 0.4f, 0.0f, 0.0f },
{ -0.25f, 0.1f, 0.0f, 0.0f },
{ 0.00f, 0.2f, 0.0f, 0.0f },
{ 0.25f, 0.1f, 0.0f, 0.0f },
{ 0.50f, 0.3f, 0.0f, 0.0f }
};
 
 
static ushort indices[3] = { 0, 2, 1 };
 
 
static void set_viewport( float x, float y,
float width, float height,
float near, float far)
{
float z = far;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)far - (float)near) / 2.0f;
struct pipe_viewport_state vp;
 
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.scale[3] = 1.0f;
 
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.translate[3] = 0.0f;
 
ctx->set_viewport_states( ctx, 0, 1, &vp );
}
 
 
static void set_vertices( void )
{
struct pipe_vertex_element ve[3];
struct pipe_vertex_buffer vbuf[2];
struct pipe_index_buffer ibuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
/* pos */
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[0].vertex_buffer_index = 0;
 
/* color */
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].vertex_buffer_index = 0;
 
/* per-instance info */
ve[2].src_offset = 0;
ve[2].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[2].vertex_buffer_index = 1;
ve[2].instance_divisor = 1;
 
handle = ctx->create_vertex_elements_state(ctx, 3, ve);
ctx->bind_vertex_elements_state(ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
/* vertex data */
vbuf[0].stride = sizeof( struct vertex );
vbuf[0].buffer_offset = 0;
vbuf[0].buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
/* instance data */
vbuf[1].stride = sizeof( inst_data[0] );
vbuf[1].buffer_offset = 0;
vbuf[1].buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(inst_data),
inst_data);
 
ctx->set_vertex_buffers(ctx, 0, 2, vbuf);
 
/* index data */
ibuf.buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_INDEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(indices),
indices);
ibuf.offset = 0;
ibuf.index_size = 2;
 
ctx->set_index_buffer(ctx, &ibuf);
 
}
 
static void set_vertex_shader( void )
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL IN[2]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], COLOR\n"
" 0: MOV OUT[1], IN[1]\n"
" 1: ADD OUT[0], IN[0], IN[2]\n" /* add instance pos to vertex pos */
" 2: END\n";
 
handle = graw_parse_vertex_shader(ctx, text);
ctx->bind_vs_state(ctx, handle);
}
 
static void set_fragment_shader( void )
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], COLOR, LINEAR\n"
"DCL OUT[0], COLOR\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: END\n";
 
handle = graw_parse_fragment_shader(ctx, text);
ctx->bind_fs_state(ctx, handle);
}
 
 
static void draw( void )
{
union pipe_color_union clear_color = { {1,0,1,1} };
struct pipe_draw_info info;
 
ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
 
util_draw_init_info(&info);
info.indexed = (draw_elements != 0);
info.mode = PIPE_PRIM_TRIANGLES;
info.start = 0;
info.count = 3;
/* draw NUM_INST triangles */
info.instance_count = NUM_INST;
 
ctx->draw_vbo(ctx, &info);
 
ctx->flush(ctx, NULL, 0);
 
graw_save_surface_to_file(ctx, surf, NULL);
 
screen->flush_frontbuffer(screen, tex, 0, 0, window);
}
 
 
static void init( void )
{
struct pipe_framebuffer_state fb;
struct pipe_resource templat;
struct pipe_surface surf_tmpl;
int i;
 
/* It's hard to say whether window or screen should be created
* first. Different environments would prefer one or the other.
*
* Also, no easy way of querying supported formats if the screen
* cannot be created first.
*/
for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
screen = graw_create_window_and_screen(0, 0, 300, 300,
formats[i],
&window);
if (window && screen)
break;
}
if (!screen || !window) {
fprintf(stderr, "Unable to create window\n");
exit(1);
}
ctx = screen->context_create(screen, NULL);
if (ctx == NULL)
exit(3);
 
templat.target = PIPE_TEXTURE_2D;
templat.format = formats[i];
templat.width0 = WIDTH;
templat.height0 = HEIGHT;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DISPLAY_TARGET);
tex = screen->resource_create(screen,
&templat);
if (tex == NULL)
exit(4);
 
surf_tmpl.format = templat.format;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
surf = ctx->create_surface(ctx, tex, &surf_tmpl);
if (surf == NULL)
exit(5);
 
memset(&fb, 0, sizeof fb);
fb.nr_cbufs = 1;
fb.width = WIDTH;
fb.height = HEIGHT;
fb.cbufs[0] = surf;
 
ctx->set_framebuffer_state(ctx, &fb);
{
struct pipe_blend_state blend;
void *handle;
memset(&blend, 0, sizeof blend);
blend.rt[0].colormask = PIPE_MASK_RGBA;
handle = ctx->create_blend_state(ctx, &blend);
ctx->bind_blend_state(ctx, handle);
}
 
{
struct pipe_depth_stencil_alpha_state depthstencil;
void *handle;
memset(&depthstencil, 0, sizeof depthstencil);
handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil);
ctx->bind_depth_stencil_alpha_state(ctx, handle);
}
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
rasterizer.depth_clip = 1;
handle = ctx->create_rasterizer_state(ctx, &rasterizer);
ctx->bind_rasterizer_state(ctx, handle);
}
 
set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000);
set_vertices();
set_vertex_shader();
set_fragment_shader();
}
 
 
static void options(int argc, char *argv[])
{
int i;
 
for (i = 1; i < argc;) {
if (graw_parse_args(&i, argc, argv)) {
continue;
}
if (strcmp(argv[i], "-e") == 0) {
draw_elements = 1;
i++;
}
else {
i++;
}
}
if (draw_elements)
printf("Using pipe_context::draw_elements_instanced()\n");
else
printf("Using pipe_context::draw_arrays_instanced()\n");
}
 
 
int main( int argc, char *argv[] )
{
options(argc, argv);
 
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/tri.c
0,0 → 1,171
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
 
#include <stdio.h>
#include "graw_util.h"
 
static struct graw_info info;
 
static const int WIDTH = 300;
static const int HEIGHT = 300;
 
 
struct vertex {
float position[4];
float color[4];
};
 
static boolean FlatShade = FALSE;
 
 
static struct vertex vertices[3] =
{
{
{ 0.0f, -0.9f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 0.0f, 1.0f }
},
{
{ -0.9f, 0.9f, 0.0f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 1.0f }
},
{
{ 0.9f, 0.9f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 1.0f, 1.0f }
}
};
 
 
static void set_vertices( void )
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = info.ctx->create_vertex_elements_state(info.ctx, 2, ve);
info.ctx->bind_vertex_elements_state(info.ctx, handle);
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof( struct vertex );
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
info.ctx->set_vertex_buffers(info.ctx, 0, 1, &vbuf);
}
 
 
static void set_vertex_shader( void )
{
void *handle;
const char *text =
"VERT\n"
"DCL IN[0]\n"
"DCL IN[1]\n"
"DCL OUT[0], POSITION\n"
"DCL OUT[1], COLOR\n"
" 0: MOV OUT[1], IN[1]\n"
" 1: MOV OUT[0], IN[0]\n"
" 2: END\n";
 
handle = graw_parse_vertex_shader(info.ctx, text);
info.ctx->bind_vs_state(info.ctx, handle);
}
 
 
static void set_fragment_shader( void )
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], COLOR, LINEAR\n"
"DCL OUT[0], COLOR\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: END\n";
 
handle = graw_parse_fragment_shader(info.ctx, text);
info.ctx->bind_fs_state(info.ctx, handle);
}
 
 
static void draw( void )
{
union pipe_color_union clear_color = { {1,0,1,1} };
 
info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
util_draw_arrays(info.ctx, PIPE_PRIM_TRIANGLES, 0, 3);
info.ctx->flush(info.ctx, NULL, 0);
 
graw_save_surface_to_file(info.ctx, info.color_surf[0], NULL);
 
graw_util_flush_front(&info);
}
 
 
static void init( void )
{
if (!graw_util_create_window(&info, WIDTH, HEIGHT, 1, FALSE))
exit(1);
 
graw_util_default_state(&info, FALSE);
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
rasterizer.flatshade = FlatShade;
rasterizer.depth_clip = 1;
handle = info.ctx->create_rasterizer_state(info.ctx, &rasterizer);
info.ctx->bind_rasterizer_state(info.ctx, handle);
}
 
 
graw_util_viewport(&info, 0, 0, WIDTH, HEIGHT, 30, 1000);
 
set_vertices();
set_vertex_shader();
set_fragment_shader();
}
 
static void args(int argc, char *argv[])
{
int i;
 
for (i = 1; i < argc; ) {
if (graw_parse_args(&i, argc, argv)) {
/* ok */
}
else if (strcmp(argv[i], "-f") == 0) {
FlatShade = TRUE;
i++;
}
else {
printf("Invalid arg %s\n", argv[i]);
exit(1);
}
}
}
 
int main( int argc, char *argv[] )
{
args(argc, argv);
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-abs.sh
0,0 → 1,15
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
 
IMM FLT32 { 0.2, 0.2, 0.0, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
ABS OUT[0], TEMP[0]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-add.sh
0,0 → 1,13
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
IMM FLT32 { 0.2, -0.1, 0.0, 0.0 }
 
ADD OUT[0], IN[0], IMM[0]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-arl.sh
0,0 → 1,23
VERT
 
DCL IN[0]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
DCL ADDR[0]
 
IMM FLT32 { 3.0, 1.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 0.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 1.0, 1.0 }
 
MOV OUT[0], IN[0]
MUL TEMP[0], IN[0], IMM[0]
ARL ADDR[0].x, TEMP[0]
MOV OUT[1], IMM[ADDR[0].x + 3]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-arr.sh
0,0 → 1,23
VERT
 
DCL IN[0]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
DCL ADDR[0]
 
IMM FLT32 { 3.0, 1.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 0.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 1.0, 1.0 }
 
MOV OUT[0], IN[0]
MUL TEMP[0], IN[0], IMM[0]
ARR ADDR[0].x, TEMP[0]
MOV OUT[1], IMM[ADDR[0].x + 3]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-cb-1d.sh
0,0 → 1,16
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL CONST[1]
DCL CONST[3]
DCL TEMP[0..1]
 
MOV OUT[0], IN[0]
ADD TEMP[0], IN[1], CONST[1]
RCP TEMP[1], CONST[3].xxxx
MUL OUT[1], TEMP[0], TEMP[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-cb-2d.sh
0,0 → 1,12
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL CONST[1][1..2]
 
MOV OUT[0], IN[0]
MAD OUT[1], IN[1], CONST[1][2], CONST[1][1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-dp3.sh
0,0 → 1,16
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
 
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
 
DP3 TEMP[0].xy, IN[0], IN[0]
MOV TEMP[0].zw, IMM[0]
MUL OUT[0], IN[0], TEMP[0]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-dp4.sh
0,0 → 1,16
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
 
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
 
DP4 TEMP[0].xy, IN[0], IN[0]
MOV TEMP[0].zw, IMM[0]
MUL OUT[0], IN[0], TEMP[0]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-dst.sh
0,0 → 1,11
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
MOV OUT[0], IN[0]
DST OUT[1], IN[1], IN[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-ex2.sh
0,0 → 1,18
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0..1]
 
IMM FLT32 { 0.3, 0.3, 0.3, 1.0 }
 
EX2 TEMP[0], IN[0]
EX2 TEMP[1], IN[1].yyyy
MUL TEMP[0], TEMP[0], IMM[0]
MOV OUT[0], IN[0]
MUL OUT[1], TEMP[0], TEMP[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-flr.sh
0,0 → 1,23
VERT
 
DCL IN[0]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
DCL ADDR[0]
 
IMM FLT32 { 3.0, 1.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 0.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 0.0, 1.0, 1.0 }
IMM FLT32 { 1.0, 1.0, 0.0, 1.0 }
IMM FLT32 { 0.0, 1.0, 1.0, 1.0 }
 
MOV OUT[0], IN[0]
MUL TEMP[0], IN[0], IMM[0]
FLR ADDR[0].x, TEMP[0]
MOV OUT[1], IMM[ADDR[0].x + 3]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-frc.sh
0,0 → 1,15
VERT
 
DCL IN[0]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 2.7, 3.1, 4.5, 1.0 }
 
MUL TEMP[0], IN[0].xyxw, IMM[0]
MOV OUT[0], IN[0]
FRC OUT[1], TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-lg2.sh
0,0 → 1,18
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
IMM FLT32 { 0.5, 0.0, 0.0, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
LG2 TEMP[0].x, TEMP[0].xxxx
ADD OUT[0], TEMP[0], IMM[1]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-lit.sh
0,0 → 1,11
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
MOV OUT[0], IN[0]
LIT OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-lrp.sh
0,0 → 1,14
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
ABS TEMP[0], IN[0]
MOV OUT[0], IN[0]
LRP OUT[1], TEMP[0], IN[1].xxxx, IN[1].yyyy
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-mad.sh
0,0 → 1,14
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
IMM FLT32 { 0.5, 1.0, 1.0, 1.0 }
IMM FLT32 { 0.5, 0.0, 0.0, 0.0 }
 
MAD OUT[0], IN[0], IMM[0], IMM[1]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-max.sh
0,0 → 1,13
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
IMM FLT32 { 0.5, 0.5, 0.5, 0.0 }
 
MOV OUT[0], IN[0]
MAX OUT[1], IN[1], IMM[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-min.sh
0,0 → 1,13
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
IMM FLT32 { 0.5, 0.5, 0.5, 0.0 }
 
MOV OUT[0], IN[0]
MIN OUT[1], IN[1], IMM[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-mov.sh
0,0 → 1,11
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
MOV OUT[0], IN[0]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-mul.sh
0,0 → 1,13
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
IMM FLT32 { 0.6, 0.6, 1.0, 1.0 }
 
MUL OUT[0], IN[0], IMM[0]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-rcp.sh
0,0 → 1,18
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
IMM[0] FLT32 { 1.0, 0.0, 0.0, 0.0 }
IMM[1] FLT32 { 1.5, 0.0, 0.0, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
RCP TEMP[0].x, TEMP[0].xxxx
SUB OUT[0], TEMP[0], IMM[1]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-rsq.sh
0,0 → 1,18
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 1.0, 0.0, 0.0, 0.0 }
IMM FLT32 { 1.5, 0.0, 0.0, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
RSQ TEMP[0].x, TEMP[0].xxxx
SUB OUT[0], TEMP[0], IMM[1]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-sge.sh
0,0 → 1,16
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { -0.1, -0.1, 1.0, 0.0 }
 
SGE TEMP[0], IN[0], IMM[0]
MOV OUT[0], IN[0]
MUL OUT[1], IN[1], TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-slt.sh
0,0 → 1,16
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
DCL TEMP[0]
 
IMM FLT32 { 0.6, 0.6, 0.0, 0.0 }
 
SLT TEMP[0], IN[0], IMM[0]
MOV OUT[0], IN[0]
MUL OUT[1], IN[1], TEMP[0]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-srcmod-abs.sh
0,0 → 1,15
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
 
IMM FLT32 { 0.1, 0.1, 0.0, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
MOV OUT[0], |TEMP[0]|
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-srcmod-absneg.sh
0,0 → 1,16
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
 
IMM FLT32 { -0.2, -0.2, 0.0, 0.0 }
 
ADD TEMP[0], IN[0], IMM[0]
MOV OUT[0].xy, -|TEMP[0]|
MOV OUT[0].zw, IN[0]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-srcmod-neg.sh
0,0 → 1,12
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
MOV OUT[0].xy, -IN[0]
MOV OUT[0].zw, IN[0]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-srcmod-swz.sh
0,0 → 1,11
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
MOV OUT[0], IN[0].yxzw
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-sub.sh
0,0 → 1,13
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
IMM FLT32 { 0.1, 0.1, 0.0, 0.0 }
 
SUB OUT[0], IN[0], IMM[0]
MOV OUT[1], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-uadd.sh
0,0 → 1,9
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], GENERIC[0]
DCL OUT[1], GENERIC[1]
IMM[0] INT32 {1, 0, 0, 0}
MOV OUT[0], IN[0]
UADD OUT[1].x, IN[1].xxxx, IMM[0].xxxx
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vertex-shader/vert-xpd.sh
0,0 → 1,11
VERT
 
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
 
MOV OUT[0], IN[0]
XPD OUT[1], IN[0], IN[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/graw/vs-test.c
0,0 → 1,509
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
 
#include "state_tracker/graw.h"
#include "pipe/p_screen.h"
#include "pipe/p_context.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/p_state.h"
#include "pipe/p_defines.h"
 
#include <stdio.h> /* for fread(), etc */
 
#include "util/u_inlines.h"
#include "util/u_memory.h" /* Offset() */
#include "util/u_draw_quad.h"
#include "util/u_box.h"
 
static const char *filename = NULL;
unsigned show_fps = 0;
 
 
static void usage(char *name)
{
fprintf(stderr, "usage: %s [ options ] shader_filename\n", name);
#ifndef _WIN32
fprintf(stderr, "\n" );
fprintf(stderr, "options:\n");
fprintf(stderr, " -fps show frames per second\n");
#endif
}
 
 
enum pipe_format formats[] = {
PIPE_FORMAT_RGBA8888_UNORM,
PIPE_FORMAT_BGRA8888_UNORM,
PIPE_FORMAT_NONE
};
 
static const int WIDTH = 250;
static const int HEIGHT = 250;
 
static struct pipe_screen *screen = NULL;
static struct pipe_context *ctx = NULL;
static struct pipe_resource *rttex = NULL;
static struct pipe_resource *constbuf = NULL;
static struct pipe_surface *surf = NULL;
static struct pipe_sampler_view *sv = NULL;
static void *sampler = NULL;
static void *window = NULL;
static struct pipe_resource *samptex = NULL;
 
struct vertex {
float position[4];
float color[3];
};
 
/* Draw a regular mesh
*/
#define MESH_SZ 16
static struct vertex vertices[MESH_SZ * MESH_SZ];
 
static float constants[] =
{ 0.4, 0, 0, 1,
1, 1, 1, 1,
2, 2, 2, 2,
4, 8, 16, 32,
 
3, 0, 0, 0,
0, .5, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
 
1, 0, 0, 0.5,
0, 1, 0, 0.5,
0, 0, 1, 0,
0, 0, 0, 1,
};
 
static void init_fs_constbuf( void )
{
struct pipe_resource templat;
struct pipe_box box;
 
templat.target = PIPE_BUFFER;
templat.format = PIPE_FORMAT_R8_UNORM;
templat.width0 = sizeof(constants);
templat.height0 = 1;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = PIPE_BIND_CONSTANT_BUFFER;
 
constbuf = screen->resource_create(screen,
&templat);
if (constbuf == NULL)
exit(4);
 
 
u_box_2d(0,0,sizeof(constants),1, &box);
 
ctx->transfer_inline_write(ctx,
constbuf,
0,
PIPE_TRANSFER_WRITE,
&box,
constants,
sizeof constants,
sizeof constants);
 
 
pipe_set_constant_buffer(ctx,
PIPE_SHADER_VERTEX, 0,
constbuf);
}
 
 
static void set_viewport( float x, float y,
float width, float height,
float near, float far)
{
float z = far;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)far - (float)near) / 2.0f;
struct pipe_viewport_state vp;
 
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.scale[3] = 1.0f;
 
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.translate[3] = 0.0f;
 
ctx->set_viewport_states( ctx, 0, 1, &vp );
}
 
static void set_vertices( void )
{
struct pipe_vertex_element ve[2];
struct pipe_vertex_buffer vbuf;
void *handle;
int x,y;
 
memset(ve, 0, sizeof ve);
 
ve[0].src_offset = Offset(struct vertex, position);
ve[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
ve[1].src_offset = Offset(struct vertex, color);
ve[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
handle = ctx->create_vertex_elements_state(ctx, 2, ve);
ctx->bind_vertex_elements_state(ctx, handle);
 
for (x = 0; x < MESH_SZ; x++) {
for (y = 0; y < MESH_SZ; y++) {
int i = y * MESH_SZ + x;
vertices[i].position[0] = ((float)x)/MESH_SZ * 2.0 - 1.0;
vertices[i].position[1] = ((float)y)/MESH_SZ * 2.0 - 1.0;
vertices[i].position[2] = 0;
vertices[i].position[3] = 1.0;
 
vertices[i].color[0] = .5;
vertices[i].color[1] = (float)x / (float)MESH_SZ;
vertices[i].color[2] = (float)y / (float)MESH_SZ;
}
}
 
memset(&vbuf, 0, sizeof vbuf);
 
vbuf.stride = sizeof( struct vertex );
vbuf.buffer_offset = 0;
vbuf.buffer = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC,
sizeof(vertices),
vertices);
 
ctx->set_vertex_buffers(ctx, 0, 1, &vbuf);
}
 
static void set_vertex_shader( void )
{
FILE *f;
char buf[50000];
void *handle;
int sz;
 
if ((f = fopen(filename, "r")) == NULL) {
fprintf(stderr, "Couldn't open %s\n", filename);
exit(1);
}
 
sz = fread(buf, 1, sizeof(buf), f);
if (!feof(f)) {
printf("file too long\n");
exit(1);
}
printf("%.*s\n", sz, buf);
buf[sz] = 0;
 
handle = graw_parse_vertex_shader(ctx, buf);
ctx->bind_vs_state(ctx, handle);
fclose(f);
}
 
static void set_fragment_shader( void )
{
void *handle;
const char *text =
"FRAG\n"
"DCL IN[0], COLOR, LINEAR\n"
"DCL OUT[0], COLOR\n"
" 0: MOV OUT[0], IN[0]\n"
" 1: END\n";
 
handle = graw_parse_fragment_shader(ctx, text);
ctx->bind_fs_state(ctx, handle);
}
 
 
 
static void draw( void )
{
union pipe_color_union clear_color = { {.1,.3,.5,0} };
 
ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
util_draw_arrays(ctx, PIPE_PRIM_POINTS, 0, Elements(vertices));
ctx->flush(ctx, NULL, 0);
 
graw_save_surface_to_file(ctx, surf, NULL);
 
screen->flush_frontbuffer(screen, rttex, 0, 0, window);
}
 
#define SIZE 16
 
static void init_tex( void )
{
struct pipe_sampler_view sv_template;
struct pipe_sampler_state sampler_desc;
struct pipe_resource templat;
struct pipe_box box;
ubyte tex2d[SIZE][SIZE][4];
int s, t;
 
#if (SIZE != 2)
for (s = 0; s < SIZE; s++) {
for (t = 0; t < SIZE; t++) {
if (0) {
int x = (s ^ t) & 1;
tex2d[t][s][0] = (x) ? 0 : 63;
tex2d[t][s][1] = (x) ? 0 : 128;
tex2d[t][s][2] = 0;
tex2d[t][s][3] = 0xff;
}
else {
int x = ((s ^ t) >> 2) & 1;
tex2d[t][s][0] = s*255/(SIZE-1);
tex2d[t][s][1] = t*255/(SIZE-1);
tex2d[t][s][2] = (x) ? 0 : 128;
tex2d[t][s][3] = 0xff;
}
}
}
#else
tex2d[0][0][0] = 0;
tex2d[0][0][1] = 255;
tex2d[0][0][2] = 255;
tex2d[0][0][3] = 0;
 
tex2d[0][1][0] = 0;
tex2d[0][1][1] = 0;
tex2d[0][1][2] = 255;
tex2d[0][1][3] = 255;
 
tex2d[1][0][0] = 255;
tex2d[1][0][1] = 255;
tex2d[1][0][2] = 0;
tex2d[1][0][3] = 255;
 
tex2d[1][1][0] = 255;
tex2d[1][1][1] = 0;
tex2d[1][1][2] = 0;
tex2d[1][1][3] = 255;
#endif
 
templat.target = PIPE_TEXTURE_2D;
templat.format = PIPE_FORMAT_B8G8R8A8_UNORM;
templat.width0 = SIZE;
templat.height0 = SIZE;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = PIPE_BIND_SAMPLER_VIEW;
 
samptex = screen->resource_create(screen,
&templat);
if (samptex == NULL)
exit(4);
 
u_box_2d(0,0,SIZE,SIZE, &box);
 
ctx->transfer_inline_write(ctx,
samptex,
0,
PIPE_TRANSFER_WRITE,
&box,
tex2d,
sizeof tex2d[0],
sizeof tex2d);
 
/* Possibly read back & compare against original data:
*/
if (0)
{
struct pipe_transfer *t;
uint32_t *ptr;
ptr = pipe_transfer_map(ctx, samptex,
0, 0, /* level, layer */
PIPE_TRANSFER_READ,
0, 0, SIZE, SIZE, &t); /* x, y, width, height */
 
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
 
ctx->transfer_unmap(ctx, t);
}
 
memset(&sv_template, 0, sizeof sv_template);
sv_template.format = samptex->format;
sv_template.texture = samptex;
sv_template.swizzle_r = 0;
sv_template.swizzle_g = 1;
sv_template.swizzle_b = 2;
sv_template.swizzle_a = 3;
sv = ctx->create_sampler_view(ctx, samptex, &sv_template);
if (sv == NULL)
exit(5);
 
ctx->set_fragment_sampler_views(ctx, 1, &sv);
 
memset(&sampler_desc, 0, sizeof sampler_desc);
sampler_desc.wrap_s = PIPE_TEX_WRAP_REPEAT;
sampler_desc.wrap_t = PIPE_TEX_WRAP_REPEAT;
sampler_desc.wrap_r = PIPE_TEX_WRAP_REPEAT;
sampler_desc.min_img_filter = PIPE_TEX_FILTER_NEAREST;
sampler_desc.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
sampler_desc.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
sampler_desc.compare_mode = PIPE_TEX_COMPARE_NONE;
sampler_desc.compare_func = 0;
sampler_desc.normalized_coords = 1;
sampler_desc.max_anisotropy = 0;
sampler = ctx->create_sampler_state(ctx, &sampler_desc);
if (sampler == NULL)
exit(6);
 
ctx->bind_fragment_sampler_states(ctx, 1, &sampler);
}
 
static void init( void )
{
struct pipe_framebuffer_state fb;
struct pipe_resource templat;
struct pipe_surface surf_tmpl;
int i;
 
/* It's hard to say whether window or screen should be created
* first. Different environments would prefer one or the other.
*
* Also, no easy way of querying supported formats if the screen
* cannot be created first.
*/
for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
screen = graw_create_window_and_screen(0, 0, 300, 300,
formats[i],
&window);
if (window && screen)
break;
}
if (!screen || !window) {
fprintf(stderr, "Unable to create window\n");
exit(1);
}
ctx = screen->context_create(screen, NULL);
if (ctx == NULL)
exit(3);
 
templat.target = PIPE_TEXTURE_2D;
templat.format = formats[i];
templat.width0 = WIDTH;
templat.height0 = HEIGHT;
templat.depth0 = 1;
templat.array_size = 1;
templat.last_level = 0;
templat.nr_samples = 1;
templat.bind = (PIPE_BIND_RENDER_TARGET |
PIPE_BIND_DISPLAY_TARGET);
rttex = screen->resource_create(screen,
&templat);
if (rttex == NULL)
exit(4);
 
surf_tmpl.format = templat.format;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
surf = ctx->create_surface(ctx, rttex, &surf_tmpl);
if (surf == NULL)
exit(5);
 
memset(&fb, 0, sizeof fb);
fb.nr_cbufs = 1;
fb.width = WIDTH;
fb.height = HEIGHT;
fb.cbufs[0] = surf;
 
ctx->set_framebuffer_state(ctx, &fb);
{
struct pipe_blend_state blend;
void *handle;
memset(&blend, 0, sizeof blend);
blend.rt[0].colormask = PIPE_MASK_RGBA;
handle = ctx->create_blend_state(ctx, &blend);
ctx->bind_blend_state(ctx, handle);
}
 
{
struct pipe_depth_stencil_alpha_state depthstencil;
void *handle;
memset(&depthstencil, 0, sizeof depthstencil);
handle = ctx->create_depth_stencil_alpha_state(ctx, &depthstencil);
ctx->bind_depth_stencil_alpha_state(ctx, handle);
}
 
{
struct pipe_rasterizer_state rasterizer;
void *handle;
memset(&rasterizer, 0, sizeof rasterizer);
rasterizer.cull_face = PIPE_FACE_NONE;
rasterizer.point_size = 8.0;
rasterizer.half_pixel_center = 1;
rasterizer.bottom_edge_rule = 1;
rasterizer.depth_clip = 1;
handle = ctx->create_rasterizer_state(ctx, &rasterizer);
ctx->bind_rasterizer_state(ctx, handle);
}
 
set_viewport(0, 0, WIDTH, HEIGHT, 30, 1000);
 
init_tex();
init_fs_constbuf();
 
set_vertices();
set_vertex_shader();
set_fragment_shader();
}
 
static void args(int argc, char *argv[])
{
int i;
 
for (i = 1; i < argc;) {
if (graw_parse_args(&i, argc, argv)) {
continue;
}
if (strcmp(argv[i], "-fps") == 0) {
show_fps = 1;
i++;
}
else if (i == argc - 1) {
filename = argv[i];
i++;
}
else {
usage(argv[0]);
exit(1);
}
}
 
if (!filename) {
usage(argv[0]);
exit(1);
}
}
 
int main( int argc, char *argv[] )
{
args(argc,argv);
init();
 
graw_set_display_func( draw );
graw_main_loop();
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/python/tests/regress/fragment-shader/frag-cmp.sh
0,0 → 1,12
FRAG
 
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
 
IMM FLT32 { 1, 0, 0, 1 }
IMM FLT32 { 0, 1, 1, 0 }
IMM FLT32 { 1, 0,-1, 0 }
 
CMP OUT[0], IMM[2], IMM[0], IMM[1]
 
END
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/trivial/Makefile.am
0,0 → 1,32
include $(top_srcdir)/src/gallium/Automake.inc
 
PIPE_SRC_DIR = $(top_builddir)/src/gallium/targets/pipe-loader
 
AM_CFLAGS = \
$(GALLIUM_CFLAGS)
 
AM_CPPFLAGS = \
-I$(top_srcdir)/src/gallium/drivers \
-I$(top_srcdir)/src/gallium/winsys \
-DPIPE_SEARCH_DIR=\"$(PIPE_SRC_DIR)/.libs\" \
$(GALLIUM_PIPE_LOADER_DEFINES)
 
LDADD = $(GALLIUM_PIPE_LOADER_LIBS) \
$(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(LIBUDEV_LIBS) \
$(DLOPEN_LIBS) \
$(PTHREAD_LIBS) \
-lm
 
noinst_PROGRAMS = compute tri quad-tex
 
compute_SOURCES = compute.c
 
tri_SOURCES = tri.c
 
quad_tex_SOURCES = quad-tex.c
 
clean-local:
-rm -f result.bmp
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/trivial/Makefile.in
0,0 → 1,809
# Makefile.in generated by automake 1.14 from Makefile.am.
# @configure_input@
 
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
 
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
 
@SET_MAKE@
 
VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
am__make_running_with_option = \
case $${target_option-} in \
?) ;; \
*) echo "am__make_running_with_option: internal error: invalid" \
"target option '$${target_option-}' specified" >&2; \
exit 1;; \
esac; \
has_opt=no; \
sane_makeflags=$$MAKEFLAGS; \
if $(am__is_gnu_make); then \
sane_makeflags=$$MFLAGS; \
else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
bs=\\; \
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
fi; \
skip_next=no; \
strip_trailopt () \
{ \
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
}; \
for flg in $$sane_makeflags; do \
test $$skip_next = yes && { skip_next=no; continue; }; \
case $$flg in \
*=*|--*) continue;; \
-*I) strip_trailopt 'I'; skip_next=yes;; \
-*I?*) strip_trailopt 'I';; \
-*O) strip_trailopt 'O'; skip_next=yes;; \
-*O?*) strip_trailopt 'O';; \
-*l) strip_trailopt 'l'; skip_next=yes;; \
-*l?*) strip_trailopt 'l';; \
-[dEDm]) skip_next=yes;; \
-[JT]) skip_next=yes;; \
esac; \
case $$flg in \
*$$target_option*) has_opt=yes; break;; \
esac; \
done; \
test $$has_opt = yes
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
DIST_COMMON = $(top_srcdir)/src/gallium/Automake.inc \
$(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/bin/depcomp
noinst_PROGRAMS = compute$(EXEEXT) tri$(EXEEXT) quad-tex$(EXEEXT)
subdir = src/gallium/tests/trivial
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_bison.m4 \
$(top_srcdir)/m4/ax_prog_cc_for_build.m4 \
$(top_srcdir)/m4/ax_prog_cxx_for_build.m4 \
$(top_srcdir)/m4/ax_prog_flex.m4 \
$(top_srcdir)/m4/ax_pthread.m4 \
$(top_srcdir)/m4/ax_python_module.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
PROGRAMS = $(noinst_PROGRAMS)
am_compute_OBJECTS = compute.$(OBJEXT)
compute_OBJECTS = $(am_compute_OBJECTS)
compute_LDADD = $(LDADD)
am__DEPENDENCIES_1 =
compute_DEPENDENCIES = $(am__DEPENDENCIES_1) \
$(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
am_quad_tex_OBJECTS = quad-tex.$(OBJEXT)
quad_tex_OBJECTS = $(am_quad_tex_OBJECTS)
quad_tex_LDADD = $(LDADD)
quad_tex_DEPENDENCIES = $(am__DEPENDENCIES_1) \
$(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1)
am_tri_OBJECTS = tri.$(OBJEXT)
tri_OBJECTS = $(am_tri_OBJECTS)
tri_LDADD = $(LDADD)
tri_DEPENDENCIES = $(am__DEPENDENCIES_1) \
$(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/bin/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
am__v_CC_0 = @echo " CC " $@;
am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(compute_SOURCES) $(quad_tex_SOURCES) $(tri_SOURCES)
DIST_SOURCES = $(compute_SOURCES) $(quad_tex_SOURCES) $(tri_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
am__uniquify_input = $(AWK) '\
BEGIN { nonempty = 0; } \
{ items[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in items) print i; }; } \
'
# Make sure the list of sources is unique. This is necessary because,
# e.g., the same source file might be shared among _SOURCES variables
# for different programs/libraries.
am__define_uniq_tagged_files = \
list='$(am__tagged_files)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BUILD_EXEEXT = @BUILD_EXEEXT@
BUILD_OBJEXT = @BUILD_OBJEXT@
CC = @CC@
CCAS = @CCAS@
CCASDEPMODE = @CCASDEPMODE@
CCASFLAGS = @CCASFLAGS@
CCDEPMODE = @CCDEPMODE@
CC_FOR_BUILD = @CC_FOR_BUILD@
CFLAGS = @CFLAGS@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
CLANG_RESOURCE_DIR = @CLANG_RESOURCE_DIR@
CLOCK_LIB = @CLOCK_LIB@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@
CPP_FOR_BUILD = @CPP_FOR_BUILD@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXCPPFLAGS_FOR_BUILD = @CXXCPPFLAGS_FOR_BUILD@
CXXCPP_FOR_BUILD = @CXXCPP_FOR_BUILD@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@
CXX_FOR_BUILD = @CXX_FOR_BUILD@
CYGPATH_W = @CYGPATH_W@
DEFINES = @DEFINES@
DEFINES_FOR_BUILD = @DEFINES_FOR_BUILD@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DLOPEN_LIBS = @DLOPEN_LIBS@
DRI2PROTO_CFLAGS = @DRI2PROTO_CFLAGS@
DRI2PROTO_LIBS = @DRI2PROTO_LIBS@
DRIGL_CFLAGS = @DRIGL_CFLAGS@
DRIGL_LIBS = @DRIGL_LIBS@
DRI_DRIVER_INSTALL_DIR = @DRI_DRIVER_INSTALL_DIR@
DRI_DRIVER_SEARCH_DIR = @DRI_DRIVER_SEARCH_DIR@
DRI_LIB_DEPS = @DRI_LIB_DEPS@
DRI_PC_REQ_PRIV = @DRI_PC_REQ_PRIV@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGL_CFLAGS = @EGL_CFLAGS@
EGL_CLIENT_APIS = @EGL_CLIENT_APIS@
EGL_DRIVER_INSTALL_DIR = @EGL_DRIVER_INSTALL_DIR@
EGL_LIB_DEPS = @EGL_LIB_DEPS@
EGL_LIB_GLOB = @EGL_LIB_GLOB@
EGL_LIB_NAME = @EGL_LIB_NAME@
EGL_NATIVE_PLATFORM = @EGL_NATIVE_PLATFORM@
EGL_PLATFORMS = @EGL_PLATFORMS@
EGREP = @EGREP@
ELF_LIB = @ELF_LIB@
EXEEXT = @EXEEXT@
EXPAT_INCLUDES = @EXPAT_INCLUDES@
FGREP = @FGREP@
FREEDRENO_CFLAGS = @FREEDRENO_CFLAGS@
FREEDRENO_LIBS = @FREEDRENO_LIBS@
GALLIUM_DRI_LIB_DEPS = @GALLIUM_DRI_LIB_DEPS@
GALLIUM_PIPE_LOADER_DEFINES = @GALLIUM_PIPE_LOADER_DEFINES@
GALLIUM_PIPE_LOADER_LIBS = @GALLIUM_PIPE_LOADER_LIBS@
GALLIUM_PIPE_LOADER_XCB_CFLAGS = @GALLIUM_PIPE_LOADER_XCB_CFLAGS@
GALLIUM_PIPE_LOADER_XCB_LIBS = @GALLIUM_PIPE_LOADER_XCB_LIBS@
GBM_PC_LIB_PRIV = @GBM_PC_LIB_PRIV@
GBM_PC_REQ_PRIV = @GBM_PC_REQ_PRIV@
GLAPI_LIB_GLOB = @GLAPI_LIB_GLOB@
GLAPI_LIB_NAME = @GLAPI_LIB_NAME@
GLESv1_CM_LIB_DEPS = @GLESv1_CM_LIB_DEPS@
GLESv1_CM_LIB_GLOB = @GLESv1_CM_LIB_GLOB@
GLESv1_CM_LIB_NAME = @GLESv1_CM_LIB_NAME@
GLESv1_CM_PC_LIB_PRIV = @GLESv1_CM_PC_LIB_PRIV@
GLESv2_LIB_DEPS = @GLESv2_LIB_DEPS@
GLESv2_LIB_GLOB = @GLESv2_LIB_GLOB@
GLESv2_LIB_NAME = @GLESv2_LIB_NAME@
GLESv2_PC_LIB_PRIV = @GLESv2_PC_LIB_PRIV@
GLPROTO_CFLAGS = @GLPROTO_CFLAGS@
GLPROTO_LIBS = @GLPROTO_LIBS@
GLX_TLS = @GLX_TLS@
GL_LIB = @GL_LIB@
GL_LIB_DEPS = @GL_LIB_DEPS@
GL_LIB_GLOB = @GL_LIB_GLOB@
GL_LIB_NAME = @GL_LIB_NAME@
GL_PC_CFLAGS = @GL_PC_CFLAGS@
GL_PC_LIB_PRIV = @GL_PC_LIB_PRIV@
GL_PC_REQ_PRIV = @GL_PC_REQ_PRIV@
GREP = @GREP@
HAVE_XF86VIDMODE = @HAVE_XF86VIDMODE@
INDENT = @INDENT@
INDENT_FLAGS = @INDENT_FLAGS@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
INTEL_CFLAGS = @INTEL_CFLAGS@
INTEL_LIBS = @INTEL_LIBS@
LD = @LD@
LDFLAGS = @LDFLAGS@
LDFLAGS_FOR_BUILD = @LDFLAGS_FOR_BUILD@
LEX = @LEX@
LEXLIB = @LEXLIB@
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
LIBCLC_INCLUDEDIR = @LIBCLC_INCLUDEDIR@
LIBCLC_LIBEXECDIR = @LIBCLC_LIBEXECDIR@
LIBDRM_CFLAGS = @LIBDRM_CFLAGS@
LIBDRM_LIBS = @LIBDRM_LIBS@
LIBDRM_XORG_CFLAGS = @LIBDRM_XORG_CFLAGS@
LIBDRM_XORG_LIBS = @LIBDRM_XORG_LIBS@
LIBKMS_XORG_CFLAGS = @LIBKMS_XORG_CFLAGS@
LIBKMS_XORG_LIBS = @LIBKMS_XORG_LIBS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LIBUDEV_CFLAGS = @LIBUDEV_CFLAGS@
LIBUDEV_LIBS = @LIBUDEV_LIBS@
LIB_DIR = @LIB_DIR@
LIPO = @LIPO@
LLVM_BINDIR = @LLVM_BINDIR@
LLVM_CFLAGS = @LLVM_CFLAGS@
LLVM_CONFIG = @LLVM_CONFIG@
LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
LLVM_CXXFLAGS = @LLVM_CXXFLAGS@
LLVM_INCLUDEDIR = @LLVM_INCLUDEDIR@
LLVM_LDFLAGS = @LLVM_LDFLAGS@
LLVM_LIBDIR = @LLVM_LIBDIR@
LLVM_LIBS = @LLVM_LIBS@
LLVM_VERSION = @LLVM_VERSION@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKE = @MAKE@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MESA_LLVM = @MESA_LLVM@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
NOUVEAU_CFLAGS = @NOUVEAU_CFLAGS@
NOUVEAU_LIBS = @NOUVEAU_LIBS@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OPENCL_LIB_INSTALL_DIR = @OPENCL_LIB_INSTALL_DIR@
OSMESA_LIB = @OSMESA_LIB@
OSMESA_LIB_DEPS = @OSMESA_LIB_DEPS@
OSMESA_LIB_NAME = @OSMESA_LIB_NAME@
OSMESA_MESA_DEPS = @OSMESA_MESA_DEPS@
OSMESA_PC_LIB_PRIV = @OSMESA_PC_LIB_PRIV@
OSMESA_PC_REQ = @OSMESA_PC_REQ@
OSMESA_VERSION = @OSMESA_VERSION@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PERL = @PERL@
PKG_CONFIG = @PKG_CONFIG@
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
POSIX_SHELL = @POSIX_SHELL@
PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_LIBS = @PTHREAD_LIBS@
PYTHON2 = @PYTHON2@
RADEON_CFLAGS = @RADEON_CFLAGS@
RADEON_LIBS = @RADEON_LIBS@
RANLIB = @RANLIB@
SED = @SED@
SELINUX_LIBS = @SELINUX_LIBS@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VDPAU_CFLAGS = @VDPAU_CFLAGS@
VDPAU_LIBS = @VDPAU_LIBS@
VDPAU_LIB_INSTALL_DIR = @VDPAU_LIB_INSTALL_DIR@
VDPAU_MAJOR = @VDPAU_MAJOR@
VDPAU_MINOR = @VDPAU_MINOR@
VERSION = @VERSION@
VG_LIB_DEPS = @VG_LIB_DEPS@
VG_LIB_GLOB = @VG_LIB_GLOB@
VG_LIB_NAME = @VG_LIB_NAME@
VG_PC_LIB_PRIV = @VG_PC_LIB_PRIV@
VISIBILITY_CFLAGS = @VISIBILITY_CFLAGS@
VISIBILITY_CXXFLAGS = @VISIBILITY_CXXFLAGS@
WAYLAND_CFLAGS = @WAYLAND_CFLAGS@
WAYLAND_LIBS = @WAYLAND_LIBS@
WAYLAND_SCANNER = @WAYLAND_SCANNER@
X11_INCLUDES = @X11_INCLUDES@
XA_MAJOR = @XA_MAJOR@
XA_MINOR = @XA_MINOR@
XA_TINY = @XA_TINY@
XA_VERSION = @XA_VERSION@
XCB_DRI2_CFLAGS = @XCB_DRI2_CFLAGS@
XCB_DRI2_LIBS = @XCB_DRI2_LIBS@
XEXT_CFLAGS = @XEXT_CFLAGS@
XEXT_LIBS = @XEXT_LIBS@
XF86VIDMODE_CFLAGS = @XF86VIDMODE_CFLAGS@
XF86VIDMODE_LIBS = @XF86VIDMODE_LIBS@
XLIBGL_CFLAGS = @XLIBGL_CFLAGS@
XLIBGL_LIBS = @XLIBGL_LIBS@
XORG_CFLAGS = @XORG_CFLAGS@
XORG_DRIVER_INSTALL_DIR = @XORG_DRIVER_INSTALL_DIR@
XORG_LIBS = @XORG_LIBS@
XVMC_CFLAGS = @XVMC_CFLAGS@
XVMC_LIBS = @XVMC_LIBS@
XVMC_LIB_INSTALL_DIR = @XVMC_LIB_INSTALL_DIR@
XVMC_MAJOR = @XVMC_MAJOR@
XVMC_MINOR = @XVMC_MINOR@
YACC = @YACC@
YFLAGS = @YFLAGS@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CC_FOR_BUILD = @ac_ct_CC_FOR_BUILD@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_CXX_FOR_BUILD = @ac_ct_CXX_FOR_BUILD@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
ax_pthread_config = @ax_pthread_config@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
GALLIUM_CFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src/gallium/include \
-I$(top_srcdir)/src/gallium/auxiliary \
$(DEFINES)
 
PIPE_SRC_DIR = $(top_builddir)/src/gallium/targets/pipe-loader
AM_CFLAGS = \
$(GALLIUM_CFLAGS)
 
AM_CPPFLAGS = \
-I$(top_srcdir)/src/gallium/drivers \
-I$(top_srcdir)/src/gallium/winsys \
-DPIPE_SEARCH_DIR=\"$(PIPE_SRC_DIR)/.libs\" \
$(GALLIUM_PIPE_LOADER_DEFINES)
 
LDADD = $(GALLIUM_PIPE_LOADER_LIBS) \
$(top_builddir)/src/gallium/auxiliary/pipe-loader/libpipe_loader.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(LIBUDEV_LIBS) \
$(DLOPEN_LIBS) \
$(PTHREAD_LIBS) \
-lm
 
compute_SOURCES = compute.c
tri_SOURCES = tri.c
quad_tex_SOURCES = quad-tex.c
all: all-am
 
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/src/gallium/Automake.inc $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/gallium/tests/trivial/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign src/gallium/tests/trivial/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_srcdir)/src/gallium/Automake.inc:
 
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
 
clean-noinstPROGRAMS:
@list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
echo " rm -f" $$list; \
rm -f $$list || exit $$?; \
test -n "$(EXEEXT)" || exit 0; \
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
 
compute$(EXEEXT): $(compute_OBJECTS) $(compute_DEPENDENCIES) $(EXTRA_compute_DEPENDENCIES)
@rm -f compute$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(compute_OBJECTS) $(compute_LDADD) $(LIBS)
 
quad-tex$(EXEEXT): $(quad_tex_OBJECTS) $(quad_tex_DEPENDENCIES) $(EXTRA_quad_tex_DEPENDENCIES)
@rm -f quad-tex$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(quad_tex_OBJECTS) $(quad_tex_LDADD) $(LIBS)
 
tri$(EXEEXT): $(tri_OBJECTS) $(tri_DEPENDENCIES) $(EXTRA_tri_DEPENDENCIES)
@rm -f tri$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(tri_OBJECTS) $(tri_LDADD) $(LIBS)
 
mostlyclean-compile:
-rm -f *.$(OBJEXT)
 
distclean-compile:
-rm -f *.tab.c
 
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/compute.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/quad-tex.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tri.Po@am__quote@
 
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
 
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
 
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
mostlyclean-libtool:
-rm -f *.lo
 
clean-libtool:
-rm -rf .libs _libs
 
ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
TAGS: tags
 
tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
$(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: ctags-am
 
CTAGS: ctags
ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
$(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
 
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
cscopelist: cscopelist-am
 
cscopelist-am: $(am__tagged_files)
list='$(am__tagged_files)'; \
case "$(srcdir)" in \
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
*) sdir=$(subdir)/$(srcdir) ;; \
esac; \
for i in $$list; do \
if test -f "$$i"; then \
echo "$(subdir)/$$i"; \
else \
echo "$$sdir/$$i"; \
fi; \
done >> $(top_builddir)/cscope.files
 
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS)
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
 
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
 
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
 
clean-generic:
 
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
 
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
 
clean-am: clean-generic clean-libtool clean-local clean-noinstPROGRAMS \
mostlyclean-am
 
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
 
dvi: dvi-am
 
dvi-am:
 
html: html-am
 
html-am:
 
info: info-am
 
info-am:
 
install-data-am:
 
install-dvi: install-dvi-am
 
install-dvi-am:
 
install-exec-am:
 
install-html: install-html-am
 
install-html-am:
 
install-info: install-info-am
 
install-info-am:
 
install-man:
 
install-pdf: install-pdf-am
 
install-pdf-am:
 
install-ps: install-ps-am
 
install-ps-am:
 
installcheck-am:
 
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
 
mostlyclean: mostlyclean-am
 
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
 
pdf: pdf-am
 
pdf-am:
 
ps: ps-am
 
ps-am:
 
uninstall-am:
 
.MAKE: install-am install-strip
 
.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
clean-libtool clean-local clean-noinstPROGRAMS cscopelist-am \
ctags ctags-am distclean distclean-compile distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-man install-pdf install-pdf-am \
install-ps install-ps-am install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags tags-am uninstall uninstall-am
 
 
clean-local:
-rm -f result.bmp
 
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/trivial/compute.c
0,0 → 1,1620
/*
* Copyright (C) 2011 Francisco Jerez.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
 
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <inttypes.h>
#include "pipe/p_state.h"
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
#include "pipe/p_defines.h"
#include "pipe/p_shader_tokens.h"
#include "util/u_memory.h"
#include "util/u_inlines.h"
#include "util/u_sampler.h"
#include "util/u_format.h"
#include "tgsi/tgsi_text.h"
#include "pipe-loader/pipe_loader.h"
 
#define MAX_RESOURCES 4
 
struct context {
struct pipe_loader_device *dev;
struct pipe_screen *screen;
struct pipe_context *pipe;
void *hwcs;
void *hwsmp[MAX_RESOURCES];
struct pipe_resource *tex[MAX_RESOURCES];
bool tex_rw[MAX_RESOURCES];
struct pipe_sampler_view *view[MAX_RESOURCES];
struct pipe_surface *surf[MAX_RESOURCES];
};
 
#define DUMP_COMPUTE_PARAM(p, c) do { \
uint64_t __v[4]; \
int __i, __n; \
\
__n = ctx->screen->get_compute_param(ctx->screen, c, __v); \
printf("%s: {", #c); \
\
for (__i = 0; __i < __n / sizeof(*__v); ++__i) \
printf(" %"PRIu64, __v[__i]); \
\
printf(" }\n"); \
} while (0)
 
static void init_ctx(struct context *ctx)
{
int ret;
 
ret = pipe_loader_probe(&ctx->dev, 1);
assert(ret);
 
ctx->screen = pipe_loader_create_screen(ctx->dev, PIPE_SEARCH_DIR);
assert(ctx->screen);
 
ctx->pipe = ctx->screen->context_create(ctx->screen, NULL);
assert(ctx->pipe);
 
DUMP_COMPUTE_PARAM(p, PIPE_COMPUTE_CAP_GRID_DIMENSION);
DUMP_COMPUTE_PARAM(p, PIPE_COMPUTE_CAP_MAX_GRID_SIZE);
DUMP_COMPUTE_PARAM(p, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
}
 
static void destroy_ctx(struct context *ctx)
{
ctx->pipe->destroy(ctx->pipe);
ctx->screen->destroy(ctx->screen);
pipe_loader_release(&ctx->dev, 1);
FREE(ctx);
}
 
static char *
preprocess_prog(struct context *ctx, const char *src, const char *defs)
{
const char header[] =
"#define RGLOBAL RES[32767]\n"
"#define RLOCAL RES[32766]\n"
"#define RPRIVATE RES[32765]\n"
"#define RINPUT RES[32764]\n";
char cmd[512];
char tmp[] = "/tmp/test-compute.tgsi-XXXXXX";
char *buf;
int fd, ret;
struct stat st;
FILE *p;
 
/* Open a temporary file */
fd = mkstemp(tmp);
assert(fd >= 0);
snprintf(cmd, sizeof(cmd), "cpp -P -nostdinc -undef %s > %s",
defs ? defs : "", tmp);
 
/* Preprocess */
p = popen(cmd, "w");
fwrite(header, strlen(header), 1, p);
fwrite(src, strlen(src), 1, p);
ret = pclose(p);
assert(!ret);
 
/* Read back */
ret = fstat(fd, &st);
assert(!ret);
 
buf = malloc(st.st_size + 1);
ret = read(fd, buf, st.st_size);
assert(ret == st.st_size);
buf[ret] = 0;
 
/* Clean up */
close(fd);
unlink(tmp);
 
return buf;
}
 
static void init_prog(struct context *ctx, unsigned local_sz,
unsigned private_sz, unsigned input_sz,
const char *src, const char *defs)
{
struct pipe_context *pipe = ctx->pipe;
struct tgsi_token prog[1024];
struct pipe_compute_state cs = {
.prog = prog,
.req_local_mem = local_sz,
.req_private_mem = private_sz,
.req_input_mem = input_sz
};
char *psrc = preprocess_prog(ctx, src, defs);
int ret;
 
ret = tgsi_text_translate(psrc, prog, Elements(prog));
assert(ret);
free(psrc);
 
ctx->hwcs = pipe->create_compute_state(pipe, &cs);
assert(ctx->hwcs);
 
pipe->bind_compute_state(pipe, ctx->hwcs);
}
 
static void destroy_prog(struct context *ctx)
{
struct pipe_context *pipe = ctx->pipe;
 
pipe->delete_compute_state(pipe, ctx->hwcs);
ctx->hwcs = NULL;
}
 
static void init_tex(struct context *ctx, int slot,
enum pipe_texture_target target, bool rw,
enum pipe_format format, int w, int h,
void (*init)(void *, int, int, int))
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_resource **tex = &ctx->tex[slot];
struct pipe_resource ttex = {
.target = target,
.format = format,
.width0 = w,
.height0 = h,
.depth0 = 1,
.array_size = 1,
.bind = (PIPE_BIND_SAMPLER_VIEW |
PIPE_BIND_COMPUTE_RESOURCE |
PIPE_BIND_GLOBAL)
};
int dx = util_format_get_blocksize(format);
int dy = util_format_get_stride(format, w);
int nx = (target == PIPE_BUFFER ? (w / dx) :
util_format_get_nblocksx(format, w));
int ny = (target == PIPE_BUFFER ? 1 :
util_format_get_nblocksy(format, h));
struct pipe_transfer *xfer;
char *map;
int x, y;
 
*tex = ctx->screen->resource_create(ctx->screen, &ttex);
assert(*tex);
 
map = pipe->transfer_map(pipe, *tex, 0, PIPE_TRANSFER_WRITE,
&(struct pipe_box) { .width = w,
.height = h,
.depth = 1 }, &xfer);
assert(xfer);
assert(map);
 
for (y = 0; y < ny; ++y) {
for (x = 0; x < nx; ++x) {
init(map + y * dy + x * dx, slot, x, y);
}
}
 
pipe->transfer_unmap(pipe, xfer);
 
ctx->tex_rw[slot] = rw;
}
 
static bool default_check(void *x, void *y, int sz) {
return !memcmp(x, y, sz);
}
 
static void check_tex(struct context *ctx, int slot,
void (*expect)(void *, int, int, int),
bool (*check)(void *, void *, int))
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_resource *tex = ctx->tex[slot];
int dx = util_format_get_blocksize(tex->format);
int dy = util_format_get_stride(tex->format, tex->width0);
int nx = (tex->target == PIPE_BUFFER ? (tex->width0 / dx) :
util_format_get_nblocksx(tex->format, tex->width0));
int ny = (tex->target == PIPE_BUFFER ? 1 :
util_format_get_nblocksy(tex->format, tex->height0));
struct pipe_transfer *xfer;
char *map;
int x, y, i;
int err = 0;
 
if (!check)
check = default_check;
 
map = pipe->transfer_map(pipe, tex, 0, PIPE_TRANSFER_READ,
&(struct pipe_box) { .width = tex->width0,
.height = tex->height0,
.depth = 1 }, &xfer);
assert(xfer);
assert(map);
 
for (y = 0; y < ny; ++y) {
for (x = 0; x < nx; ++x) {
uint32_t exp[4];
uint32_t *res = (uint32_t *)(map + y * dy + x * dx);
 
expect(exp, slot, x, y);
if (check(res, exp, dx) || (++err) > 20)
continue;
 
if (dx < 4) {
uint32_t u = 0, v = 0;
 
for (i = 0; i < dx; i++) {
u |= ((uint8_t *)exp)[i] << (8 * i);
v |= ((uint8_t *)res)[i] << (8 * i);
}
printf("(%d, %d): got 0x%x, expected 0x%x\n",
x, y, v, u);
} else {
for (i = 0; i < dx / 4; i++) {
printf("(%d, %d)[%d]: got 0x%x/%f,"
" expected 0x%x/%f\n", x, y, i,
res[i], ((float *)res)[i],
exp[i], ((float *)exp)[i]);
}
}
}
}
 
pipe->transfer_unmap(pipe, xfer);
 
if (err)
printf("(%d, %d): \x1b[31mFAIL\x1b[0m (%d)\n", x, y, err);
else
printf("(%d, %d): \x1b[32mOK\x1b[0m\n", x, y);
}
 
static void destroy_tex(struct context *ctx)
{
int i;
 
for (i = 0; i < MAX_RESOURCES; ++i) {
if (ctx->tex[i])
pipe_resource_reference(&ctx->tex[i], NULL);
}
}
 
static void init_sampler_views(struct context *ctx, const int *slots)
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_sampler_view tview;
int i;
 
for (i = 0; *slots >= 0; ++i, ++slots) {
u_sampler_view_default_template(&tview, ctx->tex[*slots],
ctx->tex[*slots]->format);
 
ctx->view[i] = pipe->create_sampler_view(pipe, ctx->tex[*slots],
&tview);
assert(ctx->view[i]);
}
 
pipe->set_compute_sampler_views(pipe, 0, i, ctx->view);
}
 
static void destroy_sampler_views(struct context *ctx)
{
struct pipe_context *pipe = ctx->pipe;
int i;
 
pipe->set_compute_sampler_views(pipe, 0, MAX_RESOURCES, NULL);
 
for (i = 0; i < MAX_RESOURCES; ++i) {
if (ctx->view[i]) {
pipe->sampler_view_destroy(pipe, ctx->view[i]);
ctx->view[i] = NULL;
}
}
}
 
static void init_compute_resources(struct context *ctx, const int *slots)
{
struct pipe_context *pipe = ctx->pipe;
int i;
 
for (i = 0; *slots >= 0; ++i, ++slots) {
struct pipe_surface tsurf = {
.format = ctx->tex[*slots]->format,
.writable = ctx->tex_rw[*slots]
};
 
if (ctx->tex[*slots]->target == PIPE_BUFFER)
tsurf.u.buf.last_element = ctx->tex[*slots]->width0 - 1;
 
ctx->surf[i] = pipe->create_surface(pipe, ctx->tex[*slots],
&tsurf);
assert(ctx->surf[i]);
}
 
pipe->set_compute_resources(pipe, 0, i, ctx->surf);
}
 
static void destroy_compute_resources(struct context *ctx)
{
struct pipe_context *pipe = ctx->pipe;
int i;
 
pipe->set_compute_resources(pipe, 0, MAX_RESOURCES, NULL);
 
for (i = 0; i < MAX_RESOURCES; ++i) {
if (ctx->surf[i]) {
pipe->surface_destroy(pipe, ctx->surf[i]);
ctx->surf[i] = NULL;
}
}
}
 
static void init_sampler_states(struct context *ctx, int n)
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_sampler_state smp = {
.normalized_coords = 1,
};
int i;
 
for (i = 0; i < n; ++i) {
ctx->hwsmp[i] = pipe->create_sampler_state(pipe, &smp);
assert(ctx->hwsmp[i]);
}
 
pipe->bind_compute_sampler_states(pipe, 0, i, ctx->hwsmp);
}
 
static void destroy_sampler_states(struct context *ctx)
{
struct pipe_context *pipe = ctx->pipe;
int i;
 
pipe->bind_compute_sampler_states(pipe, 0, MAX_RESOURCES, NULL);
 
for (i = 0; i < MAX_RESOURCES; ++i) {
if (ctx->hwsmp[i]) {
pipe->delete_sampler_state(pipe, ctx->hwsmp[i]);
ctx->hwsmp[i] = NULL;
}
}
}
 
static void init_globals(struct context *ctx, const int *slots,
uint32_t **handles)
{
struct pipe_context *pipe = ctx->pipe;
struct pipe_resource *res[MAX_RESOURCES];
int i;
 
for (i = 0; *slots >= 0; ++i, ++slots)
res[i] = ctx->tex[*slots];
 
pipe->set_global_binding(pipe, 0, i, res, handles);
}
 
static void destroy_globals(struct context *ctx)
{
struct pipe_context *pipe = ctx->pipe;
 
pipe->set_global_binding(pipe, 0, MAX_RESOURCES, NULL, NULL);
}
 
static void launch_grid(struct context *ctx, const uint *block_layout,
const uint *grid_layout, uint32_t pc,
const void *input)
{
struct pipe_context *pipe = ctx->pipe;
 
pipe->launch_grid(pipe, block_layout, grid_layout, pc, input);
}
 
static void test_system_values(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], BUFFER, RAW, WR\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL SV[1], BLOCK_SIZE[0]\n"
"DCL SV[2], GRID_SIZE[0]\n"
"DCL SV[3], THREAD_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"IMM UINT32 { 64, 0, 0, 0 }\n"
"IMM UINT32 { 16, 0, 0, 0 }\n"
"IMM UINT32 { 0, 0, 0, 0 }\n"
"\n"
"BGNSUB"
" UMUL TEMP[0], SV[0], SV[1]\n"
" UADD TEMP[0], TEMP[0], SV[3]\n"
" UMUL TEMP[1], SV[1], SV[2]\n"
" UMUL TEMP[0].w, TEMP[0], TEMP[1].zzzz\n"
" UMUL TEMP[0].zw, TEMP[0], TEMP[1].yyyy\n"
" UMUL TEMP[0].yzw, TEMP[0], TEMP[1].xxxx\n"
" UADD TEMP[0].xy, TEMP[0].xyxy, TEMP[0].zwzw\n"
" UADD TEMP[0].x, TEMP[0].xxxx, TEMP[0].yyyy\n"
" UMUL TEMP[0].x, TEMP[0], IMM[0]\n"
" STORE RES[0].xyzw, TEMP[0], SV[0]\n"
" UADD TEMP[0].x, TEMP[0], IMM[1]\n"
" STORE RES[0].xyzw, TEMP[0], SV[1]\n"
" UADD TEMP[0].x, TEMP[0], IMM[1]\n"
" STORE RES[0].xyzw, TEMP[0], SV[2]\n"
" UADD TEMP[0].x, TEMP[0], IMM[1]\n"
" STORE RES[0].xyzw, TEMP[0], SV[3]\n"
" RET\n"
"ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef;
}
void expect(void *p, int s, int x, int y) {
int id = x / 16, sv = (x % 16) / 4, c = x % 4;
int tid[] = { id % 20, (id % 240) / 20, id / 240, 0 };
int bsz[] = { 4, 3, 5, 1};
int gsz[] = { 5, 4, 1, 1};
 
switch (sv) {
case 0:
*(uint32_t *)p = tid[c] / bsz[c];
break;
case 1:
*(uint32_t *)p = bsz[c];
break;
case 2:
*(uint32_t *)p = gsz[c];
break;
case 3:
*(uint32_t *)p = tid[c] % bsz[c];
break;
}
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
76800, 0, init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){4, 3, 5}, (uint []){5, 4, 1}, 0, NULL);
check_tex(ctx, 0, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_resource_access(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], BUFFER, RAW, WR\n"
"DCL RES[1], 2D, RAW, WR\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"IMM UINT32 { 15, 0, 0, 0 }\n"
"IMM UINT32 { 16, 1, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UADD TEMP[0].x, SV[0].xxxx, SV[0].yyyy\n"
" AND TEMP[0].x, TEMP[0], IMM[0]\n"
" UMUL TEMP[0].x, TEMP[0], IMM[1]\n"
" LOAD TEMP[0].xyzw, RES[0], TEMP[0]\n"
" UMUL TEMP[1], SV[0], IMM[1]\n"
" STORE RES[1].xyzw, TEMP[1], TEMP[0]\n"
" RET\n"
" ENDSUB\n";
void init0(void *p, int s, int x, int y) {
*(float *)p = 8.0 - (float)x;
}
void init1(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef;
}
void expect(void *p, int s, int x, int y) {
*(float *)p = 8.0 - (float)((x + 4*y) & 0x3f);
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
256, 0, init0);
init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
60, 12, init1);
init_compute_resources(ctx, (int []) { 0, 1, -1 });
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){15, 12, 1}, 0, NULL);
check_tex(ctx, 1, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_function_calls(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], 2D, RAW, WR\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL SV[1], BLOCK_SIZE[0]\n"
"DCL SV[2], GRID_SIZE[0]\n"
"DCL SV[3], THREAD_ID[0]\n"
"DCL TEMP[0]\n"
"DCL TEMP[1]\n"
"DCL TEMP[2], LOCAL\n"
"IMM UINT32 { 0, 11, 22, 33 }\n"
"IMM FLT32 { 11, 33, 55, 99 }\n"
"IMM UINT32 { 4, 1, 0, 0 }\n"
"IMM UINT32 { 12, 0, 0, 0 }\n"
"\n"
"00: BGNSUB\n"
"01: UMUL TEMP[0].x, TEMP[0], TEMP[0]\n"
"02: UADD TEMP[1].x, TEMP[1], IMM[2].yyyy\n"
"03: USLT TEMP[0].x, TEMP[0], IMM[0]\n"
"04: RET\n"
"05: ENDSUB\n"
"06: BGNSUB\n"
"07: UMUL TEMP[0].x, TEMP[0], TEMP[0]\n"
"08: UADD TEMP[1].x, TEMP[1], IMM[2].yyyy\n"
"09: USLT TEMP[0].x, TEMP[0], IMM[0].yyyy\n"
"10: IF TEMP[0].xxxx\n"
"11: CAL :0\n"
"12: ENDIF\n"
"13: RET\n"
"14: ENDSUB\n"
"15: BGNSUB\n"
"16: UMUL TEMP[2], SV[0], SV[1]\n"
"17: UADD TEMP[2], TEMP[2], SV[3]\n"
"18: UMUL TEMP[2], TEMP[2], IMM[2]\n"
"00: MOV TEMP[1].x, IMM[2].wwww\n"
"19: LOAD TEMP[0].x, RES[0].xxxx, TEMP[2]\n"
"20: CAL :6\n"
"21: STORE RES[0].x, TEMP[2], TEMP[1].xxxx\n"
"22: RET\n"
"23: ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = 15 * y + x;
}
void expect(void *p, int s, int x, int y) {
*(uint32_t *)p = (15 * y + x) < 4 ? 2 : 1 ;
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
15, 12, init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){3, 3, 3}, (uint []){5, 4, 1}, 15, NULL);
check_tex(ctx, 0, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_input_global(struct context *ctx)
{
const char *src = "COMP\n"
"DCL SV[0], THREAD_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"IMM UINT32 { 8, 0, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UMUL TEMP[0], SV[0], IMM[0]\n"
" LOAD TEMP[1].xy, RINPUT, TEMP[0]\n"
" LOAD TEMP[0].x, RGLOBAL, TEMP[1].yyyy\n"
" UADD TEMP[1].x, TEMP[0], -TEMP[1]\n"
" STORE RGLOBAL.x, TEMP[1].yyyy, TEMP[1]\n"
" RET\n"
" ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef;
}
void expect(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef - (x == 0 ? 0x10001 + 2 * s : 0);
}
uint32_t input[8] = { 0x10001, 0x10002, 0x10003, 0x10004,
0x10005, 0x10006, 0x10007, 0x10008 };
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 32, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
init_tex(ctx, 1, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
init_tex(ctx, 2, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
init_tex(ctx, 3, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
init_globals(ctx, (int []){ 0, 1, 2, 3, -1 },
(uint32_t *[]){ &input[1], &input[3],
&input[5], &input[7] });
launch_grid(ctx, (uint []){4, 1, 1}, (uint []){1, 1, 1}, 0, input);
check_tex(ctx, 0, expect, NULL);
check_tex(ctx, 1, expect, NULL);
check_tex(ctx, 2, expect, NULL);
check_tex(ctx, 3, expect, NULL);
destroy_globals(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_private(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], BUFFER, RAW, WR\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL SV[1], BLOCK_SIZE[0]\n"
"DCL SV[2], THREAD_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"DCL TEMP[2], LOCAL\n"
"IMM UINT32 { 128, 0, 0, 0 }\n"
"IMM UINT32 { 4, 0, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UMUL TEMP[0].x, SV[0], SV[1]\n"
" UADD TEMP[0].x, TEMP[0], SV[2]\n"
" MOV TEMP[1].x, IMM[0].wwww\n"
" BGNLOOP\n"
" USEQ TEMP[2].x, TEMP[1], IMM[0]\n"
" IF TEMP[2]\n"
" BRK\n"
" ENDIF\n"
" UDIV TEMP[2].x, TEMP[1], IMM[1]\n"
" UADD TEMP[2].x, TEMP[2], TEMP[0]\n"
" STORE RPRIVATE.x, TEMP[1], TEMP[2]\n"
" UADD TEMP[1].x, TEMP[1], IMM[1]\n"
" ENDLOOP\n"
" MOV TEMP[1].x, IMM[0].wwww\n"
" UMUL TEMP[0].x, TEMP[0], IMM[0]\n"
" BGNLOOP\n"
" USEQ TEMP[2].x, TEMP[1], IMM[0]\n"
" IF TEMP[2]\n"
" BRK\n"
" ENDIF\n"
" LOAD TEMP[2].x, RPRIVATE, TEMP[1]\n"
" STORE RES[0].x, TEMP[0], TEMP[2]\n"
" UADD TEMP[0].x, TEMP[0], IMM[1]\n"
" UADD TEMP[1].x, TEMP[1], IMM[1]\n"
" ENDLOOP\n"
" RET\n"
" ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef;
}
void expect(void *p, int s, int x, int y) {
*(uint32_t *)p = (x / 32) + x % 32;
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 128, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
32768, 0, init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){16, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
check_tex(ctx, 0, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_local(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], BUFFER, RAW, WR\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL SV[1], BLOCK_SIZE[0]\n"
"DCL SV[2], THREAD_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"DCL TEMP[2], LOCAL\n"
"IMM UINT32 { 1, 0, 0, 0 }\n"
"IMM UINT32 { 2, 0, 0, 0 }\n"
"IMM UINT32 { 4, 0, 0, 0 }\n"
"IMM UINT32 { 32, 0, 0, 0 }\n"
"IMM UINT32 { 128, 0, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UMUL TEMP[0].x, SV[2], IMM[2]\n"
" STORE RLOCAL.x, TEMP[0], IMM[0].wwww\n"
" MFENCE RLOCAL\n"
" USLT TEMP[1].x, SV[2], IMM[3]\n"
" IF TEMP[1]\n"
" UADD TEMP[1].x, TEMP[0], IMM[4]\n"
" BGNLOOP\n"
" LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
" USEQ TEMP[2].x, TEMP[2], IMM[0]\n"
" IF TEMP[2]\n"
" BRK\n"
" ENDIF\n"
" ENDLOOP\n"
" STORE RLOCAL.x, TEMP[0], IMM[0]\n"
" MFENCE RLOCAL\n"
" BGNLOOP\n"
" LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
" USEQ TEMP[2].x, TEMP[2], IMM[1]\n"
" IF TEMP[2]\n"
" BRK\n"
" ENDIF\n"
" ENDLOOP\n"
" ELSE\n"
" UADD TEMP[1].x, TEMP[0], -IMM[4]\n"
" BGNLOOP\n"
" LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
" USEQ TEMP[2].x, TEMP[2], IMM[0].wwww\n"
" IF TEMP[2]\n"
" BRK\n"
" ENDIF\n"
" ENDLOOP\n"
" STORE RLOCAL.x, TEMP[0], IMM[0]\n"
" MFENCE RLOCAL\n"
" BGNLOOP\n"
" LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
" USEQ TEMP[2].x, TEMP[2], IMM[0]\n"
" IF TEMP[2]\n"
" BRK\n"
" ENDIF\n"
" ENDLOOP\n"
" STORE RLOCAL.x, TEMP[0], IMM[1]\n"
" MFENCE RLOCAL\n"
" ENDIF\n"
" UMUL TEMP[1].x, SV[0], SV[1]\n"
" UMUL TEMP[1].x, TEMP[1], IMM[2]\n"
" UADD TEMP[1].x, TEMP[1], TEMP[0]\n"
" LOAD TEMP[0].x, RLOCAL, TEMP[0]\n"
" STORE RES[0].x, TEMP[1], TEMP[0]\n"
" RET\n"
" ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef;
}
void expect(void *p, int s, int x, int y) {
*(uint32_t *)p = x & 0x20 ? 2 : 1;
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 256, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
4096, 0, init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
check_tex(ctx, 0, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_sample(struct context *ctx)
{
const char *src = "COMP\n"
"DCL SVIEW[0], 2D, FLOAT\n"
"DCL RES[0], 2D, RAW, WR\n"
"DCL SAMP[0]\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"IMM UINT32 { 16, 1, 0, 0 }\n"
"IMM FLT32 { 128, 32, 0, 0 }\n"
"\n"
" BGNSUB\n"
" I2F TEMP[1], SV[0]\n"
" DIV TEMP[1], TEMP[1], IMM[1]\n"
" SAMPLE TEMP[1], TEMP[1], SVIEW[0], SAMP[0]\n"
" UMUL TEMP[0], SV[0], IMM[0]\n"
" STORE RES[0].xyzw, TEMP[0], TEMP[1]\n"
" RET\n"
" ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(float *)p = s ? 1 : x * y;
}
void expect(void *p, int s, int x, int y) {
switch (x % 4) {
case 0:
*(float *)p = x / 4 * y;
break;
case 1:
case 2:
*(float *)p = 0;
break;
case 3:
*(float *)p = 1;
break;
}
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
128, 32, init);
init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
512, 32, init);
init_compute_resources(ctx, (int []) { 1, -1 });
init_sampler_views(ctx, (int []) { 0, -1 });
init_sampler_states(ctx, 2);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0, NULL);
check_tex(ctx, 1, expect, NULL);
destroy_sampler_states(ctx);
destroy_sampler_views(ctx);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_many_kern(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], BUFFER, RAW, WR\n"
"DCL TEMP[0], LOCAL\n"
"IMM UINT32 { 0, 1, 2, 3 }\n"
"IMM UINT32 { 4, 0, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UMUL TEMP[0].x, IMM[0].xxxx, IMM[1].xxxx\n"
" STORE RES[0].x, TEMP[0], IMM[0].xxxx\n"
" RET\n"
" ENDSUB\n"
" BGNSUB\n"
" UMUL TEMP[0].x, IMM[0].yyyy, IMM[1].xxxx\n"
" STORE RES[0].x, TEMP[0], IMM[0].yyyy\n"
" RET\n"
" ENDSUB\n"
" BGNSUB\n"
" UMUL TEMP[0].x, IMM[0].zzzz, IMM[1].xxxx\n"
" STORE RES[0].x, TEMP[0], IMM[0].zzzz\n"
" RET\n"
" ENDSUB\n"
" BGNSUB\n"
" UMUL TEMP[0].x, IMM[0].wwww, IMM[1].xxxx\n"
" STORE RES[0].x, TEMP[0], IMM[0].wwww\n"
" RET\n"
" ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef;
}
void expect(void *p, int s, int x, int y) {
*(uint32_t *)p = x;
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
16, 0, init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 0, NULL);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 5, NULL);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 10, NULL);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 15, NULL);
check_tex(ctx, 0, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_constant(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], BUFFER, RAW\n"
"DCL RES[1], BUFFER, RAW, WR\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"IMM UINT32 { 4, 0, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UMUL TEMP[0].x, SV[0], IMM[0]\n"
" LOAD TEMP[1].x, RES[0], TEMP[0]\n"
" STORE RES[1].x, TEMP[0], TEMP[1]\n"
" RET\n"
" ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(float *)p = s ? 0xdeadbeef : 8.0 - (float)x;
}
void expect(void *p, int s, int x, int y) {
*(float *)p = 8.0 - (float)x;
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
256, 0, init);
init_tex(ctx, 1, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
256, 0, init);
init_compute_resources(ctx, (int []) { 0, 1, -1 });
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){64, 1, 1}, 0, NULL);
check_tex(ctx, 1, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_resource_indirect(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], BUFFER, RAW, WR\n"
"DCL RES[1..3], BUFFER, RAW\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"IMM UINT32 { 4, 0, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UMUL TEMP[0].x, SV[0], IMM[0]\n"
" LOAD TEMP[1].x, RES[1], TEMP[0]\n"
" LOAD TEMP[1].x, RES[TEMP[1].x+2], TEMP[0]\n"
" STORE RES[0].x, TEMP[0], TEMP[1]\n"
" RET\n"
" ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = s == 0 ? 0xdeadbeef :
s == 1 ? x % 2 :
s == 2 ? 2 * x :
2 * x + 1;
}
void expect(void *p, int s, int x, int y) {
*(uint32_t *)p = 2 * x + (x % 2 ? 1 : 0);
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
256, 0, init);
init_tex(ctx, 1, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
256, 0, init);
init_tex(ctx, 2, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
256, 0, init);
init_tex(ctx, 3, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
256, 0, init);
init_compute_resources(ctx, (int []) { 0, 1, 2, 3, -1 });
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){64, 1, 1}, 0, NULL);
check_tex(ctx, 0, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
enum pipe_format surface_fmts[] = {
PIPE_FORMAT_B8G8R8A8_UNORM,
PIPE_FORMAT_B8G8R8X8_UNORM,
PIPE_FORMAT_A8R8G8B8_UNORM,
PIPE_FORMAT_X8R8G8B8_UNORM,
PIPE_FORMAT_X8R8G8B8_UNORM,
PIPE_FORMAT_L8_UNORM,
PIPE_FORMAT_A8_UNORM,
PIPE_FORMAT_I8_UNORM,
PIPE_FORMAT_L8A8_UNORM,
PIPE_FORMAT_R32_FLOAT,
PIPE_FORMAT_R32G32_FLOAT,
PIPE_FORMAT_R32G32B32A32_FLOAT,
PIPE_FORMAT_R32_UNORM,
PIPE_FORMAT_R32G32_UNORM,
PIPE_FORMAT_R32G32B32A32_UNORM,
PIPE_FORMAT_R32_SNORM,
PIPE_FORMAT_R32G32_SNORM,
PIPE_FORMAT_R32G32B32A32_SNORM,
PIPE_FORMAT_R8_UINT,
PIPE_FORMAT_R8G8_UINT,
PIPE_FORMAT_R8G8B8A8_UINT,
PIPE_FORMAT_R8_SINT,
PIPE_FORMAT_R8G8_SINT,
PIPE_FORMAT_R8G8B8A8_SINT,
PIPE_FORMAT_R32_UINT,
PIPE_FORMAT_R32G32_UINT,
PIPE_FORMAT_R32G32B32A32_UINT,
PIPE_FORMAT_R32_SINT,
PIPE_FORMAT_R32G32_SINT,
PIPE_FORMAT_R32G32B32A32_SINT
};
 
static void test_surface_ld(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], 2D\n"
"DCL RES[1], 2D, RAW, WR\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"IMM UINT32 { 16, 1, 0, 0 }\n"
"\n"
" BGNSUB\n"
" LOAD TEMP[1], RES[0], SV[0]\n"
" UMUL TEMP[0], SV[0], IMM[0]\n"
" STORE RES[1].xyzw, TEMP[0], TEMP[1]\n"
" RET\n"
" ENDSUB\n";
int i = 0;
void init0f(void *p, int s, int x, int y) {
float v[] = { 1.0, -.75, .50, -.25 };
util_format_write_4f(surface_fmts[i], v, 0,
p, 0, 0, 0, 1, 1);
}
void init0i(void *p, int s, int x, int y) {
int v[] = { 0xffffffff, 0xffff, 0xff, 0xf };
util_format_write_4i(surface_fmts[i], v, 0,
p, 0, 0, 0, 1, 1);
}
void init1(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef;
}
void expectf(void *p, int s, int x, int y) {
float v[4], w[4];
init0f(v, s, x / 4, y);
util_format_read_4f(surface_fmts[i], w, 0,
v, 0, 0, 0, 1, 1);
*(float *)p = w[x % 4];
}
void expecti(void *p, int s, int x, int y) {
int32_t v[4], w[4];
init0i(v, s, x / 4, y);
util_format_read_4i(surface_fmts[i], w, 0,
v, 0, 0, 0, 1, 1);
*(uint32_t *)p = w[x % 4];
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 0, src, NULL);
 
for (i = 0; i < Elements(surface_fmts); i++) {
bool is_int = util_format_is_pure_integer(surface_fmts[i]);
 
printf(" - %s\n", util_format_name(surface_fmts[i]));
 
if (!ctx->screen->is_format_supported(ctx->screen,
surface_fmts[i], PIPE_TEXTURE_2D, 1,
PIPE_BIND_COMPUTE_RESOURCE)) {
printf("(unsupported)\n");
continue;
}
 
init_tex(ctx, 0, PIPE_TEXTURE_2D, true, surface_fmts[i],
128, 32, (is_int ? init0i : init0f));
init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
512, 32, init1);
init_compute_resources(ctx, (int []) { 0, 1, -1 });
init_sampler_states(ctx, 2);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0,
NULL);
check_tex(ctx, 1, (is_int ? expecti : expectf), NULL);
destroy_sampler_states(ctx);
destroy_compute_resources(ctx);
destroy_tex(ctx);
}
 
destroy_prog(ctx);
}
 
static void test_surface_st(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], 2D, RAW\n"
"DCL RES[1], 2D, WR\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"IMM UINT32 { 16, 1, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UMUL TEMP[0], SV[0], IMM[0]\n"
" LOAD TEMP[1], RES[0], TEMP[0]\n"
" STORE RES[1], SV[0], TEMP[1]\n"
" RET\n"
" ENDSUB\n";
int i = 0;
void init0f(void *p, int s, int x, int y) {
float v[] = { 1.0, -.75, 0.5, -.25 };
*(float *)p = v[x % 4];
}
void init0i(void *p, int s, int x, int y) {
int v[] = { 0xffffffff, 0xffff, 0xff, 0xf };
*(int32_t *)p = v[x % 4];
}
void init1(void *p, int s, int x, int y) {
memset(p, 1, util_format_get_blocksize(surface_fmts[i]));
}
void expectf(void *p, int s, int x, int y) {
float vf[4];
int j;
 
for (j = 0; j < 4; j++)
init0f(&vf[j], s, 4 * x + j, y);
util_format_write_4f(surface_fmts[i], vf, 0,
p, 0, 0, 0, 1, 1);
}
void expects(void *p, int s, int x, int y) {
int32_t v[4];
int j;
 
for (j = 0; j < 4; j++)
init0i(&v[j], s, 4 * x + j, y);
util_format_write_4i(surface_fmts[i], v, 0,
p, 0, 0, 0, 1, 1);
}
void expectu(void *p, int s, int x, int y) {
uint32_t v[4];
int j;
 
for (j = 0; j < 4; j++)
init0i(&v[j], s, 4 * x + j, y);
util_format_write_4ui(surface_fmts[i], v, 0,
p, 0, 0, 0, 1, 1);
}
bool check(void *x, void *y, int sz) {
int j;
 
if (util_format_is_float(surface_fmts[i])) {
return fabs(*(float *)x - *(float *)y) < 3.92156863e-3;
 
} else if ((sz % 4) == 0) {
for (j = 0; j < sz / 4; j++)
if (abs(((uint32_t *)x)[j] -
((uint32_t *)y)[j]) > 1)
return false;
return true;
} else {
return !memcmp(x, y, sz);
}
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 0, 0, 0, src, NULL);
 
for (i = 0; i < Elements(surface_fmts); i++) {
bool is_signed = (util_format_description(surface_fmts[i])
->channel[0].type == UTIL_FORMAT_TYPE_SIGNED);
bool is_int = util_format_is_pure_integer(surface_fmts[i]);
 
printf(" - %s\n", util_format_name(surface_fmts[i]));
 
if (!ctx->screen->is_format_supported(ctx->screen,
surface_fmts[i], PIPE_TEXTURE_2D, 1,
PIPE_BIND_COMPUTE_RESOURCE)) {
printf("(unsupported)\n");
continue;
}
 
init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
512, 32, (is_int ? init0i : init0f));
init_tex(ctx, 1, PIPE_TEXTURE_2D, true, surface_fmts[i],
128, 32, init1);
init_compute_resources(ctx, (int []) { 0, 1, -1 });
init_sampler_states(ctx, 2);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0,
NULL);
check_tex(ctx, 1, (is_int && is_signed ? expects :
is_int && !is_signed ? expectu :
expectf), check);
destroy_sampler_states(ctx);
destroy_compute_resources(ctx);
destroy_tex(ctx);
}
 
destroy_prog(ctx);
}
 
static void test_barrier(struct context *ctx)
{
const char *src = "COMP\n"
"DCL RES[0], BUFFER, RAW, WR\n"
"DCL SV[0], BLOCK_ID[0]\n"
"DCL SV[1], BLOCK_SIZE[0]\n"
"DCL SV[2], THREAD_ID[0]\n"
"DCL TEMP[0], LOCAL\n"
"DCL TEMP[1], LOCAL\n"
"DCL TEMP[2], LOCAL\n"
"DCL TEMP[3], LOCAL\n"
"IMM UINT32 { 1, 0, 0, 0 }\n"
"IMM UINT32 { 4, 0, 0, 0 }\n"
"IMM UINT32 { 32, 0, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UMUL TEMP[0].x, SV[2], IMM[1]\n"
" MOV TEMP[1].x, IMM[0].wwww\n"
" BGNLOOP\n"
" BARRIER\n"
" STORE RLOCAL.x, TEMP[0], TEMP[1]\n"
" BARRIER\n"
" MOV TEMP[2].x, IMM[0].wwww\n"
" BGNLOOP\n"
" UMUL TEMP[3].x, TEMP[2], IMM[1]\n"
" LOAD TEMP[3].x, RLOCAL, TEMP[3]\n"
" USNE TEMP[3].x, TEMP[3], TEMP[1]\n"
" IF TEMP[3]\n"
" END\n"
" ENDIF\n"
" UADD TEMP[2].x, TEMP[2], IMM[0]\n"
" USEQ TEMP[3].x, TEMP[2], SV[1]\n"
" IF TEMP[3]\n"
" BRK\n"
" ENDIF\n"
" ENDLOOP\n"
" UADD TEMP[1].x, TEMP[1], IMM[0]\n"
" USEQ TEMP[2].x, TEMP[1], IMM[2]\n"
" IF TEMP[2]\n"
" BRK\n"
" ENDIF\n"
" ENDLOOP\n"
" UMUL TEMP[1].x, SV[0], SV[1]\n"
" UMUL TEMP[1].x, TEMP[1], IMM[1]\n"
" UADD TEMP[1].x, TEMP[1], TEMP[0]\n"
" LOAD TEMP[0].x, RLOCAL, TEMP[0]\n"
" STORE RES[0].x, TEMP[1], TEMP[0]\n"
" RET\n"
" ENDSUB\n";
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef;
}
void expect(void *p, int s, int x, int y) {
*(uint32_t *)p = 31;
}
 
printf("- %s\n", __func__);
 
init_prog(ctx, 256, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
4096, 0, init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
check_tex(ctx, 0, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_atom_ops(struct context *ctx, bool global)
{
const char *src = "COMP\n"
"#ifdef TARGET_GLOBAL\n"
"#define target RES[0]\n"
"#else\n"
"#define target RLOCAL\n"
"#endif\n"
""
"DCL RES[0], BUFFER, RAW, WR\n"
"#define threadid SV[0]\n"
"DCL threadid, THREAD_ID[0]\n"
""
"#define offset TEMP[0]\n"
"DCL offset, LOCAL\n"
"#define tmp TEMP[1]\n"
"DCL tmp, LOCAL\n"
""
"#define k0 IMM[0]\n"
"IMM UINT32 { 0, 0, 0, 0 }\n"
"#define k1 IMM[1]\n"
"IMM UINT32 { 1, 0, 0, 0 }\n"
"#define k2 IMM[2]\n"
"IMM UINT32 { 2, 0, 0, 0 }\n"
"#define k3 IMM[3]\n"
"IMM UINT32 { 3, 0, 0, 0 }\n"
"#define k4 IMM[4]\n"
"IMM UINT32 { 4, 0, 0, 0 }\n"
"#define k5 IMM[5]\n"
"IMM UINT32 { 5, 0, 0, 0 }\n"
"#define k6 IMM[6]\n"
"IMM UINT32 { 6, 0, 0, 0 }\n"
"#define k7 IMM[7]\n"
"IMM UINT32 { 7, 0, 0, 0 }\n"
"#define k8 IMM[8]\n"
"IMM UINT32 { 8, 0, 0, 0 }\n"
"#define k9 IMM[9]\n"
"IMM UINT32 { 9, 0, 0, 0 }\n"
"#define korig IMM[10].xxxx\n"
"#define karg IMM[10].yyyy\n"
"IMM UINT32 { 3735928559, 286331153, 0, 0 }\n"
"\n"
" BGNSUB\n"
" UMUL offset.x, threadid, k4\n"
" STORE target.x, offset, korig\n"
" USEQ tmp.x, threadid, k0\n"
" IF tmp\n"
" ATOMUADD tmp.x, target, offset, karg\n"
" ATOMUADD tmp.x, target, offset, tmp\n"
" ENDIF\n"
" USEQ tmp.x, threadid, k1\n"
" IF tmp\n"
" ATOMXCHG tmp.x, target, offset, karg\n"
" ATOMXCHG tmp.x, target, offset, tmp\n"
" ENDIF\n"
" USEQ tmp.x, threadid, k2\n"
" IF tmp\n"
" ATOMCAS tmp.x, target, offset, korig, karg\n"
" ATOMCAS tmp.x, target, offset, tmp, k0\n"
" ENDIF\n"
" USEQ tmp.x, threadid, k3\n"
" IF tmp\n"
" ATOMAND tmp.x, target, offset, karg\n"
" ATOMAND tmp.x, target, offset, tmp\n"
" ENDIF\n"
" USEQ tmp.x, threadid, k4\n"
" IF tmp\n"
" ATOMOR tmp.x, target, offset, karg\n"
" ATOMOR tmp.x, target, offset, tmp\n"
" ENDIF\n"
" USEQ tmp.x, threadid, k5\n"
" IF tmp\n"
" ATOMXOR tmp.x, target, offset, karg\n"
" ATOMXOR tmp.x, target, offset, tmp\n"
" ENDIF\n"
" USEQ tmp.x, threadid, k6\n"
" IF tmp\n"
" ATOMUMIN tmp.x, target, offset, karg\n"
" ATOMUMIN tmp.x, target, offset, tmp\n"
" ENDIF\n"
" USEQ tmp.x, threadid, k7\n"
" IF tmp\n"
" ATOMUMAX tmp.x, target, offset, karg\n"
" ATOMUMAX tmp.x, target, offset, tmp\n"
" ENDIF\n"
" USEQ tmp.x, threadid, k8\n"
" IF tmp\n"
" ATOMIMIN tmp.x, target, offset, karg\n"
" ATOMIMIN tmp.x, target, offset, tmp\n"
" ENDIF\n"
" USEQ tmp.x, threadid, k9\n"
" IF tmp\n"
" ATOMIMAX tmp.x, target, offset, karg\n"
" ATOMIMAX tmp.x, target, offset, tmp\n"
" ENDIF\n"
"#ifdef TARGET_LOCAL\n"
" LOAD tmp.x, RLOCAL, offset\n"
" STORE RES[0].x, offset, tmp\n"
"#endif\n"
" RET\n"
" ENDSUB\n";
 
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xbad;
}
void expect(void *p, int s, int x, int y) {
switch (x) {
case 0:
*(uint32_t *)p = 0xce6c8eef;
break;
case 1:
*(uint32_t *)p = 0xdeadbeef;
break;
case 2:
*(uint32_t *)p = 0x11111111;
break;
case 3:
*(uint32_t *)p = 0x10011001;
break;
case 4:
*(uint32_t *)p = 0xdfbdbfff;
break;
case 5:
*(uint32_t *)p = 0x11111111;
break;
case 6:
*(uint32_t *)p = 0x11111111;
break;
case 7:
*(uint32_t *)p = 0xdeadbeef;
break;
case 8:
*(uint32_t *)p = 0xdeadbeef;
break;
case 9:
*(uint32_t *)p = 0x11111111;
break;
}
}
 
printf("- %s (%s)\n", __func__, global ? "global" : "local");
 
init_prog(ctx, 40, 0, 0, src,
(global ? "-DTARGET_GLOBAL" : "-DTARGET_LOCAL"));
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
40, 0, init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){10, 1, 1}, (uint []){1, 1, 1}, 0, NULL);
check_tex(ctx, 0, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
static void test_atom_race(struct context *ctx, bool global)
{
const char *src = "COMP\n"
"#ifdef TARGET_GLOBAL\n"
"#define target RES[0]\n"
"#else\n"
"#define target RLOCAL\n"
"#endif\n"
""
"DCL RES[0], BUFFER, RAW, WR\n"
""
"#define blockid SV[0]\n"
"DCL blockid, BLOCK_ID[0]\n"
"#define blocksz SV[1]\n"
"DCL blocksz, BLOCK_SIZE[0]\n"
"#define threadid SV[2]\n"
"DCL threadid, THREAD_ID[0]\n"
""
"#define offset TEMP[0]\n"
"DCL offset, LOCAL\n"
"#define arg TEMP[1]\n"
"DCL arg, LOCAL\n"
"#define count TEMP[2]\n"
"DCL count, LOCAL\n"
"#define vlocal TEMP[3]\n"
"DCL vlocal, LOCAL\n"
"#define vshared TEMP[4]\n"
"DCL vshared, LOCAL\n"
"#define last TEMP[5]\n"
"DCL last, LOCAL\n"
"#define tmp0 TEMP[6]\n"
"DCL tmp0, LOCAL\n"
"#define tmp1 TEMP[7]\n"
"DCL tmp1, LOCAL\n"
""
"#define k0 IMM[0]\n"
"IMM UINT32 { 0, 0, 0, 0 }\n"
"#define k1 IMM[1]\n"
"IMM UINT32 { 1, 0, 0, 0 }\n"
"#define k4 IMM[2]\n"
"IMM UINT32 { 4, 0, 0, 0 }\n"
"#define k32 IMM[3]\n"
"IMM UINT32 { 32, 0, 0, 0 }\n"
"#define k128 IMM[4]\n"
"IMM UINT32 { 128, 0, 0, 0 }\n"
"#define kdeadcafe IMM[5]\n"
"IMM UINT32 { 3735931646, 0, 0, 0 }\n"
"#define kallowed_set IMM[6]\n"
"IMM UINT32 { 559035650, 0, 0, 0 }\n"
"#define k11111111 IMM[7]\n"
"IMM UINT32 { 286331153, 0, 0, 0 }\n"
"\n"
" BGNSUB\n"
" MOV offset.x, threadid\n"
"#ifdef TARGET_GLOBAL\n"
" UMUL tmp0.x, blockid, blocksz\n"
" UADD offset.x, offset, tmp0\n"
"#endif\n"
" UMUL offset.x, offset, k4\n"
" USLT tmp0.x, threadid, k32\n"
" STORE target.x, offset, k0\n"
" BARRIER\n"
" IF tmp0\n"
" MOV vlocal.x, k0\n"
" MOV arg.x, kdeadcafe\n"
" BGNLOOP\n"
" INEG arg.x, arg\n"
" ATOMUADD vshared.x, target, offset, arg\n"
" SFENCE target\n"
" USNE tmp0.x, vshared, vlocal\n"
" IF tmp0\n"
" BRK\n"
" ENDIF\n"
" UADD vlocal.x, vlocal, arg\n"
" ENDLOOP\n"
" UADD vlocal.x, vshared, arg\n"
" LOAD vshared.x, target, offset\n"
" USEQ tmp0.x, vshared, vlocal\n"
" STORE target.x, offset, tmp0\n"
" ELSE\n"
" UADD offset.x, offset, -k128\n"
" MOV count.x, k0\n"
" MOV last.x, k0\n"
" BGNLOOP\n"
" LOAD vshared.x, target, offset\n"
" USEQ tmp0.x, vshared, kallowed_set.xxxx\n"
" USEQ tmp1.x, vshared, kallowed_set.yyyy\n"
" OR tmp0.x, tmp0, tmp1\n"
" IF tmp0\n"
" USEQ tmp0.x, vshared, last\n"
" IF tmp0\n"
" CONT\n"
" ENDIF\n"
" MOV last.x, vshared\n"
" ELSE\n"
" END\n"
" ENDIF\n"
" UADD count.x, count, k1\n"
" USEQ tmp0.x, count, k128\n"
" IF tmp0\n"
" BRK\n"
" ENDIF\n"
" ENDLOOP\n"
" ATOMXCHG tmp0.x, target, offset, k11111111\n"
" UADD offset.x, offset, k128\n"
" ATOMXCHG tmp0.x, target, offset, k11111111\n"
" SFENCE target\n"
" ENDIF\n"
"#ifdef TARGET_LOCAL\n"
" LOAD tmp0.x, RLOCAL, offset\n"
" UMUL tmp1.x, blockid, blocksz\n"
" UMUL tmp1.x, tmp1, k4\n"
" UADD offset.x, offset, tmp1\n"
" STORE RES[0].x, offset, tmp0\n"
"#endif\n"
" RET\n"
" ENDSUB\n";
 
void init(void *p, int s, int x, int y) {
*(uint32_t *)p = 0xdeadbeef;
}
void expect(void *p, int s, int x, int y) {
*(uint32_t *)p = x & 0x20 ? 0x11111111 : 0xffffffff;
}
 
printf("- %s (%s)\n", __func__, global ? "global" : "local");
 
init_prog(ctx, 256, 0, 0, src,
(global ? "-DTARGET_GLOBAL" : "-DTARGET_LOCAL"));
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
4096, 0, init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
check_tex(ctx, 0, expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
 
int main(int argc, char *argv[])
{
struct context *ctx = CALLOC_STRUCT(context);
 
unsigned tests = (argc > 1) ? strtoul(argv[1], NULL, 0) : ~0;
 
init_ctx(ctx);
 
if (tests & (1 << 0))
test_system_values(ctx);
if (tests & (1 << 1))
test_resource_access(ctx);
if (tests & (1 << 2))
test_function_calls(ctx);
if (tests & (1 << 3))
test_input_global(ctx);
if (tests & (1 << 4))
test_private(ctx);
if (tests & (1 << 5))
test_local(ctx);
if (tests & (1 << 6))
test_sample(ctx);
if (tests & (1 << 7))
test_many_kern(ctx);
if (tests & (1 << 8))
test_constant(ctx);
if (tests & (1 << 9))
test_resource_indirect(ctx);
if (tests & (1 << 10))
test_surface_ld(ctx);
if (tests & (1 << 11))
test_surface_st(ctx);
if (tests & (1 << 12))
test_barrier(ctx);
if (tests & (1 << 13))
test_atom_ops(ctx, true);
if (tests & (1 << 14))
test_atom_race(ctx, true);
if (tests & (1 << 15))
test_atom_ops(ctx, false);
if (tests & (1 << 16))
test_atom_race(ctx, false);
 
destroy_ctx(ctx);
 
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/trivial/quad-tex.c
0,0 → 1,351
/**************************************************************************
*
* Copyright © 2010 Jakob Bornecrantz
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
 
 
#define USE_TRACE 0
#define WIDTH 300
#define HEIGHT 300
#define NEAR 30
#define FAR 1000
#define FLIP 0
 
/* pipe_*_state structs */
#include "pipe/p_state.h"
/* pipe_context */
#include "pipe/p_context.h"
/* pipe_screen */
#include "pipe/p_screen.h"
/* PIPE_* */
#include "pipe/p_defines.h"
/* TGSI_SEMANTIC_{POSITION|GENERIC} */
#include "pipe/p_shader_tokens.h"
/* pipe_buffer_* helpers */
#include "util/u_inlines.h"
 
/* constant state object helper */
#include "cso_cache/cso_context.h"
 
/* u_sampler_view_default_template */
#include "util/u_sampler.h"
/* debug_dump_surface_bmp */
#include "util/u_debug.h"
/* util_draw_vertex_buffer helper */
#include "util/u_draw_quad.h"
/* FREE & CALLOC_STRUCT */
#include "util/u_memory.h"
/* util_make_[fragment|vertex]_passthrough_shader */
#include "util/u_simple_shaders.h"
/* to get a hardware pipe driver */
#include "pipe-loader/pipe_loader.h"
 
struct program
{
struct pipe_loader_device *dev;
struct pipe_screen *screen;
struct pipe_context *pipe;
struct cso_context *cso;
 
struct pipe_blend_state blend;
struct pipe_depth_stencil_alpha_state depthstencil;
struct pipe_rasterizer_state rasterizer;
struct pipe_sampler_state sampler;
struct pipe_viewport_state viewport;
struct pipe_framebuffer_state framebuffer;
struct pipe_vertex_element velem[2];
 
void *vs;
void *fs;
 
union pipe_color_union clear_color;
 
struct pipe_resource *vbuf;
struct pipe_resource *target;
struct pipe_resource *tex;
struct pipe_sampler_view *view;
};
 
static void init_prog(struct program *p)
{
struct pipe_surface surf_tmpl;
int ret;
 
/* find a hardware device */
ret = pipe_loader_probe(&p->dev, 1);
assert(ret);
 
/* init a pipe screen */
p->screen = pipe_loader_create_screen(p->dev, PIPE_SEARCH_DIR);
assert(p->screen);
 
/* create the pipe driver context and cso context */
p->pipe = p->screen->context_create(p->screen, NULL);
p->cso = cso_create_context(p->pipe);
 
/* set clear color */
p->clear_color.f[0] = 0.3;
p->clear_color.f[1] = 0.1;
p->clear_color.f[2] = 0.3;
p->clear_color.f[3] = 1.0;
 
/* vertex buffer */
{
float vertices[4][2][4] = {
{
{ 0.9f, 0.9f, 0.0f, 1.0f },
{ 1.0f, 1.0f, 0.0f, 1.0f }
},
{
{ -0.9f, 0.9f, 0.0f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 1.0f }
},
{
{ -0.9f, -0.9f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 1.0f, 1.0f }
},
{
{ 0.9f, -0.9f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 1.0f, 1.0f }
}
};
 
p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC, sizeof(vertices));
pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices);
}
 
/* render target texture */
{
struct pipe_resource tmplt;
memset(&tmplt, 0, sizeof(tmplt));
tmplt.target = PIPE_TEXTURE_2D;
tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
tmplt.width0 = WIDTH;
tmplt.height0 = HEIGHT;
tmplt.depth0 = 1;
tmplt.array_size = 1;
tmplt.last_level = 0;
tmplt.bind = PIPE_BIND_RENDER_TARGET;
 
p->target = p->screen->resource_create(p->screen, &tmplt);
}
 
/* sampler texture */
{
uint32_t *ptr;
struct pipe_transfer *t;
struct pipe_resource t_tmplt;
struct pipe_sampler_view v_tmplt;
struct pipe_box box;
 
memset(&t_tmplt, 0, sizeof(t_tmplt));
t_tmplt.target = PIPE_TEXTURE_2D;
t_tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
t_tmplt.width0 = 2;
t_tmplt.height0 = 2;
t_tmplt.depth0 = 1;
t_tmplt.array_size = 1;
t_tmplt.last_level = 0;
t_tmplt.bind = PIPE_BIND_RENDER_TARGET;
 
p->tex = p->screen->resource_create(p->screen, &t_tmplt);
 
memset(&box, 0, sizeof(box));
box.width = 2;
box.height = 2;
 
ptr = p->pipe->transfer_map(p->pipe, p->tex, 0, PIPE_TRANSFER_WRITE, &box, &t);
ptr[0] = 0xffff0000;
ptr[1] = 0xff0000ff;
ptr[2] = 0xff00ff00;
ptr[3] = 0xffffff00;
p->pipe->transfer_unmap(p->pipe, t);
 
u_sampler_view_default_template(&v_tmplt, p->tex, p->tex->format);
 
p->view = p->pipe->create_sampler_view(p->pipe, p->tex, &v_tmplt);
}
 
/* disabled blending/masking */
memset(&p->blend, 0, sizeof(p->blend));
p->blend.rt[0].colormask = PIPE_MASK_RGBA;
 
/* no-op depth/stencil/alpha */
memset(&p->depthstencil, 0, sizeof(p->depthstencil));
 
/* rasterizer */
memset(&p->rasterizer, 0, sizeof(p->rasterizer));
p->rasterizer.cull_face = PIPE_FACE_NONE;
p->rasterizer.half_pixel_center = 1;
p->rasterizer.bottom_edge_rule = 1;
p->rasterizer.depth_clip = 1;
 
/* sampler */
memset(&p->sampler, 0, sizeof(p->sampler));
p->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
p->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
p->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
p->sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
p->sampler.min_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR;
p->sampler.normalized_coords = 1;
 
surf_tmpl.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
/* drawing destination */
memset(&p->framebuffer, 0, sizeof(p->framebuffer));
p->framebuffer.width = WIDTH;
p->framebuffer.height = HEIGHT;
p->framebuffer.nr_cbufs = 1;
p->framebuffer.cbufs[0] = p->pipe->create_surface(p->pipe, p->target, &surf_tmpl);
 
/* viewport, depth isn't really needed */
{
float x = 0;
float y = 0;
float z = FAR;
float half_width = (float)WIDTH / 2.0f;
float half_height = (float)HEIGHT / 2.0f;
float half_depth = ((float)FAR - (float)NEAR) / 2.0f;
float scale, bias;
 
if (FLIP) {
scale = -1.0f;
bias = (float)HEIGHT;
} else {
scale = 1.0f;
bias = 0.0f;
}
 
p->viewport.scale[0] = half_width;
p->viewport.scale[1] = half_height * scale;
p->viewport.scale[2] = half_depth;
p->viewport.scale[3] = 1.0f;
 
p->viewport.translate[0] = half_width + x;
p->viewport.translate[1] = (half_height + y) * scale + bias;
p->viewport.translate[2] = half_depth + z;
p->viewport.translate[3] = 0.0f;
}
 
/* vertex elements state */
memset(p->velem, 0, sizeof(p->velem));
p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */
p->velem[0].instance_divisor = 0;
p->velem[0].vertex_buffer_index = 0;
p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */
p->velem[1].instance_divisor = 0;
p->velem[1].vertex_buffer_index = 0;
p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
/* vertex shader */
{
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
TGSI_SEMANTIC_GENERIC };
const uint semantic_indexes[] = { 0, 0 };
p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes);
}
 
/* fragment shader */
p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D, TGSI_INTERPOLATE_LINEAR);
}
 
static void close_prog(struct program *p)
{
/* unset bound textures as well */
cso_set_sampler_views(p->cso, PIPE_SHADER_FRAGMENT, 0, NULL);
 
/* unset all state */
cso_release_all(p->cso);
 
p->pipe->delete_vs_state(p->pipe, p->vs);
p->pipe->delete_fs_state(p->pipe, p->fs);
 
pipe_surface_reference(&p->framebuffer.cbufs[0], NULL);
pipe_sampler_view_reference(&p->view, NULL);
pipe_resource_reference(&p->target, NULL);
pipe_resource_reference(&p->tex, NULL);
pipe_resource_reference(&p->vbuf, NULL);
 
cso_destroy_context(p->cso);
p->pipe->destroy(p->pipe);
p->screen->destroy(p->screen);
pipe_loader_release(&p->dev, 1);
 
FREE(p);
}
 
static void draw(struct program *p)
{
/* set the render target */
cso_set_framebuffer(p->cso, &p->framebuffer);
 
/* clear the render target */
p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, &p->clear_color, 0, 0);
 
/* set misc state we care about */
cso_set_blend(p->cso, &p->blend);
cso_set_depth_stencil_alpha(p->cso, &p->depthstencil);
cso_set_rasterizer(p->cso, &p->rasterizer);
cso_set_viewport(p->cso, &p->viewport);
 
/* sampler */
cso_single_sampler(p->cso, PIPE_SHADER_FRAGMENT, 0, &p->sampler);
cso_single_sampler_done(p->cso, PIPE_SHADER_FRAGMENT);
 
/* texture sampler view */
cso_set_sampler_views(p->cso, PIPE_SHADER_FRAGMENT, 1, &p->view);
 
/* shaders */
cso_set_fragment_shader_handle(p->cso, p->fs);
cso_set_vertex_shader_handle(p->cso, p->vs);
 
/* vertex element data */
cso_set_vertex_elements(p->cso, 2, p->velem);
 
util_draw_vertex_buffer(p->pipe, p->cso,
p->vbuf, 0, 0,
PIPE_PRIM_QUADS,
4, /* verts */
2); /* attribs/vert */
 
p->pipe->flush(p->pipe, NULL, 0);
 
debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]);
}
 
int main(int argc, char** argv)
{
struct program *p = CALLOC_STRUCT(program);
 
init_prog(p);
draw(p);
close_prog(p);
 
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/trivial/tri.c
0,0 → 1,285
/**************************************************************************
*
* Copyright © 2010 Jakob Bornecrantz
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
 
 
#define USE_TRACE 0
#define WIDTH 300
#define HEIGHT 300
#define NEAR 30
#define FAR 1000
#define FLIP 0
 
/* pipe_*_state structs */
#include "pipe/p_state.h"
/* pipe_context */
#include "pipe/p_context.h"
/* pipe_screen */
#include "pipe/p_screen.h"
/* PIPE_* */
#include "pipe/p_defines.h"
/* TGSI_SEMANTIC_{POSITION|GENERIC} */
#include "pipe/p_shader_tokens.h"
/* pipe_buffer_* helpers */
#include "util/u_inlines.h"
 
/* constant state object helper */
#include "cso_cache/cso_context.h"
 
/* debug_dump_surface_bmp */
#include "util/u_debug.h"
/* util_draw_vertex_buffer helper */
#include "util/u_draw_quad.h"
/* FREE & CALLOC_STRUCT */
#include "util/u_memory.h"
/* util_make_[fragment|vertex]_passthrough_shader */
#include "util/u_simple_shaders.h"
/* to get a hardware pipe driver */
#include "pipe-loader/pipe_loader.h"
 
struct program
{
struct pipe_loader_device *dev;
struct pipe_screen *screen;
struct pipe_context *pipe;
struct cso_context *cso;
 
struct pipe_blend_state blend;
struct pipe_depth_stencil_alpha_state depthstencil;
struct pipe_rasterizer_state rasterizer;
struct pipe_viewport_state viewport;
struct pipe_framebuffer_state framebuffer;
struct pipe_vertex_element velem[2];
 
void *vs;
void *fs;
 
union pipe_color_union clear_color;
 
struct pipe_resource *vbuf;
struct pipe_resource *target;
};
 
static void init_prog(struct program *p)
{
struct pipe_surface surf_tmpl;
int ret;
 
/* find a hardware device */
ret = pipe_loader_probe(&p->dev, 1);
assert(ret);
 
/* init a pipe screen */
p->screen = pipe_loader_create_screen(p->dev, PIPE_SEARCH_DIR);
assert(p->screen);
 
/* create the pipe driver context and cso context */
p->pipe = p->screen->context_create(p->screen, NULL);
p->cso = cso_create_context(p->pipe);
 
/* set clear color */
p->clear_color.f[0] = 0.3;
p->clear_color.f[1] = 0.1;
p->clear_color.f[2] = 0.3;
p->clear_color.f[3] = 1.0;
 
/* vertex buffer */
{
float vertices[4][2][4] = {
{
{ 0.0f, -0.9f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 0.0f, 1.0f }
},
{
{ -0.9f, 0.9f, 0.0f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 1.0f }
},
{
{ 0.9f, 0.9f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 1.0f, 1.0f }
}
};
 
p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_STATIC, sizeof(vertices));
pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices);
}
 
/* render target texture */
{
struct pipe_resource tmplt;
memset(&tmplt, 0, sizeof(tmplt));
tmplt.target = PIPE_TEXTURE_2D;
tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */
tmplt.width0 = WIDTH;
tmplt.height0 = HEIGHT;
tmplt.depth0 = 1;
tmplt.array_size = 1;
tmplt.last_level = 0;
tmplt.bind = PIPE_BIND_RENDER_TARGET;
 
p->target = p->screen->resource_create(p->screen, &tmplt);
}
 
/* disabled blending/masking */
memset(&p->blend, 0, sizeof(p->blend));
p->blend.rt[0].colormask = PIPE_MASK_RGBA;
 
/* no-op depth/stencil/alpha */
memset(&p->depthstencil, 0, sizeof(p->depthstencil));
 
/* rasterizer */
memset(&p->rasterizer, 0, sizeof(p->rasterizer));
p->rasterizer.cull_face = PIPE_FACE_NONE;
p->rasterizer.half_pixel_center = 1;
p->rasterizer.bottom_edge_rule = 1;
p->rasterizer.depth_clip = 1;
 
surf_tmpl.format = PIPE_FORMAT_B8G8R8A8_UNORM;
surf_tmpl.u.tex.level = 0;
surf_tmpl.u.tex.first_layer = 0;
surf_tmpl.u.tex.last_layer = 0;
/* drawing destination */
memset(&p->framebuffer, 0, sizeof(p->framebuffer));
p->framebuffer.width = WIDTH;
p->framebuffer.height = HEIGHT;
p->framebuffer.nr_cbufs = 1;
p->framebuffer.cbufs[0] = p->pipe->create_surface(p->pipe, p->target, &surf_tmpl);
 
/* viewport, depth isn't really needed */
{
float x = 0;
float y = 0;
float z = FAR;
float half_width = (float)WIDTH / 2.0f;
float half_height = (float)HEIGHT / 2.0f;
float half_depth = ((float)FAR - (float)NEAR) / 2.0f;
float scale, bias;
 
if (FLIP) {
scale = -1.0f;
bias = (float)HEIGHT;
} else {
scale = 1.0f;
bias = 0.0f;
}
 
p->viewport.scale[0] = half_width;
p->viewport.scale[1] = half_height * scale;
p->viewport.scale[2] = half_depth;
p->viewport.scale[3] = 1.0f;
 
p->viewport.translate[0] = half_width + x;
p->viewport.translate[1] = (half_height + y) * scale + bias;
p->viewport.translate[2] = half_depth + z;
p->viewport.translate[3] = 0.0f;
}
 
/* vertex elements state */
memset(p->velem, 0, sizeof(p->velem));
p->velem[0].src_offset = 0 * 4 * sizeof(float); /* offset 0, first element */
p->velem[0].instance_divisor = 0;
p->velem[0].vertex_buffer_index = 0;
p->velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
p->velem[1].src_offset = 1 * 4 * sizeof(float); /* offset 16, second element */
p->velem[1].instance_divisor = 0;
p->velem[1].vertex_buffer_index = 0;
p->velem[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
 
/* vertex shader */
{
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
TGSI_SEMANTIC_COLOR };
const uint semantic_indexes[] = { 0, 0 };
p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes);
}
 
/* fragment shader */
p->fs = util_make_fragment_passthrough_shader(p->pipe,
TGSI_SEMANTIC_COLOR, TGSI_INTERPOLATE_PERSPECTIVE, TRUE);
}
 
static void close_prog(struct program *p)
{
/* unset all state */
cso_release_all(p->cso);
 
p->pipe->delete_vs_state(p->pipe, p->vs);
p->pipe->delete_fs_state(p->pipe, p->fs);
 
pipe_surface_reference(&p->framebuffer.cbufs[0], NULL);
pipe_resource_reference(&p->target, NULL);
pipe_resource_reference(&p->vbuf, NULL);
 
cso_destroy_context(p->cso);
p->pipe->destroy(p->pipe);
p->screen->destroy(p->screen);
pipe_loader_release(&p->dev, 1);
 
FREE(p);
}
 
static void draw(struct program *p)
{
/* set the render target */
cso_set_framebuffer(p->cso, &p->framebuffer);
 
/* clear the render target */
p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, &p->clear_color, 0, 0);
 
/* set misc state we care about */
cso_set_blend(p->cso, &p->blend);
cso_set_depth_stencil_alpha(p->cso, &p->depthstencil);
cso_set_rasterizer(p->cso, &p->rasterizer);
cso_set_viewport(p->cso, &p->viewport);
 
/* shaders */
cso_set_fragment_shader_handle(p->cso, p->fs);
cso_set_vertex_shader_handle(p->cso, p->vs);
 
/* vertex element data */
cso_set_vertex_elements(p->cso, 2, p->velem);
 
util_draw_vertex_buffer(p->pipe, p->cso,
p->vbuf, 0, 0,
PIPE_PRIM_TRIANGLES,
3, /* verts */
2); /* attribs/vert */
 
p->pipe->flush(p->pipe, NULL, 0);
 
debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]);
}
 
int main(int argc, char** argv)
{
struct program *p = CALLOC_STRUCT(program);
 
init_prog(p);
draw(p);
close_prog(p);
 
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/unit/Makefile.am
0,0 → 1,34
# TODO: wire up some useful tests to make check
 
include $(top_srcdir)/src/gallium/Automake.inc
 
AM_CFLAGS = \
$(GALLIUM_CFLAGS)
 
AM_CPPFLAGS = \
-I$(top_srcdir)/src/gallium/drivers \
-I$(top_srcdir)/src/gallium/winsys
 
LDADD = \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la \
$(DLOPEN_LIBS) \
$(PTHREAD_LIBS) \
-lm
 
noinst_PROGRAMS = pipe_barrier_test u_cache_test u_half_test \
u_format_test u_format_compatible_test translate_test
 
pipe_barrier_test_SOURCES = pipe_barrier_test.c
 
u_cache_test_SOURCES = u_cache_test.c
 
u_half_test_SOURCES = u_half_test.c
 
u_format_test_SOURCES = u_format_test.c
 
u_format_compatible_test_SOURCES = u_format_compatible_test.c
 
translate_test_SOURCES = translate_test.c
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/unit/Makefile.in
0,0 → 1,858
# Makefile.in generated by automake 1.14 from Makefile.am.
# @configure_input@
 
# Copyright (C) 1994-2013 Free Software Foundation, Inc.
 
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
 
@SET_MAKE@
 
# TODO: wire up some useful tests to make check
 
VPATH = @srcdir@
am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
am__make_running_with_option = \
case $${target_option-} in \
?) ;; \
*) echo "am__make_running_with_option: internal error: invalid" \
"target option '$${target_option-}' specified" >&2; \
exit 1;; \
esac; \
has_opt=no; \
sane_makeflags=$$MAKEFLAGS; \
if $(am__is_gnu_make); then \
sane_makeflags=$$MFLAGS; \
else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
bs=\\; \
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
fi; \
skip_next=no; \
strip_trailopt () \
{ \
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
}; \
for flg in $$sane_makeflags; do \
test $$skip_next = yes && { skip_next=no; continue; }; \
case $$flg in \
*=*|--*) continue;; \
-*I) strip_trailopt 'I'; skip_next=yes;; \
-*I?*) strip_trailopt 'I';; \
-*O) strip_trailopt 'O'; skip_next=yes;; \
-*O?*) strip_trailopt 'O';; \
-*l) strip_trailopt 'l'; skip_next=yes;; \
-*l?*) strip_trailopt 'l';; \
-[dEDm]) skip_next=yes;; \
-[JT]) skip_next=yes;; \
esac; \
case $$flg in \
*$$target_option*) has_opt=yes; break;; \
esac; \
done; \
test $$has_opt = yes
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
DIST_COMMON = $(top_srcdir)/src/gallium/Automake.inc \
$(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/bin/depcomp
noinst_PROGRAMS = pipe_barrier_test$(EXEEXT) u_cache_test$(EXEEXT) \
u_half_test$(EXEEXT) u_format_test$(EXEEXT) \
u_format_compatible_test$(EXEEXT) translate_test$(EXEEXT)
subdir = src/gallium/tests/unit
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_prog_bison.m4 \
$(top_srcdir)/m4/ax_prog_cc_for_build.m4 \
$(top_srcdir)/m4/ax_prog_cxx_for_build.m4 \
$(top_srcdir)/m4/ax_prog_flex.m4 \
$(top_srcdir)/m4/ax_pthread.m4 \
$(top_srcdir)/m4/ax_python_module.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
PROGRAMS = $(noinst_PROGRAMS)
am_pipe_barrier_test_OBJECTS = pipe_barrier_test.$(OBJEXT)
pipe_barrier_test_OBJECTS = $(am_pipe_barrier_test_OBJECTS)
pipe_barrier_test_LDADD = $(LDADD)
am__DEPENDENCIES_1 =
pipe_barrier_test_DEPENDENCIES = \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
am_translate_test_OBJECTS = translate_test.$(OBJEXT)
translate_test_OBJECTS = $(am_translate_test_OBJECTS)
translate_test_LDADD = $(LDADD)
translate_test_DEPENDENCIES = \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_u_cache_test_OBJECTS = u_cache_test.$(OBJEXT)
u_cache_test_OBJECTS = $(am_u_cache_test_OBJECTS)
u_cache_test_LDADD = $(LDADD)
u_cache_test_DEPENDENCIES = \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_u_format_compatible_test_OBJECTS = \
u_format_compatible_test.$(OBJEXT)
u_format_compatible_test_OBJECTS = \
$(am_u_format_compatible_test_OBJECTS)
u_format_compatible_test_LDADD = $(LDADD)
u_format_compatible_test_DEPENDENCIES = \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_u_format_test_OBJECTS = u_format_test.$(OBJEXT)
u_format_test_OBJECTS = $(am_u_format_test_OBJECTS)
u_format_test_LDADD = $(LDADD)
u_format_test_DEPENDENCIES = \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_u_half_test_OBJECTS = u_half_test.$(OBJEXT)
u_half_test_OBJECTS = $(am_u_half_test_OBJECTS)
u_half_test_LDADD = $(LDADD)
u_half_test_DEPENDENCIES = \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/bin/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
am__v_CC_0 = @echo " CC " $@;
am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(pipe_barrier_test_SOURCES) $(translate_test_SOURCES) \
$(u_cache_test_SOURCES) $(u_format_compatible_test_SOURCES) \
$(u_format_test_SOURCES) $(u_half_test_SOURCES)
DIST_SOURCES = $(pipe_barrier_test_SOURCES) $(translate_test_SOURCES) \
$(u_cache_test_SOURCES) $(u_format_compatible_test_SOURCES) \
$(u_format_test_SOURCES) $(u_half_test_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
am__uniquify_input = $(AWK) '\
BEGIN { nonempty = 0; } \
{ items[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in items) print i; }; } \
'
# Make sure the list of sources is unique. This is necessary because,
# e.g., the same source file might be shared among _SOURCES variables
# for different programs/libraries.
am__define_uniq_tagged_files = \
list='$(am__tagged_files)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BUILD_EXEEXT = @BUILD_EXEEXT@
BUILD_OBJEXT = @BUILD_OBJEXT@
CC = @CC@
CCAS = @CCAS@
CCASDEPMODE = @CCASDEPMODE@
CCASFLAGS = @CCASFLAGS@
CCDEPMODE = @CCDEPMODE@
CC_FOR_BUILD = @CC_FOR_BUILD@
CFLAGS = @CFLAGS@
CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
CLANG_RESOURCE_DIR = @CLANG_RESOURCE_DIR@
CLOCK_LIB = @CLOCK_LIB@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@
CPP_FOR_BUILD = @CPP_FOR_BUILD@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXCPPFLAGS_FOR_BUILD = @CXXCPPFLAGS_FOR_BUILD@
CXXCPP_FOR_BUILD = @CXXCPP_FOR_BUILD@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@
CXX_FOR_BUILD = @CXX_FOR_BUILD@
CYGPATH_W = @CYGPATH_W@
DEFINES = @DEFINES@
DEFINES_FOR_BUILD = @DEFINES_FOR_BUILD@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DLOPEN_LIBS = @DLOPEN_LIBS@
DRI2PROTO_CFLAGS = @DRI2PROTO_CFLAGS@
DRI2PROTO_LIBS = @DRI2PROTO_LIBS@
DRIGL_CFLAGS = @DRIGL_CFLAGS@
DRIGL_LIBS = @DRIGL_LIBS@
DRI_DRIVER_INSTALL_DIR = @DRI_DRIVER_INSTALL_DIR@
DRI_DRIVER_SEARCH_DIR = @DRI_DRIVER_SEARCH_DIR@
DRI_LIB_DEPS = @DRI_LIB_DEPS@
DRI_PC_REQ_PRIV = @DRI_PC_REQ_PRIV@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGL_CFLAGS = @EGL_CFLAGS@
EGL_CLIENT_APIS = @EGL_CLIENT_APIS@
EGL_DRIVER_INSTALL_DIR = @EGL_DRIVER_INSTALL_DIR@
EGL_LIB_DEPS = @EGL_LIB_DEPS@
EGL_LIB_GLOB = @EGL_LIB_GLOB@
EGL_LIB_NAME = @EGL_LIB_NAME@
EGL_NATIVE_PLATFORM = @EGL_NATIVE_PLATFORM@
EGL_PLATFORMS = @EGL_PLATFORMS@
EGREP = @EGREP@
ELF_LIB = @ELF_LIB@
EXEEXT = @EXEEXT@
EXPAT_INCLUDES = @EXPAT_INCLUDES@
FGREP = @FGREP@
FREEDRENO_CFLAGS = @FREEDRENO_CFLAGS@
FREEDRENO_LIBS = @FREEDRENO_LIBS@
GALLIUM_DRI_LIB_DEPS = @GALLIUM_DRI_LIB_DEPS@
GALLIUM_PIPE_LOADER_DEFINES = @GALLIUM_PIPE_LOADER_DEFINES@
GALLIUM_PIPE_LOADER_LIBS = @GALLIUM_PIPE_LOADER_LIBS@
GALLIUM_PIPE_LOADER_XCB_CFLAGS = @GALLIUM_PIPE_LOADER_XCB_CFLAGS@
GALLIUM_PIPE_LOADER_XCB_LIBS = @GALLIUM_PIPE_LOADER_XCB_LIBS@
GBM_PC_LIB_PRIV = @GBM_PC_LIB_PRIV@
GBM_PC_REQ_PRIV = @GBM_PC_REQ_PRIV@
GLAPI_LIB_GLOB = @GLAPI_LIB_GLOB@
GLAPI_LIB_NAME = @GLAPI_LIB_NAME@
GLESv1_CM_LIB_DEPS = @GLESv1_CM_LIB_DEPS@
GLESv1_CM_LIB_GLOB = @GLESv1_CM_LIB_GLOB@
GLESv1_CM_LIB_NAME = @GLESv1_CM_LIB_NAME@
GLESv1_CM_PC_LIB_PRIV = @GLESv1_CM_PC_LIB_PRIV@
GLESv2_LIB_DEPS = @GLESv2_LIB_DEPS@
GLESv2_LIB_GLOB = @GLESv2_LIB_GLOB@
GLESv2_LIB_NAME = @GLESv2_LIB_NAME@
GLESv2_PC_LIB_PRIV = @GLESv2_PC_LIB_PRIV@
GLPROTO_CFLAGS = @GLPROTO_CFLAGS@
GLPROTO_LIBS = @GLPROTO_LIBS@
GLX_TLS = @GLX_TLS@
GL_LIB = @GL_LIB@
GL_LIB_DEPS = @GL_LIB_DEPS@
GL_LIB_GLOB = @GL_LIB_GLOB@
GL_LIB_NAME = @GL_LIB_NAME@
GL_PC_CFLAGS = @GL_PC_CFLAGS@
GL_PC_LIB_PRIV = @GL_PC_LIB_PRIV@
GL_PC_REQ_PRIV = @GL_PC_REQ_PRIV@
GREP = @GREP@
HAVE_XF86VIDMODE = @HAVE_XF86VIDMODE@
INDENT = @INDENT@
INDENT_FLAGS = @INDENT_FLAGS@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
INTEL_CFLAGS = @INTEL_CFLAGS@
INTEL_LIBS = @INTEL_LIBS@
LD = @LD@
LDFLAGS = @LDFLAGS@
LDFLAGS_FOR_BUILD = @LDFLAGS_FOR_BUILD@
LEX = @LEX@
LEXLIB = @LEXLIB@
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
LIBCLC_INCLUDEDIR = @LIBCLC_INCLUDEDIR@
LIBCLC_LIBEXECDIR = @LIBCLC_LIBEXECDIR@
LIBDRM_CFLAGS = @LIBDRM_CFLAGS@
LIBDRM_LIBS = @LIBDRM_LIBS@
LIBDRM_XORG_CFLAGS = @LIBDRM_XORG_CFLAGS@
LIBDRM_XORG_LIBS = @LIBDRM_XORG_LIBS@
LIBKMS_XORG_CFLAGS = @LIBKMS_XORG_CFLAGS@
LIBKMS_XORG_LIBS = @LIBKMS_XORG_LIBS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LIBUDEV_CFLAGS = @LIBUDEV_CFLAGS@
LIBUDEV_LIBS = @LIBUDEV_LIBS@
LIB_DIR = @LIB_DIR@
LIPO = @LIPO@
LLVM_BINDIR = @LLVM_BINDIR@
LLVM_CFLAGS = @LLVM_CFLAGS@
LLVM_CONFIG = @LLVM_CONFIG@
LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
LLVM_CXXFLAGS = @LLVM_CXXFLAGS@
LLVM_INCLUDEDIR = @LLVM_INCLUDEDIR@
LLVM_LDFLAGS = @LLVM_LDFLAGS@
LLVM_LIBDIR = @LLVM_LIBDIR@
LLVM_LIBS = @LLVM_LIBS@
LLVM_VERSION = @LLVM_VERSION@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKE = @MAKE@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MESA_LLVM = @MESA_LLVM@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
NOUVEAU_CFLAGS = @NOUVEAU_CFLAGS@
NOUVEAU_LIBS = @NOUVEAU_LIBS@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OPENCL_LIB_INSTALL_DIR = @OPENCL_LIB_INSTALL_DIR@
OSMESA_LIB = @OSMESA_LIB@
OSMESA_LIB_DEPS = @OSMESA_LIB_DEPS@
OSMESA_LIB_NAME = @OSMESA_LIB_NAME@
OSMESA_MESA_DEPS = @OSMESA_MESA_DEPS@
OSMESA_PC_LIB_PRIV = @OSMESA_PC_LIB_PRIV@
OSMESA_PC_REQ = @OSMESA_PC_REQ@
OSMESA_VERSION = @OSMESA_VERSION@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PERL = @PERL@
PKG_CONFIG = @PKG_CONFIG@
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
POSIX_SHELL = @POSIX_SHELL@
PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_LIBS = @PTHREAD_LIBS@
PYTHON2 = @PYTHON2@
RADEON_CFLAGS = @RADEON_CFLAGS@
RADEON_LIBS = @RADEON_LIBS@
RANLIB = @RANLIB@
SED = @SED@
SELINUX_LIBS = @SELINUX_LIBS@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VDPAU_CFLAGS = @VDPAU_CFLAGS@
VDPAU_LIBS = @VDPAU_LIBS@
VDPAU_LIB_INSTALL_DIR = @VDPAU_LIB_INSTALL_DIR@
VDPAU_MAJOR = @VDPAU_MAJOR@
VDPAU_MINOR = @VDPAU_MINOR@
VERSION = @VERSION@
VG_LIB_DEPS = @VG_LIB_DEPS@
VG_LIB_GLOB = @VG_LIB_GLOB@
VG_LIB_NAME = @VG_LIB_NAME@
VG_PC_LIB_PRIV = @VG_PC_LIB_PRIV@
VISIBILITY_CFLAGS = @VISIBILITY_CFLAGS@
VISIBILITY_CXXFLAGS = @VISIBILITY_CXXFLAGS@
WAYLAND_CFLAGS = @WAYLAND_CFLAGS@
WAYLAND_LIBS = @WAYLAND_LIBS@
WAYLAND_SCANNER = @WAYLAND_SCANNER@
X11_INCLUDES = @X11_INCLUDES@
XA_MAJOR = @XA_MAJOR@
XA_MINOR = @XA_MINOR@
XA_TINY = @XA_TINY@
XA_VERSION = @XA_VERSION@
XCB_DRI2_CFLAGS = @XCB_DRI2_CFLAGS@
XCB_DRI2_LIBS = @XCB_DRI2_LIBS@
XEXT_CFLAGS = @XEXT_CFLAGS@
XEXT_LIBS = @XEXT_LIBS@
XF86VIDMODE_CFLAGS = @XF86VIDMODE_CFLAGS@
XF86VIDMODE_LIBS = @XF86VIDMODE_LIBS@
XLIBGL_CFLAGS = @XLIBGL_CFLAGS@
XLIBGL_LIBS = @XLIBGL_LIBS@
XORG_CFLAGS = @XORG_CFLAGS@
XORG_DRIVER_INSTALL_DIR = @XORG_DRIVER_INSTALL_DIR@
XORG_LIBS = @XORG_LIBS@
XVMC_CFLAGS = @XVMC_CFLAGS@
XVMC_LIBS = @XVMC_LIBS@
XVMC_LIB_INSTALL_DIR = @XVMC_LIB_INSTALL_DIR@
XVMC_MAJOR = @XVMC_MAJOR@
XVMC_MINOR = @XVMC_MINOR@
YACC = @YACC@
YFLAGS = @YFLAGS@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CC_FOR_BUILD = @ac_ct_CC_FOR_BUILD@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_CXX_FOR_BUILD = @ac_ct_CXX_FOR_BUILD@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
ax_pthread_config = @ax_pthread_config@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target = @target@
target_alias = @target_alias@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
GALLIUM_CFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src/gallium/include \
-I$(top_srcdir)/src/gallium/auxiliary \
$(DEFINES)
 
AM_CFLAGS = \
$(GALLIUM_CFLAGS)
 
AM_CPPFLAGS = \
-I$(top_srcdir)/src/gallium/drivers \
-I$(top_srcdir)/src/gallium/winsys
 
LDADD = \
$(top_builddir)/src/gallium/auxiliary/libgallium.la \
$(top_builddir)/src/gallium/drivers/trace/libtrace.la \
$(top_builddir)/src/gallium/winsys/sw/null/libws_null.la \
$(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la \
$(DLOPEN_LIBS) \
$(PTHREAD_LIBS) \
-lm
 
pipe_barrier_test_SOURCES = pipe_barrier_test.c
u_cache_test_SOURCES = u_cache_test.c
u_half_test_SOURCES = u_half_test.c
u_format_test_SOURCES = u_format_test.c
u_format_compatible_test_SOURCES = u_format_compatible_test.c
translate_test_SOURCES = translate_test.c
all: all-am
 
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(top_srcdir)/src/gallium/Automake.inc $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/gallium/tests/unit/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign src/gallium/tests/unit/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_srcdir)/src/gallium/Automake.inc:
 
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
 
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
 
clean-noinstPROGRAMS:
@list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
echo " rm -f" $$list; \
rm -f $$list || exit $$?; \
test -n "$(EXEEXT)" || exit 0; \
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
 
pipe_barrier_test$(EXEEXT): $(pipe_barrier_test_OBJECTS) $(pipe_barrier_test_DEPENDENCIES) $(EXTRA_pipe_barrier_test_DEPENDENCIES)
@rm -f pipe_barrier_test$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(pipe_barrier_test_OBJECTS) $(pipe_barrier_test_LDADD) $(LIBS)
 
translate_test$(EXEEXT): $(translate_test_OBJECTS) $(translate_test_DEPENDENCIES) $(EXTRA_translate_test_DEPENDENCIES)
@rm -f translate_test$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(translate_test_OBJECTS) $(translate_test_LDADD) $(LIBS)
 
u_cache_test$(EXEEXT): $(u_cache_test_OBJECTS) $(u_cache_test_DEPENDENCIES) $(EXTRA_u_cache_test_DEPENDENCIES)
@rm -f u_cache_test$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(u_cache_test_OBJECTS) $(u_cache_test_LDADD) $(LIBS)
 
u_format_compatible_test$(EXEEXT): $(u_format_compatible_test_OBJECTS) $(u_format_compatible_test_DEPENDENCIES) $(EXTRA_u_format_compatible_test_DEPENDENCIES)
@rm -f u_format_compatible_test$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(u_format_compatible_test_OBJECTS) $(u_format_compatible_test_LDADD) $(LIBS)
 
u_format_test$(EXEEXT): $(u_format_test_OBJECTS) $(u_format_test_DEPENDENCIES) $(EXTRA_u_format_test_DEPENDENCIES)
@rm -f u_format_test$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(u_format_test_OBJECTS) $(u_format_test_LDADD) $(LIBS)
 
u_half_test$(EXEEXT): $(u_half_test_OBJECTS) $(u_half_test_DEPENDENCIES) $(EXTRA_u_half_test_DEPENDENCIES)
@rm -f u_half_test$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(u_half_test_OBJECTS) $(u_half_test_LDADD) $(LIBS)
 
mostlyclean-compile:
-rm -f *.$(OBJEXT)
 
distclean-compile:
-rm -f *.tab.c
 
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pipe_barrier_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/translate_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/u_cache_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/u_format_compatible_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/u_format_test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/u_half_test.Po@am__quote@
 
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
 
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
 
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
 
mostlyclean-libtool:
-rm -f *.lo
 
clean-libtool:
-rm -rf .libs _libs
 
ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
TAGS: tags
 
tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
$(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: ctags-am
 
CTAGS: ctags
ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
$(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
 
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
cscopelist: cscopelist-am
 
cscopelist-am: $(am__tagged_files)
list='$(am__tagged_files)'; \
case "$(srcdir)" in \
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
*) sdir=$(subdir)/$(srcdir) ;; \
esac; \
for i in $$list; do \
if test -f "$$i"; then \
echo "$(subdir)/$$i"; \
else \
echo "$$sdir/$$i"; \
fi; \
done >> $(top_builddir)/cscope.files
 
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
 
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS)
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
 
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
 
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
 
clean-generic:
 
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
 
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
 
clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
mostlyclean-am
 
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
 
dvi: dvi-am
 
dvi-am:
 
html: html-am
 
html-am:
 
info: info-am
 
info-am:
 
install-data-am:
 
install-dvi: install-dvi-am
 
install-dvi-am:
 
install-exec-am:
 
install-html: install-html-am
 
install-html-am:
 
install-info: install-info-am
 
install-info-am:
 
install-man:
 
install-pdf: install-pdf-am
 
install-pdf-am:
 
install-ps: install-ps-am
 
install-ps-am:
 
installcheck-am:
 
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
 
mostlyclean: mostlyclean-am
 
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
 
pdf: pdf-am
 
pdf-am:
 
ps: ps-am
 
ps-am:
 
uninstall-am:
 
.MAKE: install-am install-strip
 
.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
clean-libtool clean-noinstPROGRAMS cscopelist-am ctags \
ctags-am distclean distclean-compile distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-man install-pdf install-pdf-am \
install-ps install-ps-am install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags tags-am uninstall uninstall-am
 
 
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/unit/SConscript
0,0 → 1,33
Import('*')
 
env = env.Clone()
 
env.Prepend(LIBS = [gallium])
 
if env['platform'] in ('freebsd8', 'sunos'):
env.Append(LIBS = ['m'])
 
if env['platform'] == 'freebsd8':
env.Append(LIBS = ['pthread'])
 
progs = [
'pipe_barrier_test',
'u_cache_test',
'u_format_test',
'u_format_compatible_test',
'u_half_test',
'translate_test'
]
 
for progname in progs:
prog = env.Program(
target = progname,
source = progname + '.c',
)
env.Alias(progname, env.InstallProgram(prog))
 
# http://www.scons.org/wiki/UnitTests
test_alias = env.Alias('unit', [prog], prog[0].abspath)
AlwaysBuild(test_alias)
 
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/unit/pipe_barrier_test.c
0,0 → 1,86
/**************************************************************************
*
* Copyright 2009-2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
 
 
/*
* Test case for pipe_barrier.
*
* The test succeeds if no thread exits before all the other threads reach
* the barrier.
*/
 
 
#include <stdio.h>
 
#include "os/os_thread.h"
#include "os/os_time.h"
 
 
#define NUM_THREADS 10
 
static pipe_thread threads[NUM_THREADS];
static pipe_barrier barrier;
static int thread_ids[NUM_THREADS];
 
 
static PIPE_THREAD_ROUTINE(thread_function, thread_data)
{
int thread_id = *((int *) thread_data);
 
printf("thread %d starting\n", thread_id);
os_time_sleep(thread_id * 1000 * 1000);
printf("thread %d before barrier\n", thread_id);
pipe_barrier_wait(&barrier);
printf("thread %d exiting\n", thread_id);
 
return NULL;
}
 
 
int main()
{
int i;
 
printf("pipe_barrier_test starting\n");
 
pipe_barrier_init(&barrier, NUM_THREADS);
 
for (i = 0; i < NUM_THREADS; i++) {
thread_ids[i] = i;
threads[i] = pipe_thread_create(thread_function, (void *) &thread_ids[i]);
}
 
for (i = 0; i < NUM_THREADS; i++ ) {
pipe_thread_wait(threads[i]);
}
 
pipe_barrier_destroy(&barrier);
 
printf("pipe_barrier_test exiting\n");
 
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/unit/translate_test.c
0,0 → 1,324
/**************************************************************************
*
* Copyright © 2010 Luca Barbieri
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
 
#include <stdio.h>
#include "translate/translate.h"
#include "util/u_memory.h"
#include "util/u_format.h"
#include "util/u_half.h"
#include "util/u_cpu_detect.h"
#include "rtasm/rtasm_cpu.h"
 
/* don't use this for serious use */
static double rand_double()
{
const double rm = (double)RAND_MAX + 1;
double div = 1;
double v = 0;
unsigned i;
for(i = 0; i < 4; ++i)
{
div *= rm;
v += (double)rand() / div;
}
return v;
}
 
int main(int argc, char** argv)
{
struct translate *(*create_fn)(const struct translate_key *key) = 0;
 
struct translate_key key;
unsigned output_format;
unsigned input_format;
unsigned buffer_size = 4096;
unsigned char* buffer[5];
unsigned char* byte_buffer;
float* float_buffer;
double* double_buffer;
uint16_t *half_buffer;
unsigned * elts;
unsigned count = 4;
unsigned i, j, k;
unsigned passed = 0;
unsigned total = 0;
const float error = 0.03125;
 
create_fn = 0;
 
util_cpu_detect();
 
if(argc <= 1)
{}
else if (!strcmp(argv[1], "generic"))
create_fn = translate_generic_create;
else if (!strcmp(argv[1], "x86"))
create_fn = translate_sse2_create;
else if (!strcmp(argv[1], "nosse"))
{
util_cpu_caps.has_sse = 0;
util_cpu_caps.has_sse2 = 0;
util_cpu_caps.has_sse3 = 0;
util_cpu_caps.has_sse4_1 = 0;
create_fn = translate_sse2_create;
}
else if (!strcmp(argv[1], "sse"))
{
if(!util_cpu_caps.has_sse || !rtasm_cpu_has_sse())
{
printf("Error: CPU doesn't support SSE (test with qemu)\n");
return 2;
}
util_cpu_caps.has_sse2 = 0;
util_cpu_caps.has_sse3 = 0;
util_cpu_caps.has_sse4_1 = 0;
create_fn = translate_sse2_create;
}
else if (!strcmp(argv[1], "sse2"))
{
if(!util_cpu_caps.has_sse2 || !rtasm_cpu_has_sse())
{
printf("Error: CPU doesn't support SSE2 (test with qemu)\n");
return 2;
}
util_cpu_caps.has_sse3 = 0;
util_cpu_caps.has_sse4_1 = 0;
create_fn = translate_sse2_create;
}
else if (!strcmp(argv[1], "sse3"))
{
if(!util_cpu_caps.has_sse3 || !rtasm_cpu_has_sse())
{
printf("Error: CPU doesn't support SSE3 (test with qemu)\n");
return 2;
}
util_cpu_caps.has_sse4_1 = 0;
create_fn = translate_sse2_create;
}
else if (!strcmp(argv[1], "sse4.1"))
{
if(!util_cpu_caps.has_sse4_1 || !rtasm_cpu_has_sse())
{
printf("Error: CPU doesn't support SSE4.1 (test with qemu)\n");
return 2;
}
create_fn = translate_sse2_create;
}
 
if (!create_fn)
{
printf("Usage: ./translate_test [generic|x86|nosse|sse|sse2|sse3|sse4.1]\n");
return 2;
}
 
for (i = 1; i < Elements(buffer); ++i)
buffer[i] = align_malloc(buffer_size, 4096);
 
byte_buffer = align_malloc(buffer_size, 4096);
float_buffer = align_malloc(buffer_size, 4096);
double_buffer = align_malloc(buffer_size, 4096);
half_buffer = align_malloc(buffer_size, 4096);
 
elts = align_malloc(count * sizeof *elts, 4096);
 
key.nr_elements = 1;
key.element[0].input_buffer = 0;
key.element[0].input_offset = 0;
key.element[0].output_offset = 0;
key.element[0].type = TRANSLATE_ELEMENT_NORMAL;
key.element[0].instance_divisor = 0;
 
srand(4359025);
 
/* avoid negative values that work badly when converted to unsigned format*/
for (i = 0; i < buffer_size; ++i)
byte_buffer[i] = rand() & 0x7f7f7f7f;
 
for (i = 0; i < buffer_size / sizeof(float); ++i)
float_buffer[i] = (float)rand_double();
 
for (i = 0; i < buffer_size / sizeof(double); ++i)
double_buffer[i] = rand_double();
 
for (i = 0; i < buffer_size / sizeof(double); ++i)
half_buffer[i] = util_float_to_half((float) rand_double());
 
for (i = 0; i < count; ++i)
elts[i] = i;
 
for (output_format = 1; output_format < PIPE_FORMAT_COUNT; ++output_format)
{
const struct util_format_description* output_format_desc = util_format_description(output_format);
unsigned output_format_size;
unsigned output_normalized = 0;
 
if (!output_format_desc
|| !output_format_desc->fetch_rgba_float
|| !output_format_desc->pack_rgba_float
|| output_format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB
|| output_format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN
|| !translate_is_output_format_supported(output_format))
continue;
 
for(i = 0; i < output_format_desc->nr_channels; ++i)
{
if(output_format_desc->channel[i].type != UTIL_FORMAT_TYPE_FLOAT)
output_normalized |= (1 << output_format_desc->channel[i].normalized);
}
 
output_format_size = util_format_get_stride(output_format, 1);
 
for (input_format = 1; input_format < PIPE_FORMAT_COUNT; ++input_format)
{
const struct util_format_description* input_format_desc = util_format_description(input_format);
unsigned input_format_size;
struct translate* translate[2];
unsigned fail = 0;
unsigned used_generic = 0;
unsigned input_normalized = 0;
boolean input_is_float = FALSE;
 
if (!input_format_desc
|| !input_format_desc->fetch_rgba_float
|| !input_format_desc->pack_rgba_float
|| input_format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB
|| input_format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN
|| !translate_is_output_format_supported(input_format))
continue;
 
input_format_size = util_format_get_stride(input_format, 1);
 
for(i = 0; i < input_format_desc->nr_channels; ++i)
{
if(input_format_desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT)
{
input_is_float = 1;
input_normalized |= 1 << 1;
}
else
input_normalized |= (1 << input_format_desc->channel[i].normalized);
}
 
if(((input_normalized | output_normalized) == 3)
|| ((input_normalized & 1) && (output_normalized & 1)
&& input_format_size * output_format_desc->nr_channels > output_format_size * input_format_desc->nr_channels))
continue;
 
key.element[0].input_format = input_format;
key.element[0].output_format = output_format;
key.output_stride = output_format_size;
translate[0] = create_fn(&key);
if (!translate[0])
continue;
 
key.element[0].input_format = output_format;
key.element[0].output_format = input_format;
key.output_stride = input_format_size;
translate[1] = create_fn(&key);
if(!translate[1])
{
used_generic = 1;
translate[1] = translate_generic_create(&key);
if(!translate[1])
continue;
}
 
for(i = 1; i < 5; ++i)
memset(buffer[i], 0xcd - (0x22 * i), 4096);
 
if(input_is_float && input_format_desc->channel[0].size == 32)
buffer[0] = (unsigned char*)float_buffer;
else if(input_is_float && input_format_desc->channel[0].size == 64)
buffer[0] = (unsigned char*)double_buffer;
else if(input_is_float && input_format_desc->channel[0].size == 16)
buffer[0] = (unsigned char*)half_buffer;
else if(input_is_float)
abort();
else
buffer[0] = byte_buffer;
 
translate[0]->set_buffer(translate[0], 0, buffer[0], input_format_size, count - 1);
translate[0]->run_elts(translate[0], elts, count, 0, 0, buffer[1]);
translate[1]->set_buffer(translate[1], 0, buffer[1], output_format_size, count - 1);
translate[1]->run_elts(translate[1], elts, count, 0, 0, buffer[2]);
translate[0]->set_buffer(translate[0], 0, buffer[2], input_format_size, count - 1);
translate[0]->run_elts(translate[0], elts, count, 0, 0, buffer[3]);
translate[1]->set_buffer(translate[1], 0, buffer[3], output_format_size, count - 1);
translate[1]->run_elts(translate[1], elts, count, 0, 0, buffer[4]);
 
for (i = 0; i < count; ++i)
{
float a[4];
float b[4];
input_format_desc->fetch_rgba_float(a, buffer[2] + i * input_format_size, 0, 0);
input_format_desc->fetch_rgba_float(b, buffer[4] + i * input_format_size, 0, 0);
 
for (j = 0; j < count; ++j)
{
float d = a[j] - b[j];
if (d > error || d < -error)
{
fail = 1;
break;
}
}
}
 
printf("%s%s: %s -> %s -> %s -> %s -> %s\n",
fail ? "FAIL" : "PASS",
used_generic ? "[GENERIC]" : "",
input_format_desc->name, output_format_desc->name, input_format_desc->name, output_format_desc->name, input_format_desc->name);
 
if (1)
{
for (i = 0; i < Elements(buffer); ++i)
{
unsigned format_size = (i & 1) ? output_format_size : input_format_size;
printf("%c ", (i == 2 || i == 4) ? '*' : ' ');
for (j = 0; j < count; ++j)
{
for (k = 0; k < format_size; ++k)
{
printf("%02x", buffer[i][j * format_size + k]);
}
printf(" ");
}
printf("\n");
}
}
 
if (!fail)
++passed;
++total;
 
if(translate[1])
translate[1]->release(translate[1]);
translate[0]->release(translate[0]);
}
}
 
printf("%u/%u tests passed for translate_%s\n", passed, total, argv[1]);
return passed != total;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/unit/u_cache_test.c
0,0 → 1,121
/**************************************************************************
*
* Copyright 2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
 
 
/*
* Test case for u_cache.
*/
 
 
#include <assert.h>
#include <stdio.h>
 
#include "util/u_cache.h"
#include "util/u_hash.h"
 
 
typedef uint32_t cache_test_key;
typedef uint32_t cache_test_value;
 
 
static uint32_t
cache_test_hash(const void *key)
{
return util_hash_crc32(key, sizeof(cache_test_key));
}
 
 
static void
cache_test_destroy(void *key, void *value)
{
free(key);
free(value);
}
 
 
static int
cache_test_compare(const void *key1, const void *key2) {
return !(key1 == key2);
}
 
 
int main() {
unsigned cache_size;
unsigned cache_count;
 
for (cache_size = 2; cache_size < (1 << 15); cache_size *= 2) {
for (cache_count = (cache_size << 5); cache_count < (cache_size << 10); cache_count *= 2) {
struct util_cache * cache;
cache_test_key *key;
cache_test_value *value_in;
cache_test_value *value_out;
int i;
 
printf("Testing cache size of %d with %d values.\n", cache_size, cache_count);
 
cache = util_cache_create(cache_test_hash,
cache_test_compare,
cache_test_destroy,
cache_size);
 
/*
* Retrieve a value from an empty cache.
*/
key = malloc(sizeof(cache_test_key));
*key = 0xdeadbeef;
value_out = (cache_test_value *) util_cache_get(cache, key);
assert(value_out == NULL);
free(key);
 
 
/*
* Repeatedly insert into and retrieve values from the cache.
*/
for (i = 0; i < cache_count; i++) {
key = malloc(sizeof(cache_test_key));
value_in = malloc(sizeof(cache_test_value));
 
*key = rand();
*value_in = rand();
util_cache_set(cache, key, value_in);
 
value_out = util_cache_get(cache, key);
assert(value_out != NULL);
assert(value_in == value_out);
assert(*value_in == *value_out);
}
 
/*
* In debug builds, this will trigger a self-check by the cache of
* the distribution of hits in its internal cache entries.
*/
util_cache_destroy(cache);
}
}
 
return 0;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/unit/u_format_compatible_test.c
0,0 → 1,76
/**************************************************************************
*
* Copyright 2009-2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
 
 
#include <stdlib.h>
#include <stdio.h>
 
#include "util/u_format.h"
 
 
static boolean
test_all(void)
{
enum pipe_format src_format;
enum pipe_format dst_format;
 
for (src_format = 1; src_format < PIPE_FORMAT_COUNT; ++src_format) {
const struct util_format_description *src_format_desc;
src_format_desc = util_format_description(src_format);
if (!src_format_desc) {
continue;
}
 
for (dst_format = 1; dst_format < PIPE_FORMAT_COUNT; ++dst_format) {
const struct util_format_description *dst_format_desc;
dst_format_desc = util_format_description(dst_format);
if (!dst_format_desc) {
continue;
}
 
if (dst_format == src_format) {
continue;
}
 
if (util_is_format_compatible(src_format_desc, dst_format_desc)) {
printf("%s -> %s\n", src_format_desc->short_name, dst_format_desc->short_name);
}
}
}
 
return TRUE;
}
 
 
int main(int argc, char **argv)
{
boolean success;
 
success = test_all();
 
return success ? 0 : 1;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/unit/u_format_test.c
0,0 → 1,737
/**************************************************************************
*
* Copyright 2009-2010 VMware, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
 
 
#include <stdlib.h>
#include <stdio.h>
#include <float.h>
 
#include "util/u_half.h"
#include "util/u_format.h"
#include "util/u_format_tests.h"
#include "util/u_format_s3tc.h"
 
 
static boolean
compare_float(float x, float y)
{
float error = y - x;
 
if (error < 0.0f)
error = -error;
 
if (error > FLT_EPSILON) {
return FALSE;
}
 
return TRUE;
}
 
 
static void
print_packed(const struct util_format_description *format_desc,
const char *prefix,
const uint8_t *packed,
const char *suffix)
{
unsigned i;
const char *sep = "";
 
printf("%s", prefix);
for (i = 0; i < format_desc->block.bits/8; ++i) {
printf("%s%02x", sep, packed[i]);
sep = " ";
}
printf("%s", suffix);
fflush(stdout);
}
 
 
static void
print_unpacked_rgba_doubl(const struct util_format_description *format_desc,
const char *prefix,
const double unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4],
const char *suffix)
{
unsigned i, j;
const char *sep = "";
 
printf("%s", prefix);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]);
sep = ", ";
}
sep = ",\n";
}
printf("%s", suffix);
fflush(stdout);
}
 
 
static void
print_unpacked_rgba_float(const struct util_format_description *format_desc,
const char *prefix,
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4],
const char *suffix)
{
unsigned i, j;
const char *sep = "";
 
printf("%s", prefix);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
printf("%s{%f, %f, %f, %f}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]);
sep = ", ";
}
sep = ",\n";
}
printf("%s", suffix);
fflush(stdout);
}
 
 
static void
print_unpacked_rgba_8unorm(const struct util_format_description *format_desc,
const char *prefix,
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4],
const char *suffix)
{
unsigned i, j;
const char *sep = "";
 
printf("%s", prefix);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
printf("%s{0x%02x, 0x%02x, 0x%02x, 0x%02x}", sep, unpacked[i][j][0], unpacked[i][j][1], unpacked[i][j][2], unpacked[i][j][3]);
sep = ", ";
}
}
printf("%s", suffix);
fflush(stdout);
}
 
 
static void
print_unpacked_z_float(const struct util_format_description *format_desc,
const char *prefix,
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH],
const char *suffix)
{
unsigned i, j;
const char *sep = "";
 
printf("%s", prefix);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
printf("%s%f", sep, unpacked[i][j]);
sep = ", ";
}
sep = ",\n";
}
printf("%s", suffix);
fflush(stdout);
}
 
 
static void
print_unpacked_z_32unorm(const struct util_format_description *format_desc,
const char *prefix,
uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH],
const char *suffix)
{
unsigned i, j;
const char *sep = "";
 
printf("%s", prefix);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
printf("%s0x%08x", sep, unpacked[i][j]);
sep = ", ";
}
}
printf("%s", suffix);
fflush(stdout);
}
 
 
static void
print_unpacked_s_8uint(const struct util_format_description *format_desc,
const char *prefix,
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH],
const char *suffix)
{
unsigned i, j;
const char *sep = "";
 
printf("%s", prefix);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
printf("%s0x%02x", sep, unpacked[i][j]);
sep = ", ";
}
}
printf("%s", suffix);
fflush(stdout);
}
 
 
static boolean
test_format_fetch_rgba_float(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
unsigned i, j, k;
boolean success;
 
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
format_desc->fetch_rgba_float(unpacked[i][j], test->packed, j, i);
for (k = 0; k < 4; ++k) {
if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
success = FALSE;
}
}
}
}
 
if (!success) {
print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n");
print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n");
}
 
return success;
}
 
 
static boolean
test_format_unpack_rgba_float(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
unsigned i, j, k;
boolean success;
 
format_desc->unpack_rgba_float(&unpacked[0][0][0], sizeof unpacked[0],
test->packed, 0,
format_desc->block.width, format_desc->block.height);
 
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
for (k = 0; k < 4; ++k) {
if (!compare_float(test->unpacked[i][j][k], unpacked[i][j][k])) {
success = FALSE;
}
}
}
}
 
if (!success) {
print_unpacked_rgba_float(format_desc, "FAILED: ", unpacked, " obtained\n");
print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n");
}
 
return success;
}
 
 
static boolean
test_format_pack_rgba_float(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i, j, k;
boolean success;
 
if (test->format == PIPE_FORMAT_DXT1_RGBA) {
/*
* Skip S3TC as packed representation is not canonical.
*
* TODO: Do a round trip conversion.
*/
return TRUE;
}
 
memset(packed, 0, sizeof packed);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
for (k = 0; k < 4; ++k) {
unpacked[i][j][k] = (float) test->unpacked[i][j][k];
}
}
}
 
format_desc->pack_rgba_float(packed, 0,
&unpacked[0][0][0], sizeof unpacked[0],
format_desc->block.width, format_desc->block.height);
 
success = TRUE;
for (i = 0; i < format_desc->block.bits/8; ++i) {
if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
}
 
/* Ignore NaN */
if (util_is_double_nan(test->unpacked[0][0][0]))
success = TRUE;
 
if (!success) {
print_packed(format_desc, "FAILED: ", packed, " obtained\n");
print_packed(format_desc, " ", test->packed, " expected\n");
}
 
return success;
}
 
 
static boolean
convert_float_to_8unorm(uint8_t *dst, const double *src)
{
unsigned i;
boolean accurate = TRUE;
 
for (i = 0; i < UTIL_FORMAT_MAX_UNPACKED_HEIGHT*UTIL_FORMAT_MAX_UNPACKED_WIDTH*4; ++i) {
if (src[i] < 0.0) {
accurate = FALSE;
dst[i] = 0;
}
else if (src[i] > 1.0) {
accurate = FALSE;
dst[i] = 255;
}
else {
dst[i] = src[i] * 255.0;
}
}
 
return accurate;
}
 
 
static boolean
test_format_unpack_rgba_8unorm(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4] = { { { 0 } } };
unsigned i, j, k;
boolean success;
 
format_desc->unpack_rgba_8unorm(&unpacked[0][0][0], sizeof unpacked[0],
test->packed, 0,
format_desc->block.width, format_desc->block.height);
 
convert_float_to_8unorm(&expected[0][0][0], &test->unpacked[0][0][0]);
 
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
for (k = 0; k < 4; ++k) {
if (expected[i][j][k] != unpacked[i][j][k]) {
success = FALSE;
}
}
}
}
 
/* Ignore NaN */
if (util_is_double_nan(test->unpacked[0][0][0]))
success = TRUE;
 
if (!success) {
print_unpacked_rgba_8unorm(format_desc, "FAILED: ", unpacked, " obtained\n");
print_unpacked_rgba_8unorm(format_desc, " ", expected, " expected\n");
}
 
return success;
}
 
 
static boolean
test_format_pack_rgba_8unorm(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH][4];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i;
boolean success;
 
if (test->format == PIPE_FORMAT_DXT1_RGBA) {
/*
* Skip S3TC as packed representation is not canonical.
*
* TODO: Do a round trip conversion.
*/
return TRUE;
}
 
if (!convert_float_to_8unorm(&unpacked[0][0][0], &test->unpacked[0][0][0])) {
/*
* Skip test cases which cannot be represented by four unorm bytes.
*/
return TRUE;
}
 
memset(packed, 0, sizeof packed);
 
format_desc->pack_rgba_8unorm(packed, 0,
&unpacked[0][0][0], sizeof unpacked[0],
format_desc->block.width, format_desc->block.height);
 
success = TRUE;
for (i = 0; i < format_desc->block.bits/8; ++i)
if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
 
/* Ignore NaN */
if (util_is_double_nan(test->unpacked[0][0][0]))
success = TRUE;
 
/* Ignore failure cases due to unorm8 format */
if (test->unpacked[0][0][0] > 1.0f || test->unpacked[0][0][0] < 0.0f)
success = TRUE;
 
/* Multiple of 255 */
if ((test->unpacked[0][0][0] * 255.0) != (int)(test->unpacked[0][0][0] * 255.0))
success = TRUE;
 
if (!success) {
print_packed(format_desc, "FAILED: ", packed, " obtained\n");
print_packed(format_desc, " ", test->packed, " expected\n");
}
 
return success;
}
 
 
static boolean
test_format_unpack_z_float(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
unsigned i, j;
boolean success;
 
format_desc->unpack_z_float(&unpacked[0][0], sizeof unpacked[0],
test->packed, 0,
format_desc->block.width, format_desc->block.height);
 
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
if (!compare_float(test->unpacked[i][j][0], unpacked[i][j])) {
success = FALSE;
}
}
}
 
if (!success) {
print_unpacked_z_float(format_desc, "FAILED: ", unpacked, " obtained\n");
print_unpacked_rgba_doubl(format_desc, " ", test->unpacked, " expected\n");
}
 
return success;
}
 
 
static boolean
test_format_pack_z_float(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
float unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i, j;
boolean success;
 
memset(packed, 0, sizeof packed);
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
unpacked[i][j] = (float) test->unpacked[i][j][0];
if (test->unpacked[i][j][1]) {
return TRUE;
}
}
}
 
format_desc->pack_z_float(packed, 0,
&unpacked[0][0], sizeof unpacked[0],
format_desc->block.width, format_desc->block.height);
 
success = TRUE;
for (i = 0; i < format_desc->block.bits/8; ++i)
if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
 
if (!success) {
print_packed(format_desc, "FAILED: ", packed, " obtained\n");
print_packed(format_desc, " ", test->packed, " expected\n");
}
 
return success;
}
 
 
static boolean
test_format_unpack_z_32unorm(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
uint32_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
unsigned i, j;
boolean success;
 
format_desc->unpack_z_32unorm(&unpacked[0][0], sizeof unpacked[0],
test->packed, 0,
format_desc->block.width, format_desc->block.height);
 
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
expected[i][j] = test->unpacked[i][j][0] * 0xffffffff;
}
}
 
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
if (expected[i][j] != unpacked[i][j]) {
success = FALSE;
}
}
}
 
if (!success) {
print_unpacked_z_32unorm(format_desc, "FAILED: ", unpacked, " obtained\n");
print_unpacked_z_32unorm(format_desc, " ", expected, " expected\n");
}
 
return success;
}
 
 
static boolean
test_format_pack_z_32unorm(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
uint32_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i, j;
boolean success;
 
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
unpacked[i][j] = test->unpacked[i][j][0] * 0xffffffff;
if (test->unpacked[i][j][1]) {
return TRUE;
}
}
}
 
memset(packed, 0, sizeof packed);
 
format_desc->pack_z_32unorm(packed, 0,
&unpacked[0][0], sizeof unpacked[0],
format_desc->block.width, format_desc->block.height);
 
success = TRUE;
for (i = 0; i < format_desc->block.bits/8; ++i)
if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
 
if (!success) {
print_packed(format_desc, "FAILED: ", packed, " obtained\n");
print_packed(format_desc, " ", test->packed, " expected\n");
}
 
return success;
}
 
 
static boolean
test_format_unpack_s_8uint(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
uint8_t expected[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH] = { { 0 } };
unsigned i, j;
boolean success;
 
format_desc->unpack_s_8uint(&unpacked[0][0], sizeof unpacked[0],
test->packed, 0,
format_desc->block.width, format_desc->block.height);
 
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
expected[i][j] = test->unpacked[i][j][1];
}
}
 
success = TRUE;
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
if (expected[i][j] != unpacked[i][j]) {
success = FALSE;
}
}
}
 
if (!success) {
print_unpacked_s_8uint(format_desc, "FAILED: ", unpacked, " obtained\n");
print_unpacked_s_8uint(format_desc, " ", expected, " expected\n");
}
 
return success;
}
 
 
static boolean
test_format_pack_s_8uint(const struct util_format_description *format_desc,
const struct util_format_test_case *test)
{
uint8_t unpacked[UTIL_FORMAT_MAX_UNPACKED_HEIGHT][UTIL_FORMAT_MAX_UNPACKED_WIDTH];
uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES];
unsigned i, j;
boolean success;
 
for (i = 0; i < format_desc->block.height; ++i) {
for (j = 0; j < format_desc->block.width; ++j) {
unpacked[i][j] = test->unpacked[i][j][1];
if (test->unpacked[i][j][0]) {
return TRUE;
}
}
}
 
memset(packed, 0, sizeof packed);
 
format_desc->pack_s_8uint(packed, 0,
&unpacked[0][0], sizeof unpacked[0],
format_desc->block.width, format_desc->block.height);
 
success = TRUE;
for (i = 0; i < format_desc->block.bits/8; ++i)
if ((test->packed[i] & test->mask[i]) != (packed[i] & test->mask[i]))
success = FALSE;
 
if (!success) {
print_packed(format_desc, "FAILED: ", packed, " obtained\n");
print_packed(format_desc, " ", test->packed, " expected\n");
}
 
return success;
}
 
 
typedef boolean
(*test_func_t)(const struct util_format_description *format_desc,
const struct util_format_test_case *test);
 
 
static boolean
test_one_func(const struct util_format_description *format_desc,
test_func_t func,
const char *suffix)
{
unsigned i;
boolean success = TRUE;
 
printf("Testing util_format_%s_%s ...\n",
format_desc->short_name, suffix);
fflush(stdout);
 
for (i = 0; i < util_format_nr_test_cases; ++i) {
const struct util_format_test_case *test = &util_format_test_cases[i];
 
if (test->format == format_desc->format) {
if (!func(format_desc, &util_format_test_cases[i])) {
success = FALSE;
}
}
}
 
return success;
}
 
 
static boolean
test_all(void)
{
enum pipe_format format;
boolean success = TRUE;
 
for (format = 1; format < PIPE_FORMAT_COUNT; ++format) {
const struct util_format_description *format_desc;
 
format_desc = util_format_description(format);
if (!format_desc) {
continue;
}
 
if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC &&
!util_format_s3tc_enabled) {
continue;
}
 
# define TEST_ONE_FUNC(name) \
if (format_desc->name) { \
if (!test_one_func(format_desc, &test_format_##name, #name)) { \
success = FALSE; \
} \
}
 
TEST_ONE_FUNC(fetch_rgba_float);
TEST_ONE_FUNC(pack_rgba_float);
TEST_ONE_FUNC(unpack_rgba_float);
TEST_ONE_FUNC(pack_rgba_8unorm);
TEST_ONE_FUNC(unpack_rgba_8unorm);
 
TEST_ONE_FUNC(unpack_z_32unorm);
TEST_ONE_FUNC(pack_z_32unorm);
TEST_ONE_FUNC(unpack_z_float);
TEST_ONE_FUNC(pack_z_float);
TEST_ONE_FUNC(unpack_s_8uint);
TEST_ONE_FUNC(pack_s_8uint);
 
# undef TEST_ONE_FUNC
}
 
return success;
}
 
 
int main(int argc, char **argv)
{
boolean success;
 
util_format_s3tc_init();
 
success = test_all();
 
return success ? 0 : 1;
}
/contrib/sdk/sources/Mesa/mesa-9.2.5/src/gallium/tests/unit/u_half_test.c
0,0 → 1,35
#include <stdlib.h>
#include <stdio.h>
#include <float.h>
 
#include "util/u_math.h"
#include "util/u_half.h"
 
int
main(int argc, char **argv)
{
unsigned i;
unsigned roundtrip_fails = 0;
 
for(i = 0; i < 1 << 16; ++i)
{
uint16_t h = (uint16_t) i;
union fi f;
uint16_t rh;
 
f.f = util_half_to_float(h);
rh = util_float_to_half(f.f);
 
if (h != rh && !(util_is_half_nan(h) && util_is_half_nan(rh))) {
printf("Roundtrip failed: %x -> %x = %f -> %x\n", h, f.ui, f.f, rh);
++roundtrip_fails;
}
}
 
if(roundtrip_fails)
printf("Failure! %u/65536 half floats failed a conversion to float and back.\n", roundtrip_fails);
else
printf("Success!\n");
 
return 0;
}