1c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell/* 2c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * Copyright 2008 Tungsten Graphics, inc. 3c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * All Rights Reserved. 4c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * 5c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 6c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * copy of this software and associated documentation files (the "Software"), 7c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * to deal in the Software without restriction, including without limitation 8c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * on the rights to use, copy, modify, merge, publish, distribute, sub 9c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * license, and/or sell copies of the Software, and to permit persons to whom 10c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * the Software is furnished to do so, subject to the following conditions: 11c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * 12c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * The above copyright notice and this permission notice (including the next 13c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * paragraph) shall be included in all copies or substantial portions of the 14c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * Software. 15c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * 16c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * USE OR OTHER DEALINGS IN THE SOFTWARE. 23c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell */ 24c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 25c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 26c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell/** 27c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * Vertex fetch/store/convert code. This functionality is used in two places: 28c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * 1. Vertex fetch/convert - to grab vertex data from incoming vertex 29c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * arrays and convert to format needed by vertex shaders. 30c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * 2. Vertex store/emit - to convert simple float[][4] vertex attributes 31c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * (which is the organization used throughout the draw/prim pipeline) to 32c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * hardware-specific formats and emit into hardware vertex buffers. 33c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * 34c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * 35c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * Authors: 36c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell * Keith Whitwell <keithw@tungstengraphics.com> 37c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell */ 38c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 39c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell#ifndef _TRANSLATE_H 40c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell#define _TRANSLATE_H 41c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 42c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 43c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell#include "pipe/p_compiler.h" 44c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell#include "pipe/p_format.h" 457400bc4b6fb0c20a935cd108afa92814eeafec6dKeith Whitwell#include "pipe/p_state.h" 46c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 47543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krolenum translate_element_type { 48543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol TRANSLATE_ELEMENT_NORMAL, 49543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol TRANSLATE_ELEMENT_INSTANCE_ID 50543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol}; 51543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol 52c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwellstruct translate_element 53c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell{ 54543b9566bdaa48fea2df1866fa1310c1cdbcde27Michal Krol enum translate_element_type type; 55c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell enum pipe_format input_format; 56c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell enum pipe_format output_format; 570557fa72c0e39a3cb4c241690b495ca142c06616Keith Whitwell unsigned input_buffer:8; 580557fa72c0e39a3cb4c241690b495ca142c06616Keith Whitwell unsigned input_offset:24; 597ca0ce38340144794267609646048b3820d594abMichal Krol unsigned instance_divisor; 60c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell unsigned output_offset; 61c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell}; 62c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 63c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 64a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwellstruct translate_key { 65a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell unsigned output_stride; 66a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell unsigned nr_elements; 67d756f9512d295531ff6a600c736a68ac2dcff58bJosé Fonseca struct translate_element element[PIPE_MAX_ATTRIBS + 1]; 68a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell}; 69a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell 70a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell 7181d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paulstruct translate; 7281d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul 7381d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul 7481d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paultypedef void (PIPE_CDECL *run_elts_func)(struct translate *, 7581d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul const unsigned *elts, 7681d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul unsigned count, 7781d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul unsigned instance_id, 7881d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul void *output_buffer); 7981d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul 8081d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paultypedef void (PIPE_CDECL *run_elts16_func)(struct translate *, 8181d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul const uint16_t *elts, 8281d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul unsigned count, 8381d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul unsigned instance_id, 8481d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul void *output_buffer); 8581d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul 8681d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paultypedef void (PIPE_CDECL *run_elts8_func)(struct translate *, 8781d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul const uint8_t *elts, 8881d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul unsigned count, 8981d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul unsigned instance_id, 9081d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul void *output_buffer); 9181d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul 9281d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paultypedef void (PIPE_CDECL *run_func)(struct translate *, 9381d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul unsigned start, 9481d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul unsigned count, 9581d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul unsigned instance_id, 9681d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul void *output_buffer); 9781d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul 98c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwellstruct translate { 99a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell struct translate_key key; 100a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell 101a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell void (*release)( struct translate * ); 102c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 103c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell void (*set_buffer)( struct translate *, 104c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell unsigned i, 105c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell const void *ptr, 106fc431a58dc1446383edc11aec2a0b7de5b363e5eJosé Fonseca unsigned stride, 107fc431a58dc1446383edc11aec2a0b7de5b363e5eJosé Fonseca unsigned max_index ); 108c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 10981d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul run_elts_func run_elts; 11081d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul run_elts16_func run_elts16; 11181d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul run_elts8_func run_elts8; 11281d5afbbecce4ccf2b4bf10b10f47585febfe9c8Brian Paul run_func run; 113c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell}; 114c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 115c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 116c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 1177400bc4b6fb0c20a935cd108afa92814eeafec6dKeith Whitwellstruct translate *translate_create( const struct translate_key *key ); 1187400bc4b6fb0c20a935cd108afa92814eeafec6dKeith Whitwell 11910adb7840c3a37dedc940fe593b246336eebd71eLuca Barbieriboolean translate_is_output_format_supported(enum pipe_format format); 12010adb7840c3a37dedc940fe593b246336eebd71eLuca Barbieri 121c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwellstatic INLINE int translate_keysize( const struct translate_key *key ) 122c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell{ 123c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell return 2 * sizeof(int) + key->nr_elements * sizeof(struct translate_element); 124c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell} 125c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell 126c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwellstatic INLINE int translate_key_compare( const struct translate_key *a, 127c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell const struct translate_key *b ) 128c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell{ 1297124fa16efe0f8ffb402bcd182f276032bed378dMichal Krol int keysize_a = translate_keysize(a); 1307124fa16efe0f8ffb402bcd182f276032bed378dMichal Krol int keysize_b = translate_keysize(b); 1317124fa16efe0f8ffb402bcd182f276032bed378dMichal Krol 1327124fa16efe0f8ffb402bcd182f276032bed378dMichal Krol if (keysize_a != keysize_b) { 1337124fa16efe0f8ffb402bcd182f276032bed378dMichal Krol return keysize_a - keysize_b; 1347124fa16efe0f8ffb402bcd182f276032bed378dMichal Krol } 1357124fa16efe0f8ffb402bcd182f276032bed378dMichal Krol return memcmp(a, b, keysize_a); 136c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell} 137c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell 138c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell 139c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwellstatic INLINE void translate_key_sanitize( struct translate_key *a ) 140c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell{ 141c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell int keysize = translate_keysize(a); 142c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell char *ptr = (char *)a; 143c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell memset(ptr + keysize, 0, sizeof(*a) - keysize); 144c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell} 145c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell 146c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell 147a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell/******************************************************************************* 148a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell * Private: 149a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell */ 150a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwellstruct translate *translate_sse2_create( const struct translate_key *key ); 151c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 152a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwellstruct translate *translate_generic_create( const struct translate_key *key ); 153c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 15410adb7840c3a37dedc940fe593b246336eebd71eLuca Barbieriboolean translate_generic_is_output_format_supported(enum pipe_format format); 155c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell 156c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell#endif 157