delete graw tests

These seem abandoned and they make interfaces changes less easy.

Acked-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18705>
This commit is contained in:
Mike Blumenkrantz
2022-09-29 23:00:41 -04:00
committed by Marge Bot
parent 4b0f28d706
commit 1af804d554
94 changed files with 0 additions and 6578 deletions
-121
View File
@@ -1,121 +0,0 @@
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
#include <stdio.h>
#include "frontend/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, NULL, &clear_color, 0, 0);
ctx->flush(ctx, NULL, 0);
graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, ctx, tex, 0, 0, window, NULL);
}
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, 0);
if (ctx == NULL)
exit(3);
memset(&templat, 0, sizeof(templat));
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.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;
}
-90
View File
@@ -1,90 +0,0 @@
/**************************************************************************
*
* 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;
}
@@ -1,13 +0,0 @@
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
@@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
ADD OUT[0], IN[0], IN[0]
END
@@ -1,13 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL CONST[0][1]
DCL CONST[0][3]
DCL TEMP[0..1]
ADD TEMP[0], IN[0], CONST[0][1]
RCP TEMP[1], CONST[0][3].xxxx
MUL OUT[0], TEMP[0], TEMP[1]
END
@@ -1,9 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DCL CONST[1][6]
MOV OUT[0], CONST[1][6]
END
@@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DP3 OUT[0], IN[0], IN[0]
END
@@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DP4 OUT[0], IN[0].xyzx, IN[0].xyzx
END
@@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
DST OUT[0], IN[0], IN[0]
END
@@ -1,11 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
LIT OUT[0], IN[0]
END
@@ -1,11 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,11 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
MOV OUT[0], IN[0]
END
@@ -1,10 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,11 +0,0 @@
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
@@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
MOV OUT[0], IN[0].yxzw
END
@@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
SUB OUT[0], IN[0], IN[0].yzxw
END
@@ -1,14 +0,0 @@
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
@@ -1,11 +0,0 @@
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
@@ -1,8 +0,0 @@
FRAG
DCL IN[0], COLOR, LINEAR
DCL OUT[0], COLOR
XPD OUT[0], IN[0], IN[0].yzxw
END
-264
View File
@@ -1,264 +0,0 @@
/* 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"
#include "util/macros.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 ARRAY_SIZE(vertices)
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.resource = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &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,
NULL,
&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;
}
-211
View File
@@ -1,211 +0,0 @@
/* Test the TGSI_SEMANTIC_FACE fragment shader input.
*/
#include <stdio.h>
#include "graw_util.h"
#include "util/macros.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 ARRAY_SIZE(vertices)
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.resource = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &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,
NULL,
&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;
}
-518
View File
@@ -1,518 +0,0 @@
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
#include "frontend/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, false,
&cb1);
memset(&cb2, 0, sizeof cb2);
cb2.buffer_size = sizeof constants2;
cb2.user_buffer = constants2;
ctx->set_constant_buffer(ctx,
PIPE_SHADER_FRAGMENT, 1, false,
&cb2);
}
static void set_viewport( float x, float y,
float width, float height,
float zNear, float zFar)
{
float z = zFar;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)zFar - (float)zNear) / 2.0f;
struct pipe_viewport_state vp;
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
vp.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
vp.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
vp.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
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.resource = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
ctx->set_vertex_buffers(ctx, 0, 1, 0, false, &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, NULL, &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, ctx, rttex, 0, 0, window, NULL);
}
#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
memset(&templat, 0, sizeof(templat));
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.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->texture_subdata(ctx,
samptex,
0,
PIPE_MAP_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_texture_map(ctx, samptex,
0, 0, /* level, layer */
PIPE_MAP_READ,
0, 0, SIZE, SIZE, &t); /* x, y, width, height */
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
ctx->texture_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_sampler_views(ctx, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &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_sampler_states(ctx, PIPE_SHADER_FRAGMENT, 0, 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, 0);
if (ctx == NULL)
exit(3);
memset(&templat, 0, sizeof(templat));
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.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_near = 1;
rasterizer.depth_clip_far = 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;
}
-227
View File
@@ -1,227 +0,0 @@
/* 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"
#include "util/macros.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 ARRAY_SIZE(vertices)
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.resource = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &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,
NULL,
&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;
}
@@ -1,24 +0,0 @@
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
@@ -1,24 +0,0 @@
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
@@ -1,28 +0,0 @@
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
@@ -1,25 +0,0 @@
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
@@ -1,24 +0,0 @@
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
@@ -1,42 +0,0 @@
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
-329
View File
@@ -1,329 +0,0 @@
#include "frontend/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_debug_image.h"
#include "util/u_draw_quad.h"
#include "util/format/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));
memset(&resource_temp, 0, sizeof(resource_temp));
/* 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, 0);
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.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.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 zNear, float zFar)
{
float z = zNear;
float half_width = width / 2.0f;
float half_height = height / 2.0f;
float half_depth = (zFar - zNear) / 2.0f;
struct pipe_viewport_state vp;
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
vp.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
vp.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
vp.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
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->ctx, info->color_buf[0],
0, 0, info->window, NULL);
}
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;
memset(&temp, 0, sizeof(temp));
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.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->texture_subdata(info->ctx,
tex,
0,
PIPE_MAP_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_texture_map(info->ctx, samptex,
0, 0, /* level, layer */
PIPE_MAP_READ,
0, 0, SIZE, SIZE); /* x, y, width, height */
ptr = info->ctx->texture_map(info->ctx, t);
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
info->ctx->texture_unmap(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_X;
sv_temp.swizzle_g = PIPE_SWIZZLE_Y;
sv_temp.swizzle_b = PIPE_SWIZZLE_Z;
sv_temp.swizzle_a = PIPE_SWIZZLE_W;
sv = info->ctx->create_sampler_view(info->ctx, texture, &sv_temp);
return sv;
}
-613
View File
@@ -1,613 +0,0 @@
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
#include "frontend/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;
memset(&templat, 0, sizeof(templat));
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.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);
{
ctx->buffer_subdata(ctx, constbuf1,
PIPE_MAP_WRITE,
0, sizeof(constants1), constants1);
pipe_set_constant_buffer(ctx,
PIPE_SHADER_GEOMETRY, 0,
constbuf1);
}
{
ctx->buffer_subdata(ctx, constbuf2,
PIPE_MAP_WRITE,
0, sizeof(constants2), constants2);
pipe_set_constant_buffer(ctx,
PIPE_SHADER_GEOMETRY, 1,
constbuf2);
}
}
static void set_viewport( float x, float y,
float width, float height,
float zNear, float zFar)
{
float z = zFar;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)zFar - (float)zNear) / 2.0f;
struct pipe_viewport_state vp;
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
vp.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
vp.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
vp.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
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.resource = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices_strip),
vertices_strip);
} else {
vbuf.buffer.resource = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
}
ctx->set_vertex_buffers(ctx, 0, 1, 0, false, &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, NULL, &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, ctx, rttex, 0, 0, window, NULL);
}
#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
memset(&templat, 0, sizeof(templat));
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.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->texture_subdata(ctx,
samptex,
0,
PIPE_MAP_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_texture_map(ctx, samptex,
0, 0, /* level, layer */
PIPE_MAP_READ,
0, 0, SIZE, SIZE, &t); /* x, y, width, height */
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
ctx->texture_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_sampler_views(ctx, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &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_sampler_states(ctx, PIPE_SHADER_FRAGMENT, 0, 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, 0);
if (ctx == NULL)
exit(3);
memset(&templat, 0, sizeof(templat));
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.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_near = 1;
rasterizer.depth_clip_far = 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;
}
-36
View File
@@ -1,36 +0,0 @@
# Copyright © 2018 Intel Corporation
# 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 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.
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-large', 'tri-gs', 'tri-instanced',
'vs-test',
]
foreach t : progs
executable(
'graw-' + t,
t + '.c',
include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
link_with : [libgraw, libgraw_util, libgallium],
dependencies : [dep_m, idep_mesautil],
)
endforeach
-245
View File
@@ -1,245 +0,0 @@
/* Test gallium occlusion queries.
*/
#include <stdio.h>
#include <inttypes.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.resource = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
bytes,
vertices);
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &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,
NULL,
&clear_color, 1.0, 0);
q1 = info.ctx->create_query(info.ctx, PIPE_QUERY_OCCLUSION_COUNTER, 0);
q2 = info.ctx->create_query(info.ctx, PIPE_QUERY_OCCLUSION_COUNTER, 0);
/* 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 = %" PRIu64 " result2 = %" PRIu64 "\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;
}
-417
View File
@@ -1,417 +0,0 @@
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
#include "frontend/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 zNear, float zFar)
{
float z = zFar;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)zFar - (float)zNear) / 2.0f;
struct pipe_viewport_state vp;
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
vp.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
vp.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
vp.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
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.resource = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
ctx->set_vertex_buffers(ctx, 0, 1, 0, false, &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, NULL, &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, ctx, rttex, 0, 0, window, NULL);
}
#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
memset(&templat, 0, sizeof(templat));
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.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->texture_subdata(ctx,
samptex,
0,
PIPE_MAP_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_texture_map(ctx, samptex,
0, 0, /* level, layer */
PIPE_MAP_READ,
0, 0, SIZE, SIZE, &t); /* x, y, width, height */
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
ctx->texture_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_sampler_views(ctx, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &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_sampler_states(ctx, PIPE_SHADER_FRAGMENT, 0, 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, 0);
if (ctx == NULL)
exit(3);
memset(&templat, 0, sizeof(templat));
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.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_near = 1;
rasterizer.depth_clip_far = 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;
}
-231
View File
@@ -1,231 +0,0 @@
/* 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.resource = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &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"
"DCL SVIEW[0], 2D, FLOAT\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, NULL, &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_sampler_views(info.ctx, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &sv);
sampler = graw_util_create_simple_sampler(&info,
PIPE_TEX_WRAP_REPEAT,
PIPE_TEX_FILTER_NEAREST);
info.ctx->bind_sampler_states(info.ctx, PIPE_SHADER_FRAGMENT,
0, 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_near = 1;
rasterizer.depth_clip_far = 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;
}
-282
View File
@@ -1,282 +0,0 @@
/**
* Create shaders in a loop to test memory usage.
*/
#include <stdio.h>
#include "frontend/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 zNear, float zFar)
{
float z = zFar;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)zFar - (float)zNear) / 2.0f;
struct pipe_viewport_state vp;
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
vp.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
vp.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
vp.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
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.resource = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
ctx->set_vertex_buffers(ctx, 0, 1, 0, false, &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, NULL, &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, ctx, tex, 0, 0, window, NULL);
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, 0);
if (ctx == NULL)
exit(3);
memset(&templat, 0, sizeof(templat));
templat.target = PIPE_TEXTURE_2D;
templat.format = formats[i];
templat.width0 = WIDTH;
templat.height0 = HEIGHT;
templat.depth0 = 1;
templat.last_level = 0;
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_near = 1;
rasterizer.depth_clip_far = 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;
}
-228
View File
@@ -1,228 +0,0 @@
/* 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.resource = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
num_verts * sizeof(struct vertex),
verts);
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &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"
"DCL SVIEW[0], 2D, FLOAT\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, NULL, &clear_color, 0, 0);
info.ctx->set_sampler_views(info.ctx, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &linear_sv);
set_vertices(vertices1, 4);
util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, 4);
info.ctx->set_sampler_views(info.ctx, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &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_sampler_states(info.ctx, PIPE_SHADER_FRAGMENT,
0, 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_X;
sv_temp.swizzle_g = PIPE_SWIZZLE_Y;
sv_temp.swizzle_b = PIPE_SWIZZLE_Z;
sv_temp.swizzle_a = PIPE_SWIZZLE_W;
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_X;
sv_temp.swizzle_g = PIPE_SWIZZLE_Y;
sv_temp.swizzle_b = PIPE_SWIZZLE_Z;
sv_temp.swizzle_a = PIPE_SWIZZLE_W;
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;
}
-230
View File
@@ -1,230 +0,0 @@
/* 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.resource = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &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"
"DCL SVIEW[0], 2D, FLOAT\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, NULL, &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_sampler_views(info.ctx, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &sv);
sampler = graw_util_create_simple_sampler(&info,
PIPE_TEX_WRAP_REPEAT,
PIPE_TEX_FILTER_NEAREST);
info.ctx->bind_sampler_states(info.ctx, PIPE_SHADER_FRAGMENT,
0, 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_X;
case 'g':
return PIPE_SWIZZLE_Y;
case 'b':
return PIPE_SWIZZLE_Z;
case 'a':
return PIPE_SWIZZLE_W;
case '0':
return PIPE_SWIZZLE_0;
case '1':
return PIPE_SWIZZLE_1;
default:
return PIPE_SWIZZLE_X;
}
}
int main(int argc, char *argv[])
{
const char swizzle_names[] = "rgba01";
uint swizzle[4];
int i;
swizzle[0] = PIPE_SWIZZLE_X;
swizzle[1] = PIPE_SWIZZLE_Y;
swizzle[2] = PIPE_SWIZZLE_Z;
swizzle[3] = PIPE_SWIZZLE_W;
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;
}
-6
View File
@@ -1,6 +0,0 @@
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
-284
View File
@@ -1,284 +0,0 @@
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
#include <stdio.h>
#include "frontend/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 zNear, float zFar)
{
float z = zFar;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)zFar - (float)zNear) / 2.0f;
struct pipe_viewport_state vp;
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
vp.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
vp.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
vp.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
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.resource = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
ctx->set_vertex_buffers(ctx, 0, 1, 0, false, &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, NULL, &clear_color, 0, 0);
util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3);
ctx->flush(ctx, NULL, 0);
screen->flush_frontbuffer(screen, ctx, tex, 0, 0, window, NULL);
}
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, 0);
if (ctx == NULL)
exit(3);
memset(&templat, 0, sizeof(templat));
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.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_near = 1;
rasterizer.depth_clip_far = 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;
}
-361
View File
@@ -1,361 +0,0 @@
/*
* Test draw instancing.
*/
#include <stdio.h>
#include <string.h>
#include "frontend/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 zNear, float zFar)
{
float z = zFar;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)zFar - (float)zNear) / 2.0f;
struct pipe_viewport_state vp;
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
vp.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
vp.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
vp.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
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];
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.resource = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
/* instance data */
vbuf[1].stride = sizeof( inst_data[0] );
vbuf[1].buffer_offset = 0;
vbuf[1].buffer.resource = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(inst_data),
inst_data);
ctx->set_vertex_buffers(ctx, 0, 2, 0, false, 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\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;
struct pipe_draw_start_count_bias draw;
ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
util_draw_init_info(&info);
info.index_size = draw_elements ? 2 : 0;
info.mode = PIPE_PRIM_TRIANGLES;
draw.start = 0;
draw.count = 3;
draw.index_bias = 0;
/* draw NUM_INST triangles */
info.instance_count = NUM_INST;
/* index data */
if (info.index_size) {
info.index.resource =
pipe_buffer_create_with_data(ctx,
PIPE_BIND_INDEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(indices),
indices);
}
ctx->draw_vbo(ctx, &info, 0, NULL, &draw, 1);
pipe_resource_reference(&info.index.resource, NULL);
ctx->flush(ctx, NULL, 0);
graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, ctx, tex, 0, 0, window, NULL);
}
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, 0);
if (ctx == NULL)
exit(3);
memset(&templat, 0, sizeof(templat));
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.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_near = 1;
rasterizer.depth_clip_far = 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;
}
-175
View File
@@ -1,175 +0,0 @@
/* Display a huge triangle on a 8192x8192 canvas.
* This demo has no dependencies on any utility code,
* just the graw interface and gallium.
*/
#include "graw_util.h"
#include "util/u_debug.h"
#include <stdio.h>
static struct graw_info info;
static const int WIDTH = 4*2048;
static const int HEIGHT = 4*2048;
struct vertex {
float position[4];
float color[4];
};
static boolean FlatShade = FALSE;
static struct vertex vertices[3] =
{
{
{ -1.0f, -1.0f, 0.0f, 1.0f },
{ 1.0f, 0.0f, 0.0f, 1.0f }
},
{
{ -1.0f, 1.0f, 0.0f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 1.0f }
},
{
{ 1.0f, 1.0f, 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.resource = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &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, NULL, &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_near = 1;
rasterizer.depth_clip_far = 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;
}
-172
View File
@@ -1,172 +0,0 @@
/* 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.resource = pipe_buffer_create_with_data(info.ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
info.ctx->set_vertex_buffers(info.ctx, 0, 1, 0, false, &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, NULL, &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_near = 1;
rasterizer.depth_clip_far = 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;
}
@@ -1,15 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,23 +0,0 @@
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
@@ -1,23 +0,0 @@
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
@@ -1,16 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL CONST[0][1]
DCL CONST[0][3]
DCL TEMP[0..1]
MOV OUT[0], IN[0]
ADD TEMP[0], IN[1], CONST[0][1]
RCP TEMP[1], CONST[0][3].xxxx
MUL OUT[1], TEMP[0], TEMP[1]
END
@@ -1,12 +0,0 @@
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
@@ -1,16 +0,0 @@
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
@@ -1,16 +0,0 @@
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
@@ -1,11 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1,23 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,13 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
DCL TEMP[1]
IMM[0] INT32 {-2147483648, 2, 0, -1}
MOV OUT[0], IN[0]
IMUL_HI TEMP[0], IMM[0].xzzx, IMM[0].yzzy
UMUL TEMP[0], TEMP[0], IMM[0].wwww
I2F OUT[1], TEMP[0]
END
@@ -1,18 +0,0 @@
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
@@ -1,11 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,11 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1,16 +0,0 @@
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
@@ -1,16 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,16 +0,0 @@
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
@@ -1,12 +0,0 @@
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
@@ -1,11 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,9 +0,0 @@
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
@@ -1,11 +0,0 @@
VERT
DCL IN[0]
DCL IN[1]
DCL OUT[0], POSITION
DCL OUT[1], COLOR
DCL TEMP[0]
IMM[0] INT32 {4, 1073741824, 0, 1}
MOV OUT[0], IN[0]
UMUL_HI TEMP[0], IMM[0].xzzx, IMM[0].yzzy
I2F OUT[1], TEMP[0]
END
@@ -1,11 +0,0 @@
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
-507
View File
@@ -1,507 +0,0 @@
/* Display a cleared blue window. This demo has no dependencies on
* any utility code, just the graw interface and gallium.
*/
#include "frontend/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;
memset(&templat, 0, sizeof(templat));
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.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->buffer_subdata(ctx, constbuf,
PIPE_MAP_WRITE,
0, sizeof(constants), constants);
pipe_set_constant_buffer(ctx,
PIPE_SHADER_VERTEX, 0,
constbuf);
}
static void set_viewport( float x, float y,
float width, float height,
float zNear, float zFar)
{
float z = zFar;
float half_width = (float)width / 2.0f;
float half_height = (float)height / 2.0f;
float half_depth = ((float)zFar - (float)zNear) / 2.0f;
struct pipe_viewport_state vp;
vp.scale[0] = half_width;
vp.scale[1] = half_height;
vp.scale[2] = half_depth;
vp.translate[0] = half_width + x;
vp.translate[1] = half_height + y;
vp.translate[2] = half_depth + z;
vp.swizzle_x = PIPE_VIEWPORT_SWIZZLE_POSITIVE_X;
vp.swizzle_y = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Y;
vp.swizzle_z = PIPE_VIEWPORT_SWIZZLE_POSITIVE_Z;
vp.swizzle_w = PIPE_VIEWPORT_SWIZZLE_POSITIVE_W;
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.resource = pipe_buffer_create_with_data(ctx,
PIPE_BIND_VERTEX_BUFFER,
PIPE_USAGE_DEFAULT,
sizeof(vertices),
vertices);
ctx->set_vertex_buffers(ctx, 0, 1, 0, false, &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, NULL, &clear_color, 0, 0);
util_draw_arrays(ctx, PIPE_PRIM_POINTS, 0, ARRAY_SIZE(vertices));
ctx->flush(ctx, NULL, 0);
graw_save_surface_to_file(ctx, surf, NULL);
screen->flush_frontbuffer(screen, ctx, rttex, 0, 0, window, NULL);
}
#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
memset(&templat, 0, sizeof(templat));
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.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->texture_subdata(ctx,
samptex,
0,
PIPE_MAP_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_texture_map(ctx, samptex,
0, 0, /* level, layer */
PIPE_MAP_READ,
0, 0, SIZE, SIZE, &t); /* x, y, width, height */
if (memcmp(ptr, tex2d, sizeof tex2d) != 0) {
assert(0);
exit(9);
}
ctx->texture_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_sampler_views(ctx, PIPE_SHADER_FRAGMENT, 0, 1, 0, false, &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_sampler_states(ctx, PIPE_SHADER_FRAGMENT, 0, 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, 0);
if (ctx == NULL)
exit(3);
memset(&templat, 0, sizeof(templat));
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.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_near = 1;
rasterizer.depth_clip_far = 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;
}
-2
View File
@@ -25,5 +25,3 @@ endif
if with_gallium_softpipe
subdir('unit')
endif
subdir('graw')