#include <tgsi/util/tgsi_build.h>
#include "vl_shader_build.h"
#include "vl_data.h"
+#include "vl_util.h"
static int vlInitIDCT(struct VL_CONTEXT *context)
{
pipe = context->pipe;
- context->states.mc.viewport.scale[0] = context->video_width;
- context->states.mc.viewport.scale[1] = context->video_height;
+ /* For MC we render to textures, which are rounded up to nearest POT */
+ context->states.mc.viewport.scale[0] = vlRoundUpPOT(context->video_width);
+ context->states.mc.viewport.scale[1] = vlRoundUpPOT(context->video_height);
context->states.mc.viewport.scale[2] = 1;
context->states.mc.viewport.scale[3] = 1;
context->states.mc.viewport.translate[0] = 0;
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 texcoord rect to source size
+ * decl c1 ; Translation vector to move texcoord rect into position
+ */
+ decl = vl_decl_constants(TGSI_SEMANTIC_GENERIC, 0, 0, 1);
+ ti += tgsi_build_full_declaration(&decl, &tokens[ti], header, max_tokens - ti);
/*
* decl o0 ; Vertex pos
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 pos in to pos out */
+ inst = vl_inst2(TGSI_OPCODE_MOV, TGSI_FILE_OUTPUT, 0, TGSI_FILE_INPUT, 0);
+ ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
+
+ /* mul t0, i1, c0 ; Scale unit texcoord rect to source size */
+ inst = vl_inst3(TGSI_OPCODE_MUL, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_INPUT, 1, TGSI_FILE_CONSTANT, 0);
+ ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
- /*
- * mov o0, i0 ; Move pos in to pos out
- * mov o1, i1 ; Move input texcoords to output
- */
- for (i = 0; i < 2; 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 o1, t0, c1 ; Translate texcoord rect into position */
+ inst = vl_inst3(TGSI_OPCODE_ADD, TGSI_FILE_OUTPUT, 1, TGSI_FILE_TEMPORARY, 0, TGSI_FILE_CONSTANT, 1);
+ ti += tgsi_build_full_instruction(&inst, &tokens[ti], header, max_tokens - ti);
/* end */
inst = vl_end();
context->states.csc.vertex_buf_elems[1].nr_components = 2;
context->states.csc.vertex_buf_elems[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
+ /*
+ Create our vertex shader's constant buffer
+ Const buffer contains scaling and translation vectors
+ */
+ context->states.csc.vs_const_buf.size = sizeof(struct VL_CSC_VS_CONSTS);
+ context->states.csc.vs_const_buf.buffer = pipe->winsys->buffer_create
+ (
+ pipe->winsys,
+ 1,
+ PIPE_BUFFER_USAGE_CONSTANT,
+ context->states.csc.vs_const_buf.size
+ );
+
/*
Create our fragment shader's constant buffer
Const buffer contains the color conversion matrix and bias vectors
context->pipe->delete_fs_state(context->pipe, context->states.csc.fragment_shader);
context->pipe->winsys->buffer_destroy(context->pipe->winsys, context->states.csc.vertex_bufs[0].buffer);
context->pipe->winsys->buffer_destroy(context->pipe->winsys, context->states.csc.vertex_bufs[1].buffer);
+ context->pipe->winsys->buffer_destroy(context->pipe->winsys, context->states.csc.vs_const_buf.buffer);
context->pipe->winsys->buffer_destroy(context->pipe->winsys, context->states.csc.fs_const_buf.buffer);
return 0;
pipe->bind_fs_state(pipe, context->states.csc.fragment_shader);
pipe->set_vertex_buffers(pipe, 2, context->states.csc.vertex_bufs);
pipe->set_vertex_elements(pipe, 2, context->states.csc.vertex_buf_elems);
+ pipe->set_constant_buffer(pipe, PIPE_SHADER_VERTEX, 0, &context->states.csc.vs_const_buf);
pipe->set_constant_buffer(pipe, PIPE_SHADER_FRAGMENT, 0, &context->states.csc.fs_const_buf);
return 0;
#include <pipe/p_inlines.h>
#include "vl_context.h"
#include "vl_defs.h"
+#include "vl_util.h"
static int vlGrabFrameCodedFullBlock(short *src, short *dst, unsigned int dst_pitch)
{
pipe_surface_unmap(tex_surface);
}
- /* XXX: Texture cache is not invalidated when texture contents change */
- context->pipe->flush(context->pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL);
-
return 0;
}
sfc = calloc(1, sizeof(struct VL_SURFACE));
sfc->context = context;
- sfc->width = context->video_width;
- sfc->height = context->video_height;
+ sfc->width = vlRoundUpPOT(context->video_width);
+ sfc->height = vlRoundUpPOT(context->video_height);
sfc->format = context->video_format;
memset(&template, 0, sizeof(struct pipe_texture));
template.depth[0] = 1;
template.compressed = 0;
pf_get_block(template.format, &template.block);
+ /* XXX: Needed? */
template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET;
sfc->texture = pipe->screen->texture_create(pipe->screen, &template);
{
unsigned int create_fb = 0;
struct pipe_context *pipe;
+ struct VL_CSC_VS_CONSTS *vs_consts;
assert(surface);
vlEndRender(surface->context);
+ vs_consts = pipe->winsys->buffer_map
+ (
+ pipe->winsys,
+ surface->context->states.csc.vs_const_buf.buffer,
+ PIPE_BUFFER_USAGE_CPU_WRITE
+ );
+
+ vs_consts->src_scale.x = srcw / (float)surface->width;
+ vs_consts->src_scale.y = srch / (float)surface->height;
+ vs_consts->src_scale.z = 1;
+ vs_consts->src_scale.w = 1;
+ vs_consts->src_trans.x = srcx / (float)surface->width;
+ vs_consts->src_trans.y = srcy / (float)surface->height;
+ vs_consts->src_trans.z = 0;
+ vs_consts->src_trans.w = 0;
+
+ pipe->winsys->buffer_unmap(pipe->winsys, surface->context->states.csc.vs_const_buf.buffer);
+
pipe->set_sampler_textures(pipe, 1, &surface->texture);
pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLE_STRIP, 0, 4);
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+ /* XXX: Need to take destx, desty into consideration */
pipe->winsys->flush_frontbuffer
(
pipe->winsys,