1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2008 Tungsten Graphics, inc. 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved. 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"), 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * on the rights to use, copy, modify, merge, publish, distribute, sub 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * license, and/or sell copies of the Software, and to permit persons to whom 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the Software is furnished to do so, subject to the following conditions: 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the next 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * paragraph) shall be included in all copies or substantial portions of the 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software. 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * USE OR OTHER DEALINGS IN THE SOFTWARE. 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/** 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Vertex fetch/store/convert code. This functionality is used in two places: 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 1. Vertex fetch/convert - to grab vertex data from incoming vertex 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * arrays and convert to format needed by vertex shaders. 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 2. Vertex store/emit - to convert simple float[][4] vertex attributes 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * (which is the organization used throughout the draw/prim pipeline) to 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * hardware-specific formats and emit into hardware vertex buffers. 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Authors: 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Keith Whitwell <keithw@tungstengraphics.com> 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef _TRANSLATE_H 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define _TRANSLATE_H 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_compiler.h" 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_format.h" 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_state.h" 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgenum translate_element_type { 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org TRANSLATE_ELEMENT_NORMAL, 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org TRANSLATE_ELEMENT_INSTANCE_ID 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct translate_element 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org enum translate_element_type type; 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org enum pipe_format input_format; 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org enum pipe_format output_format; 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned input_buffer:8; 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned input_offset:24; 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned instance_divisor; 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned output_offset; 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct translate_key { 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned output_stride; 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned nr_elements; 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct translate_element element[PIPE_MAX_ATTRIBS + 1]; 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct translate; 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (PIPE_CDECL *run_elts_func)(struct translate *, 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const unsigned *elts, 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned count, 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned instance_id, 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void *output_buffer); 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (PIPE_CDECL *run_elts16_func)(struct translate *, 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const uint16_t *elts, 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned count, 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned instance_id, 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void *output_buffer); 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (PIPE_CDECL *run_elts8_func)(struct translate *, 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const uint8_t *elts, 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned count, 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned instance_id, 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void *output_buffer); 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (PIPE_CDECL *run_func)(struct translate *, 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned start, 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned count, 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned instance_id, 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void *output_buffer); 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct translate { 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org struct translate_key key; 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void (*release)( struct translate * ); 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org void (*set_buffer)( struct translate *, 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned i, 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const void *ptr, 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned stride, 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org unsigned max_index ); 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org run_elts_func run_elts; 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org run_elts16_func run_elts16; 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org run_elts8_func run_elts8; 112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org run_func run; 113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}; 114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct translate *translate_create( const struct translate_key *key ); 118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgboolean translate_is_output_format_supported(enum pipe_format format); 120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE int translate_keysize( const struct translate_key *key ) 122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return 2 * sizeof(int) + key->nr_elements * sizeof(struct translate_element); 124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE int translate_key_compare( const struct translate_key *a, 127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org const struct translate_key *b ) 128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int keysize_a = translate_keysize(a); 130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int keysize_b = translate_keysize(b); 131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org if (keysize_a != keysize_b) { 133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return keysize_a - keysize_b; 134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } 135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org return memcmp(a, b, keysize_a); 136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE void translate_key_sanitize( struct translate_key *a ) 140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{ 141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org int keysize = translate_keysize(a); 142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org char *ptr = (char *)a; 143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org memset(ptr + keysize, 0, sizeof(*a) - keysize); 144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/******************************************************************************* 148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Private: 149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct translate *translate_sse2_create( const struct translate_key *key ); 151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct translate *translate_generic_create( const struct translate_key *key ); 153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgboolean translate_generic_is_output_format_supported(enum pipe_format format); 155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 157