X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Ftests%2Ftrivial%2Fquad-tex.c;h=4c5a9200a52b7bb8b7a8c7b2e5c2fb15c884099b;hb=74d41a32bc179425e866f8afa33a222488ea7760;hp=7ad157c5ac79ac0006e0276b6ecad49fd60b103f;hpb=1318848f782cce716d6376ca13aebf68b728e24c;p=mesa.git diff --git a/src/gallium/tests/trivial/quad-tex.c b/src/gallium/tests/trivial/quad-tex.c index 7ad157c5ac7..4c5a9200a52 100644 --- a/src/gallium/tests/trivial/quad-tex.c +++ b/src/gallium/tests/trivial/quad-tex.c @@ -57,21 +57,12 @@ #include "util/u_memory.h" /* util_make_[fragment|vertex]_passthrough_shader */ #include "util/u_simple_shaders.h" - -/* softpipe software driver */ -#include "softpipe/sp_public.h" - -/* null software winsys */ -#include "sw/null/null_sw_winsys.h" - -/* traceing support see src/gallium/drivers/trace/README for more info. */ -#if USE_TRACE -#include "trace/tr_screen.h" -#include "trace/tr_context.h" -#endif +/* to get a hardware pipe driver */ +#include "pipe-loader/pipe_loader.h" struct program { + struct pipe_loader_device *dev; struct pipe_screen *screen; struct pipe_context *pipe; struct cso_context *cso; @@ -87,29 +78,36 @@ struct program void *vs; void *fs; - float clear_color[4]; + union pipe_color_union clear_color; - struct pipe_buffer *vbuf; - struct pipe_texture *target; - struct pipe_texture *tex; + struct pipe_resource *vbuf; + struct pipe_resource *target; + struct pipe_resource *tex; struct pipe_sampler_view *view; }; static void init_prog(struct program *p) { - /* create the software rasterizer */ - p->screen = softpipe_create_screen(null_sw_create()); -#if USE_TRACE - p->screen = trace_screen_create(p->screen); -#endif - p->pipe = p->screen->context_create(p->screen, NULL); + struct pipe_surface surf_tmpl; + int ret; + + /* find a hardware device */ + ret = pipe_loader_probe(&p->dev, 1); + assert(ret); + + /* init a pipe screen */ + p->screen = pipe_loader_create_screen(p->dev); + assert(p->screen); + + /* create the pipe driver context and cso context */ + p->pipe = p->screen->context_create(p->screen, NULL, 0); p->cso = cso_create_context(p->pipe); /* set clear color */ - p->clear_color[0] = 0.3; - p->clear_color[1] = 0.1; - p->clear_color[2] = 0.3; - p->clear_color[3] = 1.0; + p->clear_color.f[0] = 0.3; + p->clear_color.f[1] = 0.1; + p->clear_color.f[2] = 0.3; + p->clear_color.f[3] = 1.0; /* vertex buffer */ { @@ -132,19 +130,21 @@ static void init_prog(struct program *p) } }; - p->vbuf = pipe_buffer_create(p->screen, 16, PIPE_BUFFER_USAGE_VERTEX, sizeof(vertices)); - pipe_buffer_write(p->screen, p->vbuf, 0, sizeof(vertices), vertices); + p->vbuf = pipe_buffer_create(p->screen, PIPE_BIND_VERTEX_BUFFER, + PIPE_USAGE_DEFAULT, sizeof(vertices)); + pipe_buffer_write(p->pipe, p->vbuf, 0, sizeof(vertices), vertices); } /* render target texture */ { - struct pipe_texture tmplt; + struct pipe_resource tmplt; memset(&tmplt, 0, sizeof(tmplt)); tmplt.target = PIPE_TEXTURE_2D; tmplt.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ tmplt.width0 = WIDTH; tmplt.height0 = HEIGHT; tmplt.depth0 = 1; + tmplt.array_size = 1; tmplt.last_level = 0; tmplt.bind = PIPE_BIND_RENDER_TARGET; @@ -155,8 +155,9 @@ static void init_prog(struct program *p) { uint32_t *ptr; struct pipe_transfer *t; - struct pipe_texture t_tmplt; + struct pipe_resource t_tmplt; struct pipe_sampler_view v_tmplt; + struct pipe_box box; memset(&t_tmplt, 0, sizeof(t_tmplt)); t_tmplt.target = PIPE_TEXTURE_2D; @@ -164,25 +165,23 @@ static void init_prog(struct program *p) t_tmplt.width0 = 2; t_tmplt.height0 = 2; t_tmplt.depth0 = 1; + t_tmplt.array_size = 1; t_tmplt.last_level = 0; t_tmplt.bind = PIPE_BIND_RENDER_TARGET; p->tex = p->screen->resource_create(p->screen, &t_tmplt); - t = p->pipe->get_tex_transfer(p->pipe, p->tex, - 0, 0, 0, /* face, level, zslice */ - PIPE_TRANSFER_WRITE, - 0, 0, 2, 2); /* x, y, width, height */ + memset(&box, 0, sizeof(box)); + box.width = 2; + box.height = 2; - ptr = p->pipe->transfer_map(p->pipe, t); + ptr = p->pipe->transfer_map(p->pipe, p->tex, 0, PIPE_TRANSFER_WRITE, &box, &t); ptr[0] = 0xffff0000; ptr[1] = 0xff0000ff; ptr[2] = 0xff00ff00; ptr[3] = 0xffffff00; p->pipe->transfer_unmap(p->pipe, t); - p->pipe->tex_transfer_destroy(p->pipe, t); - u_sampler_view_default_template(&v_tmplt, p->tex, p->tex->format); p->view = p->pipe->create_sampler_view(p->pipe, p->tex, &v_tmplt); @@ -197,9 +196,10 @@ static void init_prog(struct program *p) /* rasterizer */ memset(&p->rasterizer, 0, sizeof(p->rasterizer)); - p->rasterizer.front_winding = PIPE_WINDING_CW; - p->rasterizer.cull_mode = PIPE_WINDING_NONE; - p->rasterizer.gl_rasterization_rules = 1; + p->rasterizer.cull_face = PIPE_FACE_NONE; + p->rasterizer.half_pixel_center = 1; + p->rasterizer.bottom_edge_rule = 1; + p->rasterizer.depth_clip = 1; /* sampler */ memset(&p->sampler, 0, sizeof(p->sampler)); @@ -211,12 +211,16 @@ static void init_prog(struct program *p) p->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_LINEAR; p->sampler.normalized_coords = 1; + surf_tmpl.format = PIPE_FORMAT_B8G8R8A8_UNORM; /* All drivers support this */ + surf_tmpl.u.tex.level = 0; + surf_tmpl.u.tex.first_layer = 0; + surf_tmpl.u.tex.last_layer = 0; /* drawing destination */ memset(&p->framebuffer, 0, sizeof(p->framebuffer)); p->framebuffer.width = WIDTH; p->framebuffer.height = HEIGHT; p->framebuffer.nr_cbufs = 1; - p->framebuffer.cbufs[0] = p->screen->get_tex_surface(p->screen, p->target, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE); + p->framebuffer.cbufs[0] = p->pipe->create_surface(p->pipe, p->target, &surf_tmpl); /* viewport, depth isn't really needed */ { @@ -239,12 +243,10 @@ static void init_prog(struct program *p) p->viewport.scale[0] = half_width; p->viewport.scale[1] = half_height * scale; p->viewport.scale[2] = half_depth; - p->viewport.scale[3] = 1.0f; p->viewport.translate[0] = half_width + x; p->viewport.translate[1] = (half_height + y) * scale + bias; p->viewport.translate[2] = half_depth + z; - p->viewport.translate[3] = 0.0f; } /* vertex elements state */ @@ -264,44 +266,44 @@ static void init_prog(struct program *p) const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC }; const uint semantic_indexes[] = { 0, 0 }; - p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes); + p->vs = util_make_vertex_passthrough_shader(p->pipe, 2, semantic_names, semantic_indexes, FALSE); } /* fragment shader */ - p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D); + p->fs = util_make_fragment_tex_shader(p->pipe, TGSI_TEXTURE_2D, + TGSI_INTERPOLATE_LINEAR, + TGSI_RETURN_TYPE_FLOAT); } static void close_prog(struct program *p) { - /* unset bound textures as well */ - cso_set_fragment_sampler_views(p->cso, 0, NULL); - - /* unset all state */ - cso_release_all(p->cso); + cso_destroy_context(p->cso); p->pipe->delete_vs_state(p->pipe, p->vs); p->pipe->delete_fs_state(p->pipe, p->fs); pipe_surface_reference(&p->framebuffer.cbufs[0], NULL); pipe_sampler_view_reference(&p->view, NULL); - pipe_texture_reference(&p->target, NULL); - pipe_texture_reference(&p->tex, NULL); - pipe_buffer_reference(&p->vbuf, NULL); + pipe_resource_reference(&p->target, NULL); + pipe_resource_reference(&p->tex, NULL); + pipe_resource_reference(&p->vbuf, NULL); - cso_destroy_context(p->cso); p->pipe->destroy(p->pipe); p->screen->destroy(p->screen); + pipe_loader_release(&p->dev, 1); FREE(p); } static void draw(struct program *p) { + const struct pipe_sampler_state *samplers[] = {&p->sampler}; + /* set the render target */ cso_set_framebuffer(p->cso, &p->framebuffer); /* clear the render target */ - p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, p->clear_color, 0, 0); + p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, &p->clear_color, 0, 0); /* set misc state we care about */ cso_set_blend(p->cso, &p->blend); @@ -310,11 +312,10 @@ static void draw(struct program *p) cso_set_viewport(p->cso, &p->viewport); /* sampler */ - cso_single_sampler(p->cso, 0, &p->sampler); - cso_single_sampler_done(p->cso); + cso_set_samplers(p->cso, PIPE_SHADER_FRAGMENT, 1, samplers); /* texture sampler view */ - cso_set_fragment_sampler_views(p->cso, 1, &p->view); + cso_set_sampler_views(p->cso, PIPE_SHADER_FRAGMENT, 1, &p->view); /* shaders */ cso_set_fragment_shader_handle(p->cso, p->fs); @@ -323,13 +324,13 @@ static void draw(struct program *p) /* vertex element data */ cso_set_vertex_elements(p->cso, 2, p->velem); - util_draw_vertex_buffer(p->pipe, - p->vbuf, 0, + util_draw_vertex_buffer(p->pipe, p->cso, + p->vbuf, 0, 0, PIPE_PRIM_QUADS, 4, /* verts */ 2); /* attribs/vert */ - p->pipe->flush(p->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); + p->pipe->flush(p->pipe, NULL, 0); debug_dump_surface_bmp(p->pipe, "result.bmp", p->framebuffer.cbufs[0]); }