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