#include "tgsi/tgsi_scan.h"
#include "svga_state.h"
+#include "svga_tgsi.h"
#include "svga_hw_reg.h"
#include "svga3d_shaderdefs.h"
struct svga_fragment_shader
{
struct svga_shader base;
+
+ /** Mask of which generic varying variables are read by this shader */
+ unsigned generic_inputs;
+ /** Table mapping original TGSI generic indexes to low integers */
+ int8_t generic_remap_table[MAX_GENERIC_VARYING];
};
struct svga_vertex_shader
fs->base.id = svga->debug.shader_id++;
+ fs->generic_inputs = svga_get_generic_inputs_mask(&fs->base.info);
+
+ svga_remap_generics(fs->generic_inputs, fs->generic_remap_table);
+
if (SVGA_DEBUG & DEBUG_TGSI || 0) {
debug_printf("%s id: %u, inputs: %u, outputs: %u\n",
__FUNCTION__, fs->base.id,
*/
static enum pipe_error
make_fs_key(const struct svga_context *svga,
+ struct svga_fragment_shader *fs,
struct svga_fs_compile_key *key)
{
int i;
* SVGA_NEW_NEED_SWTNL
* SVGA_NEW_SAMPLER
*/
- ret = make_fs_key( svga, &key );
+ ret = make_fs_key( svga, fs, &key );
if (ret != PIPE_OK)
return ret;
return ret;
}
-/* SVGA_NEW_PRESCALE, SVGA_NEW_RAST, SVGA_NEW_ZERO_STRIDE
+/* SVGA_NEW_PRESCALE, SVGA_NEW_RAST, SVGA_NEW_ZERO_STRIDE, SVGA_NEW_FS
*/
static void
make_vs_key(struct svga_context *svga, struct svga_vs_compile_key *key)
svga->curr.zero_stride_vertex_elements;
key->num_zero_stride_vertex_elements =
svga->curr.num_zero_stride_vertex_elements;
+
+ /* SVGA_NEW_FS */
+ key->fs_generic_inputs = svga->curr.fs->generic_inputs;
}
{
"vertex shader (hwtnl)",
(SVGA_NEW_VS |
+ SVGA_NEW_FS |
SVGA_NEW_PRESCALE |
SVGA_NEW_NEED_SWTNL |
SVGA_NEW_ZERO_STRIDE),
#include "svga_context.h"
#include "svga_swtnl.h"
#include "svga_state.h"
-
+#include "svga_tgsi.h"
#include "svga_swtnl_private.h"
nr_decls++;
for (i = 0; i < fs->base.info.num_inputs; i++) {
- unsigned name = fs->base.info.input_semantic_name[i];
- unsigned index = fs->base.info.input_semantic_index[i];
- src = draw_find_shader_output(draw, name, index);
+ const unsigned sem_name = fs->base.info.input_semantic_name[i];
+ const unsigned sem_index = fs->base.info.input_semantic_index[i];
+
+ src = draw_find_shader_output(draw, sem_name, sem_index);
+
vdecl[nr_decls].array.offset = offset;
- vdecl[nr_decls].identity.usageIndex = fs->base.info.input_semantic_index[i];
+ vdecl[nr_decls].identity.usageIndex = sem_index;
- switch (name) {
+ switch (sem_name) {
case TGSI_SEMANTIC_COLOR:
draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src);
vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_COLOR;
draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_TEXCOORD;
vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT4;
- vdecl[nr_decls].identity.usageIndex += 1;
+ vdecl[nr_decls].identity.usageIndex =
+ svga_remap_generic_index(fs->generic_remap_table, sem_index);
offset += 16;
nr_decls++;
break;
#include "tgsi/tgsi_parse.h"
#include "tgsi/tgsi_dump.h"
#include "tgsi/tgsi_scan.h"
+#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_bitmask.h"
}
+/**
+ * Use the shader info to generate a bitmask indicating which generic
+ * inputs are used by the shader. A set bit indicates that GENERIC[i]
+ * is used.
+ */
+unsigned
+svga_get_generic_inputs_mask(const struct tgsi_shader_info *info)
+{
+ unsigned i, mask = 0x0;
+
+ for (i = 0; i < info->num_inputs; i++) {
+ if (info->input_semantic_name[i] == TGSI_SEMANTIC_GENERIC) {
+ unsigned j = info->input_semantic_index[i];
+ assert(j < sizeof(mask) * 8);
+ mask |= 1 << j;
+ }
+ }
+ return mask;
+}
+
+
+/**
+ * Given a mask of used generic variables (as returned by the above functions)
+ * fill in a table which maps those indexes to small integers.
+ * This table is used by the remap_generic_index() function in
+ * svga_tgsi_decl_sm30.c
+ * Example: if generics_mask = binary(1010) it means that GENERIC[1] and
+ * GENERIC[3] are used. The remap_table will contain:
+ * table[1] = 0;
+ * table[3] = 1;
+ * The remaining table entries will be filled in with the next unused
+ * generic index (in this example, 2).
+ */
+void
+svga_remap_generics(unsigned generics_mask,
+ int8_t remap_table[MAX_GENERIC_VARYING])
+{
+ /* Note texcoord[0] is reserved so start at 1 */
+ unsigned count = 1, i;
+
+ for (i = 0; i < MAX_GENERIC_VARYING; i++) {
+ remap_table[i] = -1;
+ }
+
+ /* for each bit set in generic_mask */
+ while (generics_mask) {
+ unsigned index = ffs(generics_mask) - 1;
+ remap_table[index] = count++;
+ generics_mask &= ~(1 << index);
+ }
+
+ for (i = 0; i < MAX_GENERIC_VARYING; i++) {
+ if (remap_table[i] == -1)
+ remap_table[i] = count;
+ }
+}
+
+
+/**
+ * Use the generic remap table to map a TGSI generic varying variable
+ * index to a small integer.
+ */
+int
+svga_remap_generic_index(const int8_t remap_table[MAX_GENERIC_VARYING],
+ int generic_index)
+{
+ assert(generic_index < MAX_GENERIC_VARYING);
+
+ if (generic_index >= MAX_GENERIC_VARYING) {
+ /* just don't return a random/garbage value */
+ generic_index = MAX_GENERIC_VARYING - 1;
+ }
+
+ return remap_table[generic_index];
+}
/* Parse TGSI shader and translate to SVGA/DX9 serialized
*/
static struct svga_shader_result *
svga_tgsi_translate( const struct svga_shader *shader,
- union svga_compile_key key,
+ struct svga_compile_key key,
unsigned unit )
{
struct svga_shader_result *result = NULL;
svga_translate_fragment_program( const struct svga_fragment_shader *fs,
const struct svga_fs_compile_key *fkey )
{
- union svga_compile_key key;
+ struct svga_compile_key key;
+
memcpy(&key.fkey, fkey, sizeof *fkey);
+ memcpy(key.generic_remap_table, fs->generic_remap_table,
+ sizeof(fs->generic_remap_table));
+
return svga_tgsi_translate( &fs->base,
key,
PIPE_SHADER_FRAGMENT );
svga_translate_vertex_program( const struct svga_vertex_shader *vs,
const struct svga_vs_compile_key *vkey )
{
- union svga_compile_key key;
+ struct svga_compile_key key;
+
memcpy(&key.vkey, vkey, sizeof *vkey);
+ /* Note: we could alternately store the remap table in the vkey but
+ * that would make it larger. We just regenerate it here instead.
+ */
+ svga_remap_generics(vkey->fs_generic_inputs, key.generic_remap_table);
+
return svga_tgsi_translate( &vs->base,
key,
PIPE_SHADER_VERTEX );
#include "svga_hw_reg.h"
+
+/**
+ * We use a 32-bit mask to keep track of the generic indexes.
+ */
+#define MAX_GENERIC_VARYING 32
+
+
struct svga_fragment_shader;
struct svga_vertex_shader;
struct svga_shader;
struct svga_vs_compile_key
{
+ unsigned fs_generic_inputs;
unsigned zero_stride_vertex_elements;
unsigned need_prescale:1;
unsigned allow_psiz:1;
} tex[PIPE_MAX_SAMPLERS];
};
-union svga_compile_key {
+struct svga_compile_key {
struct svga_vs_compile_key vkey;
struct svga_fs_compile_key fkey;
+ int8_t generic_remap_table[MAX_GENERIC_VARYING];
};
struct svga_shader_result
/* Parameters used to generate this compilation result:
*/
- union svga_compile_key key;
+ struct svga_compile_key key;
/* Compiled shader tokens:
*/
void svga_destroy_shader_result( struct svga_shader_result *result );
+unsigned
+svga_get_generic_inputs_mask(const struct tgsi_shader_info *info);
+
+unsigned
+svga_get_generic_outputs_mask(const struct tgsi_shader_info *info);
+
+void
+svga_remap_generics(unsigned generics_mask,
+ int8_t remap_table[MAX_GENERIC_VARYING]);
+
+int
+svga_remap_generic_index(const int8_t remap_table[MAX_GENERIC_VARYING],
+ int generic_index);
+
#endif
#include "svga_tgsi_emit.h"
-static boolean translate_vs_ps_semantic( struct tgsi_declaration_semantic semantic,
+
+static boolean translate_vs_ps_semantic( struct svga_shader_emitter *emit,
+ struct tgsi_declaration_semantic semantic,
unsigned *usage,
unsigned *idx )
{
*usage = SVGA3D_DECLUSAGE_PSIZE;
break;
case TGSI_SEMANTIC_GENERIC:
- *idx = semantic.Index + 1; /* texcoord[0] is reserved for fog & position */
+ *idx = svga_remap_generic_index(emit->key.generic_remap_table,
+ semantic.Index);
*usage = SVGA3D_DECLUSAGE_TEXCOORD;
break;
case TGSI_SEMANTIC_NORMAL:
SVGA3DOpDclArgs dcl;
SVGA3dShaderInstToken opcode;
+ /* check values against bitfield sizes */
+ assert(index < 16);
+ assert(usage <= SVGA3D_DECLUSAGE_MAX);
+
opcode = inst_token( SVGA3DOP_DCL );
dcl.values[0] = 0;
dcl.values[1] = 0;
else if (emit->key.fkey.light_twoside &&
(semantic.Name == TGSI_SEMANTIC_COLOR)) {
- if (!translate_vs_ps_semantic( semantic, &usage, &index ))
+ if (!translate_vs_ps_semantic( emit, semantic, &usage, &index ))
return FALSE;
emit->internal_color_idx[emit->internal_color_count] = idx;
return FALSE;
semantic.Name = TGSI_SEMANTIC_BCOLOR;
- if (!translate_vs_ps_semantic( semantic, &usage, &index ))
+ if (!translate_vs_ps_semantic( emit, semantic, &usage, &index ))
return FALSE;
if (emit->ps30_input_count >= SVGA3D_INPUTREG_MAX)
}
else {
- if (!translate_vs_ps_semantic( semantic, &usage, &index ))
+ if (!translate_vs_ps_semantic( emit, semantic, &usage, &index ))
return FALSE;
if (emit->ps30_input_count >= SVGA3D_INPUTREG_MAX)
dcl.values[0] = 0;
dcl.values[1] = 0;
- if (!translate_vs_ps_semantic( semantic, &usage, &index ))
+ if (!translate_vs_ps_semantic( emit, semantic, &usage, &index ))
return FALSE;
if (emit->vs30_output_count >= SVGA3D_OUTPUTREG_MAX)
char *buf;
char *ptr;
- union svga_compile_key key;
+ struct svga_compile_key key;
struct tgsi_shader_info info;
int unit;
{
SVGA3dShaderDestToken dest;
+ /* check values against bitfield sizes */
+ assert(number < (1 << 11));
+ assert((file >> 3) < 4);
+ assert((file & 0x7) < 8);
+
dest.value = 0;
dest.num = number;
dest.type_upper = file >> 3;
{
SVGA3dShaderSrcToken src;
+ /* check values against bitfield sizes */
+ assert(number < (1 << 11));
+ assert((file >> 3) < 4);
+ assert((file & 0x7) < 8);
+
src.value = 0;
src.num = number;
src.type_upper = file >> 3;