Path: blob/21.2-virgl/src/gallium/auxiliary/translate/translate.h
4565 views
/*1* Copyright 2008 VMware, Inc.2* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE.22*/232425/**26* Vertex fetch/store/convert code. This functionality is used in two places:27* 1. Vertex fetch/convert - to grab vertex data from incoming vertex28* arrays and convert to format needed by vertex shaders.29* 2. Vertex store/emit - to convert simple float[][4] vertex attributes30* (which is the organization used throughout the draw/prim pipeline) to31* hardware-specific formats and emit into hardware vertex buffers.32*33*34* Authors:35* Keith Whitwell <[email protected]>36*/3738#ifndef _TRANSLATE_H39#define _TRANSLATE_H404142#include "pipe/p_compiler.h"43#include "pipe/p_format.h"44#include "pipe/p_state.h"4546/**47* Translate has to work on two more attributes because48* the draw module has to be able to pass a few fixed49* function vertex shader outputs even if the fragment50* shader already consumes PIPE_MAX_ATTRIBS inputs.51*52* These vertex shader outputs include:53* - position54* - bcolor (up to two)55* - point-size56* - viewport index57* - layer58*/59#define TRANSLATE_MAX_ATTRIBS (PIPE_MAX_ATTRIBS + 6)6061enum translate_element_type {62TRANSLATE_ELEMENT_NORMAL,63TRANSLATE_ELEMENT_INSTANCE_ID64};6566struct translate_element67{68enum translate_element_type type;69enum pipe_format input_format;70enum pipe_format output_format;71unsigned input_buffer:8;72unsigned input_offset:24;73unsigned instance_divisor;74unsigned output_offset;75};767778struct translate_key {79unsigned output_stride;80unsigned nr_elements;81struct translate_element element[TRANSLATE_MAX_ATTRIBS];82};838485struct translate;868788typedef void (PIPE_CDECL *run_elts_func)(struct translate *,89const unsigned *elts,90unsigned count,91unsigned start_instance,92unsigned instance_id,93void *output_buffer);9495typedef void (PIPE_CDECL *run_elts16_func)(struct translate *,96const uint16_t *elts,97unsigned count,98unsigned start_instance,99unsigned instance_id,100void *output_buffer);101102typedef void (PIPE_CDECL *run_elts8_func)(struct translate *,103const uint8_t *elts,104unsigned count,105unsigned start_instance,106unsigned instance_id,107void *output_buffer);108109typedef void (PIPE_CDECL *run_func)(struct translate *,110unsigned start,111unsigned count,112unsigned start_instance,113unsigned instance_id,114void *output_buffer);115116struct translate {117struct translate_key key;118119void (*release)( struct translate * );120121void (*set_buffer)( struct translate *,122unsigned i,123const void *ptr,124unsigned stride,125unsigned max_index );126127run_elts_func run_elts;128run_elts16_func run_elts16;129run_elts8_func run_elts8;130run_func run;131};132133134135struct translate *translate_create( const struct translate_key *key );136137boolean translate_is_output_format_supported(enum pipe_format format);138139static inline int translate_keysize( const struct translate_key *key )140{141assert(key->nr_elements <= TRANSLATE_MAX_ATTRIBS);142return 2 * sizeof(int) + key->nr_elements * sizeof(struct translate_element);143}144145static inline int translate_key_compare( const struct translate_key *a,146const struct translate_key *b )147{148int keysize_a = translate_keysize(a);149int keysize_b = translate_keysize(b);150151if (keysize_a != keysize_b) {152return keysize_a - keysize_b;153}154return memcmp(a, b, keysize_a);155}156157158static inline void translate_key_sanitize( struct translate_key *a )159{160int keysize = translate_keysize(a);161char *ptr = (char *)a;162memset(ptr + keysize, 0, sizeof(*a) - keysize);163}164165166/*******************************************************************************167* Private:168*/169struct translate *translate_sse2_create( const struct translate_key *key );170171struct translate *translate_generic_create( const struct translate_key *key );172173boolean translate_generic_is_output_format_supported(enum pipe_format format);174175#endif176177178