translate.h revision c0a6040f568e0c9be07797b2dc2fdd8a3624ec34
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
47c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwellstruct translate_element
48c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell{
49c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell   enum pipe_format input_format;
50c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell   enum pipe_format output_format;
51b514f5f3ba4c9cf6c39cbcdf5bf0d2d8efb8d19bKeith Whitwell   unsigned input_buffer;
52b514f5f3ba4c9cf6c39cbcdf5bf0d2d8efb8d19bKeith Whitwell   unsigned input_offset;       /* can't really reduce the size of these */
53c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell   unsigned output_offset;
54c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell};
55c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
56c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
57a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwellstruct translate_key {
58a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell   unsigned output_stride;
59a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell   unsigned nr_elements;
60a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell   struct translate_element element[PIPE_MAX_ATTRIBS];
61a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell};
62a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell
63a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell
64c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwellstruct translate {
65a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell   struct translate_key key;
66a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell
67a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell   void (*release)( struct translate * );
68c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
69c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell   void (*set_buffer)( struct translate *,
70c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell		       unsigned i,
71c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell		       const void *ptr,
72c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell		       unsigned stride );
73c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
74c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell   void (*run_elts)( struct translate *,
75c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell		     const unsigned *elts,
76c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell		     unsigned count,
77c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell		     void *output_buffer);
78a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell
79a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell   void (*run)( struct translate *,
80a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell		unsigned start,
81a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell		unsigned count,
82a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell		void *output_buffer);
83c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell};
84c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
85c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
86c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
87a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell#if 0
88a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwellstruct translate_context *translate_context_create( void );
89a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwellvoid translate_context_destroy( struct translate_context * );
90a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell
91a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwellstruct translate *translate_lookup_or_create( struct translate_context *tctx,
92a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell					      const struct translate_key *key );
93a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell#endif
94a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell
95a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell
967400bc4b6fb0c20a935cd108afa92814eeafec6dKeith Whitwellstruct translate *translate_create( const struct translate_key *key );
977400bc4b6fb0c20a935cd108afa92814eeafec6dKeith Whitwell
98c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwellstatic INLINE int translate_keysize( const struct translate_key *key )
99c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell{
100c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell   return 2 * sizeof(int) + key->nr_elements * sizeof(struct translate_element);
101c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell}
102c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell
103c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwellstatic INLINE int translate_key_compare( const struct translate_key *a,
104c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell                                         const struct translate_key *b )
105c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell{
106c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell   int keysize = translate_keysize(a);
107c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell   return memcmp(a, b, keysize);
108c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell}
109c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell
110c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell
111c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwellstatic INLINE void translate_key_sanitize( struct translate_key *a )
112c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell{
113c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell   int keysize = translate_keysize(a);
114c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell   char *ptr = (char *)a;
115c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell   memset(ptr + keysize, 0, sizeof(*a) - keysize);
116c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell}
117c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell
118c0a6040f568e0c9be07797b2dc2fdd8a3624ec34Keith Whitwell
119a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell/*******************************************************************************
120a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell *  Private:
121a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwell */
122a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwellstruct translate *translate_sse2_create( const struct translate_key *key );
123c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
124a5a7dc24ba2dcf9bbdd73709c4c182e324bdc3a5Keith Whitwellstruct translate *translate_generic_create( const struct translate_key *key );
125c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
126c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell
127c81bbab6f6c0413996799800cac6fb49a698e765Keith Whitwell#endif
128