* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <assert.h>
-#include <pipe/p_screen.h>
-#include <pipe/p_context.h>
+#include "pipe/p_screen.h"
+#include "pipe/p_context.h"
-#include <util/u_draw.h>
-#include <util/u_sampler.h>
-#include <util/u_inlines.h>
-#include <util/u_memory.h>
+#include "util/u_draw.h"
+#include "util/u_sampler.h"
+#include "util/u_inlines.h"
+#include "util/u_memory.h"
-#include <tgsi/tgsi_ureg.h>
+#include "tgsi/tgsi_ureg.h"
-#include <vl/vl_defines.h>
-#include <vl/vl_types.h>
+#include "vl_defines.h"
+#include "vl_types.h"
#include "vl_zscan.h"
#include "vl_vertex_buffers.h"
enum VS_OUTPUT
{
- VS_O_VPOS,
- VS_O_VTEX
+ VS_O_VPOS = 0,
+ VS_O_VTEX = 0
+};
+
+const int vl_zscan_normal_16[] =
+{
+ /* Zig-Zag scan pattern */
+ 0, 1, 4, 8, 5, 2, 3, 6,
+ 9,12,13,10, 7,11,14,15
};
const int vl_zscan_linear[] =
38,46,54,62,39,47,55,63
};
+const int vl_zscan_h265_up_right_diagonal_16[] =
+{
+ /* Up-right diagonal scan order for 4x4 blocks - see H.265 section 6.5.3. */
+ 0, 4, 1, 8, 5, 2, 12, 9,
+ 6, 3, 13, 10, 7, 14, 11, 15,
+};
+
+const int vl_zscan_h265_up_right_diagonal[] =
+{
+ /* Up-right diagonal scan order for 8x8 blocks - see H.265 section 6.5.3. */
+ 0, 8, 1, 16, 9, 2, 24, 17,
+ 10, 3, 32, 25, 18, 11, 4, 40,
+ 33, 26, 19, 12, 5, 48, 41, 34,
+ 27, 20, 13, 6, 56, 49, 42, 35,
+ 28, 21, 14, 7, 57, 50, 43, 36,
+ 29, 22, 15, 58, 51, 44, 37, 30,
+ 23, 59, 52, 45, 38, 31, 60, 53,
+ 46, 39, 61, 54, 47, 62, 55, 63,
+};
+
+
static void *
create_vert_shader(struct vl_zscan *zscan)
{
struct ureg_program *shader;
-
struct ureg_src scale;
struct ureg_src vrect, vpos, block_num;
-
struct ureg_dst tmp;
struct ureg_dst o_vpos;
struct ureg_dst *o_vtex;
+ unsigned i;
- signed i;
-
- shader = ureg_create(TGSI_PROCESSOR_VERTEX);
+ shader = ureg_create(PIPE_SHADER_VERTEX);
if (!shader)
return NULL;
o_vtex = MALLOC(zscan->num_channels * sizeof(struct ureg_dst));
scale = ureg_imm2f(shader,
- (float)BLOCK_WIDTH / zscan->buffer_width,
- (float)BLOCK_HEIGHT / zscan->buffer_height);
+ (float)VL_BLOCK_WIDTH / zscan->buffer_width,
+ (float)VL_BLOCK_HEIGHT / zscan->buffer_height);
vrect = ureg_DECL_vs_input(shader, VS_I_RECT);
vpos = ureg_DECL_vs_input(shader, VS_I_VPOS);
for (i = 0; i < zscan->num_channels; ++i) {
ureg_ADD(shader, ureg_writemask(tmp, TGSI_WRITEMASK_X), ureg_scalar(ureg_src(tmp), TGSI_SWIZZLE_Y),
- ureg_imm1f(shader, 1.0f / (zscan->blocks_per_line * BLOCK_WIDTH) * (i - (signed)zscan->num_channels / 2)));
+ ureg_imm1f(shader, 1.0f / (zscan->blocks_per_line * VL_BLOCK_WIDTH)
+ * ((signed)i - (signed)zscan->num_channels / 2)));
ureg_MAD(shader, ureg_writemask(o_vtex[i], TGSI_WRITEMASK_X), vrect,
ureg_imm1f(shader, 1.0f / zscan->blocks_per_line), ureg_src(tmp));
unsigned i;
- shader = ureg_create(TGSI_PROCESSOR_FRAGMENT);
+ shader = ureg_create(PIPE_SHADER_FRAGMENT);
if (!shader)
return NULL;
assert(zscan);
memset(&rs_state, 0, sizeof(rs_state));
- rs_state.gl_rasterization_rules = true;
+ rs_state.half_pixel_center = true;
+ rs_state.bottom_edge_rule = true;
+ rs_state.depth_clip_near = 1;
+ rs_state.depth_clip_far = 1;
+
zscan->rs_state = zscan->pipe->create_rasterizer_state(zscan->pipe, &rs_state);
if (!zscan->rs_state)
goto error_rs_state;
struct pipe_sampler_view *
vl_zscan_layout(struct pipe_context *pipe, const int layout[64], unsigned blocks_per_line)
{
- const unsigned total_size = blocks_per_line * BLOCK_WIDTH * BLOCK_HEIGHT;
+ const unsigned total_size = blocks_per_line * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT;
int patched_layout[64];
struct pipe_box rect =
{
0, 0, 0,
- BLOCK_WIDTH * blocks_per_line,
- BLOCK_HEIGHT,
+ VL_BLOCK_WIDTH * blocks_per_line,
+ VL_BLOCK_HEIGHT,
1
};
memset(&res_tmpl, 0, sizeof(res_tmpl));
res_tmpl.target = PIPE_TEXTURE_2D;
res_tmpl.format = PIPE_FORMAT_R32_FLOAT;
- res_tmpl.width0 = BLOCK_WIDTH * blocks_per_line;
- res_tmpl.height0 = BLOCK_HEIGHT;
+ res_tmpl.width0 = VL_BLOCK_WIDTH * blocks_per_line;
+ res_tmpl.height0 = VL_BLOCK_HEIGHT;
res_tmpl.depth0 = 1;
res_tmpl.array_size = 1;
res_tmpl.usage = PIPE_USAGE_IMMUTABLE;
if (!res)
goto error_resource;
- buf_transfer = pipe->get_transfer
- (
- pipe, res,
- 0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
- &rect
- );
- if (!buf_transfer)
- goto error_transfer;
-
- pitch = buf_transfer->stride / sizeof(float);
-
- f = pipe->transfer_map(pipe, buf_transfer);
+ f = pipe->transfer_map(pipe, res,
+ 0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD_RANGE,
+ &rect, &buf_transfer);
if (!f)
goto error_map;
+ pitch = buf_transfer->stride / sizeof(float);
+
for (i = 0; i < blocks_per_line; ++i)
- for (y = 0; y < BLOCK_HEIGHT; ++y)
- for (x = 0; x < BLOCK_WIDTH; ++x) {
- float addr = patched_layout[x + y * BLOCK_WIDTH] +
- i * BLOCK_WIDTH * BLOCK_HEIGHT;
+ for (y = 0; y < VL_BLOCK_HEIGHT; ++y)
+ for (x = 0; x < VL_BLOCK_WIDTH; ++x) {
+ float addr = patched_layout[x + y * VL_BLOCK_WIDTH] +
+ i * VL_BLOCK_WIDTH * VL_BLOCK_HEIGHT;
addr /= total_size;
- f[i * BLOCK_WIDTH + y * pitch + x] = addr;
+ f[i * VL_BLOCK_WIDTH + y * pitch + x] = addr;
}
pipe->transfer_unmap(pipe, buf_transfer);
- pipe->transfer_destroy(pipe, buf_transfer);
memset(&sv_tmpl, 0, sizeof(sv_tmpl));
u_sampler_view_default_template(&sv_tmpl, res, res->format);
return sv;
error_map:
- pipe->transfer_destroy(pipe, buf_transfer);
-
-error_transfer:
pipe_resource_reference(&res, NULL);
error_resource:
memset(buffer, 0, sizeof(struct vl_zscan_buffer));
- buffer->zscan = zscan;
-
pipe_sampler_view_reference(&buffer->src, src);
buffer->viewport.scale[0] = dst->width;
buffer->viewport.scale[1] = dst->height;
buffer->viewport.scale[2] = 1;
- buffer->viewport.scale[3] = 1;
buffer->viewport.translate[0] = 0;
buffer->viewport.translate[1] = 0;
buffer->viewport.translate[2] = 0;
- buffer->viewport.translate[3] = 0;
buffer->fb_state.width = dst->width;
buffer->fb_state.height = dst->height;
memset(&res_tmpl, 0, sizeof(res_tmpl));
res_tmpl.target = PIPE_TEXTURE_3D;
res_tmpl.format = PIPE_FORMAT_R8_UNORM;
- res_tmpl.width0 = BLOCK_WIDTH * zscan->blocks_per_line;
- res_tmpl.height0 = BLOCK_HEIGHT;
+ res_tmpl.width0 = VL_BLOCK_WIDTH * zscan->blocks_per_line;
+ res_tmpl.height0 = VL_BLOCK_HEIGHT;
res_tmpl.depth0 = 2;
res_tmpl.array_size = 1;
res_tmpl.usage = PIPE_USAGE_IMMUTABLE;
}
void
-vl_zscan_upload_quant(struct vl_zscan_buffer *buffer, const uint8_t matrix[64], bool intra)
+vl_zscan_upload_quant(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer,
+ const uint8_t matrix[64], bool intra)
{
struct pipe_context *pipe;
struct pipe_transfer *buf_transfer;
struct pipe_box rect =
{
0, 0, intra ? 1 : 0,
- BLOCK_WIDTH,
- BLOCK_HEIGHT,
+ VL_BLOCK_WIDTH,
+ VL_BLOCK_HEIGHT,
1
};
assert(buffer);
assert(matrix);
- pipe = buffer->zscan->pipe;
+ pipe = zscan->pipe;
- rect.width *= buffer->zscan->blocks_per_line;
+ rect.width *= zscan->blocks_per_line;
- buf_transfer = pipe->get_transfer
- (
- pipe, buffer->quant->texture,
- 0, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
- &rect
- );
- if (!buf_transfer)
- goto error_transfer;
+ data = pipe->transfer_map(pipe, buffer->quant->texture,
+ 0, PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_DISCARD_RANGE,
+ &rect, &buf_transfer);
+ if (!data)
+ return;
pitch = buf_transfer->stride;
- data = pipe->transfer_map(pipe, buf_transfer);
- if (!data)
- goto error_map;
-
- for (i = 0; i < buffer->zscan->blocks_per_line; ++i)
- for (y = 0; y < BLOCK_HEIGHT; ++y)
- for (x = 0; x < BLOCK_WIDTH; ++x)
- data[i * BLOCK_WIDTH + y * pitch + x] = matrix[x + y * BLOCK_WIDTH];
+ for (i = 0; i < zscan->blocks_per_line; ++i)
+ for (y = 0; y < VL_BLOCK_HEIGHT; ++y)
+ for (x = 0; x < VL_BLOCK_WIDTH; ++x)
+ data[i * VL_BLOCK_WIDTH + y * pitch + x] = matrix[x + y * VL_BLOCK_WIDTH];
pipe->transfer_unmap(pipe, buf_transfer);
-
-error_map:
- pipe->transfer_destroy(pipe, buf_transfer);
-
-error_transfer:
- return;
}
void
-vl_zscan_render(struct vl_zscan_buffer *buffer, unsigned num_instances)
+vl_zscan_render(struct vl_zscan *zscan, struct vl_zscan_buffer *buffer, unsigned num_instances)
{
- struct vl_zscan *zscan;
-
assert(buffer);
- zscan = buffer->zscan;
-
zscan->pipe->bind_rasterizer_state(zscan->pipe, zscan->rs_state);
zscan->pipe->bind_blend_state(zscan->pipe, zscan->blend);
- zscan->pipe->bind_fragment_sampler_states(zscan->pipe, 3, zscan->samplers);
+ zscan->pipe->bind_sampler_states(zscan->pipe, PIPE_SHADER_FRAGMENT,
+ 0, 3, zscan->samplers);
zscan->pipe->set_framebuffer_state(zscan->pipe, &buffer->fb_state);
- zscan->pipe->set_viewport_state(zscan->pipe, &buffer->viewport);
- zscan->pipe->set_fragment_sampler_views(zscan->pipe, 3, &buffer->src);
+ zscan->pipe->set_viewport_states(zscan->pipe, 0, 1, &buffer->viewport);
+ zscan->pipe->set_sampler_views(zscan->pipe, PIPE_SHADER_FRAGMENT,
+ 0, 3, &buffer->src);
zscan->pipe->bind_vs_state(zscan->pipe, zscan->vs);
zscan->pipe->bind_fs_state(zscan->pipe, zscan->fs);
util_draw_arrays_instanced(zscan->pipe, PIPE_PRIM_QUADS, 0, 4, 0, num_instances);