From 577f12fbba0b30925f43832ffd15214ca2218dca Mon Sep 17 00:00:00 2001 From: Younes Manton Date: Thu, 1 Oct 2009 22:17:47 -0400 Subject: [PATCH] g3dvl: Delete state_trackers/g3dvl, other unused files. --- src/gallium/state_trackers/g3dvl/Makefile | 21 - .../state_trackers/g3dvl/vl_basic_csc.c | 720 ---------- .../state_trackers/g3dvl/vl_basic_csc.h | 13 - src/gallium/state_trackers/g3dvl/vl_context.c | 204 --- src/gallium/state_trackers/g3dvl/vl_context.h | 73 - src/gallium/state_trackers/g3dvl/vl_csc.h | 53 - src/gallium/state_trackers/g3dvl/vl_defs.h | 11 - src/gallium/state_trackers/g3dvl/vl_display.c | 48 - src/gallium/state_trackers/g3dvl/vl_display.h | 29 - .../state_trackers/g3dvl/vl_r16snorm_mc_buf.c | 1155 ---------------- .../state_trackers/g3dvl/vl_r16snorm_mc_buf.h | 18 - .../g3dvl/vl_r16snorm_mc_buf_shaders.inc | 1185 ----------------- src/gallium/state_trackers/g3dvl/vl_render.h | 38 - src/gallium/state_trackers/g3dvl/vl_screen.c | 115 -- src/gallium/state_trackers/g3dvl/vl_screen.h | 63 - .../state_trackers/g3dvl/vl_shader_build.c | 215 --- .../state_trackers/g3dvl/vl_shader_build.h | 61 - src/gallium/state_trackers/g3dvl/vl_surface.c | 242 ---- src/gallium/state_trackers/g3dvl/vl_surface.h | 86 -- src/gallium/state_trackers/g3dvl/vl_types.h | 115 -- src/gallium/state_trackers/g3dvl/vl_util.c | 16 - src/gallium/state_trackers/g3dvl/vl_util.h | 6 - src/gallium/winsys/g3dvl/xsp_winsys.c | 291 ---- 23 files changed, 4778 deletions(-) delete mode 100644 src/gallium/state_trackers/g3dvl/Makefile delete mode 100644 src/gallium/state_trackers/g3dvl/vl_basic_csc.c delete mode 100644 src/gallium/state_trackers/g3dvl/vl_basic_csc.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_context.c delete mode 100644 src/gallium/state_trackers/g3dvl/vl_context.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_csc.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_defs.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_display.c delete mode 100644 src/gallium/state_trackers/g3dvl/vl_display.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.c delete mode 100644 src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf_shaders.inc delete mode 100644 src/gallium/state_trackers/g3dvl/vl_render.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_screen.c delete mode 100644 src/gallium/state_trackers/g3dvl/vl_screen.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_shader_build.c delete mode 100644 src/gallium/state_trackers/g3dvl/vl_shader_build.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_surface.c delete mode 100644 src/gallium/state_trackers/g3dvl/vl_surface.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_types.h delete mode 100644 src/gallium/state_trackers/g3dvl/vl_util.c delete mode 100644 src/gallium/state_trackers/g3dvl/vl_util.h delete mode 100644 src/gallium/winsys/g3dvl/xsp_winsys.c diff --git a/src/gallium/state_trackers/g3dvl/Makefile b/src/gallium/state_trackers/g3dvl/Makefile deleted file mode 100644 index f9f4d6be3c3..00000000000 --- a/src/gallium/state_trackers/g3dvl/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -TARGET = libg3dvl.a -OBJECTS = vl_display.o vl_screen.o vl_context.o vl_surface.o vl_shader_build.o vl_util.o vl_basic_csc.o \ - vl_r16snorm_mc_buf.o -GALLIUMDIR = ../.. - -CFLAGS += -g -Wall -Werror-implicit-function-declaration -fPIC \ - -I${GALLIUMDIR}/include \ - -I${GALLIUMDIR}/auxiliary \ - -I${GALLIUMDIR}/winsys/g3dvl \ - -############################################# - -.PHONY = all clean - -all: ${TARGET} - -${TARGET}: ${OBJECTS} - ar rcs $@ $^ - -clean: - rm -rf ${OBJECTS} ${TARGET} diff --git a/src/gallium/state_trackers/g3dvl/vl_basic_csc.c b/src/gallium/state_trackers/g3dvl/vl_basic_csc.c deleted file mode 100644 index b1683b891be..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_basic_csc.c +++ /dev/null @@ -1,720 +0,0 @@ -#define VL_INTERNAL -#include "vl_basic_csc.h" -#include -#include -#include -#include -#include -#include -#include -#include "vl_csc.h" -#include "vl_surface.h" -#include "vl_shader_build.h" -#include "vl_types.h" - -struct vlVertexShaderConsts -{ - struct vlVertex4f dst_scale; - struct vlVertex4f dst_trans; - struct vlVertex4f src_scale; - struct vlVertex4f src_trans; -}; - -struct vlFragmentShaderConsts -{ - struct vlVertex4f bias; - float matrix[16]; -}; - -struct vlBasicCSC -{ - struct vlCSC base; - - struct pipe_context *pipe; - struct pipe_viewport_state viewport; - struct pipe_framebuffer_state framebuffer; - struct pipe_texture *framebuffer_tex; - void *sampler; - void *vertex_shader, *fragment_shader; - struct pipe_vertex_buffer vertex_bufs[2]; - struct pipe_vertex_element vertex_elems[2]; - struct pipe_constant_buffer vs_const_buf, fs_const_buf; -}; - -static int vlResizeFrameBuffer -( - struct vlCSC *csc, - unsigned int width, - unsigned int height -) -{ - struct vlBasicCSC *basic_csc; - struct pipe_context *pipe; - struct pipe_texture template; - float clear_color[4]; - - assert(csc); - - basic_csc = (struct vlBasicCSC*)csc; - pipe = basic_csc->pipe; - - if (basic_csc->framebuffer.width == width && basic_csc->framebuffer.height == height) - return 0; - - basic_csc->viewport.scale[0] = width; - basic_csc->viewport.scale[1] = height; - basic_csc->viewport.scale[2] = 1; - basic_csc->viewport.scale[3] = 1; - basic_csc->viewport.translate[0] = 0; - basic_csc->viewport.translate[1] = 0; - basic_csc->viewport.translate[2] = 0; - basic_csc->viewport.translate[3] = 0; - - clear_color[0] = 0.0f; - clear_color[1] = 0.0f; - clear_color[2] = 0.0f; - clear_color[3] = 0.0f; - - if (basic_csc->framebuffer_tex) - { - pipe_surface_reference(&basic_csc->framebuffer.cbufs[0], NULL); - pipe_texture_reference(&basic_csc->framebuffer_tex, NULL); - } - - memset(&template, 0, sizeof(struct pipe_texture)); - template.target = PIPE_TEXTURE_2D; - template.format = PIPE_FORMAT_A8R8G8B8_UNORM; - template.last_level = 0; - template.width[0] = width; - template.height[0] = height; - template.depth[0] = 1; - pf_get_block(template.format, &template.block); - template.tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET; - - basic_csc->framebuffer_tex = pipe->screen->texture_create(pipe->screen, &template); - - basic_csc->framebuffer.width = width; - basic_csc->framebuffer.height = height; - basic_csc->framebuffer.cbufs[0] = pipe->screen->get_tex_surface - ( - pipe->screen, - basic_csc->framebuffer_tex, - 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE - ); - - /* Clear to black, in case video doesn't fill the entire window */ - pipe->set_framebuffer_state(pipe, &basic_csc->framebuffer); - pipe->clear(pipe, PIPE_CLEAR_COLOR, clear_color, 0.0f, 0); - - return 0; -} - -static int vlBegin -( - struct vlCSC *csc -) -{ - struct vlBasicCSC *basic_csc; - struct pipe_context *pipe; - - assert(csc); - - basic_csc = (struct vlBasicCSC*)csc; - pipe = basic_csc->pipe; - - pipe->set_framebuffer_state(pipe, &basic_csc->framebuffer); - pipe->set_viewport_state(pipe, &basic_csc->viewport); - pipe->bind_sampler_states(pipe, 1, (void**)&basic_csc->sampler); - /* Source texture set in vlPutPictureCSC() */ - pipe->bind_vs_state(pipe, basic_csc->vertex_shader); - pipe->bind_fs_state(pipe, basic_csc->fragment_shader); - pipe->set_vertex_buffers(pipe, 2, basic_csc->vertex_bufs); - pipe->set_vertex_elements(pipe, 2, basic_csc->vertex_elems); - pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &basic_csc->vs_const_buf); - pipe->set_constant_buffer(pipe, PIPE_SHADER_FRAGMENT, 0, &basic_csc->fs_const_buf); - - return 0; -} - -static int vlPutPictureCSC -( - struct vlCSC *csc, - struct vlSurface *surface, - int srcx, - int srcy, - int srcw, - int srch, - int destx, - int desty, - int destw, - int desth, - enum vlPictureType picture_type -) -{ - struct vlBasicCSC *basic_csc; - struct pipe_context *pipe; - struct vlVertexShaderConsts *vs_consts; - - assert(csc); - assert(surface); - - basic_csc = (struct vlBasicCSC*)csc; - pipe = basic_csc->pipe; - - vs_consts = pipe_buffer_map - ( - pipe->screen, - basic_csc->vs_const_buf.buffer, - PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD - ); - - vs_consts->dst_scale.x = destw / (float)basic_csc->framebuffer.cbufs[0]->width; - vs_consts->dst_scale.y = desth / (float)basic_csc->framebuffer.cbufs[0]->height; - vs_consts->dst_scale.z = 1; - vs_consts->dst_scale.w = 1; - vs_consts->dst_trans.x = destx / (float)basic_csc->framebuffer.cbufs[0]->width; - vs_consts->dst_trans.y = desty / (float)basic_csc->framebuffer.cbufs[0]->height; - vs_consts->dst_trans.z = 0; - vs_consts->dst_trans.w = 0; - - vs_consts->src_scale.x = srcw / (float)surface->texture->width[0]; - vs_consts->src_scale.y = srch / (float)surface->texture->height[0]; - vs_consts->src_scale.z = 1; - vs_consts->src_scale.w = 1; - vs_consts->src_trans.x = srcx / (float)surface->texture->width[0]; - vs_consts->src_trans.y = srcy / (float)surface->texture->height[0]; - vs_consts->src_trans.z = 0; - vs_consts->src_trans.w = 0; - - pipe_buffer_unmap(pipe->screen, basic_csc->vs_const_buf.buffer); - - pipe->set_sampler_textures(pipe, 1, &surface->texture); - pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLE_STRIP, 0, 4); - - return 0; -} - -static int vlEnd -( - struct vlCSC *csc -) -{ - assert(csc); - - return 0; -} - -static struct pipe_surface* vlGetFrameBuffer -( - struct vlCSC *csc -) -{ - struct vlBasicCSC *basic_csc; - - assert(csc); - - basic_csc = (struct vlBasicCSC*)csc; - - return basic_csc->framebuffer.cbufs[0]; -} - -static int vlDestroy -( - struct vlCSC *csc -) -{ - struct vlBasicCSC *basic_csc; - struct pipe_context *pipe; - unsigned int i; - - assert(csc); - - basic_csc = (struct vlBasicCSC*)csc; - pipe = basic_csc->pipe; - - if (basic_csc->framebuffer_tex) - { - pipe_surface_reference(&basic_csc->framebuffer.cbufs[0], NULL); - pipe_texture_reference(&basic_csc->framebuffer_tex, NULL); - } - - pipe->delete_sampler_state(pipe, basic_csc->sampler); - pipe->delete_vs_state(pipe, basic_csc->vertex_shader); - pipe->delete_fs_state(pipe, basic_csc->fragment_shader); - - for (i = 0; i < 2; ++i) - pipe_buffer_reference(&basic_csc->vertex_bufs[i].buffer, NULL); - - pipe_buffer_reference(&basic_csc->vs_const_buf.buffer, NULL); - pipe_buffer_reference(&basic_csc->fs_const_buf.buffer, NULL); - - FREE(basic_csc); - - return 0; -} - -/* - * Represents 2 triangles in a strip in normalized coords. - * Used to render the surface onto the frame buffer. - */ -static const struct vlVertex2f surface_verts[4] = -{ - {0.0f, 0.0f}, - {0.0f, 1.0f}, - {1.0f, 0.0f}, - {1.0f, 1.0f} -}; - -/* - * Represents texcoords for the above. We can use the position values directly. - * TODO: Duplicate these in the shader, no need to create a buffer. - */ -static const struct vlVertex2f *surface_texcoords = surface_verts; - -/* - * Identity color conversion constants, for debugging - */ -static const struct vlFragmentShaderConsts identity = -{ - { - 0.0f, 0.0f, 0.0f, 0.0f - }, - { - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - } -}; - -/* - * Converts ITU-R BT.601 YCbCr pixels to RGB pixels where: - * Y is in [16,235], Cb and Cr are in [16,240] - * R, G, and B are in [16,235] - */ -static const struct vlFragmentShaderConsts bt_601 = -{ - { - 0.0f, 0.501960784f, 0.501960784f, 0.0f - }, - { - 1.0f, 0.0f, 1.371f, 0.0f, - 1.0f, -0.336f, -0.698f, 0.0f, - 1.0f, 1.732f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - } -}; - -/* - * Converts ITU-R BT.601 YCbCr pixels to RGB pixels where: - * Y is in [16,235], Cb and Cr are in [16,240] - * R, G, and B are in [0,255] - */ -static const struct vlFragmentShaderConsts bt_601_full = -{ - { - 0.062745098f, 0.501960784f, 0.501960784f, 0.0f - }, - { - 1.164f, 0.0f, 1.596f, 0.0f, - 1.164f, -0.391f, -0.813f, 0.0f, - 1.164f, 2.018f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - } -}; - -/* - * Converts ITU-R BT.709 YCbCr pixels to RGB pixels where: - * Y is in [16,235], Cb and Cr are in [16,240] - * R, G, and B are in [16,235] - */ -static const struct vlFragmentShaderConsts bt_709 = -{ - { - 0.0f, 0.501960784f, 0.501960784f, 0.0f - }, - { - 1.0f, 0.0f, 1.540f, 0.0f, - 1.0f, -0.183f, -0.459f, 0.0f, - 1.0f, 1.816f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - } -}; - -/* - * Converts ITU-R BT.709 YCbCr pixels to RGB pixels where: - * Y is in [16,235], Cb and Cr are in [16,240] - * R, G, and B are in [0,255] - */ -const struct vlFragmentShaderConsts bt_709_full = -{ - { - 0.062745098f, 0.501960784f, 0.501960784f, 0.0f - }, - { - 1.164f, 0.0f, 1.793f, 0.0f, - 1.164f, -0.213f, -0.534f, 0.0f, - 1.164f, 2.115f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f - } -}; - -static int vlCreateVertexShader -( - struct vlBasicCSC *csc -) -{ - const unsigned int max_tokens = 50; - - struct pipe_context *pipe; - struct pipe_shader_state vs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(csc); - - pipe = csc->pipe; - tokens = (struct tgsi_token*)MALLOC(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header); - - ti = 3; - - /* - * decl i0 ; Vertex pos - * decl i1 ; Vertex texcoords - */ - for (i = 0; i < 2; i++) - { - decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * decl c0 ; Scaling vector to scale vertex pos rect to destination size - * decl c1 ; Translation vector to move vertex pos rect into position - * decl c2 ; Scaling vector to scale texcoord rect to source size - * decl c3 ; Translation vector to move texcoord rect into position - */ - decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 3); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * decl o0 ; Vertex pos - * decl o1 ; Vertex texcoords - */ - for (i = 0; i < 2; i++) - { - decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* decl t0, t1 */ - decl = vl_decl_temps(0, 1); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * madd o0, i0, c0, c1 ; Scale and translate unit output rect to destination size and pos - * madd o1, i1, c2, c3 ; Scale and translate unit texcoord rect to source size and pos - */ - for (i = 0; i < 2; ++i) - { - inst = vl_inst4(TGSI_OPCODE_MAD, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i, TGSI_FILE_CONSTANT, i * 2, TGSI_FILE_CONSTANT, i * 2 + 1); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - vs.tokens = tokens; - csc->vertex_shader = pipe->create_vs_state(pipe, &vs); - FREE(tokens); - - return 0; -} - -static int vlCreateFragmentShader -( - struct vlBasicCSC *csc -) -{ - const unsigned int max_tokens = 50; - - struct pipe_context *pipe; - struct pipe_shader_state fs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(csc); - - pipe = csc->pipe; - tokens = (struct tgsi_token*)MALLOC(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header); - - ti = 3; - - /* decl i0 ; Texcoords for s0 */ - decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, 1, 0, 0, TGSI_INTERPOLATE_LINEAR); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * decl c0 ; Bias vector for CSC - * decl c1-c4 ; CSC matrix c1-c4 - */ - decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 4); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl o0 ; Fragment color */ - decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl t0 */ - decl = vl_decl_temps(0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl s0 ; Sampler for tex containing picture to display */ - decl = vl_decl_samplers(0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* tex2d t0, i0, s0 ; Read src pixel */ - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_INPUT, 0, TGSI_FILE_SAMPLER, 0); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* sub t0, t0, c0 ; Subtract bias vector from pixel */ - inst = vl_inst3(TGSI_OPCODE_SUB, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* - * dp4 o0.x, t0, c1 ; Multiply pixel by the color conversion matrix - * dp4 o0.y, t0, c2 - * dp4 o0.z, t0, c3 - */ - for (i = 0; i < 3; ++i) - { - inst = vl_inst3(TGSI_OPCODE_DP4, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, i + 1); - inst.FullDstRegisters[0].DstRegister.WriteMask = TGSI_WRITEMASK_X << i; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - fs.tokens = tokens; - csc->fragment_shader = pipe->create_fs_state(pipe, &fs); - FREE(tokens); - - return 0; -} - -static int vlCreateDataBufs -( - struct vlBasicCSC *csc -) -{ - struct pipe_context *pipe; - - assert(csc); - - pipe = csc->pipe; - - /* - * Create our vertex buffer and vertex buffer element - * VB contains 4 vertices that render a quad covering the entire window - * to display a rendered surface - * Quad is rendered as a tri strip - */ - csc->vertex_bufs[0].stride = sizeof(struct vlVertex2f); - csc->vertex_bufs[0].max_index = 3; - csc->vertex_bufs[0].buffer_offset = 0; - csc->vertex_bufs[0].buffer = pipe_buffer_create - ( - pipe->screen, - 1, - PIPE_BUFFER_USAGE_VERTEX, - sizeof(struct vlVertex2f) * 4 - ); - - memcpy - ( - pipe_buffer_map(pipe->screen, csc->vertex_bufs[0].buffer, PIPE_BUFFER_USAGE_CPU_WRITE), - surface_verts, - sizeof(struct vlVertex2f) * 4 - ); - - pipe_buffer_unmap(pipe->screen, csc->vertex_bufs[0].buffer); - - csc->vertex_elems[0].src_offset = 0; - csc->vertex_elems[0].vertex_buffer_index = 0; - csc->vertex_elems[0].nr_components = 2; - csc->vertex_elems[0].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* - * Create our texcoord buffer and texcoord buffer element - * Texcoord buffer contains the TCs for mapping the rendered surface to the 4 vertices - */ - csc->vertex_bufs[1].stride = sizeof(struct vlVertex2f); - csc->vertex_bufs[1].max_index = 3; - csc->vertex_bufs[1].buffer_offset = 0; - csc->vertex_bufs[1].buffer = pipe_buffer_create - ( - pipe->screen, - 1, - PIPE_BUFFER_USAGE_VERTEX, - sizeof(struct vlVertex2f) * 4 - ); - - memcpy - ( - pipe_buffer_map(pipe->screen, csc->vertex_bufs[1].buffer, PIPE_BUFFER_USAGE_CPU_WRITE), - surface_texcoords, - sizeof(struct vlVertex2f) * 4 - ); - - pipe_buffer_unmap(pipe->screen, csc->vertex_bufs[1].buffer); - - csc->vertex_elems[1].src_offset = 0; - csc->vertex_elems[1].vertex_buffer_index = 1; - csc->vertex_elems[1].nr_components = 2; - csc->vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* - * Create our vertex shader's constant buffer - * Const buffer contains scaling and translation vectors - */ - csc->vs_const_buf.buffer = pipe_buffer_create - ( - pipe->screen, - 1, - PIPE_BUFFER_USAGE_CONSTANT | PIPE_BUFFER_USAGE_DISCARD, - sizeof(struct vlVertexShaderConsts) - ); - - /* - * Create our fragment shader's constant buffer - * Const buffer contains the color conversion matrix and bias vectors - */ - csc->fs_const_buf.buffer = pipe_buffer_create - ( - pipe->screen, - 1, - PIPE_BUFFER_USAGE_CONSTANT, - sizeof(struct vlFragmentShaderConsts) - ); - - /* - * TODO: Refactor this into a seperate function, - * allow changing the CSC matrix at runtime to switch between regular & full versions - */ - memcpy - ( - pipe_buffer_map(pipe->screen, csc->fs_const_buf.buffer, PIPE_BUFFER_USAGE_CPU_WRITE), - &bt_601_full, - sizeof(struct vlFragmentShaderConsts) - ); - - pipe_buffer_unmap(pipe->screen, csc->fs_const_buf.buffer); - - return 0; -} - -static int vlInit -( - struct vlBasicCSC *csc -) -{ - struct pipe_context *pipe; - struct pipe_sampler_state sampler; - - assert(csc); - - pipe = csc->pipe; - - /* Delay creating the FB until vlPutPictureCSC() so we know window size */ - csc->framebuffer_tex = NULL; - csc->framebuffer.width = 0; - csc->framebuffer.height = 0; - csc->framebuffer.nr_cbufs = 1; - csc->framebuffer.cbufs[0] = NULL; - csc->framebuffer.zsbuf = NULL; - - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.min_img_filter = PIPE_TEX_FILTER_LINEAR; - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; - sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR; - sampler.compare_mode = PIPE_TEX_COMPARE_NONE; - sampler.compare_func = PIPE_FUNC_ALWAYS; - sampler.normalized_coords = 1; - /*sampler.prefilter = ;*/ - /*sampler.lod_bias = ;*/ - /*sampler.min_lod = ;*/ - /*sampler.max_lod = ;*/ - /*sampler.border_color[i] = ;*/ - /*sampler.max_anisotropy = ;*/ - csc->sampler = pipe->create_sampler_state(pipe, &sampler); - - vlCreateVertexShader(csc); - vlCreateFragmentShader(csc); - vlCreateDataBufs(csc); - - return 0; -} - -int vlCreateBasicCSC -( - struct pipe_context *pipe, - struct vlCSC **csc -) -{ - struct vlBasicCSC *basic_csc; - - assert(pipe); - assert(csc); - - basic_csc = CALLOC_STRUCT(vlBasicCSC); - - if (!basic_csc) - return 1; - - basic_csc->base.vlResizeFrameBuffer = &vlResizeFrameBuffer; - basic_csc->base.vlBegin = &vlBegin; - basic_csc->base.vlPutPicture = &vlPutPictureCSC; - basic_csc->base.vlEnd = &vlEnd; - basic_csc->base.vlGetFrameBuffer = &vlGetFrameBuffer; - basic_csc->base.vlDestroy = &vlDestroy; - basic_csc->pipe = pipe; - - vlInit(basic_csc); - - *csc = &basic_csc->base; - - return 0; -} diff --git a/src/gallium/state_trackers/g3dvl/vl_basic_csc.h b/src/gallium/state_trackers/g3dvl/vl_basic_csc.h deleted file mode 100644 index 2e17f1d814a..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_basic_csc.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef vl_basic_csc_h -#define vl_basic_csc_h - -struct pipe_context; -struct vlCSC; - -int vlCreateBasicCSC -( - struct pipe_context *pipe, - struct vlCSC **csc -); - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_context.c b/src/gallium/state_trackers/g3dvl/vl_context.c deleted file mode 100644 index cfbf618d742..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_context.c +++ /dev/null @@ -1,204 +0,0 @@ -#define VL_INTERNAL -#include "vl_context.h" -#include -#include -#include -#include -#include "vl_render.h" -#include "vl_r16snorm_mc_buf.h" -#include "vl_csc.h" -#include "vl_basic_csc.h" - -static int vlInitCommon(struct vlContext *context) -{ - struct pipe_context *pipe; - struct pipe_rasterizer_state rast; - struct pipe_blend_state blend; - struct pipe_depth_stencil_alpha_state dsa; - unsigned int i; - - assert(context); - - pipe = context->pipe; - - rast.flatshade = 1; - rast.flatshade_first = 0; - rast.light_twoside = 0; - rast.front_winding = PIPE_WINDING_CCW; - rast.cull_mode = PIPE_WINDING_CW; - rast.fill_cw = PIPE_POLYGON_MODE_FILL; - rast.fill_ccw = PIPE_POLYGON_MODE_FILL; - rast.offset_cw = 0; - rast.offset_ccw = 0; - rast.scissor = 0; - rast.poly_smooth = 0; - rast.poly_stipple_enable = 0; - rast.point_sprite = 0; - rast.point_size_per_vertex = 0; - rast.multisample = 0; - rast.line_smooth = 0; - rast.line_stipple_enable = 0; - rast.line_stipple_factor = 0; - rast.line_stipple_pattern = 0; - rast.line_last_pixel = 0; - rast.bypass_vs_clip_and_viewport = 0; - rast.line_width = 1; - rast.point_smooth = 0; - rast.point_size = 1; - rast.offset_units = 1; - rast.offset_scale = 1; - /*rast.sprite_coord_mode[i] = ;*/ - context->raster = pipe->create_rasterizer_state(pipe, &rast); - pipe->bind_rasterizer_state(pipe, context->raster); - - blend.blend_enable = 0; - blend.rgb_func = PIPE_BLEND_ADD; - blend.rgb_src_factor = PIPE_BLENDFACTOR_ONE; - blend.rgb_dst_factor = PIPE_BLENDFACTOR_ONE; - blend.alpha_func = PIPE_BLEND_ADD; - blend.alpha_src_factor = PIPE_BLENDFACTOR_ONE; - blend.alpha_dst_factor = PIPE_BLENDFACTOR_ONE; - blend.logicop_enable = 0; - blend.logicop_func = PIPE_LOGICOP_CLEAR; - /* Needed to allow color writes to FB, even if blending disabled */ - blend.colormask = PIPE_MASK_RGBA; - blend.dither = 0; - context->blend = pipe->create_blend_state(pipe, &blend); - pipe->bind_blend_state(pipe, context->blend); - - dsa.depth.enabled = 0; - dsa.depth.writemask = 0; - dsa.depth.func = PIPE_FUNC_ALWAYS; - for (i = 0; i < 2; ++i) - { - dsa.stencil[i].enabled = 0; - dsa.stencil[i].func = PIPE_FUNC_ALWAYS; - dsa.stencil[i].fail_op = PIPE_STENCIL_OP_KEEP; - dsa.stencil[i].zpass_op = PIPE_STENCIL_OP_KEEP; - dsa.stencil[i].zfail_op = PIPE_STENCIL_OP_KEEP; - dsa.stencil[i].ref_value = 0; - dsa.stencil[i].valuemask = 0; - dsa.stencil[i].writemask = 0; - } - dsa.alpha.enabled = 0; - dsa.alpha.func = PIPE_FUNC_ALWAYS; - dsa.alpha.ref_value = 0; - context->dsa = pipe->create_depth_stencil_alpha_state(pipe, &dsa); - pipe->bind_depth_stencil_alpha_state(pipe, context->dsa); - - return 0; -} - -int vlCreateContext -( - struct vlScreen *screen, - struct pipe_context *pipe, - unsigned int picture_width, - unsigned int picture_height, - enum vlFormat picture_format, - enum vlProfile profile, - enum vlEntryPoint entry_point, - struct vlContext **context -) -{ - struct vlContext *ctx; - - assert(screen); - assert(context); - assert(pipe); - - ctx = CALLOC_STRUCT(vlContext); - - if (!ctx) - return 1; - - ctx->screen = screen; - ctx->pipe = pipe; - ctx->picture_width = picture_width; - ctx->picture_height = picture_height; - ctx->picture_format = picture_format; - ctx->profile = profile; - ctx->entry_point = entry_point; - - vlInitCommon(ctx); - - vlCreateR16SNormBufferedMC(pipe, picture_width, picture_height, picture_format, &ctx->render); - vlCreateBasicCSC(pipe, &ctx->csc); - - *context = ctx; - - return 0; -} - -int vlDestroyContext -( - struct vlContext *context -) -{ - assert(context); - - /* XXX: Must unbind shaders before we can delete them for some reason */ - context->pipe->bind_vs_state(context->pipe, NULL); - context->pipe->bind_fs_state(context->pipe, NULL); - - context->render->vlDestroy(context->render); - context->csc->vlDestroy(context->csc); - - context->pipe->delete_blend_state(context->pipe, context->blend); - context->pipe->delete_rasterizer_state(context->pipe, context->raster); - context->pipe->delete_depth_stencil_alpha_state(context->pipe, context->dsa); - - FREE(context); - - return 0; -} - -struct vlScreen* vlContextGetScreen -( - struct vlContext *context -) -{ - assert(context); - - return context->screen; -} - -struct pipe_context* vlGetPipeContext -( - struct vlContext *context -) -{ - assert(context); - - return context->pipe; -} - -unsigned int vlGetPictureWidth -( - struct vlContext *context -) -{ - assert(context); - - return context->picture_width; -} - -unsigned int vlGetPictureHeight -( - struct vlContext *context -) -{ - assert(context); - - return context->picture_height; -} - -enum vlFormat vlGetPictureFormat -( - struct vlContext *context -) -{ - assert(context); - - return context->picture_format; -} diff --git a/src/gallium/state_trackers/g3dvl/vl_context.h b/src/gallium/state_trackers/g3dvl/vl_context.h deleted file mode 100644 index 3d14634c44e..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_context.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef vl_context_h -#define vl_context_h - -#include "vl_types.h" - -struct pipe_context; - -#ifdef VL_INTERNAL -struct vlRender; -struct vlCSC; - -struct vlContext -{ - struct vlScreen *screen; - struct pipe_context *pipe; - unsigned int picture_width; - unsigned int picture_height; - enum vlFormat picture_format; - enum vlProfile profile; - enum vlEntryPoint entry_point; - - void *raster; - void *dsa; - void *blend; - - struct vlRender *render; - struct vlCSC *csc; -}; -#endif - -int vlCreateContext -( - struct vlScreen *screen, - struct pipe_context *pipe, - unsigned int picture_width, - unsigned int picture_height, - enum vlFormat picture_format, - enum vlProfile profile, - enum vlEntryPoint entry_point, - struct vlContext **context -); - -int vlDestroyContext -( - struct vlContext *context -); - -struct vlScreen* vlContextGetScreen -( - struct vlContext *context -); - -struct pipe_context* vlGetPipeContext -( - struct vlContext *context -); - -unsigned int vlGetPictureWidth -( - struct vlContext *context -); - -unsigned int vlGetPictureHeight -( - struct vlContext *context -); - -enum vlFormat vlGetPictureFormat -( - struct vlContext *context -); - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_csc.h b/src/gallium/state_trackers/g3dvl/vl_csc.h deleted file mode 100644 index 36417a27929..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_csc.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef vl_csc_h -#define vl_csc_h - -#include "vl_types.h" - -struct pipe_surface; - -struct vlCSC -{ - int (*vlResizeFrameBuffer) - ( - struct vlCSC *csc, - unsigned int width, - unsigned int height - ); - - int (*vlBegin) - ( - struct vlCSC *csc - ); - - int (*vlPutPicture) - ( - struct vlCSC *csc, - struct vlSurface *surface, - int srcx, - int srcy, - int srcw, - int srch, - int destx, - int desty, - int destw, - int desth, - enum vlPictureType picture_type - ); - - int (*vlEnd) - ( - struct vlCSC *csc - ); - - struct pipe_surface* (*vlGetFrameBuffer) - ( - struct vlCSC *csc - ); - - int (*vlDestroy) - ( - struct vlCSC *csc - ); -}; - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_defs.h b/src/gallium/state_trackers/g3dvl/vl_defs.h deleted file mode 100644 index d612d02502f..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_defs.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef vl_defs_h -#define vl_defs_h - -#define VL_BLOCK_WIDTH 8 -#define VL_BLOCK_HEIGHT 8 -#define VL_BLOCK_SIZE (VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT) -#define VL_MACROBLOCK_WIDTH 16 -#define VL_MACROBLOCK_HEIGHT 16 -#define VL_MACROBLOCK_SIZE (VL_MACROBLOCK_WIDTH * VL_MACROBLOCK_HEIGHT) - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_display.c b/src/gallium/state_trackers/g3dvl/vl_display.c deleted file mode 100644 index dce06de7583..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_display.c +++ /dev/null @@ -1,48 +0,0 @@ -#define VL_INTERNAL -#include "vl_display.h" -#include -#include - -int vlCreateDisplay -( - vlNativeDisplay native_display, - struct vlDisplay **display -) -{ - struct vlDisplay *dpy; - - assert(native_display); - assert(display); - - dpy = CALLOC_STRUCT(vlDisplay); - - if (!dpy) - return 1; - - dpy->native = native_display; - *display = dpy; - - return 0; -} - -int vlDestroyDisplay -( - struct vlDisplay *display -) -{ - assert(display); - - FREE(display); - - return 0; -} - -vlNativeDisplay vlGetNativeDisplay -( - struct vlDisplay *display -) -{ - assert(display); - - return display->native; -} diff --git a/src/gallium/state_trackers/g3dvl/vl_display.h b/src/gallium/state_trackers/g3dvl/vl_display.h deleted file mode 100644 index e11fd407993..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_display.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef vl_display_h -#define vl_display_h - -#include "vl_types.h" - -#ifdef VL_INTERNAL -struct vlDisplay -{ - vlNativeDisplay native; -}; -#endif - -int vlCreateDisplay -( - vlNativeDisplay native_display, - struct vlDisplay **display -); - -int vlDestroyDisplay -( - struct vlDisplay *display -); - -vlNativeDisplay vlGetNativeDisplay -( - struct vlDisplay *display -); - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.c b/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.c deleted file mode 100644 index 23631adb693..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.c +++ /dev/null @@ -1,1155 +0,0 @@ -#define VL_INTERNAL -#include "vl_r16snorm_mc_buf.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "vl_render.h" -#include "vl_shader_build.h" -#include "vl_surface.h" -#include "vl_util.h" -#include "vl_types.h" -#include "vl_defs.h" - -const unsigned int DEFAULT_BUF_ALIGNMENT = 1; - -enum vlMacroBlockTypeEx -{ - vlMacroBlockExTypeIntra, - vlMacroBlockExTypeFwdPredictedFrame, - vlMacroBlockExTypeFwdPredictedField, - vlMacroBlockExTypeBkwdPredictedFrame, - vlMacroBlockExTypeBkwdPredictedField, - vlMacroBlockExTypeBiPredictedFrame, - vlMacroBlockExTypeBiPredictedField, - - vlNumMacroBlockExTypes -}; - -struct vlVertexShaderConsts -{ - struct vlVertex4f denorm; -}; - -struct vlFragmentShaderConsts -{ - struct vlVertex4f multiplier; - struct vlVertex4f div; -}; - -struct vlMacroBlockVertexStream0 -{ - struct vlVertex2f pos; - struct vlVertex2f luma_tc; - struct vlVertex2f cb_tc; - struct vlVertex2f cr_tc; -}; - -struct vlR16SnormBufferedMC -{ - struct vlRender base; - - unsigned int picture_width; - unsigned int picture_height; - enum vlFormat picture_format; - unsigned int macroblocks_per_picture; - - struct vlSurface *buffered_surface; - struct vlSurface *past_surface; - struct vlSurface *future_surface; - struct vlVertex2f surface_tex_inv_size; - struct vlVertex2f zero_block[3]; - unsigned int num_macroblocks; - struct vlMpeg2MacroBlock *macroblocks; - struct pipe_transfer *tex_transfer[3]; - short *texels[3]; - - struct pipe_context *pipe; - struct pipe_viewport_state viewport; - struct pipe_framebuffer_state render_target; - - union - { - void *all[5]; - struct - { - void *y; - void *cb; - void *cr; - void *ref[2]; - }; - } samplers; - - union - { - struct pipe_texture *all[5]; - struct - { - struct pipe_texture *y; - struct pipe_texture *cb; - struct pipe_texture *cr; - struct pipe_texture *ref[2]; - }; - } textures; - - union - { - struct pipe_vertex_buffer all[3]; - struct - { - struct pipe_vertex_buffer ycbcr; - struct pipe_vertex_buffer ref[2]; - }; - } vertex_bufs; - - void *i_vs, *p_vs[2], *b_vs[2]; - void *i_fs, *p_fs[2], *b_fs[2]; - struct pipe_vertex_element vertex_elems[8]; - struct pipe_constant_buffer vs_const_buf; - struct pipe_constant_buffer fs_const_buf; -}; - -static inline int vlBegin -( - struct vlRender *render -) -{ - assert(render); - - return 0; -} - -static inline int vlGrabFrameCodedBlock(short *src, short *dst, unsigned int dst_pitch) -{ - unsigned int y; - - for (y = 0; y < VL_BLOCK_HEIGHT; ++y) - memcpy - ( - dst + y * dst_pitch, - src + y * VL_BLOCK_WIDTH, - VL_BLOCK_WIDTH * 2 - ); - - return 0; -} - -static inline int vlGrabFieldCodedBlock(short *src, short *dst, unsigned int dst_pitch) -{ - unsigned int y; - - for (y = 0; y < VL_BLOCK_HEIGHT; ++y) - memcpy - ( - dst + y * dst_pitch * 2, - src + y * VL_BLOCK_WIDTH, - VL_BLOCK_WIDTH * 2 - ); - - return 0; -} - -static inline int vlGrabNoBlock(short *dst, unsigned int dst_pitch) -{ - unsigned int y; - - for (y = 0; y < VL_BLOCK_HEIGHT; ++y) - memset - ( - dst + y * dst_pitch, - 0, - VL_BLOCK_WIDTH * 2 - ); - - return 0; -} - -static inline int vlGrabBlocks -( - struct vlR16SnormBufferedMC *mc, - unsigned int mbx, - unsigned int mby, - enum vlDCTType dct_type, - unsigned int coded_block_pattern, - short *blocks -) -{ - short *texels; - unsigned int tex_pitch; - unsigned int x, y, tb = 0, sb = 0; - unsigned int mbpx = mbx * VL_MACROBLOCK_WIDTH, mbpy = mby * VL_MACROBLOCK_HEIGHT; - - assert(mc); - assert(blocks); - - tex_pitch = mc->tex_transfer[0]->stride / mc->tex_transfer[0]->block.size; - texels = mc->texels[0] + mbpy * tex_pitch + mbpx; - - for (y = 0; y < 2; ++y) - { - for (x = 0; x < 2; ++x, ++tb) - { - if ((coded_block_pattern >> (5 - tb)) & 1) - { - short *cur_block = blocks + sb * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT; - - if (dct_type == vlDCTTypeFrameCoded) - { - vlGrabFrameCodedBlock - ( - cur_block, - texels + y * tex_pitch * VL_BLOCK_HEIGHT + x * VL_BLOCK_WIDTH, - tex_pitch - ); - } - else - { - vlGrabFieldCodedBlock - ( - cur_block, - texels + y * tex_pitch + x * VL_BLOCK_WIDTH, - tex_pitch - ); - } - - ++sb; - } - else if (mc->zero_block[0].x < 0.0f) - { - vlGrabNoBlock(texels + y * tex_pitch * VL_BLOCK_HEIGHT + x * VL_BLOCK_WIDTH, tex_pitch); - - mc->zero_block[0].x = (mbpx + x * 8) * mc->surface_tex_inv_size.x; - mc->zero_block[0].y = (mbpy + y * 8) * mc->surface_tex_inv_size.y; - } - } - } - - /* TODO: Implement 422, 444 */ - mbpx >>= 1; - mbpy >>= 1; - - for (tb = 0; tb < 2; ++tb) - { - tex_pitch = mc->tex_transfer[tb + 1]->stride / mc->tex_transfer[tb + 1]->block.size; - texels = mc->texels[tb + 1] + mbpy * tex_pitch + mbpx; - - if ((coded_block_pattern >> (1 - tb)) & 1) - { - short *cur_block = blocks + sb * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT; - - vlGrabFrameCodedBlock - ( - cur_block, - texels, - tex_pitch - ); - - ++sb; - } - else if (mc->zero_block[tb + 1].x < 0.0f) - { - vlGrabNoBlock(texels, tex_pitch); - - mc->zero_block[tb + 1].x = (mbpx << 1) * mc->surface_tex_inv_size.x; - mc->zero_block[tb + 1].y = (mbpy << 1) * mc->surface_tex_inv_size.y; - } - } - - return 0; -} - -static inline enum vlMacroBlockTypeEx vlGetMacroBlockTypeEx(struct vlMpeg2MacroBlock *mb) -{ - assert(mb); - - switch (mb->mb_type) - { - case vlMacroBlockTypeIntra: - return vlMacroBlockExTypeIntra; - case vlMacroBlockTypeFwdPredicted: - return mb->mo_type == vlMotionTypeFrame ? - vlMacroBlockExTypeFwdPredictedFrame : vlMacroBlockExTypeFwdPredictedField; - case vlMacroBlockTypeBkwdPredicted: - return mb->mo_type == vlMotionTypeFrame ? - vlMacroBlockExTypeBkwdPredictedFrame : vlMacroBlockExTypeBkwdPredictedField; - case vlMacroBlockTypeBiPredicted: - return mb->mo_type == vlMotionTypeFrame ? - vlMacroBlockExTypeBiPredictedFrame : vlMacroBlockExTypeBiPredictedField; - default: - assert(0); - } - - /* Unreachable */ - return -1; -} - -static inline int vlGrabMacroBlock -( - struct vlR16SnormBufferedMC *mc, - struct vlMpeg2MacroBlock *macroblock -) -{ - assert(mc); - assert(macroblock); - assert(mc->num_macroblocks < mc->macroblocks_per_picture); - - mc->macroblocks[mc->num_macroblocks].mbx = macroblock->mbx; - mc->macroblocks[mc->num_macroblocks].mby = macroblock->mby; - mc->macroblocks[mc->num_macroblocks].mb_type = macroblock->mb_type; - mc->macroblocks[mc->num_macroblocks].mo_type = macroblock->mo_type; - mc->macroblocks[mc->num_macroblocks].dct_type = macroblock->dct_type; - mc->macroblocks[mc->num_macroblocks].PMV[0][0][0] = macroblock->PMV[0][0][0]; - mc->macroblocks[mc->num_macroblocks].PMV[0][0][1] = macroblock->PMV[0][0][1]; - mc->macroblocks[mc->num_macroblocks].PMV[0][1][0] = macroblock->PMV[0][1][0]; - mc->macroblocks[mc->num_macroblocks].PMV[0][1][1] = macroblock->PMV[0][1][1]; - mc->macroblocks[mc->num_macroblocks].PMV[1][0][0] = macroblock->PMV[1][0][0]; - mc->macroblocks[mc->num_macroblocks].PMV[1][0][1] = macroblock->PMV[1][0][1]; - mc->macroblocks[mc->num_macroblocks].PMV[1][1][0] = macroblock->PMV[1][1][0]; - mc->macroblocks[mc->num_macroblocks].PMV[1][1][1] = macroblock->PMV[1][1][1]; - mc->macroblocks[mc->num_macroblocks].cbp = macroblock->cbp; - mc->macroblocks[mc->num_macroblocks].blocks = macroblock->blocks; - - vlGrabBlocks - ( - mc, - macroblock->mbx, - macroblock->mby, - macroblock->dct_type, - macroblock->cbp, - macroblock->blocks - ); - - mc->num_macroblocks++; - - return 0; -} - -#define SET_BLOCK(vb, cbp, mbx, mby, unitx, unity, ofsx, ofsy, hx, hy, lm, cbm, crm, zb) \ - do { \ - (vb)[0].pos.x = (mbx) * (unitx) + (ofsx); (vb)[0].pos.y = (mby) * (unity) + (ofsy); \ - (vb)[1].pos.x = (mbx) * (unitx) + (ofsx); (vb)[1].pos.y = (mby) * (unity) + (ofsy) + (hy); \ - (vb)[2].pos.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[2].pos.y = (mby) * (unity) + (ofsy); \ - (vb)[3].pos.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[3].pos.y = (mby) * (unity) + (ofsy); \ - (vb)[4].pos.x = (mbx) * (unitx) + (ofsx); (vb)[4].pos.y = (mby) * (unity) + (ofsy) + (hy); \ - (vb)[5].pos.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[5].pos.y = (mby) * (unity) + (ofsy) + (hy); \ - \ - if ((cbp) & (lm)) \ - { \ - (vb)[0].luma_tc.x = (mbx) * (unitx) + (ofsx); (vb)[0].luma_tc.y = (mby) * (unity) + (ofsy); \ - (vb)[1].luma_tc.x = (mbx) * (unitx) + (ofsx); (vb)[1].luma_tc.y = (mby) * (unity) + (ofsy) + (hy); \ - (vb)[2].luma_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[2].luma_tc.y = (mby) * (unity) + (ofsy); \ - (vb)[3].luma_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[3].luma_tc.y = (mby) * (unity) + (ofsy); \ - (vb)[4].luma_tc.x = (mbx) * (unitx) + (ofsx); (vb)[4].luma_tc.y = (mby) * (unity) + (ofsy) + (hy); \ - (vb)[5].luma_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[5].luma_tc.y = (mby) * (unity) + (ofsy) + (hy); \ - } \ - else \ - { \ - (vb)[0].luma_tc.x = (zb)[0].x; (vb)[0].luma_tc.y = (zb)[0].y; \ - (vb)[1].luma_tc.x = (zb)[0].x; (vb)[1].luma_tc.y = (zb)[0].y + (hy); \ - (vb)[2].luma_tc.x = (zb)[0].x + (hx); (vb)[2].luma_tc.y = (zb)[0].y; \ - (vb)[3].luma_tc.x = (zb)[0].x + (hx); (vb)[3].luma_tc.y = (zb)[0].y; \ - (vb)[4].luma_tc.x = (zb)[0].x; (vb)[4].luma_tc.y = (zb)[0].y + (hy); \ - (vb)[5].luma_tc.x = (zb)[0].x + (hx); (vb)[5].luma_tc.y = (zb)[0].y + (hy); \ - } \ - \ - if ((cbp) & (cbm)) \ - { \ - (vb)[0].cb_tc.x = (mbx) * (unitx) + (ofsx); (vb)[0].cb_tc.y = (mby) * (unity) + (ofsy); \ - (vb)[1].cb_tc.x = (mbx) * (unitx) + (ofsx); (vb)[1].cb_tc.y = (mby) * (unity) + (ofsy) + (hy); \ - (vb)[2].cb_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[2].cb_tc.y = (mby) * (unity) + (ofsy); \ - (vb)[3].cb_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[3].cb_tc.y = (mby) * (unity) + (ofsy); \ - (vb)[4].cb_tc.x = (mbx) * (unitx) + (ofsx); (vb)[4].cb_tc.y = (mby) * (unity) + (ofsy) + (hy); \ - (vb)[5].cb_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[5].cb_tc.y = (mby) * (unity) + (ofsy) + (hy); \ - } \ - else \ - { \ - (vb)[0].cb_tc.x = (zb)[1].x; (vb)[0].cb_tc.y = (zb)[1].y; \ - (vb)[1].cb_tc.x = (zb)[1].x; (vb)[1].cb_tc.y = (zb)[1].y + (hy); \ - (vb)[2].cb_tc.x = (zb)[1].x + (hx); (vb)[2].cb_tc.y = (zb)[1].y; \ - (vb)[3].cb_tc.x = (zb)[1].x + (hx); (vb)[3].cb_tc.y = (zb)[1].y; \ - (vb)[4].cb_tc.x = (zb)[1].x; (vb)[4].cb_tc.y = (zb)[1].y + (hy); \ - (vb)[5].cb_tc.x = (zb)[1].x + (hx); (vb)[5].cb_tc.y = (zb)[1].y + (hy); \ - } \ - \ - if ((cbp) & (crm)) \ - { \ - (vb)[0].cr_tc.x = (mbx) * (unitx) + (ofsx); (vb)[0].cr_tc.y = (mby) * (unity) + (ofsy); \ - (vb)[1].cr_tc.x = (mbx) * (unitx) + (ofsx); (vb)[1].cr_tc.y = (mby) * (unity) + (ofsy) + (hy); \ - (vb)[2].cr_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[2].cr_tc.y = (mby) * (unity) + (ofsy); \ - (vb)[3].cr_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[3].cr_tc.y = (mby) * (unity) + (ofsy); \ - (vb)[4].cr_tc.x = (mbx) * (unitx) + (ofsx); (vb)[4].cr_tc.y = (mby) * (unity) + (ofsy) + (hy); \ - (vb)[5].cr_tc.x = (mbx) * (unitx) + (ofsx) + (hx); (vb)[5].cr_tc.y = (mby) * (unity) + (ofsy) + (hy); \ - } \ - else \ - { \ - (vb)[0].cr_tc.x = (zb)[2].x; (vb)[0].cr_tc.y = (zb)[2].y; \ - (vb)[1].cr_tc.x = (zb)[2].x; (vb)[1].cr_tc.y = (zb)[2].y + (hy); \ - (vb)[2].cr_tc.x = (zb)[2].x + (hx); (vb)[2].cr_tc.y = (zb)[2].y; \ - (vb)[3].cr_tc.x = (zb)[2].x + (hx); (vb)[3].cr_tc.y = (zb)[2].y; \ - (vb)[4].cr_tc.x = (zb)[2].x; (vb)[4].cr_tc.y = (zb)[2].y + (hy); \ - (vb)[5].cr_tc.x = (zb)[2].x + (hx); (vb)[5].cr_tc.y = (zb)[2].y + (hy); \ - } \ - } while (0) - -static inline int vlGenMacroblockVerts -( - struct vlR16SnormBufferedMC *mc, - struct vlMpeg2MacroBlock *macroblock, - unsigned int pos, - struct vlMacroBlockVertexStream0 *ycbcr_vb, - struct vlVertex2f **ref_vb -) -{ - struct vlVertex2f mo_vec[2]; - unsigned int i; - - assert(mc); - assert(macroblock); - assert(ycbcr_vb); - assert(pos < mc->macroblocks_per_picture); - - switch (macroblock->mb_type) - { - case vlMacroBlockTypeBiPredicted: - { - struct vlVertex2f *vb; - - assert(ref_vb && ref_vb[1]); - - vb = ref_vb[1] + pos * 2 * 24; - - mo_vec[0].x = macroblock->PMV[0][1][0] * 0.5f * mc->surface_tex_inv_size.x; - mo_vec[0].y = macroblock->PMV[0][1][1] * 0.5f * mc->surface_tex_inv_size.y; - - if (macroblock->mo_type == vlMotionTypeFrame) - { - for (i = 0; i < 24 * 2; i += 2) - { - vb[i].x = mo_vec[0].x; - vb[i].y = mo_vec[0].y; - } - } - else - { - mo_vec[1].x = macroblock->PMV[1][1][0] * 0.5f * mc->surface_tex_inv_size.x; - mo_vec[1].y = macroblock->PMV[1][1][1] * 0.5f * mc->surface_tex_inv_size.y; - - for (i = 0; i < 24 * 2; i += 2) - { - vb[i].x = mo_vec[0].x; - vb[i].y = mo_vec[0].y; - vb[i + 1].x = mo_vec[1].x; - vb[i + 1].y = mo_vec[1].y; - } - } - - /* fall-through */ - } - case vlMacroBlockTypeFwdPredicted: - case vlMacroBlockTypeBkwdPredicted: - { - struct vlVertex2f *vb; - - assert(ref_vb && ref_vb[0]); - - vb = ref_vb[0] + pos * 2 * 24; - - if (macroblock->mb_type == vlMacroBlockTypeBkwdPredicted) - { - mo_vec[0].x = macroblock->PMV[0][1][0] * 0.5f * mc->surface_tex_inv_size.x; - mo_vec[0].y = macroblock->PMV[0][1][1] * 0.5f * mc->surface_tex_inv_size.y; - - if (macroblock->mo_type == vlMotionTypeField) - { - mo_vec[1].x = macroblock->PMV[1][1][0] * 0.5f * mc->surface_tex_inv_size.x; - mo_vec[1].y = macroblock->PMV[1][1][1] * 0.5f * mc->surface_tex_inv_size.y; - } - } - else - { - mo_vec[0].x = macroblock->PMV[0][0][0] * 0.5f * mc->surface_tex_inv_size.x; - mo_vec[0].y = macroblock->PMV[0][0][1] * 0.5f * mc->surface_tex_inv_size.y; - - if (macroblock->mo_type == vlMotionTypeField) - { - mo_vec[1].x = macroblock->PMV[1][0][0] * 0.5f * mc->surface_tex_inv_size.x; - mo_vec[1].y = macroblock->PMV[1][0][1] * 0.5f * mc->surface_tex_inv_size.y; - } - } - - if (macroblock->mo_type == vlMotionTypeFrame) - { - for (i = 0; i < 24 * 2; i += 2) - { - vb[i].x = mo_vec[0].x; - vb[i].y = mo_vec[0].y; - } - } - else - { - for (i = 0; i < 24 * 2; i += 2) - { - vb[i].x = mo_vec[0].x; - vb[i].y = mo_vec[0].y; - vb[i + 1].x = mo_vec[1].x; - vb[i + 1].y = mo_vec[1].y; - } - } - - /* fall-through */ - } - case vlMacroBlockTypeIntra: - { - const struct vlVertex2f unit = - { - mc->surface_tex_inv_size.x * VL_MACROBLOCK_WIDTH, - mc->surface_tex_inv_size.y * VL_MACROBLOCK_HEIGHT - }; - const struct vlVertex2f half = - { - mc->surface_tex_inv_size.x * (VL_MACROBLOCK_WIDTH / 2), - mc->surface_tex_inv_size.y * (VL_MACROBLOCK_HEIGHT / 2) - }; - - struct vlMacroBlockVertexStream0 *vb; - - vb = ycbcr_vb + pos * 24; - - SET_BLOCK - ( - vb, - macroblock->cbp, macroblock->mbx, macroblock->mby, - unit.x, unit.y, 0, 0, half.x, half.y, - 32, 2, 1, mc->zero_block - ); - - SET_BLOCK - ( - vb + 6, - macroblock->cbp, macroblock->mbx, macroblock->mby, - unit.x, unit.y, half.x, 0, half.x, half.y, - 16, 2, 1, mc->zero_block - ); - - SET_BLOCK - ( - vb + 12, - macroblock->cbp, macroblock->mbx, macroblock->mby, - unit.x, unit.y, 0, half.y, half.x, half.y, - 8, 2, 1, mc->zero_block - ); - - SET_BLOCK - ( - vb + 18, - macroblock->cbp, macroblock->mbx, macroblock->mby, - unit.x, unit.y, half.x, half.y, half.x, half.y, - 4, 2, 1, mc->zero_block - ); - - break; - } - default: - assert(0); - } - - return 0; -} - -static int vlFlush -( - struct vlRender *render -) -{ - struct vlR16SnormBufferedMC *mc; - struct pipe_context *pipe; - struct vlVertexShaderConsts *vs_consts; - unsigned int num_macroblocks[vlNumMacroBlockExTypes] = {0}; - unsigned int offset[vlNumMacroBlockExTypes]; - unsigned int vb_start = 0; - unsigned int i; - - assert(render); - - mc = (struct vlR16SnormBufferedMC*)render; - - if (!mc->buffered_surface) - return 0; - - if (mc->num_macroblocks < mc->macroblocks_per_picture) - return 0; - - assert(mc->num_macroblocks <= mc->macroblocks_per_picture); - - pipe = mc->pipe; - - for (i = 0; i < mc->num_macroblocks; ++i) - { - enum vlMacroBlockTypeEx mb_type_ex = vlGetMacroBlockTypeEx(&mc->macroblocks[i]); - - num_macroblocks[mb_type_ex]++; - } - - offset[0] = 0; - - for (i = 1; i < vlNumMacroBlockExTypes; ++i) - offset[i] = offset[i - 1] + num_macroblocks[i - 1]; - - { - struct vlMacroBlockVertexStream0 *ycbcr_vb; - struct vlVertex2f *ref_vb[2]; - - ycbcr_vb = (struct vlMacroBlockVertexStream0*)pipe_buffer_map - ( - pipe->screen, - mc->vertex_bufs.ycbcr.buffer, - PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD - ); - - for (i = 0; i < 2; ++i) - ref_vb[i] = (struct vlVertex2f*)pipe_buffer_map - ( - pipe->screen, - mc->vertex_bufs.ref[i].buffer, - PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD - ); - - for (i = 0; i < mc->num_macroblocks; ++i) - { - enum vlMacroBlockTypeEx mb_type_ex = vlGetMacroBlockTypeEx(&mc->macroblocks[i]); - - vlGenMacroblockVerts(mc, &mc->macroblocks[i], offset[mb_type_ex], ycbcr_vb, ref_vb); - - offset[mb_type_ex]++; - } - - pipe_buffer_unmap(pipe->screen, mc->vertex_bufs.ycbcr.buffer); - for (i = 0; i < 2; ++i) - pipe_buffer_unmap(pipe->screen, mc->vertex_bufs.ref[i].buffer); - } - - for (i = 0; i < 3; ++i) - { - pipe->screen->transfer_unmap(pipe->screen, mc->tex_transfer[i]); - pipe->screen->tex_transfer_destroy(mc->tex_transfer[i]); - } - - mc->render_target.cbufs[0] = pipe->screen->get_tex_surface - ( - pipe->screen, - mc->buffered_surface->texture, - 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE - ); - - pipe->set_framebuffer_state(pipe, &mc->render_target); - pipe->set_viewport_state(pipe, &mc->viewport); - vs_consts = pipe_buffer_map - ( - pipe->screen, - mc->vs_const_buf.buffer, - PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD - ); - - vs_consts->denorm.x = mc->buffered_surface->texture->width[0]; - vs_consts->denorm.y = mc->buffered_surface->texture->height[0]; - - pipe_buffer_unmap(pipe->screen, mc->vs_const_buf.buffer); - pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &mc->vs_const_buf); - pipe->set_constant_buffer(pipe, PIPE_SHADER_FRAGMENT, 0, &mc->fs_const_buf); - - if (num_macroblocks[vlMacroBlockExTypeIntra] > 0) - { - pipe->set_vertex_buffers(pipe, 1, mc->vertex_bufs.all); - pipe->set_vertex_elements(pipe, 4, mc->vertex_elems); - pipe->set_sampler_textures(pipe, 3, mc->textures.all); - pipe->bind_sampler_states(pipe, 3, mc->samplers.all); - pipe->bind_vs_state(pipe, mc->i_vs); - pipe->bind_fs_state(pipe, mc->i_fs); - - pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLES, vb_start, num_macroblocks[vlMacroBlockExTypeIntra] * 24); - vb_start += num_macroblocks[vlMacroBlockExTypeIntra] * 24; - } - - if (num_macroblocks[vlMacroBlockExTypeFwdPredictedFrame] > 0) - { - pipe->set_vertex_buffers(pipe, 2, mc->vertex_bufs.all); - pipe->set_vertex_elements(pipe, 6, mc->vertex_elems); - mc->textures.ref[0] = mc->past_surface->texture; - pipe->set_sampler_textures(pipe, 4, mc->textures.all); - pipe->bind_sampler_states(pipe, 4, mc->samplers.all); - pipe->bind_vs_state(pipe, mc->p_vs[0]); - pipe->bind_fs_state(pipe, mc->p_fs[0]); - - pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLES, vb_start, num_macroblocks[vlMacroBlockExTypeFwdPredictedFrame] * 24); - vb_start += num_macroblocks[vlMacroBlockExTypeFwdPredictedFrame] * 24; - } - - if (num_macroblocks[vlMacroBlockExTypeFwdPredictedField] > 0) - { - pipe->set_vertex_buffers(pipe, 2, mc->vertex_bufs.all); - pipe->set_vertex_elements(pipe, 6, mc->vertex_elems); - mc->textures.ref[0] = mc->past_surface->texture; - pipe->set_sampler_textures(pipe, 4, mc->textures.all); - pipe->bind_sampler_states(pipe, 4, mc->samplers.all); - pipe->bind_vs_state(pipe, mc->p_vs[1]); - pipe->bind_fs_state(pipe, mc->p_fs[1]); - - pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLES, vb_start, num_macroblocks[vlMacroBlockExTypeFwdPredictedField] * 24); - vb_start += num_macroblocks[vlMacroBlockExTypeFwdPredictedField] * 24; - } - - if (num_macroblocks[vlMacroBlockExTypeBkwdPredictedFrame] > 0) - { - pipe->set_vertex_buffers(pipe, 2, mc->vertex_bufs.all); - pipe->set_vertex_elements(pipe, 6, mc->vertex_elems); - mc->textures.ref[0] = mc->future_surface->texture; - pipe->set_sampler_textures(pipe, 4, mc->textures.all); - pipe->bind_sampler_states(pipe, 4, mc->samplers.all); - pipe->bind_vs_state(pipe, mc->p_vs[0]); - pipe->bind_fs_state(pipe, mc->p_fs[0]); - - pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLES, vb_start, num_macroblocks[vlMacroBlockExTypeBkwdPredictedFrame] * 24); - vb_start += num_macroblocks[vlMacroBlockExTypeBkwdPredictedFrame] * 24; - } - - if (num_macroblocks[vlMacroBlockExTypeBkwdPredictedField] > 0) - { - pipe->set_vertex_buffers(pipe, 2, mc->vertex_bufs.all); - pipe->set_vertex_elements(pipe, 6, mc->vertex_elems); - mc->textures.ref[0] = mc->future_surface->texture; - pipe->set_sampler_textures(pipe, 4, mc->textures.all); - pipe->bind_sampler_states(pipe, 4, mc->samplers.all); - pipe->bind_vs_state(pipe, mc->p_vs[1]); - pipe->bind_fs_state(pipe, mc->p_fs[1]); - - pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLES, vb_start, num_macroblocks[vlMacroBlockExTypeBkwdPredictedField] * 24); - vb_start += num_macroblocks[vlMacroBlockExTypeBkwdPredictedField] * 24; - } - - if (num_macroblocks[vlMacroBlockExTypeBiPredictedFrame] > 0) - { - pipe->set_vertex_buffers(pipe, 3, mc->vertex_bufs.all); - pipe->set_vertex_elements(pipe, 8, mc->vertex_elems); - mc->textures.ref[0] = mc->past_surface->texture; - mc->textures.ref[1] = mc->future_surface->texture; - pipe->set_sampler_textures(pipe, 5, mc->textures.all); - pipe->bind_sampler_states(pipe, 5, mc->samplers.all); - pipe->bind_vs_state(pipe, mc->b_vs[0]); - pipe->bind_fs_state(pipe, mc->b_fs[0]); - - pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLES, vb_start, num_macroblocks[vlMacroBlockExTypeBiPredictedFrame] * 24); - vb_start += num_macroblocks[vlMacroBlockExTypeBiPredictedFrame] * 24; - } - - if (num_macroblocks[vlMacroBlockExTypeBiPredictedField] > 0) - { - pipe->set_vertex_buffers(pipe, 3, mc->vertex_bufs.all); - pipe->set_vertex_elements(pipe, 8, mc->vertex_elems); - mc->textures.ref[0] = mc->past_surface->texture; - mc->textures.ref[1] = mc->future_surface->texture; - pipe->set_sampler_textures(pipe, 5, mc->textures.all); - pipe->bind_sampler_states(pipe, 5, mc->samplers.all); - pipe->bind_vs_state(pipe, mc->b_vs[1]); - pipe->bind_fs_state(pipe, mc->b_fs[1]); - - pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLES, vb_start, num_macroblocks[vlMacroBlockExTypeBiPredictedField] * 24); - vb_start += num_macroblocks[vlMacroBlockExTypeBiPredictedField] * 24; - } - - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, &mc->buffered_surface->render_fence); - pipe_surface_reference(&mc->render_target.cbufs[0], NULL); - - for (i = 0; i < 3; ++i) - mc->zero_block[i].x = -1.0f; - - mc->buffered_surface = NULL; - mc->num_macroblocks = 0; - - return 0; -} - -static int vlRenderMacroBlocksMpeg2R16SnormBuffered -( - struct vlRender *render, - struct vlMpeg2MacroBlockBatch *batch, - struct vlSurface *surface -) -{ - struct vlR16SnormBufferedMC *mc; - bool new_surface = false; - unsigned int i; - - assert(render); - - mc = (struct vlR16SnormBufferedMC*)render; - - if (mc->buffered_surface) - { - if (mc->buffered_surface != surface) - { - vlFlush(&mc->base); - new_surface = true; - } - } - else - new_surface = true; - - if (new_surface) - { - mc->buffered_surface = surface; - mc->past_surface = batch->past_surface; - mc->future_surface = batch->future_surface; - mc->surface_tex_inv_size.x = 1.0f / surface->texture->width[0]; - mc->surface_tex_inv_size.y = 1.0f / surface->texture->height[0]; - - for (i = 0; i < 3; ++i) - { - mc->tex_transfer[i] = mc->pipe->screen->get_tex_transfer - ( - mc->pipe->screen, - mc->textures.all[i], - 0, 0, 0, PIPE_TRANSFER_WRITE, 0, 0, - surface->texture->width[0], - surface->texture->height[0] - ); - - mc->texels[i] = mc->pipe->screen->transfer_map(mc->pipe->screen, mc->tex_transfer[i]); - } - } - - for (i = 0; i < batch->num_macroblocks; ++i) - vlGrabMacroBlock(mc, &batch->macroblocks[i]); - - return 0; -} - -static inline int vlEnd -( - struct vlRender *render -) -{ - assert(render); - - return 0; -} - -static int vlDestroy -( - struct vlRender *render -) -{ - struct vlR16SnormBufferedMC *mc; - struct pipe_context *pipe; - unsigned int i; - - assert(render); - - mc = (struct vlR16SnormBufferedMC*)render; - pipe = mc->pipe; - - for (i = 0; i < 5; ++i) - pipe->delete_sampler_state(pipe, mc->samplers.all[i]); - - for (i = 0; i < 3; ++i) - pipe_buffer_reference(&mc->vertex_bufs.all[i].buffer, NULL); - - /* Textures 3 & 4 are not created directly, no need to release them here */ - for (i = 0; i < 3; ++i) - pipe_texture_reference(&mc->textures.all[i], NULL); - - pipe->delete_vs_state(pipe, mc->i_vs); - pipe->delete_fs_state(pipe, mc->i_fs); - - for (i = 0; i < 2; ++i) - { - pipe->delete_vs_state(pipe, mc->p_vs[i]); - pipe->delete_fs_state(pipe, mc->p_fs[i]); - pipe->delete_vs_state(pipe, mc->b_vs[i]); - pipe->delete_fs_state(pipe, mc->b_fs[i]); - } - - pipe_buffer_reference(&mc->vs_const_buf.buffer, NULL); - pipe_buffer_reference(&mc->fs_const_buf.buffer, NULL); - - FREE(mc->macroblocks); - FREE(mc); - - return 0; -} - -/* - * Muliplier renormalizes block samples from 16 bits to 12 bits. - * Divider is used when calculating Y % 2 for choosing top or bottom - * field for P or B macroblocks. - * TODO: Use immediates. - */ -static const struct vlFragmentShaderConsts fs_consts = -{ - {32767.0f / 255.0f, 32767.0f / 255.0f, 32767.0f / 255.0f, 0.0f}, - {0.5f, 2.0f, 0.0f, 0.0f} -}; - -#include "vl_r16snorm_mc_buf_shaders.inc" - -static int vlCreateDataBufs -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int mbw = align(mc->picture_width, VL_MACROBLOCK_WIDTH) / VL_MACROBLOCK_WIDTH; - const unsigned int mbh = align(mc->picture_height, VL_MACROBLOCK_HEIGHT) / VL_MACROBLOCK_HEIGHT; - - struct pipe_context *pipe; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - mc->macroblocks_per_picture = mbw * mbh; - - /* Create our vertex buffers */ - mc->vertex_bufs.ycbcr.stride = sizeof(struct vlVertex2f) * 4; - mc->vertex_bufs.ycbcr.max_index = 24 * mc->macroblocks_per_picture - 1; - mc->vertex_bufs.ycbcr.buffer_offset = 0; - mc->vertex_bufs.ycbcr.buffer = pipe_buffer_create - ( - pipe->screen, - DEFAULT_BUF_ALIGNMENT, - PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_DISCARD, - sizeof(struct vlVertex2f) * 4 * 24 * mc->macroblocks_per_picture - ); - - for (i = 1; i < 3; ++i) - { - mc->vertex_bufs.all[i].stride = sizeof(struct vlVertex2f) * 2; - mc->vertex_bufs.all[i].max_index = 24 * mc->macroblocks_per_picture - 1; - mc->vertex_bufs.all[i].buffer_offset = 0; - mc->vertex_bufs.all[i].buffer = pipe_buffer_create - ( - pipe->screen, - DEFAULT_BUF_ALIGNMENT, - PIPE_BUFFER_USAGE_VERTEX | PIPE_BUFFER_USAGE_DISCARD, - sizeof(struct vlVertex2f) * 2 * 24 * mc->macroblocks_per_picture - ); - } - - /* Position element */ - mc->vertex_elems[0].src_offset = 0; - mc->vertex_elems[0].vertex_buffer_index = 0; - mc->vertex_elems[0].nr_components = 2; - mc->vertex_elems[0].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* Luma, texcoord element */ - mc->vertex_elems[1].src_offset = sizeof(struct vlVertex2f); - mc->vertex_elems[1].vertex_buffer_index = 0; - mc->vertex_elems[1].nr_components = 2; - mc->vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* Chroma Cr texcoord element */ - mc->vertex_elems[2].src_offset = sizeof(struct vlVertex2f) * 2; - mc->vertex_elems[2].vertex_buffer_index = 0; - mc->vertex_elems[2].nr_components = 2; - mc->vertex_elems[2].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* Chroma Cb texcoord element */ - mc->vertex_elems[3].src_offset = sizeof(struct vlVertex2f) * 3; - mc->vertex_elems[3].vertex_buffer_index = 0; - mc->vertex_elems[3].nr_components = 2; - mc->vertex_elems[3].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* First ref surface top field texcoord element */ - mc->vertex_elems[4].src_offset = 0; - mc->vertex_elems[4].vertex_buffer_index = 1; - mc->vertex_elems[4].nr_components = 2; - mc->vertex_elems[4].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* First ref surface bottom field texcoord element */ - mc->vertex_elems[5].src_offset = sizeof(struct vlVertex2f); - mc->vertex_elems[5].vertex_buffer_index = 1; - mc->vertex_elems[5].nr_components = 2; - mc->vertex_elems[5].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* Second ref surface top field texcoord element */ - mc->vertex_elems[6].src_offset = 0; - mc->vertex_elems[6].vertex_buffer_index = 2; - mc->vertex_elems[6].nr_components = 2; - mc->vertex_elems[6].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* Second ref surface bottom field texcoord element */ - mc->vertex_elems[7].src_offset = sizeof(struct vlVertex2f); - mc->vertex_elems[7].vertex_buffer_index = 2; - mc->vertex_elems[7].nr_components = 2; - mc->vertex_elems[7].src_format = PIPE_FORMAT_R32G32_FLOAT; - - /* Create our constant buffer */ - mc->vs_const_buf.buffer = pipe_buffer_create - ( - pipe->screen, - DEFAULT_BUF_ALIGNMENT, - PIPE_BUFFER_USAGE_CONSTANT | PIPE_BUFFER_USAGE_DISCARD, - sizeof(struct vlVertexShaderConsts) - ); - - mc->fs_const_buf.buffer = pipe_buffer_create - ( - pipe->screen, - DEFAULT_BUF_ALIGNMENT, - PIPE_BUFFER_USAGE_CONSTANT, - sizeof(struct vlFragmentShaderConsts) - ); - - memcpy - ( - pipe_buffer_map(pipe->screen, mc->fs_const_buf.buffer, PIPE_BUFFER_USAGE_CPU_WRITE), - &fs_consts, - sizeof(struct vlFragmentShaderConsts) - ); - - pipe_buffer_unmap(pipe->screen, mc->fs_const_buf.buffer); - - mc->macroblocks = MALLOC(sizeof(struct vlMpeg2MacroBlock) * mc->macroblocks_per_picture); - - return 0; -} - -static int vlInit -( - struct vlR16SnormBufferedMC *mc -) -{ - struct pipe_context *pipe; - struct pipe_sampler_state sampler; - struct pipe_texture template; - unsigned int filters[5]; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - - mc->buffered_surface = NULL; - mc->past_surface = NULL; - mc->future_surface = NULL; - for (i = 0; i < 3; ++i) - mc->zero_block[i].x = -1.0f; - mc->num_macroblocks = 0; - - /* For MC we render to textures, which are rounded up to nearest POT */ - mc->viewport.scale[0] = vlRoundUpPOT(mc->picture_width); - mc->viewport.scale[1] = vlRoundUpPOT(mc->picture_height); - mc->viewport.scale[2] = 1; - mc->viewport.scale[3] = 1; - mc->viewport.translate[0] = 0; - mc->viewport.translate[1] = 0; - mc->viewport.translate[2] = 0; - mc->viewport.translate[3] = 0; - - mc->render_target.width = vlRoundUpPOT(mc->picture_width); - mc->render_target.height = vlRoundUpPOT(mc->picture_height); - mc->render_target.nr_cbufs = 1; - /* FB for MC stage is a vlSurface created by the user, set at render time */ - mc->render_target.zsbuf = NULL; - - filters[0] = PIPE_TEX_FILTER_NEAREST; - /* FIXME: Linear causes discoloration around block edges */ - filters[1] = /*mc->picture_format == vlFormatYCbCr444 ?*/ PIPE_TEX_FILTER_NEAREST /*: PIPE_TEX_FILTER_LINEAR*/; - filters[2] = /*mc->picture_format == vlFormatYCbCr444 ?*/ PIPE_TEX_FILTER_NEAREST /*: PIPE_TEX_FILTER_LINEAR*/; - filters[3] = PIPE_TEX_FILTER_LINEAR; - filters[4] = PIPE_TEX_FILTER_LINEAR; - - for (i = 0; i < 5; ++i) - { - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.min_img_filter = filters[i]; - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; - sampler.mag_img_filter = filters[i]; - sampler.compare_mode = PIPE_TEX_COMPARE_NONE; - sampler.compare_func = PIPE_FUNC_ALWAYS; - sampler.normalized_coords = 1; - /*sampler.prefilter = ;*/ - /*sampler.lod_bias = ;*/ - sampler.min_lod = 0; - /*sampler.max_lod = ;*/ - /*sampler.border_color[i] = ;*/ - /*sampler.max_anisotropy = ;*/ - mc->samplers.all[i] = pipe->create_sampler_state(pipe, &sampler); - } - - memset(&template, 0, sizeof(struct pipe_texture)); - template.target = PIPE_TEXTURE_2D; - template.format = PIPE_FORMAT_R16_SNORM; - template.last_level = 0; - template.width[0] = vlRoundUpPOT(mc->picture_width); - template.height[0] = vlRoundUpPOT(mc->picture_height); - template.depth[0] = 1; - pf_get_block(template.format, &template.block); - template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_DYNAMIC; - - mc->textures.y = pipe->screen->texture_create(pipe->screen, &template); - - if (mc->picture_format == vlFormatYCbCr420) - { - template.width[0] = vlRoundUpPOT(mc->picture_width / 2); - template.height[0] = vlRoundUpPOT(mc->picture_height / 2); - } - else if (mc->picture_format == vlFormatYCbCr422) - template.height[0] = vlRoundUpPOT(mc->picture_height / 2); - - mc->textures.cb = pipe->screen->texture_create(pipe->screen, &template); - mc->textures.cr = pipe->screen->texture_create(pipe->screen, &template); - - /* textures.all[3] & textures.all[4] are assigned from vlSurfaces for P and B macroblocks at render time */ - - vlCreateVertexShaderIMB(mc); - vlCreateFragmentShaderIMB(mc); - vlCreateVertexShaderFramePMB(mc); - vlCreateVertexShaderFieldPMB(mc); - vlCreateFragmentShaderFramePMB(mc); - vlCreateFragmentShaderFieldPMB(mc); - vlCreateVertexShaderFrameBMB(mc); - vlCreateVertexShaderFieldBMB(mc); - vlCreateFragmentShaderFrameBMB(mc); - vlCreateFragmentShaderFieldBMB(mc); - vlCreateDataBufs(mc); - - return 0; -} - -int vlCreateR16SNormBufferedMC -( - struct pipe_context *pipe, - unsigned int picture_width, - unsigned int picture_height, - enum vlFormat picture_format, - struct vlRender **render -) -{ - struct vlR16SnormBufferedMC *mc; - - assert(pipe); - assert(render); - - mc = CALLOC_STRUCT(vlR16SnormBufferedMC); - - mc->base.vlBegin = &vlBegin; - mc->base.vlRenderMacroBlocksMpeg2 = &vlRenderMacroBlocksMpeg2R16SnormBuffered; - mc->base.vlEnd = &vlEnd; - mc->base.vlFlush = &vlFlush; - mc->base.vlDestroy = &vlDestroy; - mc->pipe = pipe; - mc->picture_width = picture_width; - mc->picture_height = picture_height; - - vlInit(mc); - - *render = &mc->base; - - return 0; -} diff --git a/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.h b/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.h deleted file mode 100644 index 27177d64cad..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef vl_r16snorm_mc_buf_h -#define vl_r16snorm_mc_buf_h - -#include "vl_types.h" - -struct pipe_context; -struct vlRender; - -int vlCreateR16SNormBufferedMC -( - struct pipe_context *pipe, - unsigned int picture_width, - unsigned int picture_height, - enum vlFormat picture_format, - struct vlRender **render -); - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf_shaders.inc b/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf_shaders.inc deleted file mode 100644 index 34d93e1df0a..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_r16snorm_mc_buf_shaders.inc +++ /dev/null @@ -1,1185 +0,0 @@ -static int vlCreateVertexShaderIMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 50; - - struct pipe_context *pipe; - struct pipe_shader_state vs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header); - - ti = 3; - - /* - * decl i0 ; Vertex pos - * decl i1 ; Luma texcoords - * decl i2 ; Chroma Cb texcoords - * decl i3 ; Chroma Cr texcoords - */ - for (i = 0; i < 4; i++) - { - decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * decl o0 ; Vertex pos - * decl o1 ; Luma texcoords - * decl o2 ; Chroma Cb texcoords - * decl o3 ; Chroma Cr texcoords - */ - for (i = 0; i < 4; i++) - { - decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * mov o0, i0 ; Move input vertex pos to output - * mov o1, i1 ; Move input luma texcoords to output - * mov o2, i2 ; Move input chroma Cb texcoords to output - * mov o3, i3 ; Move input chroma Cr texcoords to output - */ - for (i = 0; i < 4; ++i) - { - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - vs.tokens = tokens; - mc->i_vs = pipe->create_vs_state(pipe, &vs); - free(tokens); - - return 0; -} - -static int vlCreateFragmentShaderIMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 100; - - struct pipe_context *pipe; - struct pipe_shader_state fs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header); - - ti = 3; - - /* - * decl i0 ; Luma texcoords - * decl i1 ; Chroma Cb texcoords - * decl i2 ; Chroma Cr texcoords - */ - for (i = 0; i < 3; ++i) - { - decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* decl c0 ; Scaling factor, rescales 16-bit snorm to 9-bit snorm */ - decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl o0 ; Fragment color */ - decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl t0, t1 */ - decl = vl_decl_temps(0, 1); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * decl s0 ; Sampler for luma texture - * decl s1 ; Sampler for chroma Cb texture - * decl s2 ; Sampler for chroma Cr texture - */ - for (i = 0; i < 3; ++i) - { - decl = vl_decl_samplers(i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header,max_tokens - ti); - } - - /* - * tex2d t1, i0, s0 ; Read texel from luma texture - * mov t0.x, t1.x ; Move luma sample into .x component - * tex2d t1, i1, s1 ; Read texel from chroma Cb texture - * mov t0.y, t1.x ; Move Cb sample into .y component - * tex2d t1, i2, s2 ; Read texel from chroma Cr texture - * mov t0.z, t1.x ; Move Cr sample into .z component - */ - for (i = 0; i < 3; ++i) - { - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1); - inst.FullSrcRegisters[0].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullDstRegisters[0].DstRegister.WriteMask = TGSI_WRITEMASK_X << i; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* mul o0, t0, c0 ; Rescale texel to correct range */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - fs.tokens = tokens; - mc->i_fs = pipe->create_fs_state(pipe, &fs); - free(tokens); - - return 0; -} - -static int vlCreateVertexShaderFramePMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 100; - - struct pipe_context *pipe; - struct pipe_shader_state vs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header); - - ti = 3; - - /* - * decl i0 ; Vertex pos - * decl i1 ; Luma texcoords - * decl i2 ; Chroma Cb texcoords - * decl i3 ; Chroma Cr texcoords - * decl i4 ; Ref surface top field texcoords - * decl i5 ; Ref surface bottom field texcoords (unused, packed in the same stream) - */ - for (i = 0; i < 6; i++) - { - decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * decl o0 ; Vertex pos - * decl o1 ; Luma texcoords - * decl o2 ; Chroma Cb texcoords - * decl o3 ; Chroma Cr texcoords - * decl o4 ; Ref macroblock texcoords - */ - for (i = 0; i < 5; i++) - { - decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * mov o0, i0 ; Move input vertex pos to output - * mov o1, i1 ; Move input luma texcoords to output - * mov o2, i2 ; Move input chroma Cb texcoords to output - * mov o3, i3 ; Move input chroma Cr texcoords to output - */ - for (i = 0; i < 4; ++i) - { - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* add o4, i0, i4 ; Translate vertex pos by motion vec to form ref macroblock texcoords */ - inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 4, TGSI_FILE_INPUT, 0, TGSI_FILE_INPUT, 4); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - vs.tokens = tokens; - mc->p_vs[0] = pipe->create_vs_state(pipe, &vs); - free(tokens); - - return 0; -} - -static int vlCreateVertexShaderFieldPMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 100; - - struct pipe_context *pipe; - struct pipe_shader_state vs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header); - - ti = 3; - - /* - * decl i0 ; Vertex pos - * decl i1 ; Luma texcoords - * decl i2 ; Chroma Cb texcoords - * decl i3 ; Chroma Cr texcoords - * decl i4 ; Ref macroblock top field texcoords - * decl i5 ; Ref macroblock bottom field texcoords - */ - for (i = 0; i < 6; i++) - { - decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* decl c0 ; Render target dimensions */ - decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * decl o0 ; Vertex pos - * decl o1 ; Luma texcoords - * decl o2 ; Chroma Cb texcoords - * decl o3 ; Chroma Cr texcoords - * decl o4 ; Ref macroblock top field texcoords - * decl o5 ; Ref macroblock bottom field texcoords - * decl o6 ; Denormalized vertex pos - */ - for (i = 0; i < 7; i++) - { - decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * mov o0, i0 ; Move input vertex pos to output - * mov o1, i1 ; Move input luma texcoords to output - * mov o2, i2 ; Move input chroma Cb texcoords to output - * mov o3, i3 ; Move input chroma Cr texcoords to output - */ - for (i = 0; i < 4; ++i) - { - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* - * add o4, i0, i4 ; Translate vertex pos by motion vec to form top field macroblock texcoords - * add o5, i0, i5 ; Translate vertex pos by motion vec to form bottom field macroblock texcoords - */ - for (i = 0; i < 2; ++i) - { - inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, i + 4, TGSI_FILE_INPUT, 0, TGSI_FILE_INPUT, i + 4); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* mul o6, i0, c0 ; Denorm vertex pos */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_OUTPUT, 6, TGSI_FILE_INPUT, 0, TGSI_FILE_CONSTANT, 0); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - vs.tokens = tokens; - mc->p_vs[1] = pipe->create_vs_state(pipe, &vs); - free(tokens); - - return 0; -} - -static int vlCreateFragmentShaderFramePMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 100; - - struct pipe_context *pipe; - struct pipe_shader_state fs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header); - - ti = 3; - - /* - * decl i0 ; Luma texcoords - * decl i1 ; Chroma Cb texcoords - * decl i2 ; Chroma Cr texcoords - * decl i3 ; Ref macroblock texcoords - */ - for (i = 0; i < 4; ++i) - { - decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* decl c0 ; Scaling factor, rescales 16-bit snorm to 9-bit snorm */ - decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl o0 ; Fragment color */ - decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl t0, t1 */ - decl = vl_decl_temps(0, 1); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * decl s0 ; Sampler for luma texture - * decl s1 ; Sampler for chroma Cb texture - * decl s2 ; Sampler for chroma Cr texture - * decl s3 ; Sampler for ref surface texture - */ - for (i = 0; i < 4; ++i) - { - decl = vl_decl_samplers(i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * tex2d t1, i0, s0 ; Read texel from luma texture - * mov t0.x, t1.x ; Move luma sample into .x component - * tex2d t1, i1, s1 ; Read texel from chroma Cb texture - * mov t0.y, t1.x ; Move Cb sample into .y component - * tex2d t1, i2, s2 ; Read texel from chroma Cr texture - * mov t0.z, t1.x ; Move Cr sample into .z component - */ - for (i = 0; i < 3; ++i) - { - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1); - inst.FullSrcRegisters[0].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullDstRegisters[0].DstRegister.WriteMask = TGSI_WRITEMASK_X << i; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* mul t0, t0, c0 ; Rescale texel to correct range */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* tex2d t1, i3, s3 ; Read texel from ref macroblock */ - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, 3, TGSI_FILE_SAMPLER, 3); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* add o0, t0, t1 ; Add ref and differential to form final output */ - inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - fs.tokens = tokens; - mc->p_fs[0] = pipe->create_fs_state(pipe, &fs); - free(tokens); - - return 0; -} - -static int vlCreateFragmentShaderFieldPMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 200; - - struct pipe_context *pipe; - struct pipe_shader_state fs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header); - - ti = 3; - - /* - * decl i0 ; Luma texcoords - * decl i1 ; Chroma Cb texcoords - * decl i2 ; Chroma Cr texcoords - * decl i3 ; Ref macroblock top field texcoords - * decl i4 ; Ref macroblock bottom field texcoords - * decl i5 ; Denormalized vertex pos - */ - for (i = 0; i < 6; ++i) - { - decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * decl c0 ; Scaling factor, rescales 16-bit snorm to 9-bit snorm - * decl c1 ; Constants 1/2 & 2 in .x, .y channels for Y-mod-2 top/bottom field selection - */ - decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 1); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl o0 ; Fragment color */ - decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl t0-t4 */ - decl = vl_decl_temps(0, 4); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * decl s0 ; Sampler for luma texture - * decl s1 ; Sampler for chroma Cb texture - * decl s2 ; Sampler for chroma Cr texture - * decl s3 ; Sampler for ref surface texture - */ - for (i = 0; i < 4; ++i) - { - decl = vl_decl_samplers(i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * tex2d t1, i0, s0 ; Read texel from luma texture - * mov t0.x, t1.x ; Move luma sample into .x component - * tex2d t1, i1, s1 ; Read texel from chroma Cb texture - * mov t0.y, t1.x ; Move Cb sample into .y component - * tex2d t1, i2, s2 ; Read texel from chroma Cr texture - * mov t0.z, t1.x ; Move Cr sample into .z component - */ - for (i = 0; i < 3; ++i) - { - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1); - inst.FullSrcRegisters[0].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullDstRegisters[0].DstRegister.WriteMask = TGSI_WRITEMASK_X << i; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* mul t0, t0, c0 ; Rescale texel to correct range */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* - * tex2d t1, i3, s3 ; Read texel from ref macroblock top field - * tex2d t2, i4, s3 ; Read texel from ref macroblock bottom field - */ - for (i = 0; i < 2; ++i) - { - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, i + 1, TGSI_FILE_INPUT, i + 3, TGSI_FILE_SAMPLER, 3); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* XXX: Pos values off by 0.5? */ - /* sub t4, i5.y, c1.x ; Sub 0.5 from denormalized pos */ - inst = vl_inst3(TGSI_OPCODE_SUB, TGSI_FILE_TEMPORARY, 4, TGSI_FILE_INPUT, 5, TGSI_FILE_CONSTANT, 1); - inst.FullSrcRegisters[0].SrcRegister.SwizzleX = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[0].SrcRegister.SwizzleY = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[0].SrcRegister.SwizzleZ = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[0].SrcRegister.SwizzleW = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[1].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleW = TGSI_SWIZZLE_X; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* mul t3, t4, c1.x ; Multiply pos Y-coord by 1/2 */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 4, TGSI_FILE_CONSTANT, 1); - inst.FullSrcRegisters[1].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleW = TGSI_SWIZZLE_X; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* floor t3, t3 ; Get rid of fractional part */ - inst = vl_inst2(TGSI_OPCODE_FLR, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 3); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* mul t3, t3, c1.y ; Multiply by 2 */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_CONSTANT, 1); - inst.FullSrcRegisters[1].SrcRegister.SwizzleX = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[1].SrcRegister.SwizzleY = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[1].SrcRegister.SwizzleZ = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[1].SrcRegister.SwizzleW = TGSI_SWIZZLE_Y; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* sub t3, t4, t3 ; Subtract from original Y to get Y % 2 */ - inst = vl_inst3(TGSI_OPCODE_SUB, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 4, TGSI_FILE_TEMPORARY, 3); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* TODO: Move to conditional tex fetch on t3 instead of lerp */ - /* lerp t1, t3, t1, t2 ; Choose between top and bottom fields based on Y % 2 */ - inst = vl_inst4(TGSI_OPCODE_LRP, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_TEMPORARY, 2); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* add o0, t0, t1 ; Add ref and differential to form final output */ - inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - fs.tokens = tokens; - mc->p_fs[1] = pipe->create_fs_state(pipe, &fs); - free(tokens); - - return 0; -} - -static int vlCreateVertexShaderFrameBMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 100; - - struct pipe_context *pipe; - struct pipe_shader_state vs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header); - - ti = 3; - - /* - * decl i0 ; Vertex pos - * decl i1 ; Luma texcoords - * decl i2 ; Chroma Cb texcoords - * decl i3 ; Chroma Cr texcoords - * decl i4 ; First ref macroblock top field texcoords - * decl i5 ; First ref macroblock bottom field texcoords (unused, packed in the same stream) - * decl i6 ; Second ref macroblock top field texcoords - * decl i7 ; Second ref macroblock bottom field texcoords (unused, packed in the same stream) - */ - for (i = 0; i < 8; i++) - { - decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * decl o0 ; Vertex pos - * decl o1 ; Luma texcoords - * decl o2 ; Chroma Cb texcoords - * decl o3 ; Chroma Cr texcoords - * decl o4 ; First ref macroblock texcoords - * decl o5 ; Second ref macroblock texcoords - */ - for (i = 0; i < 6; i++) - { - decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * mov o0, i0 ; Move input vertex pos to output - * mov o1, i1 ; Move input luma texcoords to output - * mov o2, i2 ; Move input chroma Cb texcoords to output - * mov o3, i3 ; Move input chroma Cr texcoords to output - */ - for (i = 0; i < 4; ++i) - { - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* - * add o4, i0, i4 ; Translate vertex pos by motion vec to form first ref macroblock texcoords - * add o5, i0, i6 ; Translate vertex pos by motion vec to form second ref macroblock texcoords - */ - for (i = 0; i < 2; ++i) - { - inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, i + 4, TGSI_FILE_INPUT, 0, TGSI_FILE_INPUT, (i + 2) * 2); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - vs.tokens = tokens; - mc->b_vs[0] = pipe->create_vs_state(pipe, &vs); - free(tokens); - - return 0; -} - -static int vlCreateVertexShaderFieldBMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 100; - - struct pipe_context *pipe; - struct pipe_shader_state vs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header); - - ti = 3; - - /* - * decl i0 ; Vertex pos - * decl i1 ; Luma texcoords - * decl i2 ; Chroma Cb texcoords - * decl i3 ; Chroma Cr texcoords - * decl i4 ; First ref macroblock top field texcoords - * decl i5 ; First ref macroblock bottom field texcoords - * decl i6 ; Second ref macroblock top field texcoords - * decl i7 ; Second ref macroblock bottom field texcoords - */ - for (i = 0; i < 8; i++) - { - decl = vl_decl_input(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* decl c0 ; Render target dimensions */ - decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * decl o0 ; Vertex pos - * decl o1 ; Luma texcoords - * decl o2 ; Chroma Cb texcoords - * decl o3 ; Chroma Cr texcoords - * decl o4 ; First ref macroblock top field texcoords - * decl o5 ; First ref macroblock Bottom field texcoords - * decl o6 ; Second ref macroblock top field texcoords - * decl o7 ; Second ref macroblock Bottom field texcoords - * decl o8 ; Denormalized vertex pos - */ - for (i = 0; i < 9; i++) - { - decl = vl_decl_output(i == 0 ? TGSI_SEMANTIC_POSITION : TGSI_SEMANTIC_GENERIC, i, i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* decl t0, t1 */ - decl = vl_decl_temps(0, 1); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * mov o0, i0 ; Move input vertex pos to output - * mov o1, i1 ; Move input luma texcoords to output - * mov o2, i2 ; Move input chroma Cb texcoords to output - * mov o3, i3 ; Move input chroma Cr texcoords to output - */ - for (i = 0; i < 4; ++i) - { - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, i, TGSI_FILE_INPUT, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* - * add o4, i0, i4 ; Translate vertex pos by motion vec to form first top field macroblock texcoords - * add o5, i0, i5 ; Translate vertex pos by motion vec to form first bottom field macroblock texcoords - * add o6, i0, i6 ; Translate vertex pos by motion vec to form second top field macroblock texcoords - * add o7, i0, i7 ; Translate vertex pos by motion vec to form second bottom field macroblock texcoords - */ - for (i = 0; i < 4; ++i) - { - inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, i + 4, TGSI_FILE_INPUT, 0, TGSI_FILE_INPUT, i + 4); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* mul o8, i0, c0 ; Denorm vertex pos */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_OUTPUT, 8, TGSI_FILE_INPUT, 0, TGSI_FILE_CONSTANT, 0); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - vs.tokens = tokens; - mc->b_vs[1] = pipe->create_vs_state(pipe, &vs); - free(tokens); - - return 0; -} - -static int vlCreateFragmentShaderFrameBMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 100; - - struct pipe_context *pipe; - struct pipe_shader_state fs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header); - - ti = 3; - - /* - * decl i0 ; Luma texcoords - * decl i1 ; Chroma Cb texcoords - * decl i2 ; Chroma Cr texcoords - * decl i3 ; First ref macroblock texcoords - * decl i4 ; Second ref macroblock texcoords - */ - for (i = 0; i < 5; ++i) - { - decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * decl c0 ; Scaling factor, rescales 16-bit snorm to 9-bit snorm - * decl c1 ; Constant 1/2 in .x channel to use as weight to blend past and future texels - */ - decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 1); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl o0 ; Fragment color */ - decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl t0-t2 */ - decl = vl_decl_temps(0, 2); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * decl s0 ; Sampler for luma texture - * decl s1 ; Sampler for chroma Cb texture - * decl s2 ; Sampler for chroma Cr texture - * decl s3 ; Sampler for first ref surface texture - * decl s4 ; Sampler for second ref surface texture - */ - for (i = 0; i < 5; ++i) - { - decl = vl_decl_samplers(i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * tex2d t1, i0, s0 ; Read texel from luma texture - * mov t0.x, t1.x ; Move luma sample into .x component - * tex2d t1, i1, s1 ; Read texel from chroma Cb texture - * mov t0.y, t1.x ; Move Cb sample into .y component - * tex2d t1, i2, s2 ; Read texel from chroma Cr texture - * mov t0.z, t1.x ; Move Cr sample into .z component - */ - for (i = 0; i < 3; ++i) - { - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1); - inst.FullSrcRegisters[0].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullDstRegisters[0].DstRegister.WriteMask = TGSI_WRITEMASK_X << i; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* mul t0, t0, c0 ; Rescale texel to correct range */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* - * tex2d t1, i3, s3 ; Read texel from first ref macroblock - * tex2d t2, i4, s4 ; Read texel from second ref macroblock - */ - for (i = 0; i < 2; ++i) - { - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, i + 1, TGSI_FILE_INPUT, i + 3, TGSI_FILE_SAMPLER, i + 3); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* lerp t1, c1.x, t1, t2 ; Blend past and future texels */ - inst = vl_inst4(TGSI_OPCODE_LRP, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_CONSTANT, 1, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_TEMPORARY, 2); - inst.FullSrcRegisters[0].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleW = TGSI_SWIZZLE_X; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* add o0, t0, t1 ; Add past/future ref and differential to form final output */ - inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - fs.tokens = tokens; - mc->b_fs[0] = pipe->create_fs_state(pipe, &fs); - free(tokens); - - return 0; -} - -static int vlCreateFragmentShaderFieldBMB -( - struct vlR16SnormBufferedMC *mc -) -{ - const unsigned int max_tokens = 200; - - struct pipe_context *pipe; - struct pipe_shader_state fs; - struct tgsi_token *tokens; - struct tgsi_header *header; - - struct tgsi_full_declaration decl; - struct tgsi_full_instruction inst; - - unsigned int ti; - unsigned int i; - - assert(mc); - - pipe = mc->pipe; - tokens = (struct tgsi_token*)malloc(max_tokens * sizeof(struct tgsi_token)); - - /* Version */ - *(struct tgsi_version*)&tokens[0] = tgsi_build_version(); - /* Header */ - header = (struct tgsi_header*)&tokens[1]; - *header = tgsi_build_header(); - /* Processor */ - *(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_FRAGMENT, header); - - ti = 3; - - /* - * decl i0 ; Luma texcoords - * decl i1 ; Chroma Cb texcoords - * decl i2 ; Chroma Cr texcoords - * decl i3 ; First ref macroblock top field texcoords - * decl i4 ; First ref macroblock bottom field texcoords - * decl i5 ; Second ref macroblock top field texcoords - * decl i6 ; Second ref macroblock bottom field texcoords - * decl i7 ; Denormalized vertex pos - */ - for (i = 0; i < 8; ++i) - { - decl = vl_decl_interpolated_input(TGSI_SEMANTIC_GENERIC, i + 1, i, i, TGSI_INTERPOLATE_LINEAR); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * decl c0 ; Scaling factor, rescales 16-bit snorm to 9-bit snorm - * decl c1 ; Constants 1/2 & 2 in .x, .y channels to use as weight to blend past and future texels - * ; and for Y-mod-2 top/bottom field selection - */ - decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 1); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl o0 ; Fragment color */ - decl = vl_decl_output(TGSI_SEMANTIC_COLOR, 0, 0, 0); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* decl t0-t5 */ - decl = vl_decl_temps(0, 5); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - - /* - * decl s0 ; Sampler for luma texture - * decl s1 ; Sampler for chroma Cb texture - * decl s2 ; Sampler for chroma Cr texture - * decl s3 ; Sampler for first ref surface texture - * decl s4 ; Sampler for second ref surface texture - */ - for (i = 0; i < 5; ++i) - { - decl = vl_decl_samplers(i, i); - ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti); - } - - /* - * tex2d t1, i0, s0 ; Read texel from luma texture - * mov t0.x, t1.x ; Move luma sample into .x component - * tex2d t1, i1, s1 ; Read texel from chroma Cb texture - * mov t0.y, t1.x ; Move Cb sample into .y component - * tex2d t1, i2, s2 ; Read texel from chroma Cr texture - * mov t0.z, t1.x ; Move Cr sample into .z component - */ - for (i = 0; i < 3; ++i) - { - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_INPUT, i, TGSI_FILE_SAMPLER, i); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1); - inst.FullSrcRegisters[0].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullDstRegisters[0].DstRegister.WriteMask = TGSI_WRITEMASK_X << i; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* mul t0, t0, c0 ; Rescale texel to correct range */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 0); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* XXX: Pos values off by 0.5? */ - /* sub t4, i7.y, c1.x ; Sub 0.5 from denormalized pos */ - inst = vl_inst3(TGSI_OPCODE_SUB, TGSI_FILE_TEMPORARY, 4, TGSI_FILE_INPUT, 7, TGSI_FILE_CONSTANT, 1); - inst.FullSrcRegisters[0].SrcRegister.SwizzleX = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[0].SrcRegister.SwizzleY = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[0].SrcRegister.SwizzleZ = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[0].SrcRegister.SwizzleW = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[1].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleW = TGSI_SWIZZLE_X; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* mul t3, t4, c1.x ; Multiply pos Y-coord by 1/2 */ - inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 4, TGSI_FILE_CONSTANT, 1); - inst.FullSrcRegisters[1].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[1].SrcRegister.SwizzleW = TGSI_SWIZZLE_X; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* floor t3, t3 ; Get rid of fractional part */ - inst = vl_inst2(TGSI_OPCODE_FLR, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 3); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* mul t3, t3, c1.y ; Multiply by 2 */ - inst = vl_inst3( TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_CONSTANT, 1); - inst.FullSrcRegisters[1].SrcRegister.SwizzleX = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[1].SrcRegister.SwizzleY = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[1].SrcRegister.SwizzleZ = TGSI_SWIZZLE_Y; - inst.FullSrcRegisters[1].SrcRegister.SwizzleW = TGSI_SWIZZLE_Y; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* sub t3, t4, t3 ; Subtract from original Y to get Y % 2 */ - inst = vl_inst3(TGSI_OPCODE_SUB, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 4, TGSI_FILE_TEMPORARY, 3); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* - * tex2d t1, i3, s3 ; Read texel from past ref macroblock top field - * tex2d t2, i4, s3 ; Read texel from past ref macroblock bottom field - */ - for (i = 0; i < 2; ++i) - { - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, i + 1, TGSI_FILE_INPUT, i + 3, TGSI_FILE_SAMPLER, 3); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* TODO: Move to conditional tex fetch on t3 instead of lerp */ - /* lerp t1, t3, t1, t2 ; Choose between top and bottom fields based on Y % 2 */ - inst = vl_inst4(TGSI_OPCODE_LRP, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_TEMPORARY, 2); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* - * tex2d t4, i5, s4 ; Read texel from future ref macroblock top field - * tex2d t5, i6, s4 ; Read texel from future ref macroblock bottom field - */ - for (i = 0; i < 2; ++i) - { - inst = vl_tex(TGSI_TEXTURE_2D, TGSI_FILE_TEMPORARY, i + 4, TGSI_FILE_INPUT, i + 5, TGSI_FILE_SAMPLER, 4); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - } - - /* TODO: Move to conditional tex fetch on t3 instead of lerp */ - /* lerp t2, t3, t4, t5 ; Choose between top and bottom fields based on Y % 2 */ - inst = vl_inst4(TGSI_OPCODE_LRP, TGSI_FILE_TEMPORARY, 2, TGSI_FILE_TEMPORARY, 3, TGSI_FILE_TEMPORARY, 4, TGSI_FILE_TEMPORARY, 5); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* lerp t1, c1.x, t1, t2 ; Blend past and future texels */ - inst = vl_inst4(TGSI_OPCODE_LRP, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_CONSTANT, 1, TGSI_FILE_TEMPORARY, 1, TGSI_FILE_TEMPORARY, 2); - inst.FullSrcRegisters[0].SrcRegister.SwizzleX = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleY = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleZ = TGSI_SWIZZLE_X; - inst.FullSrcRegisters[0].SrcRegister.SwizzleW = TGSI_SWIZZLE_X; - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* add o0, t0, t1 ; Add past/future ref and differential to form final output */ - inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 0, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_TEMPORARY, 1); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - /* end */ - inst = vl_end(); - ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti); - - fs.tokens = tokens; - mc->b_fs[1] = pipe->create_fs_state(pipe, &fs); - free(tokens); - - return 0; -} diff --git a/src/gallium/state_trackers/g3dvl/vl_render.h b/src/gallium/state_trackers/g3dvl/vl_render.h deleted file mode 100644 index 166030b4988..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_render.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef vl_render_h -#define vl_render_h - -#include "vl_types.h" - -struct pipe_surface; - -struct vlRender -{ - int (*vlBegin) - ( - struct vlRender *render - ); - - int (*vlRenderMacroBlocksMpeg2) - ( - struct vlRender *render, - struct vlMpeg2MacroBlockBatch *batch, - struct vlSurface *surface - ); - - int (*vlEnd) - ( - struct vlRender *render - ); - - int (*vlFlush) - ( - struct vlRender *render - ); - - int (*vlDestroy) - ( - struct vlRender *render - ); -}; - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_screen.c b/src/gallium/state_trackers/g3dvl/vl_screen.c deleted file mode 100644 index ade8643a66a..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_screen.c +++ /dev/null @@ -1,115 +0,0 @@ -#define VL_INTERNAL -#include "vl_screen.h" -#include -#include - -int vlCreateScreen -( - struct vlDisplay *display, - int screen, - struct pipe_screen *pscreen, - struct vlScreen **vl_screen -) -{ - struct vlScreen *scrn; - - assert(display); - assert(pscreen); - assert(vl_screen); - - scrn = CALLOC_STRUCT(vlScreen); - - if (!scrn) - return 1; - - scrn->display = display; - scrn->ordinal = screen; - scrn->pscreen = pscreen; - *vl_screen = scrn; - - return 0; -} - -int vlDestroyScreen -( - struct vlScreen *screen -) -{ - assert(screen); - - FREE(screen); - - return 0; -} - -struct vlDisplay* vlGetDisplay -( - struct vlScreen *screen -) -{ - assert(screen); - - return screen->display; -} - -struct pipe_screen* vlGetPipeScreen -( - struct vlScreen *screen -) -{ - assert(screen); - - return screen->pscreen; -} - -unsigned int vlGetMaxProfiles -( - struct vlScreen *screen -) -{ - assert(screen); - - return vlProfileCount; -} - -int vlQueryProfiles -( - struct vlScreen *screen, - enum vlProfile *profiles -) -{ - assert(screen); - assert(profiles); - - profiles[0] = vlProfileMpeg2Simple; - profiles[1] = vlProfileMpeg2Main; - - return 0; -} - -unsigned int vlGetMaxEntryPoints -( - struct vlScreen *screen -) -{ - assert(screen); - - return vlEntryPointCount; -} - -int vlQueryEntryPoints -( - struct vlScreen *screen, - enum vlProfile profile, - enum vlEntryPoint *entry_points -) -{ - assert(screen); - assert(entry_points); - - entry_points[0] = vlEntryPointIDCT; - entry_points[1] = vlEntryPointMC; - entry_points[2] = vlEntryPointCSC; - - return 0; -} diff --git a/src/gallium/state_trackers/g3dvl/vl_screen.h b/src/gallium/state_trackers/g3dvl/vl_screen.h deleted file mode 100644 index 98f3d429b61..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_screen.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef vl_screen_h -#define vl_screen_h - -#include "vl_types.h" - -struct pipe_screen; - -#ifdef VL_INTERNAL -struct vlScreen -{ - struct vlDisplay *display; - unsigned int ordinal; - struct pipe_screen *pscreen; -}; -#endif - -int vlCreateScreen -( - struct vlDisplay *display, - int screen, - struct pipe_screen *pscreen, - struct vlScreen **vl_screen -); - -int vlDestroyScreen -( - struct vlScreen *screen -); - -struct vlDisplay* vlGetDisplay -( - struct vlScreen *screen -); - -struct pipe_screen* vlGetPipeScreen -( - struct vlScreen *screen -); - -unsigned int vlGetMaxProfiles -( - struct vlScreen *screen -); - -int vlQueryProfiles -( - struct vlScreen *screen, - enum vlProfile *profiles -); - -unsigned int vlGetMaxEntryPoints -( - struct vlScreen *screen -); - -int vlQueryEntryPoints -( - struct vlScreen *screen, - enum vlProfile profile, - enum vlEntryPoint *entry_points -); - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_shader_build.c b/src/gallium/state_trackers/g3dvl/vl_shader_build.c deleted file mode 100644 index 51f1721a332..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_shader_build.c +++ /dev/null @@ -1,215 +0,0 @@ -#include "vl_shader_build.h" -#include -#include -#include - -struct tgsi_full_declaration vl_decl_input(unsigned int name, unsigned int index, unsigned int first, unsigned int last) -{ - struct tgsi_full_declaration decl = tgsi_default_full_declaration(); - - decl.Declaration.File = TGSI_FILE_INPUT; - decl.Declaration.Semantic = 1; - decl.Semantic.SemanticName = name; - decl.Semantic.SemanticIndex = index; - decl.DeclarationRange.First = first; - decl.DeclarationRange.Last = last; - - return decl; -} - -struct tgsi_full_declaration vl_decl_interpolated_input -( - unsigned int name, - unsigned int index, - unsigned int first, - unsigned int last, - int interpolation -) -{ - struct tgsi_full_declaration decl = tgsi_default_full_declaration(); - - assert - ( - interpolation == TGSI_INTERPOLATE_CONSTANT || - interpolation == TGSI_INTERPOLATE_LINEAR || - interpolation == TGSI_INTERPOLATE_PERSPECTIVE - ); - - decl.Declaration.File = TGSI_FILE_INPUT; - decl.Declaration.Semantic = 1; - decl.Semantic.SemanticName = name; - decl.Semantic.SemanticIndex = index; - decl.Declaration.Interpolate = interpolation;; - decl.DeclarationRange.First = first; - decl.DeclarationRange.Last = last; - - return decl; -} - -struct tgsi_full_declaration vl_decl_constants(unsigned int name, unsigned int index, unsigned int first, unsigned int last) -{ - struct tgsi_full_declaration decl = tgsi_default_full_declaration(); - - decl.Declaration.File = TGSI_FILE_CONSTANT; - decl.Declaration.Semantic = 1; - decl.Semantic.SemanticName = name; - decl.Semantic.SemanticIndex = index; - decl.DeclarationRange.First = first; - decl.DeclarationRange.Last = last; - - return decl; -} - -struct tgsi_full_declaration vl_decl_output(unsigned int name, unsigned int index, unsigned int first, unsigned int last) -{ - struct tgsi_full_declaration decl = tgsi_default_full_declaration(); - - decl.Declaration.File = TGSI_FILE_OUTPUT; - decl.Declaration.Semantic = 1; - decl.Semantic.SemanticName = name; - decl.Semantic.SemanticIndex = index; - decl.DeclarationRange.First = first; - decl.DeclarationRange.Last = last; - - return decl; -} - -struct tgsi_full_declaration vl_decl_temps(unsigned int first, unsigned int last) -{ - struct tgsi_full_declaration decl = tgsi_default_full_declaration(); - - decl = tgsi_default_full_declaration(); - decl.Declaration.File = TGSI_FILE_TEMPORARY; - decl.DeclarationRange.First = first; - decl.DeclarationRange.Last = last; - - return decl; -} - -struct tgsi_full_declaration vl_decl_samplers(unsigned int first, unsigned int last) -{ - struct tgsi_full_declaration decl = tgsi_default_full_declaration(); - - decl = tgsi_default_full_declaration(); - decl.Declaration.File = TGSI_FILE_SAMPLER; - decl.DeclarationRange.First = first; - decl.DeclarationRange.Last = last; - - return decl; -} - -struct tgsi_full_instruction vl_inst2 -( - int opcode, - enum tgsi_file_type dst_file, - unsigned int dst_index, - enum tgsi_file_type src_file, - unsigned int src_index -) -{ - struct tgsi_full_instruction inst = tgsi_default_full_instruction(); - - inst.Instruction.Opcode = opcode; - inst.Instruction.NumDstRegs = 1; - inst.FullDstRegisters[0].DstRegister.File = dst_file; - inst.FullDstRegisters[0].DstRegister.Index = dst_index; - inst.Instruction.NumSrcRegs = 1; - inst.FullSrcRegisters[0].SrcRegister.File = src_file; - inst.FullSrcRegisters[0].SrcRegister.Index = src_index; - - return inst; -} - -struct tgsi_full_instruction vl_inst3 -( - int opcode, - enum tgsi_file_type dst_file, - unsigned int dst_index, - enum tgsi_file_type src1_file, - unsigned int src1_index, - enum tgsi_file_type src2_file, - unsigned int src2_index -) -{ - struct tgsi_full_instruction inst = tgsi_default_full_instruction(); - - inst.Instruction.Opcode = opcode; - inst.Instruction.NumDstRegs = 1; - inst.FullDstRegisters[0].DstRegister.File = dst_file; - inst.FullDstRegisters[0].DstRegister.Index = dst_index; - inst.Instruction.NumSrcRegs = 2; - inst.FullSrcRegisters[0].SrcRegister.File = src1_file; - inst.FullSrcRegisters[0].SrcRegister.Index = src1_index; - inst.FullSrcRegisters[1].SrcRegister.File = src2_file; - inst.FullSrcRegisters[1].SrcRegister.Index = src2_index; - - return inst; -} - -struct tgsi_full_instruction vl_tex -( - int tex, - enum tgsi_file_type dst_file, - unsigned int dst_index, - enum tgsi_file_type src1_file, - unsigned int src1_index, - enum tgsi_file_type src2_file, - unsigned int src2_index -) -{ - struct tgsi_full_instruction inst = tgsi_default_full_instruction(); - - inst.Instruction.Opcode = TGSI_OPCODE_TEX; - inst.Instruction.NumDstRegs = 1; - inst.FullDstRegisters[0].DstRegister.File = dst_file; - inst.FullDstRegisters[0].DstRegister.Index = dst_index; - inst.Instruction.NumSrcRegs = 2; - inst.InstructionExtTexture.Texture = tex; - inst.FullSrcRegisters[0].SrcRegister.File = src1_file; - inst.FullSrcRegisters[0].SrcRegister.Index = src1_index; - inst.FullSrcRegisters[1].SrcRegister.File = src2_file; - inst.FullSrcRegisters[1].SrcRegister.Index = src2_index; - - return inst; -} - -struct tgsi_full_instruction vl_inst4 -( - int opcode, - enum tgsi_file_type dst_file, - unsigned int dst_index, - enum tgsi_file_type src1_file, - unsigned int src1_index, - enum tgsi_file_type src2_file, - unsigned int src2_index, - enum tgsi_file_type src3_file, - unsigned int src3_index -) -{ - struct tgsi_full_instruction inst = tgsi_default_full_instruction(); - - inst.Instruction.Opcode = opcode; - inst.Instruction.NumDstRegs = 1; - inst.FullDstRegisters[0].DstRegister.File = dst_file; - inst.FullDstRegisters[0].DstRegister.Index = dst_index; - inst.Instruction.NumSrcRegs = 3; - inst.FullSrcRegisters[0].SrcRegister.File = src1_file; - inst.FullSrcRegisters[0].SrcRegister.Index = src1_index; - inst.FullSrcRegisters[1].SrcRegister.File = src2_file; - inst.FullSrcRegisters[1].SrcRegister.Index = src2_index; - inst.FullSrcRegisters[2].SrcRegister.File = src3_file; - inst.FullSrcRegisters[2].SrcRegister.Index = src3_index; - - return inst; -} - -struct tgsi_full_instruction vl_end(void) -{ - struct tgsi_full_instruction inst = tgsi_default_full_instruction(); - - inst.Instruction.Opcode = TGSI_OPCODE_END; - inst.Instruction.NumDstRegs = 0; - inst.Instruction.NumSrcRegs = 0; - - return inst; -} diff --git a/src/gallium/state_trackers/g3dvl/vl_shader_build.h b/src/gallium/state_trackers/g3dvl/vl_shader_build.h deleted file mode 100644 index dc615cb1566..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_shader_build.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef vl_shader_build_h -#define vl_shader_build_h - -#include - -struct tgsi_full_declaration vl_decl_input(unsigned int name, unsigned int index, unsigned int first, unsigned int last); -struct tgsi_full_declaration vl_decl_interpolated_input -( - unsigned int name, - unsigned int index, - unsigned int first, - unsigned int last, - int interpolation -); -struct tgsi_full_declaration vl_decl_constants(unsigned int name, unsigned int index, unsigned int first, unsigned int last); -struct tgsi_full_declaration vl_decl_output(unsigned int name, unsigned int index, unsigned int first, unsigned int last); -struct tgsi_full_declaration vl_decl_temps(unsigned int first, unsigned int last); -struct tgsi_full_declaration vl_decl_samplers(unsigned int first, unsigned int last); -struct tgsi_full_instruction vl_inst2 -( - int opcode, - enum tgsi_file_type dst_file, - unsigned int dst_index, - enum tgsi_file_type src_file, - unsigned int src_index -); -struct tgsi_full_instruction vl_inst3 -( - int opcode, - enum tgsi_file_type dst_file, - unsigned int dst_index, - enum tgsi_file_type src1_file, - unsigned int src1_index, - enum tgsi_file_type src2_file, - unsigned int src2_index -); -struct tgsi_full_instruction vl_tex -( - int tex, - enum tgsi_file_type dst_file, - unsigned int dst_index, - enum tgsi_file_type src1_file, - unsigned int src1_index, - enum tgsi_file_type src2_file, - unsigned int src2_index -); -struct tgsi_full_instruction vl_inst4 -( - int opcode, - enum tgsi_file_type dst_file, - unsigned int dst_index, - enum tgsi_file_type src1_file, - unsigned int src1_index, - enum tgsi_file_type src2_file, - unsigned int src2_index, - enum tgsi_file_type src3_file, - unsigned int src3_index -); -struct tgsi_full_instruction vl_end(void); - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_surface.c b/src/gallium/state_trackers/g3dvl/vl_surface.c deleted file mode 100644 index 7f60852cae8..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_surface.c +++ /dev/null @@ -1,242 +0,0 @@ -#define VL_INTERNAL -#include "vl_surface.h" -#include -#include -#include -#include -#include -#include -#include -#include "vl_screen.h" -#include "vl_context.h" -#include "vl_render.h" -#include "vl_csc.h" -#include "vl_util.h" - -int vlCreateSurface -( - struct vlScreen *screen, - unsigned int width, - unsigned int height, - enum vlFormat format, - struct vlSurface **surface -) -{ - struct vlSurface *sfc; - struct pipe_texture template; - - assert(screen); - assert(surface); - - sfc = CALLOC_STRUCT(vlSurface); - - if (!sfc) - return 1; - - sfc->screen = screen; - sfc->width = width; - sfc->height = height; - sfc->format = format; - - memset(&template, 0, sizeof(struct pipe_texture)); - template.target = PIPE_TEXTURE_2D; - template.format = PIPE_FORMAT_A8R8G8B8_UNORM; - template.last_level = 0; - template.width[0] = vlRoundUpPOT(sfc->width); - template.height[0] = vlRoundUpPOT(sfc->height); - template.depth[0] = 1; - pf_get_block(template.format, &template.block); - template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET; - - sfc->texture = vlGetPipeScreen(screen)->texture_create(vlGetPipeScreen(screen), &template); - - if (!sfc->texture) - { - FREE(sfc); - return 1; - } - - *surface = sfc; - - return 0; -} - -int vlDestroySurface -( - struct vlSurface *surface -) -{ - assert(surface); - - pipe_texture_reference(&surface->texture, NULL); - FREE(surface); - - return 0; -} - -int vlRenderMacroBlocksMpeg2 -( - struct vlMpeg2MacroBlockBatch *batch, - struct vlSurface *surface -) -{ - assert(batch); - assert(surface); - assert(surface->context); - - surface->context->render->vlBegin(surface->context->render); - - surface->context->render->vlRenderMacroBlocksMpeg2 - ( - surface->context->render, - batch, - surface - ); - - surface->context->render->vlEnd(surface->context->render); - - return 0; -} - -int vlPutPicture -( - struct vlSurface *surface, - vlNativeDrawable drawable, - int srcx, - int srcy, - int srcw, - int srch, - int destx, - int desty, - int destw, - int desth, - int drawable_w, - int drawable_h, - enum vlPictureType picture_type -) -{ - struct vlCSC *csc; - struct pipe_context *pipe; - - assert(surface); - assert(surface->context); - - surface->context->render->vlFlush(surface->context->render); - - csc = surface->context->csc; - pipe = surface->context->pipe; - - csc->vlResizeFrameBuffer(csc, drawable_w, drawable_h); - - csc->vlBegin(csc); - - csc->vlPutPicture - ( - csc, - surface, - srcx, - srcy, - srcw, - srch, - destx, - desty, - destw, - desth, - picture_type - ); - - csc->vlEnd(csc); - - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, &surface->disp_fence); - - bind_pipe_drawable(pipe, drawable); - - pipe->screen->flush_frontbuffer - ( - pipe->screen, - csc->vlGetFrameBuffer(csc), - pipe->priv - ); - - return 0; -} - -int vlSurfaceGetStatus -( - struct vlSurface *surface, - enum vlResourceStatus *status -) -{ - assert(surface); - assert(surface->context); - assert(status); - - if (surface->render_fence && !surface->context->pipe->screen->fence_signalled(surface->context->pipe->screen, surface->render_fence, 0)) - { - *status = vlResourceStatusRendering; - return 0; - } - - if (surface->disp_fence && !surface->context->pipe->screen->fence_signalled(surface->context->pipe->screen, surface->disp_fence, 0)) - { - *status = vlResourceStatusDisplaying; - return 0; - } - - *status = vlResourceStatusFree; - - return 0; -} - -int vlSurfaceFlush -( - struct vlSurface *surface -) -{ - assert(surface); - assert(surface->context); - - surface->context->render->vlFlush(surface->context->render); - - return 0; -} - -int vlSurfaceSync -( - struct vlSurface *surface -) -{ - assert(surface); - assert(surface->context); - assert(surface->render_fence); - - surface->context->pipe->screen->fence_finish(surface->context->pipe->screen, surface->render_fence, 0); - - return 0; -} - -struct vlScreen* vlSurfaceGetScreen -( - struct vlSurface *surface -) -{ - assert(surface); - - return surface->screen; -} - -struct vlContext* vlBindToContext -( - struct vlSurface *surface, - struct vlContext *context -) -{ - struct vlContext *old; - - assert(surface); - - old = surface->context; - surface->context = context; - - return old; -} diff --git a/src/gallium/state_trackers/g3dvl/vl_surface.h b/src/gallium/state_trackers/g3dvl/vl_surface.h deleted file mode 100644 index 133e1515ef3..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_surface.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef vl_surface_h -#define vl_surface_h - -#include "vl_types.h" - -#ifdef VL_INTERNAL -struct pipe_texture; - -struct vlSurface -{ - struct vlScreen *screen; - struct vlContext *context; - unsigned int width; - unsigned int height; - enum vlFormat format; - struct pipe_texture *texture; - struct pipe_fence_handle *render_fence; - struct pipe_fence_handle *disp_fence; -}; -#endif - -int vlCreateSurface -( - struct vlScreen *screen, - unsigned int width, - unsigned int height, - enum vlFormat format, - struct vlSurface **surface -); - -int vlDestroySurface -( - struct vlSurface *surface -); - -int vlRenderMacroBlocksMpeg2 -( - struct vlMpeg2MacroBlockBatch *batch, - struct vlSurface *surface -); - -int vlPutPicture -( - struct vlSurface *surface, - vlNativeDrawable drawable, - int srcx, - int srcy, - int srcw, - int srch, - int destx, - int desty, - int destw, - int desth, - int drawable_w, - int drawable_h, - enum vlPictureType picture_type -); - -int vlSurfaceGetStatus -( - struct vlSurface *surface, - enum vlResourceStatus *status -); - -int vlSurfaceFlush -( - struct vlSurface *surface -); - -int vlSurfaceSync -( - struct vlSurface *surface -); - -struct vlScreen* vlSurfaceGetScreen -( - struct vlSurface *surface -); - -struct vlContext* vlBindToContext -( - struct vlSurface *surface, - struct vlContext *context -); - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_types.h b/src/gallium/state_trackers/g3dvl/vl_types.h deleted file mode 100644 index 274e1f74377..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_types.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef vl_types_h -#define vl_types_h - -#if 1 /*#ifdef X11*/ -#include - -typedef Display* vlNativeDisplay; -typedef Drawable vlNativeDrawable; -#endif - -struct vlDisplay; -struct vlScreen; -struct vlContext; -struct vlSurface; - -enum vlResourceStatus -{ - vlResourceStatusFree, - vlResourceStatusRendering, - vlResourceStatusDisplaying -}; - -enum vlProfile -{ - vlProfileMpeg2Simple, - vlProfileMpeg2Main, - - vlProfileCount -}; - -enum vlEntryPoint -{ - vlEntryPointIDCT, - vlEntryPointMC, - vlEntryPointCSC, - - vlEntryPointCount -}; - -enum vlFormat -{ - vlFormatYCbCr420, - vlFormatYCbCr422, - vlFormatYCbCr444 -}; - -enum vlPictureType -{ - vlPictureTypeTopField, - vlPictureTypeBottomField, - vlPictureTypeFrame -}; - -enum vlMotionType -{ - vlMotionTypeField, - vlMotionTypeFrame, - vlMotionTypeDualPrime, - vlMotionType16x8 -}; - -enum vlFieldOrder -{ - vlFieldOrderFirst, - vlFieldOrderSecond -}; - -enum vlDCTType -{ - vlDCTTypeFrameCoded, - vlDCTTypeFieldCoded -}; - -struct vlVertex2f -{ - float x, y; -}; - -struct vlVertex4f -{ - float x, y, z, w; -}; - -enum vlMacroBlockType -{ - vlMacroBlockTypeIntra, - vlMacroBlockTypeFwdPredicted, - vlMacroBlockTypeBkwdPredicted, - vlMacroBlockTypeBiPredicted, - - vlNumMacroBlockTypes -}; - -struct vlMpeg2MacroBlock -{ - unsigned int mbx, mby; - enum vlMacroBlockType mb_type; - enum vlMotionType mo_type; - enum vlDCTType dct_type; - int PMV[2][2][2]; - unsigned int cbp; - short *blocks; -}; - -struct vlMpeg2MacroBlockBatch -{ - struct vlSurface *past_surface; - struct vlSurface *future_surface; - enum vlPictureType picture_type; - enum vlFieldOrder field_order; - unsigned int num_macroblocks; - struct vlMpeg2MacroBlock *macroblocks; -}; - -#endif diff --git a/src/gallium/state_trackers/g3dvl/vl_util.c b/src/gallium/state_trackers/g3dvl/vl_util.c deleted file mode 100644 index 50aa9af66f2..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_util.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "vl_util.h" -#include - -unsigned int vlRoundUpPOT(unsigned int x) -{ - unsigned int i; - - assert(x > 0); - - --x; - - for (i = 1; i < sizeof(unsigned int) * 8; i <<= 1) - x |= x >> i; - - return x + 1; -} diff --git a/src/gallium/state_trackers/g3dvl/vl_util.h b/src/gallium/state_trackers/g3dvl/vl_util.h deleted file mode 100644 index bc98e79df47..00000000000 --- a/src/gallium/state_trackers/g3dvl/vl_util.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef vl_util_h -#define vl_util_h - -unsigned int vlRoundUpPOT(unsigned int x); - -#endif diff --git a/src/gallium/winsys/g3dvl/xsp_winsys.c b/src/gallium/winsys/g3dvl/xsp_winsys.c deleted file mode 100644 index 37d60ce5406..00000000000 --- a/src/gallium/winsys/g3dvl/xsp_winsys.c +++ /dev/null @@ -1,291 +0,0 @@ -#include "vl_winsys.h" -#include -#include -#include -#include -#include -#include -#include -#include - -/* pipe_winsys implementation */ - -struct xsp_pipe_winsys -{ - struct pipe_winsys base; - XImage fbimage; -}; - -struct xsp_context -{ - Display *display; - int screen; - Drawable drawable; - int drawable_bound; -}; - -struct xsp_buffer -{ - struct pipe_buffer base; - boolean is_user_buffer; - void *data; - void *mapped_data; -}; - -static struct pipe_buffer* xsp_buffer_create(struct pipe_winsys *pws, unsigned alignment, unsigned usage, unsigned size) -{ - struct xsp_buffer *buffer; - - assert(pws); - - buffer = calloc(1, sizeof(struct xsp_buffer)); - pipe_reference_init(&buffer->base.reference, 1); - buffer->base.alignment = alignment; - buffer->base.usage = usage; - buffer->base.size = size; - buffer->data = align_malloc(size, alignment); - - return (struct pipe_buffer*)buffer; -} - -static struct pipe_buffer* xsp_user_buffer_create(struct pipe_winsys *pws, void *data, unsigned size) -{ - struct xsp_buffer *buffer; - - assert(pws); - - buffer = calloc(1, sizeof(struct xsp_buffer)); - pipe_reference_init(&buffer->base.reference, 1); - buffer->base.size = size; - buffer->is_user_buffer = TRUE; - buffer->data = data; - - return (struct pipe_buffer*)buffer; -} - -static void* xsp_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buffer, unsigned flags) -{ - struct xsp_buffer *xsp_buf = (struct xsp_buffer*)buffer; - - assert(pws); - assert(buffer); - - xsp_buf->mapped_data = xsp_buf->data; - - return xsp_buf->mapped_data; -} - -static void xsp_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buffer) -{ - struct xsp_buffer *xsp_buf = (struct xsp_buffer*)buffer; - - assert(pws); - assert(buffer); - - xsp_buf->mapped_data = NULL; -} - -static void xsp_buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buffer) -{ - struct xsp_buffer *xsp_buf = (struct xsp_buffer*)buffer; - - assert(pws); - assert(buffer); - - if (!xsp_buf->is_user_buffer) - align_free(xsp_buf->data); - - free(xsp_buf); -} - -static struct pipe_buffer* xsp_surface_buffer_create -( - struct pipe_winsys *pws, - unsigned width, - unsigned height, - enum pipe_format format, - unsigned usage, - unsigned tex_usage, - unsigned *stride -) -{ - const unsigned int ALIGNMENT = 1; - struct pipe_format_block block; - unsigned nblocksx, nblocksy; - - pf_get_block(format, &block); - nblocksx = pf_get_nblocksx(&block, width); - nblocksy = pf_get_nblocksy(&block, height); - *stride = align(nblocksx * block.size, ALIGNMENT); - - return pws->buffer_create(pws, ALIGNMENT, - usage, - *stride * nblocksy); -} - -static void xsp_fence_reference(struct pipe_winsys *pws, struct pipe_fence_handle **ptr, struct pipe_fence_handle *fence) -{ - assert(pws); - assert(ptr); - assert(fence); -} - -static int xsp_fence_signalled(struct pipe_winsys *pws, struct pipe_fence_handle *fence, unsigned flag) -{ - assert(pws); - assert(fence); - - return 0; -} - -static int xsp_fence_finish(struct pipe_winsys *pws, struct pipe_fence_handle *fence, unsigned flag) -{ - assert(pws); - assert(fence); - - return 0; -} - -static void xsp_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surface, void *context_private) -{ - struct xsp_pipe_winsys *xsp_winsys; - struct xsp_context *xsp_context; - - assert(pws); - assert(surface); - assert(context_private); - - xsp_winsys = (struct xsp_pipe_winsys*)pws; - xsp_context = (struct xsp_context*)context_private; - - if (!xsp_context->drawable_bound) - return; - - xsp_winsys->fbimage.width = surface->width; - xsp_winsys->fbimage.height = surface->height; - xsp_winsys->fbimage.bytes_per_line = surface->width * (xsp_winsys->fbimage.bits_per_pixel >> 3); - xsp_winsys->fbimage.data = ((struct xsp_buffer *)softpipe_texture(surface->texture)->buffer)->data + surface->offset; - - XPutImage - ( - xsp_context->display, - xsp_context->drawable, - XDefaultGC(xsp_context->display, xsp_context->screen), - &xsp_winsys->fbimage, - 0, - 0, - 0, - 0, - surface->width, - surface->height - ); - XFlush(xsp_context->display); -} - -static const char* xsp_get_name(struct pipe_winsys *pws) -{ - assert(pws); - return "X11 SoftPipe"; -} - -/* Show starts here */ - -int bind_pipe_drawable(struct pipe_context *pipe, Drawable drawable) -{ - struct xsp_context *xsp_context; - - assert(pipe); - - xsp_context = pipe->priv; - xsp_context->drawable = drawable; - xsp_context->drawable_bound = 1; - - return 0; -} - -int unbind_pipe_drawable(struct pipe_context *pipe) -{ - struct xsp_context *xsp_context; - - assert(pipe); - - xsp_context = pipe->priv; - xsp_context->drawable_bound = 0; - - return 0; -} - -struct pipe_context* create_pipe_context(Display *display, int screen) -{ - struct xsp_pipe_winsys *xsp_winsys; - struct xsp_context *xsp_context; - struct pipe_screen *sp_screen; - struct pipe_context *sp_pipe; - - assert(display); - - xsp_winsys = calloc(1, sizeof(struct xsp_pipe_winsys)); - xsp_winsys->base.buffer_create = xsp_buffer_create; - xsp_winsys->base.user_buffer_create = xsp_user_buffer_create; - xsp_winsys->base.buffer_map = xsp_buffer_map; - xsp_winsys->base.buffer_unmap = xsp_buffer_unmap; - xsp_winsys->base.buffer_destroy = xsp_buffer_destroy; - xsp_winsys->base.surface_buffer_create = xsp_surface_buffer_create; - xsp_winsys->base.fence_reference = xsp_fence_reference; - xsp_winsys->base.fence_signalled = xsp_fence_signalled; - xsp_winsys->base.fence_finish = xsp_fence_finish; - xsp_winsys->base.flush_frontbuffer = xsp_flush_frontbuffer; - xsp_winsys->base.get_name = xsp_get_name; - - { - /* XXX: Can't use the returned XImage* directly, - since we don't have control over winsys destruction - and we wouldn't be able to free it */ - XImage *template = XCreateImage - ( - display, - XDefaultVisual(display, XDefaultScreen(display)), - XDefaultDepth(display, XDefaultScreen(display)), - ZPixmap, - 0, - NULL, - 0, /* Don't know the width and height until flush_frontbuffer */ - 0, - 32, - 0 - ); - - memcpy(&xsp_winsys->fbimage, template, sizeof(XImage)); - XInitImage(&xsp_winsys->fbimage); - - XDestroyImage(template); - } - - sp_screen = softpipe_create_screen((struct pipe_winsys*)xsp_winsys); - sp_pipe = softpipe_create(sp_screen); - - xsp_context = calloc(1, sizeof(struct xsp_context)); - xsp_context->display = display; - xsp_context->screen = screen; - - sp_pipe->priv = xsp_context; - - return sp_pipe; -} - -int destroy_pipe_context(struct pipe_context *pipe) -{ - struct pipe_screen *screen; - struct pipe_winsys *winsys; - - assert(pipe); - - screen = pipe->screen; - winsys = pipe->winsys; - free(pipe->priv); - pipe->destroy(pipe); - screen->destroy(screen); - free(winsys); - - return 0; -} -- 2.30.2