g3dvl: pipe_video_context interface, softpipe impl, auxiliary libs

This commit is contained in:
Younes Manton
2009-09-27 19:49:06 -04:00
parent da793b7434
commit f547472bfa
24 changed files with 3561 additions and 5 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ EGL_DRIVERS_DIRS = demo
# Gallium directories and
GALLIUM_DIRS = auxiliary drivers state_trackers
GALLIUM_AUXILIARY_DIRS = rbug draw translate cso_cache pipebuffer tgsi sct rtasm util indices
GALLIUM_AUXILIARY_DIRS = rbug draw translate cso_cache pipebuffer tgsi sct rtasm util indices vl
GALLIUM_AUXILIARIES = $(foreach DIR,$(GALLIUM_AUXILIARY_DIRS),$(TOP)/src/gallium/auxiliary/$(DIR)/lib$(DIR).a)
GALLIUM_DRIVERS_DIRS = softpipe i915simple failover trace identity
GALLIUM_DRIVERS = $(foreach DIR,$(GALLIUM_DRIVERS_DIRS),$(TOP)/src/gallium/drivers/$(DIR)/lib$(DIR).a)
+1 -1
View File
@@ -417,7 +417,7 @@ WINDOW_SYSTEM=""
GALLIUM_DIRS="auxiliary drivers state_trackers"
GALLIUM_WINSYS_DIRS=""
GALLIUM_WINSYS_DRM_DIRS=""
GALLIUM_AUXILIARY_DIRS="rbug draw translate cso_cache pipebuffer tgsi sct rtasm util indices"
GALLIUM_AUXILIARY_DIRS="rbug draw translate cso_cache pipebuffer tgsi sct rtasm util indices vl"
GALLIUM_DRIVERS_DIRS="softpipe failover trace identity"
GALLIUM_STATE_TRACKERS_DIRS=""
+1
View File
@@ -23,6 +23,7 @@ SConscript([
'auxiliary/pipebuffer/SConscript',
'auxiliary/indices/SConscript',
'auxiliary/rbug/SConscript',
'auxiliary/vl/SConscript',
])
for driver in env['drivers']:
+12
View File
@@ -0,0 +1,12 @@
TOP = ../../../..
include $(TOP)/configs/current
LIBNAME = vl
C_SOURCES = \
vl_bitstream_parser.c \
vl_mpeg12_mc_renderer.c \
vl_compositor.c \
vl_shader_build.c
include ../../Makefile.template
+12
View File
@@ -0,0 +1,12 @@
Import('*')
vl = env.ConvenienceLibrary(
target = 'vl',
source = [
'vl_bitstream_parser.c',
'vl_mpeg12_mc_renderer.c',
'vl_compositor.c',
'vl_shader_build.c',
])
auxiliaries.insert(0, vl)
@@ -0,0 +1,144 @@
#include "vl_bitstream_parser.h"
#include <assert.h>
#include <limits.h>
#include <util/u_memory.h>
static unsigned
grab_bits(unsigned cursor, unsigned how_many_bits, unsigned bitstream_elt)
{
unsigned excess_bits = sizeof(unsigned) * CHAR_BIT - how_many_bits - cursor;
assert(cursor < sizeof(unsigned) * CHAR_BIT);
assert(how_many_bits > 0 && how_many_bits <= sizeof(unsigned) * CHAR_BIT);
assert(cursor + how_many_bits <= sizeof(unsigned) * CHAR_BIT);
return (bitstream_elt << excess_bits) >> (excess_bits + cursor);
}
static unsigned
show_bits(unsigned cursor, unsigned how_many_bits, const unsigned *bitstream)
{
unsigned cur_int = cursor / (sizeof(unsigned) * CHAR_BIT);
unsigned cur_bit = cursor % (sizeof(unsigned) * CHAR_BIT);
assert(bitstream);
if (cur_bit + how_many_bits > sizeof(unsigned) * CHAR_BIT)
{
return grab_bits(cur_bit, sizeof(unsigned) * CHAR_BIT - cur_bit,
bitstream[cur_int]) |
grab_bits(0, cur_bit + how_many_bits - sizeof(unsigned) * CHAR_BIT,
bitstream[cur_int + 1]) << (sizeof(unsigned) * CHAR_BIT - cur_bit);
}
else
return grab_bits(cur_bit, how_many_bits, bitstream[cur_int]);
}
bool vl_bitstream_parser_init(struct vl_bitstream_parser *parser,
unsigned num_bitstreams,
const void **bitstreams,
const unsigned *sizes)
{
assert(parser);
assert(num_bitstreams);
assert(bitstreams);
assert(sizes);
parser->num_bitstreams = num_bitstreams;
parser->bitstreams = (const unsigned**)bitstreams;
parser->sizes = sizes;
parser->cur_bitstream = 0;
parser->cursor = 0;
return true;
}
void vl_bitstream_parser_cleanup(struct vl_bitstream_parser *parser)
{
assert(parser);
}
unsigned
vl_bitstream_parser_get_bits(struct vl_bitstream_parser *parser,
unsigned how_many_bits)
{
unsigned bits;
assert(parser);
bits = vl_bitstream_parser_show_bits(parser, how_many_bits);
vl_bitstream_parser_forward(parser, how_many_bits);
return bits;
}
unsigned
vl_bitstream_parser_show_bits(struct vl_bitstream_parser *parser,
unsigned how_many_bits)
{
unsigned bits = 0;
unsigned shift = 0;
unsigned cursor;
unsigned cur_bitstream;
assert(parser);
cursor = parser->cursor;
cur_bitstream = parser->cur_bitstream;
while (1)
{
unsigned bits_left = parser->sizes[cur_bitstream] * CHAR_BIT - cursor;
unsigned bits_to_show = how_many_bits > bits_left ? bits_left : how_many_bits;
bits |= show_bits(cursor, bits_to_show,
parser->bitstreams[cur_bitstream]) << shift;
if (how_many_bits > bits_to_show)
{
how_many_bits -= bits_to_show;
cursor = 0;
++cur_bitstream;
shift += bits_to_show;
}
else
break;
}
return bits;
}
void vl_bitstream_parser_forward(struct vl_bitstream_parser *parser,
unsigned how_many_bits)
{
assert(parser);
assert(how_many_bits);
parser->cursor += how_many_bits;
while (parser->cursor > parser->sizes[parser->cur_bitstream] * CHAR_BIT)
{
parser->cursor -= parser->sizes[parser->cur_bitstream++] * CHAR_BIT;
assert(parser->cur_bitstream < parser->num_bitstreams);
}
}
void vl_bitstream_parser_rewind(struct vl_bitstream_parser *parser,
unsigned how_many_bits)
{
signed c;
assert(parser);
assert(how_many_bits);
c = parser->cursor - how_many_bits;
while (c < 0)
{
c += parser->sizes[parser->cur_bitstream--] * CHAR_BIT;
assert(parser->cur_bitstream < parser->num_bitstreams);
}
parser->cursor = (unsigned)c;
}
@@ -0,0 +1,36 @@
#ifndef vl_bitstream_parser_h
#define vl_bitstream_parser_h
#include <stdbool.h>
struct vl_bitstream_parser
{
unsigned num_bitstreams;
const unsigned **bitstreams;
const unsigned *sizes;
unsigned cur_bitstream;
unsigned cursor;
};
bool vl_bitstream_parser_init(struct vl_bitstream_parser *parser,
unsigned num_bitstreams,
const void **bitstreams,
const unsigned *sizes);
void vl_bitstream_parser_cleanup(struct vl_bitstream_parser *parser);
unsigned
vl_bitstream_parser_get_bits(struct vl_bitstream_parser *parser,
unsigned how_many_bits);
unsigned
vl_bitstream_parser_show_bits(struct vl_bitstream_parser *parser,
unsigned how_many_bits);
void vl_bitstream_parser_forward(struct vl_bitstream_parser *parser,
unsigned how_many_bits);
void vl_bitstream_parser_rewind(struct vl_bitstream_parser *parser,
unsigned how_many_bits);
#endif /* vl_bitstream_parser_h */
+590
View File
@@ -0,0 +1,590 @@
#include "vl_compositor.h"
#include <assert.h>
#include <pipe/p_context.h>
#include <pipe/p_inlines.h>
#include <tgsi/tgsi_parse.h>
#include <tgsi/tgsi_build.h>
#include <util/u_memory.h>
#include "vl_shader_build.h"
struct vertex2f
{
float x, y;
};
struct vertex4f
{
float x, y, z, w;
};
struct vertex_shader_consts
{
struct vertex4f dst_scale;
struct vertex4f dst_trans;
struct vertex4f src_scale;
struct vertex4f src_trans;
};
struct fragment_shader_consts
{
struct vertex4f bias;
float matrix[16];
};
/*
* Represents 2 triangles in a strip in normalized coords.
* Used to render the surface onto the frame buffer.
*/
static const struct vertex2f 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 vertex2f *surface_texcoords = surface_verts;
/*
* Identity color conversion constants, for debugging
*/
static const struct fragment_shader_consts 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 fragment_shader_consts 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 fragment_shader_consts 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 fragment_shader_consts 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 fragment_shader_consts 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 void
create_vert_shader(struct vl_compositor *c)
{
const unsigned max_tokens = 50;
struct pipe_shader_state vs;
struct tgsi_token *tokens;
struct tgsi_header *header;
struct tgsi_full_declaration decl;
struct tgsi_full_instruction inst;
unsigned ti;
assert(c);
tokens = (struct tgsi_token*)MALLOC(max_tokens * sizeof(struct tgsi_token));
*(struct tgsi_version*)&tokens[0] = tgsi_build_version();
header = (struct tgsi_header*)&tokens[1];
*header = tgsi_build_header();
*(struct tgsi_processor*)&tokens[2] = tgsi_build_processor(TGSI_PROCESSOR_VERTEX, header);
ti = 3;
/*
* decl i0 ; Vertex pos
* decl i1 ; Vertex texcoords
*/
for (unsigned 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 (unsigned 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);
/*
* mad o0, i0, c0, c1 ; Scale and translate unit output rect to destination size and pos
* mad o1, i1, c2, c3 ; Scale and translate unit texcoord rect to source size and pos
*/
for (unsigned 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);
assert(ti <= max_tokens);
vs.tokens = tokens;
c->vertex_shader = c->pipe->create_vs_state(c->pipe, &vs);
FREE(tokens);
}
static void
create_frag_shader(struct vl_compositor *c)
{
const unsigned max_tokens = 50;
struct pipe_shader_state fs;
struct tgsi_token *tokens;
struct tgsi_header *header;
struct tgsi_full_declaration decl;
struct tgsi_full_instruction inst;
unsigned ti;
assert(c);
tokens = (struct tgsi_token*)MALLOC(max_tokens * sizeof(struct tgsi_token));
*(struct tgsi_version*)&tokens[0] = tgsi_build_version();
header = (struct tgsi_header*)&tokens[1];
*header = tgsi_build_header();
*(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 (unsigned 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);
assert(ti <= max_tokens);
fs.tokens = tokens;
c->fragment_shader = c->pipe->create_fs_state(c->pipe, &fs);
FREE(tokens);
}
static bool
init_pipe_state(struct vl_compositor *c)
{
struct pipe_sampler_state sampler;
assert(c);
c->fb_state.nr_cbufs = 1;
c->fb_state.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 = ;*/
c->sampler = c->pipe->create_sampler_state(c->pipe, &sampler);
return true;
}
static void cleanup_pipe_state(struct vl_compositor *c)
{
assert(c);
c->pipe->delete_sampler_state(c->pipe, c->sampler);
}
static bool
init_shaders(struct vl_compositor *c)
{
assert(c);
create_vert_shader(c);
create_frag_shader(c);
return true;
}
static void cleanup_shaders(struct vl_compositor *c)
{
assert(c);
c->pipe->delete_vs_state(c->pipe, c->vertex_shader);
c->pipe->delete_fs_state(c->pipe, c->fragment_shader);
}
static bool
init_buffers(struct vl_compositor *c)
{
assert(c);
/*
* 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
*/
c->vertex_bufs[0].stride = sizeof(struct vertex2f);
c->vertex_bufs[0].max_index = 3;
c->vertex_bufs[0].buffer_offset = 0;
c->vertex_bufs[0].buffer = pipe_buffer_create
(
c->pipe->screen,
1,
PIPE_BUFFER_USAGE_VERTEX,
sizeof(struct vertex2f) * 4
);
memcpy
(
pipe_buffer_map(c->pipe->screen, c->vertex_bufs[0].buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
surface_verts,
sizeof(struct vertex2f) * 4
);
pipe_buffer_unmap(c->pipe->screen, c->vertex_bufs[0].buffer);
c->vertex_elems[0].src_offset = 0;
c->vertex_elems[0].vertex_buffer_index = 0;
c->vertex_elems[0].nr_components = 2;
c->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
*/
c->vertex_bufs[1].stride = sizeof(struct vertex2f);
c->vertex_bufs[1].max_index = 3;
c->vertex_bufs[1].buffer_offset = 0;
c->vertex_bufs[1].buffer = pipe_buffer_create
(
c->pipe->screen,
1,
PIPE_BUFFER_USAGE_VERTEX,
sizeof(struct vertex2f) * 4
);
memcpy
(
pipe_buffer_map(c->pipe->screen, c->vertex_bufs[1].buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
surface_texcoords,
sizeof(struct vertex2f) * 4
);
pipe_buffer_unmap(c->pipe->screen, c->vertex_bufs[1].buffer);
c->vertex_elems[1].src_offset = 0;
c->vertex_elems[1].vertex_buffer_index = 1;
c->vertex_elems[1].nr_components = 2;
c->vertex_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
/*
* Create our vertex shader's constant buffer
* Const buffer contains scaling and translation vectors
*/
c->vs_const_buf.buffer = pipe_buffer_create
(
c->pipe->screen,
1,
PIPE_BUFFER_USAGE_CONSTANT | PIPE_BUFFER_USAGE_DISCARD,
sizeof(struct vertex_shader_consts)
);
/*
* Create our fragment shader's constant buffer
* Const buffer contains the color conversion matrix and bias vectors
*/
c->fs_const_buf.buffer = pipe_buffer_create
(
c->pipe->screen,
1,
PIPE_BUFFER_USAGE_CONSTANT,
sizeof(struct fragment_shader_consts)
);
/*
* TODO: Refactor this into a seperate function,
* allow changing the CSC matrix at runtime to switch between regular & full versions
*/
memcpy
(
pipe_buffer_map(c->pipe->screen, c->fs_const_buf.buffer, PIPE_BUFFER_USAGE_CPU_WRITE),
&bt_601_full,
sizeof(struct fragment_shader_consts)
);
pipe_buffer_unmap(c->pipe->screen, c->fs_const_buf.buffer);
return true;
}
static void
cleanup_buffers(struct vl_compositor *c)
{
assert(c);
for (unsigned i = 0; i < 2; ++i)
pipe_buffer_reference(&c->vertex_bufs[i].buffer, NULL);
pipe_buffer_reference(&c->vs_const_buf.buffer, NULL);
pipe_buffer_reference(&c->fs_const_buf.buffer, NULL);
}
bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe)
{
assert(compositor);
memset(compositor, 0, sizeof(struct vl_compositor));
compositor->pipe = pipe;
if (!init_pipe_state(compositor))
return false;
if (!init_shaders(compositor))
{
cleanup_pipe_state(compositor);
return false;
}
if (!init_buffers(compositor))
{
cleanup_shaders(compositor);
cleanup_pipe_state(compositor);
return false;
}
return true;
}
void vl_compositor_cleanup(struct vl_compositor *compositor)
{
assert(compositor);
cleanup_buffers(compositor);
cleanup_shaders(compositor);
cleanup_pipe_state(compositor);
}
void vl_compositor_render(struct vl_compositor *compositor,
/*struct pipe_texture *backround,
struct pipe_video_rect *backround_area,*/
struct pipe_texture *src_surface,
enum pipe_mpeg12_picture_type picture_type,
/*unsigned num_past_surfaces,
struct pipe_texture *past_surfaces,
unsigned num_future_surfaces,
struct pipe_texture *future_surfaces,*/
struct pipe_video_rect *src_area,
struct pipe_texture *dst_surface,
struct pipe_video_rect *dst_area,
/*unsigned num_layers,
struct pipe_texture *layers,
struct pipe_video_rect *layer_src_areas,
struct pipe_video_rect *layer_dst_areas*/
struct pipe_fence_handle **fence)
{
struct vertex_shader_consts *vs_consts;
assert(compositor);
assert(src_surface);
assert(src_area);
assert(dst_surface);
assert(dst_area);
assert(picture_type == PIPE_MPEG12_PICTURE_TYPE_FRAME);
compositor->fb_state.width = dst_surface->width[0];
compositor->fb_state.height = dst_surface->height[0];
compositor->fb_state.cbufs[0] = compositor->pipe->screen->get_tex_surface
(
compositor->pipe->screen,
dst_surface,
0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE
);
compositor->viewport.scale[0] = compositor->fb_state.width;
compositor->viewport.scale[1] = compositor->fb_state.height;
compositor->viewport.scale[2] = 1;
compositor->viewport.scale[3] = 1;
compositor->viewport.translate[0] = 0;
compositor->viewport.translate[1] = 0;
compositor->viewport.translate[2] = 0;
compositor->viewport.translate[3] = 0;
compositor->pipe->set_framebuffer_state(compositor->pipe, &compositor->fb_state);
compositor->pipe->set_viewport_state(compositor->pipe, &compositor->viewport);
compositor->pipe->bind_sampler_states(compositor->pipe, 1, &compositor->sampler);
compositor->pipe->set_sampler_textures(compositor->pipe, 1, &src_surface);
compositor->pipe->bind_vs_state(compositor->pipe, compositor->vertex_shader);
compositor->pipe->bind_fs_state(compositor->pipe, compositor->fragment_shader);
compositor->pipe->set_vertex_buffers(compositor->pipe, 2, compositor->vertex_bufs);
compositor->pipe->set_vertex_elements(compositor->pipe, 2, compositor->vertex_elems);
compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_VERTEX, 0, &compositor->vs_const_buf);
compositor->pipe->set_constant_buffer(compositor->pipe, PIPE_SHADER_FRAGMENT, 0, &compositor->fs_const_buf);
vs_consts = pipe_buffer_map
(
compositor->pipe->screen,
compositor->vs_const_buf.buffer,
PIPE_BUFFER_USAGE_CPU_WRITE | PIPE_BUFFER_USAGE_DISCARD
);
vs_consts->dst_scale.x = dst_area->w / (float)compositor->fb_state.cbufs[0]->width;
vs_consts->dst_scale.y = dst_area->h / (float)compositor->fb_state.cbufs[0]->height;
vs_consts->dst_scale.z = 1;
vs_consts->dst_scale.w = 1;
vs_consts->dst_trans.x = dst_area->x / (float)compositor->fb_state.cbufs[0]->width;
vs_consts->dst_trans.y = dst_area->y / (float)compositor->fb_state.cbufs[0]->height;
vs_consts->dst_trans.z = 0;
vs_consts->dst_trans.w = 0;
vs_consts->src_scale.x = src_area->w / (float)src_surface->width[0];
vs_consts->src_scale.y = src_area->h / (float)src_surface->height[0];
vs_consts->src_scale.z = 1;
vs_consts->src_scale.w = 1;
vs_consts->src_trans.x = src_area->x / (float)src_surface->width[0];
vs_consts->src_trans.y = src_area->y / (float)src_surface->height[0];
vs_consts->src_trans.z = 0;
vs_consts->src_trans.w = 0;
pipe_buffer_unmap(compositor->pipe->screen, compositor->vs_const_buf.buffer);
compositor->pipe->draw_arrays(compositor->pipe, PIPE_PRIM_TRIANGLE_STRIP, 0, 4);
compositor->pipe->flush(compositor->pipe, PIPE_FLUSH_RENDER_CACHE, fence);
pipe_surface_reference(&compositor->fb_state.cbufs[0], NULL);
}
+47
View File
@@ -0,0 +1,47 @@
#ifndef vl_compositor_h
#define vl_compositor_h
#include <stdbool.h>
#include <pipe/p_state.h>
#include <pipe/p_video_state.h>
struct pipe_context;
struct pipe_texture;
struct vl_compositor
{
struct pipe_context *pipe;
struct pipe_framebuffer_state fb_state;
void *sampler;
void *vertex_shader;
void *fragment_shader;
struct pipe_viewport_state viewport;
struct pipe_vertex_buffer vertex_bufs[2];
struct pipe_vertex_element vertex_elems[2];
struct pipe_constant_buffer vs_const_buf, fs_const_buf;
};
bool vl_compositor_init(struct vl_compositor *compositor, struct pipe_context *pipe);
void vl_compositor_cleanup(struct vl_compositor *compositor);
void vl_compositor_render(struct vl_compositor *compositor,
/*struct pipe_texture *backround,
struct pipe_video_rect *backround_area,*/
struct pipe_texture *src_surface,
enum pipe_mpeg12_picture_type picture_type,
/*unsigned num_past_surfaces,
struct pipe_texture *past_surfaces,
unsigned num_future_surfaces,
struct pipe_texture *future_surfaces,*/
struct pipe_video_rect *src_area,
struct pipe_texture *dst_surface,
struct pipe_video_rect *dst_area,
/*unsigned num_layers,
struct pipe_texture *layers,
struct pipe_video_rect *layer_src_areas,
struct pipe_video_rect *layer_dst_areas,*/
struct pipe_fence_handle **fence);
#endif /* vl_compositor_h */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,93 @@
#ifndef vl_mpeg12_mc_renderer_h
#define vl_mpeg12_mc_renderer_h
#include <stdbool.h>
#include <pipe/p_state.h>
#include <pipe/p_video_state.h>
struct pipe_context;
struct pipe_video_surface;
struct pipe_macroblock;
/* A slice is video-width (rounded up to a multiple of macroblock width) x macroblock height */
enum VL_MPEG12_MC_RENDERER_BUFFER_MODE
{
VL_MPEG12_MC_RENDERER_BUFFER_SLICE, /* Saves memory at the cost of smaller batches */
VL_MPEG12_MC_RENDERER_BUFFER_PICTURE /* Larger batches, more memory */
};
enum VL_MPEG12_MC_RENDERER_EMPTY_BLOCK
{
VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ALL, /* Waste of memory bandwidth */
VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE, /* Can only do point-filtering when interpolating subsampled chroma channels */
VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_NONE /* Needs conditional texel fetch! */
};
struct vl_mpeg12_mc_renderer
{
struct pipe_context *pipe;
unsigned picture_width;
unsigned picture_height;
enum pipe_video_chroma_format chroma_format;
enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode;
enum VL_MPEG12_MC_RENDERER_EMPTY_BLOCK eb_handling;
bool pot_buffers;
unsigned macroblocks_per_batch;
struct pipe_viewport_state viewport;
struct pipe_constant_buffer vs_const_buf;
struct pipe_constant_buffer fs_const_buf;
struct pipe_framebuffer_state fb_state;
struct pipe_vertex_element vertex_elems[8];
union
{
void *all[5];
struct { void *y, *cb, *cr, *ref[2]; } individual;
} samplers;
void *i_vs, *p_vs[2], *b_vs[2];
void *i_fs, *p_fs[2], *b_fs[2];
union
{
struct pipe_texture *all[5];
struct { struct pipe_texture *y, *cb, *cr, *ref[2]; } individual;
} textures;
union
{
struct pipe_vertex_buffer all[3];
struct { struct pipe_vertex_buffer ycbcr, ref[2]; } individual;
} vertex_bufs;
struct pipe_texture *surface, *past, *future;
struct pipe_fence_handle **fence;
unsigned num_macroblocks;
struct pipe_mpeg12_macroblock *macroblock_buf;
struct pipe_transfer *tex_transfer[3];
short *texels[3];
struct { float x, y; } surface_tex_inv_size;
struct { float x, y; } zero_block[3];
};
bool vl_mpeg12_mc_renderer_init(struct vl_mpeg12_mc_renderer *renderer,
struct pipe_context *pipe,
unsigned picture_width,
unsigned picture_height,
enum pipe_video_chroma_format chroma_format,
enum VL_MPEG12_MC_RENDERER_BUFFER_MODE bufmode,
enum VL_MPEG12_MC_RENDERER_EMPTY_BLOCK eb_handling,
bool pot_buffers);
void vl_mpeg12_mc_renderer_cleanup(struct vl_mpeg12_mc_renderer *renderer);
void vl_mpeg12_mc_renderer_render_macroblocks(struct vl_mpeg12_mc_renderer *renderer,
struct pipe_texture *surface,
struct pipe_texture *past,
struct pipe_texture *future,
unsigned num_macroblocks,
struct pipe_mpeg12_macroblock *mpeg12_macroblocks,
struct pipe_fence_handle **fence);
#endif /* vl_mpeg12_mc_renderer_h */
+215
View File
@@ -0,0 +1,215 @@
#include "vl_shader_build.h"
#include <assert.h>
#include <tgsi/tgsi_parse.h>
#include <tgsi/tgsi_build.h>
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;
}
@@ -0,0 +1,61 @@
#ifndef vl_shader_build_h
#define vl_shader_build_h
#include <pipe/p_shader_tokens.h>
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
+2 -1
View File
@@ -31,6 +31,7 @@ C_SOURCES = \
sp_tex_sample.c \
sp_tex_tile_cache.c \
sp_tile_cache.c \
sp_surface.c
sp_surface.c \
sp_video_context.c
include ../../Makefile.template
+2 -1
View File
@@ -33,6 +33,7 @@ softpipe = env.ConvenienceLibrary(
'sp_tex_tile_cache.c',
'sp_texture.c',
'sp_tile_cache.c',
'sp_video_context.c',
])
Export('softpipe')
Export('softpipe')
+56
View File
@@ -381,6 +381,59 @@ softpipe_transfer_unmap(struct pipe_screen *screen,
}
}
static struct pipe_video_surface*
softpipe_video_surface_create(struct pipe_screen *screen,
enum pipe_video_chroma_format chroma_format,
unsigned width, unsigned height)
{
struct softpipe_video_surface *sp_vsfc;
struct pipe_texture template;
assert(screen);
assert(width && height);
sp_vsfc = CALLOC_STRUCT(softpipe_video_surface);
if (!sp_vsfc)
return NULL;
pipe_reference_init(&sp_vsfc->base.reference, 1);
sp_vsfc->base.screen = screen;
sp_vsfc->base.chroma_format = chroma_format;
/*sp_vsfc->base.surface_format = PIPE_VIDEO_SURFACE_FORMAT_VUYA;*/
sp_vsfc->base.width = width;
sp_vsfc->base.height = height;
memset(&template, 0, sizeof(struct pipe_texture));
template.target = PIPE_TEXTURE_2D;
template.format = PIPE_FORMAT_X8R8G8B8_UNORM;
template.last_level = 0;
/* vl_mpeg12_mc_renderer expects this when it's initialized with pot_buffers=true */
template.width[0] = util_next_power_of_two(width);
template.height[0] = util_next_power_of_two(height);
template.depth[0] = 1;
pf_get_block(template.format, &template.block);
template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET;
sp_vsfc->tex = screen->texture_create(screen, &template);
if (!sp_vsfc->tex)
{
FREE(sp_vsfc);
return NULL;
}
return &sp_vsfc->base;
}
static void
softpipe_video_surface_destroy(struct pipe_video_surface *vsfc)
{
struct softpipe_video_surface *sp_vsfc = softpipe_video_surface(vsfc);
pipe_texture_reference(&sp_vsfc->tex, NULL);
FREE(sp_vsfc);
}
void
softpipe_init_screen_texture_funcs(struct pipe_screen *screen)
@@ -396,6 +449,9 @@ softpipe_init_screen_texture_funcs(struct pipe_screen *screen)
screen->tex_transfer_destroy = softpipe_tex_transfer_destroy;
screen->transfer_map = softpipe_transfer_map;
screen->transfer_unmap = softpipe_transfer_unmap;
screen->video_surface_create = softpipe_video_surface_create;
screen->video_surface_destroy = softpipe_video_surface_destroy;
}
+16
View File
@@ -30,6 +30,7 @@
#include "pipe/p_state.h"
#include "pipe/p_video_state.h"
struct pipe_context;
@@ -62,6 +63,15 @@ struct softpipe_transfer
unsigned long offset;
};
struct softpipe_video_surface
{
struct pipe_video_surface base;
/* The data is held here:
*/
struct pipe_texture *tex;
};
/** cast wrappers */
static INLINE struct softpipe_texture *
@@ -76,6 +86,12 @@ softpipe_transfer(struct pipe_transfer *pt)
return (struct softpipe_transfer *) pt;
}
static INLINE struct softpipe_video_surface *
softpipe_video_surface(struct pipe_video_surface *pvs)
{
return (struct softpipe_video_surface *) pvs;
}
extern void
softpipe_init_screen_texture_funcs(struct pipe_screen *screen);
@@ -0,0 +1,273 @@
#include "sp_video_context.h"
#include <pipe/p_inlines.h>
#include <util/u_memory.h>
#include "softpipe/sp_winsys.h"
#include "softpipe/sp_texture.h"
static void
sp_mpeg12_destroy(struct pipe_video_context *vpipe)
{
struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
assert(vpipe);
/* Asserted in softpipe_delete_fs_state() for some reason */
ctx->pipe->bind_vs_state(ctx->pipe, NULL);
ctx->pipe->bind_fs_state(ctx->pipe, NULL);
ctx->pipe->delete_blend_state(ctx->pipe, ctx->blend);
ctx->pipe->delete_rasterizer_state(ctx->pipe, ctx->rast);
ctx->pipe->delete_depth_stencil_alpha_state(ctx->pipe, ctx->dsa);
pipe_video_surface_reference(&ctx->decode_target, NULL);
vl_compositor_cleanup(&ctx->compositor);
vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
ctx->pipe->destroy(ctx->pipe);
FREE(ctx);
}
static void
sp_mpeg12_decode_macroblocks(struct pipe_video_context *vpipe,
struct pipe_video_surface *past,
struct pipe_video_surface *future,
unsigned num_macroblocks,
struct pipe_macroblock *macroblocks,
struct pipe_fence_handle **fence)
{
struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
struct pipe_mpeg12_macroblock *mpeg12_macroblocks = (struct pipe_mpeg12_macroblock*)macroblocks;
assert(vpipe);
assert(num_macroblocks);
assert(macroblocks);
assert(macroblocks->codec == PIPE_VIDEO_CODEC_MPEG12);
assert(ctx->decode_target);
vl_mpeg12_mc_renderer_render_macroblocks(&ctx->mc_renderer,
softpipe_video_surface(ctx->decode_target)->tex,
past ? softpipe_video_surface(past)->tex : NULL,
future ? softpipe_video_surface(future)->tex : NULL,
num_macroblocks, mpeg12_macroblocks, fence);
}
static void
sp_mpeg12_clear_surface(struct pipe_video_context *vpipe,
unsigned x, unsigned y,
unsigned width, unsigned height,
unsigned value,
struct pipe_surface *surface)
{
struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
assert(vpipe);
assert(surface);
ctx->pipe->surface_fill(ctx->pipe, surface, x, y, width, height, value);
}
static void
sp_mpeg12_render_picture(struct pipe_video_context *vpipe,
/*struct pipe_surface *backround,
struct pipe_video_rect *backround_area,*/
struct pipe_video_surface *src_surface,
enum pipe_mpeg12_picture_type picture_type,
/*unsigned num_past_surfaces,
struct pipe_video_surface *past_surfaces,
unsigned num_future_surfaces,
struct pipe_video_surface *future_surfaces,*/
struct pipe_video_rect *src_area,
struct pipe_surface *dst_surface,
struct pipe_video_rect *dst_area,
/*unsigned num_layers,
struct pipe_surface *layers,
struct pipe_video_rect *layer_src_areas,
struct pipe_video_rect *layer_dst_areas*/
struct pipe_fence_handle **fence)
{
struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
assert(vpipe);
assert(src_surface);
assert(src_area);
assert(dst_surface);
assert(dst_area);
vl_compositor_render(&ctx->compositor, softpipe_video_surface(src_surface)->tex,
picture_type, src_area, dst_surface->texture, dst_area, fence);
}
static void
sp_mpeg12_set_decode_target(struct pipe_video_context *vpipe,
struct pipe_video_surface *dt)
{
struct sp_mpeg12_context *ctx = (struct sp_mpeg12_context*)vpipe;
assert(vpipe);
assert(dt);
pipe_video_surface_reference(&ctx->decode_target, dt);
}
static bool
init_pipe_state(struct sp_mpeg12_context *ctx)
{
struct pipe_rasterizer_state rast;
struct pipe_blend_state blend;
struct pipe_depth_stencil_alpha_state dsa;
assert(ctx);
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] = ;*/
ctx->rast = ctx->pipe->create_rasterizer_state(ctx->pipe, &rast);
ctx->pipe->bind_rasterizer_state(ctx->pipe, ctx->rast);
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;
ctx->blend = ctx->pipe->create_blend_state(ctx->pipe, &blend);
ctx->pipe->bind_blend_state(ctx->pipe, ctx->blend);
dsa.depth.enabled = 0;
dsa.depth.writemask = 0;
dsa.depth.func = PIPE_FUNC_ALWAYS;
dsa.depth.occlusion_count = 0;
for (unsigned 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;
ctx->dsa = ctx->pipe->create_depth_stencil_alpha_state(ctx->pipe, &dsa);
ctx->pipe->bind_depth_stencil_alpha_state(ctx->pipe, ctx->dsa);
return true;
}
static struct pipe_video_context *
sp_mpeg12_create(struct pipe_screen *screen, enum pipe_video_profile profile,
enum pipe_video_chroma_format chroma_format,
unsigned width, unsigned height)
{
struct sp_mpeg12_context *ctx;
assert(u_reduce_video_profile(profile) == PIPE_VIDEO_CODEC_MPEG12);
ctx = CALLOC_STRUCT(sp_mpeg12_context);
if (!ctx)
return NULL;
ctx->base.profile = profile;
ctx->base.chroma_format = chroma_format;
ctx->base.width = width;
ctx->base.height = height;
ctx->base.screen = screen;
ctx->base.destroy = sp_mpeg12_destroy;
ctx->base.decode_macroblocks = sp_mpeg12_decode_macroblocks;
ctx->base.clear_surface = sp_mpeg12_clear_surface;
ctx->base.render_picture = sp_mpeg12_render_picture;
ctx->base.set_decode_target = sp_mpeg12_set_decode_target;
ctx->pipe = softpipe_create(screen);
if (!ctx->pipe)
{
FREE(ctx);
return NULL;
}
/* TODO: Use slice buffering for softpipe when implemented, no advantage to buffering an entire picture */
if (!vl_mpeg12_mc_renderer_init(&ctx->mc_renderer, ctx->pipe,
width, height, chroma_format,
VL_MPEG12_MC_RENDERER_BUFFER_PICTURE,
/* TODO: Use XFER_NONE when implemented */
VL_MPEG12_MC_RENDERER_EMPTY_BLOCK_XFER_ONE,
true))
{
ctx->pipe->destroy(ctx->pipe);
FREE(ctx);
return NULL;
}
if (!vl_compositor_init(&ctx->compositor, ctx->pipe))
{
vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
ctx->pipe->destroy(ctx->pipe);
FREE(ctx);
return NULL;
}
if (!init_pipe_state(ctx))
{
vl_compositor_cleanup(&ctx->compositor);
vl_mpeg12_mc_renderer_cleanup(&ctx->mc_renderer);
ctx->pipe->destroy(ctx->pipe);
FREE(ctx);
return NULL;
}
return &ctx->base;
}
struct pipe_video_context *
sp_video_create(struct pipe_screen *screen, enum pipe_video_profile profile,
enum pipe_video_chroma_format chroma_format,
unsigned width, unsigned height)
{
assert(screen);
assert(width && height);
switch (u_reduce_video_profile(profile))
{
case PIPE_VIDEO_CODEC_MPEG12:
return sp_mpeg12_create(screen, profile,
chroma_format,
width, height);
default:
return NULL;
}
}
@@ -0,0 +1,30 @@
#ifndef SP_VIDEO_CONTEXT_H
#define SP_VIDEO_CONTEXT_H
#include <pipe/p_video_context.h>
#include <vl/vl_mpeg12_mc_renderer.h>
#include <vl/vl_compositor.h>
struct pipe_screen;
struct pipe_context;
struct pipe_video_surface;
struct sp_mpeg12_context
{
struct pipe_video_context base;
struct pipe_context *pipe;
struct pipe_video_surface *decode_target;
struct vl_mpeg12_mc_renderer mc_renderer;
struct vl_compositor compositor;
void *rast;
void *dsa;
void *blend;
};
struct pipe_video_context *
sp_video_create(struct pipe_screen *screen, enum pipe_video_profile profile,
enum pipe_video_chroma_format chroma_format,
unsigned width, unsigned height);
#endif /* SP_VIDEO_CONTEXT_H */
+24
View File
@@ -315,6 +315,30 @@ enum pipe_transfer_usage {
#define PIPE_REFERENCED_FOR_READ (1 << 0)
#define PIPE_REFERENCED_FOR_WRITE (1 << 1)
enum pipe_video_codec
{
PIPE_VIDEO_CODEC_MPEG12, /**< MPEG1, MPEG2 */
PIPE_VIDEO_CODEC_MPEG4, /**< DIVX, XVID */
PIPE_VIDEO_CODEC_VC1, /**< WMV */
PIPE_VIDEO_CODEC_MPEG4_AVC /**< H.264 */
};
enum pipe_video_profile
{
PIPE_VIDEO_PROFILE_MPEG1,
PIPE_VIDEO_PROFILE_MPEG2_SIMPLE,
PIPE_VIDEO_PROFILE_MPEG2_MAIN,
PIPE_VIDEO_PROFILE_MPEG4_SIMPLE,
PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE,
PIPE_VIDEO_PROFILE_VC1_SIMPLE,
PIPE_VIDEO_PROFILE_VC1_MAIN,
PIPE_VIDEO_PROFILE_VC1_ADVANCED,
PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE,
PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN,
PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH
};
#ifdef __cplusplus
}
#endif
+18
View File
@@ -613,6 +613,24 @@ pf_has_alpha( enum pipe_format format )
}
}
enum pipe_video_chroma_format
{
PIPE_VIDEO_CHROMA_FORMAT_420,
PIPE_VIDEO_CHROMA_FORMAT_422,
PIPE_VIDEO_CHROMA_FORMAT_444
};
#if 0
enum pipe_video_surface_format
{
PIPE_VIDEO_SURFACE_FORMAT_NV12, /**< Planar; Y plane, UV plane */
PIPE_VIDEO_SURFACE_FORMAT_YV12, /**< Planar; Y plane, U plane, V plane */
PIPE_VIDEO_SURFACE_FORMAT_YUYV, /**< Interleaved; Y,U,Y,V,Y,U,Y,V */
PIPE_VIDEO_SURFACE_FORMAT_UYVY, /**< Interleaved; U,Y,V,Y,U,Y,V,Y */
PIPE_VIDEO_SURFACE_FORMAT_VUYA /**< Packed; A31-24|Y23-16|U15-8|V7-0 */
};
#endif
#ifdef __cplusplus
}
#endif
+15 -1
View File
@@ -53,7 +53,10 @@ extern "C" {
struct pipe_fence_handle;
struct pipe_winsys;
struct pipe_buffer;
struct pipe_texture;
struct pipe_surface;
struct pipe_video_surface;
struct pipe_transfer;
/**
@@ -252,6 +255,17 @@ struct pipe_screen {
void (*buffer_destroy)( struct pipe_buffer *buf );
/**
* Create a video surface suitable for use as a decoding target by the
* driver's pipe_video_context.
*/
struct pipe_video_surface*
(*video_surface_create)( struct pipe_screen *screen,
enum pipe_video_chroma_format chroma_format,
unsigned width, unsigned height );
void (*video_surface_destroy)( struct pipe_video_surface *vsfc );
/**
* Do any special operations to ensure frontbuffer contents are
@@ -0,0 +1,92 @@
#ifndef PIPE_VIDEO_CONTEXT_H
#define PIPE_VIDEO_CONTEXT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <pipe/p_video_state.h>
struct pipe_screen;
struct pipe_buffer;
struct pipe_surface;
struct pipe_video_surface;
struct pipe_macroblock;
struct pipe_picture_desc;
struct pipe_fence_handle;
/**
* Gallium video rendering context
*/
struct pipe_video_context
{
struct pipe_screen *screen;
enum pipe_video_profile profile;
enum pipe_video_chroma_format chroma_format;
unsigned width;
unsigned height;
void *priv; /**< context private data (for DRI for example) */
void (*destroy)(struct pipe_video_context *vpipe);
/**
* Picture decoding and displaying
*/
/*@{*/
void (*decode_bitstream)(struct pipe_video_context *vpipe,
unsigned num_bufs,
struct pipe_buffer **bitstream_buf);
void (*decode_macroblocks)(struct pipe_video_context *vpipe,
struct pipe_video_surface *past,
struct pipe_video_surface *future,
unsigned num_macroblocks,
struct pipe_macroblock *macroblocks,
struct pipe_fence_handle **fence);
void (*clear_surface)(struct pipe_video_context *vpipe,
unsigned x, unsigned y,
unsigned width, unsigned height,
unsigned value,
struct pipe_surface *surface);
void (*render_picture)(struct pipe_video_context *vpipe,
/*struct pipe_surface *backround,
struct pipe_video_rect *backround_area,*/
struct pipe_video_surface *src_surface,
enum pipe_mpeg12_picture_type picture_type,
/*unsigned num_past_surfaces,
struct pipe_video_surface *past_surfaces,
unsigned num_future_surfaces,
struct pipe_video_surface *future_surfaces,*/
struct pipe_video_rect *src_area,
struct pipe_surface *dst_surface,
struct pipe_video_rect *dst_area,
/*unsigned num_layers,
struct pipe_texture *layers,
struct pipe_video_rect *layer_src_areas,
struct pipe_video_rect *layer_dst_areas,*/
struct pipe_fence_handle **fence);
/*@}*/
/**
* Parameter-like states (or properties)
*/
/*@{*/
void (*set_picture_desc)(struct pipe_video_context *vpipe,
const struct pipe_picture_desc *desc);
void (*set_decode_target)(struct pipe_video_context *vpipe,
struct pipe_video_surface *dt);
/* TODO: Interface for CSC matrix, scaling modes, post-processing, etc. */
/*@}*/
};
#ifdef __cplusplus
}
#endif
#endif /* PIPE_VIDEO_CONTEXT_H */
+158
View File
@@ -0,0 +1,158 @@
#ifndef PIPE_VIDEO_STATE_H
#define PIPE_VIDEO_STATE_H
/* u_reduce_video_profile() needs these */
#include <assert.h>
#include <pipe/p_compiler.h>
#include <pipe/p_defines.h>
#include <pipe/p_format.h>
#include <pipe/p_refcnt.h>
#include <pipe/p_screen.h>
#ifdef __cplusplus
extern "C" {
#endif
struct pipe_video_surface
{
struct pipe_reference reference;
struct pipe_screen *screen;
enum pipe_video_chroma_format chroma_format;
/*enum pipe_video_surface_format surface_format;*/
unsigned width;
unsigned height;
};
static INLINE void
pipe_video_surface_reference(struct pipe_video_surface **ptr, struct pipe_video_surface *surf)
{
struct pipe_video_surface *old_surf = *ptr;
if (pipe_reference((struct pipe_reference **)ptr, &surf->reference))
old_surf->screen->video_surface_destroy(old_surf);
}
struct pipe_video_rect
{
unsigned x, y, w, h;
};
static INLINE enum pipe_video_codec
u_reduce_video_profile(enum pipe_video_profile profile)
{
switch (profile)
{
case PIPE_VIDEO_PROFILE_MPEG1:
case PIPE_VIDEO_PROFILE_MPEG2_SIMPLE:
case PIPE_VIDEO_PROFILE_MPEG2_MAIN:
return PIPE_VIDEO_CODEC_MPEG12;
case PIPE_VIDEO_PROFILE_MPEG4_SIMPLE:
case PIPE_VIDEO_PROFILE_MPEG4_ADVANCED_SIMPLE:
return PIPE_VIDEO_CODEC_MPEG4;
case PIPE_VIDEO_PROFILE_VC1_SIMPLE:
case PIPE_VIDEO_PROFILE_VC1_MAIN:
case PIPE_VIDEO_PROFILE_VC1_ADVANCED:
return PIPE_VIDEO_CODEC_VC1;
case PIPE_VIDEO_PROFILE_MPEG4_AVC_BASELINE:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_MAIN:
case PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH:
return PIPE_VIDEO_CODEC_MPEG4_AVC;
default:
assert(false);
}
return -1;
}
enum pipe_mpeg12_picture_type
{
PIPE_MPEG12_PICTURE_TYPE_FIELD_TOP,
PIPE_MPEG12_PICTURE_TYPE_FIELD_BOTTOM,
PIPE_MPEG12_PICTURE_TYPE_FRAME
};
enum pipe_mpeg12_macroblock_type
{
PIPE_MPEG12_MACROBLOCK_TYPE_INTRA,
PIPE_MPEG12_MACROBLOCK_TYPE_FWD,
PIPE_MPEG12_MACROBLOCK_TYPE_BKWD,
PIPE_MPEG12_MACROBLOCK_TYPE_BI,
PIPE_MPEG12_MACROBLOCK_NUM_TYPES
};
enum pipe_mpeg12_motion_type
{
PIPE_MPEG12_MOTION_TYPE_FIELD,
PIPE_MPEG12_MOTION_TYPE_FRAME,
PIPE_MPEG12_MOTION_TYPE_DUALPRIME,
PIPE_MPEG12_MOTION_TYPE_16x8
};
enum pipe_mpeg12_dct_type
{
PIPE_MPEG12_DCT_TYPE_FIELD,
PIPE_MPEG12_DCT_TYPE_FRAME
};
struct pipe_macroblock
{
enum pipe_video_codec codec;
};
struct pipe_mpeg12_macroblock
{
struct pipe_macroblock base;
unsigned mbx;
unsigned mby;
enum pipe_mpeg12_macroblock_type mb_type;
enum pipe_mpeg12_motion_type mo_type;
enum pipe_mpeg12_dct_type dct_type;
signed pmv[2][2][2];
unsigned cbp;
void *blocks;
};
#if 0
struct pipe_picture_desc
{
enum pipe_video_format format;
};
struct pipe_mpeg12_picture_desc
{
struct pipe_picture_desc base;
/* TODO: Use bitfields where possible? */
struct pipe_surface *forward_reference;
struct pipe_surface *backward_reference;
unsigned picture_coding_type;
unsigned fcode;
unsigned intra_dc_precision;
unsigned picture_structure;
unsigned top_field_first;
unsigned frame_pred_frame_dct;
unsigned concealment_motion_vectors;
unsigned q_scale_type;
unsigned intra_vlc_format;
unsigned alternate_scan;
unsigned full_pel_forward_vector;
unsigned full_pel_backward_vector;
struct pipe_buffer *intra_quantizer_matrix;
struct pipe_buffer *non_intra_quantizer_matrix;
struct pipe_buffer *chroma_intra_quantizer_matrix;
struct pipe_buffer *chroma_non_intra_quantizer_matrix;
};
#endif
#ifdef __cplusplus
}
#endif
#endif /* PIPE_VIDEO_STATE_H */