X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fsvga%2Fsvga_tgsi_decl_sm30.c;h=42a3593ed2aa3a98597a4cabcdfcd8440633f721;hb=ca531aeeb120cdda966120a17cdf50aa14c3129b;hp=6f4087048636b25cde8a2c0a19d3787521ead46c;hpb=49a6f5e68eeb6b23bb040cfc1f93befc2f1eb35a;p=mesa.git diff --git a/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c b/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c index 6f408704863..42a3593ed2a 100644 --- a/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c +++ b/src/gallium/drivers/svga/svga_tgsi_decl_sm30.c @@ -30,9 +30,16 @@ #include "svga_tgsi_emit.h" -static boolean translate_vs_ps_semantic( struct tgsi_declaration_semantic semantic, - unsigned *usage, - unsigned *idx ) + +/** + * Translate TGSI semantic info into SVGA3d semantic info. + * This is called for VS outputs and PS inputs only. + */ +static boolean +translate_vs_ps_semantic(struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned *usage, + unsigned *idx) { switch (semantic.Name) { case TGSI_SEMANTIC_POSITION: @@ -40,7 +47,6 @@ static boolean translate_vs_ps_semantic( struct tgsi_declaration_semantic semant *usage = SVGA3D_DECLUSAGE_POSITION; break; case TGSI_SEMANTIC_COLOR: - *idx = semantic.Index; *usage = SVGA3D_DECLUSAGE_COLOR; break; @@ -58,13 +64,21 @@ static boolean translate_vs_ps_semantic( struct tgsi_declaration_semantic semant *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: *idx = semantic.Index; *usage = SVGA3D_DECLUSAGE_NORMAL; break; + case TGSI_SEMANTIC_CLIPDIST: + case TGSI_SEMANTIC_CLIPVERTEX: + /* XXX at this time we don't support clip distance or clip vertices */ + debug_warn_once("unsupported clip distance/vertex attribute\n"); + *usage = SVGA3D_DECLUSAGE_TEXCOORD; + *idx = 0; + return TRUE; default: assert(0); *usage = SVGA3D_DECLUSAGE_TEXCOORD; @@ -76,14 +90,24 @@ static boolean translate_vs_ps_semantic( struct tgsi_declaration_semantic semant } -static boolean emit_decl( struct svga_shader_emitter *emit, - SVGA3dShaderDestToken reg, - unsigned usage, - unsigned index ) +/** + * Emit a PS input (or VS depth/fog output) register declaration. + * For example, if usage = SVGA3D_DECLUSAGE_TEXCOORD, reg.num = 1, and + * index = 3, we'll emit "dcl_texcoord3 v1". + */ +static boolean +emit_decl(struct svga_shader_emitter *emit, + SVGA3dShaderDestToken reg, + unsigned usage, + unsigned index) { 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; @@ -93,16 +117,20 @@ static boolean emit_decl( struct svga_shader_emitter *emit, dcl.index = index; dcl.values[0] |= 1<<31; - return (emit_instruction(emit, opcode) && - svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, ARRAY_SIZE(dcl.values))); } -static boolean emit_vface_decl( struct svga_shader_emitter *emit ) + +/** + * Emit declaration for PS front/back-face input register. + */ +static boolean +emit_vface_decl(struct svga_shader_emitter *emit) { if (!emit->emitted_vface) { SVGA3dShaderDestToken reg = - dst_register( SVGA3DREG_MISCTYPE, - SVGA3DMISCREG_FACE ); + dst_register(SVGA3DREG_MISCTYPE, SVGA3DMISCREG_FACE); if (!emit_decl( emit, reg, 0, 0 )) return FALSE; @@ -112,13 +140,17 @@ static boolean emit_vface_decl( struct svga_shader_emitter *emit ) return TRUE; } + +/** + * Emit PS input register to pass depth/fog coordinates. + * Note that this always goes into texcoord[0]. + */ static boolean ps30_input_emit_depth_fog( struct svga_shader_emitter *emit, struct src_register *out ) { struct src_register reg; - if (emit->emitted_depth_fog) { *out = emit->ps_depth_fog; return TRUE; @@ -137,9 +169,15 @@ ps30_input_emit_depth_fog( struct svga_shader_emitter *emit, return emit_decl( emit, dst( reg ), SVGA3D_DECLUSAGE_TEXCOORD, 0 ); } -static boolean ps30_input( struct svga_shader_emitter *emit, - struct tgsi_declaration_semantic semantic, - unsigned idx ) + +/** + * Process a PS input declaration. + * We'll emit a declaration like "dcl_texcoord1 v2" + */ +static boolean +ps30_input(struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx) { unsigned usage, index; SVGA3dShaderDestToken reg; @@ -178,10 +216,10 @@ static boolean ps30_input( struct svga_shader_emitter *emit, return emit_decl( emit, reg, 0, 0 ); } - else if (emit->key.fkey.light_twoside && + else if (emit->key.fs.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; @@ -195,7 +233,7 @@ static boolean ps30_input( struct svga_shader_emitter *emit, 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) @@ -234,7 +272,7 @@ static boolean ps30_input( struct svga_shader_emitter *emit, } 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) @@ -247,9 +285,9 @@ static boolean ps30_input( struct svga_shader_emitter *emit, return FALSE; if (semantic.Name == TGSI_SEMANTIC_GENERIC && - emit->key.fkey.sprite_origin_lower_left && + emit->key.sprite_origin_lower_left && index >= 1 && - emit->key.fkey.tex[index - 1].sprite_texgen) { + emit->key.tex[index - 1].sprite_texgen) { /* This is a sprite texture coord with lower-left origin. * We need to invert the texture T coordinate since the SVGA3D * device only supports an upper-left origin. @@ -278,24 +316,47 @@ static boolean ps30_input( struct svga_shader_emitter *emit, } -/* PS output registers are the same as 2.0 +/** + * Process a PS output declaration. + * Note that we don't actually emit a SVGA3DOpDcl for PS outputs. + * \idx register index, such as OUT[2] (not semantic index) */ -static boolean ps30_output( struct svga_shader_emitter *emit, - struct tgsi_declaration_semantic semantic, - unsigned idx ) +static boolean +ps30_output(struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx) { - SVGA3dShaderDestToken reg; - switch (semantic.Name) { case TGSI_SEMANTIC_COLOR: - if (emit->unit == PIPE_SHADER_FRAGMENT && - emit->key.fkey.white_fragments) { - - emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, - emit->nr_hw_temp++ ); - emit->temp_col[idx] = emit->output_map[idx]; - emit->true_col[idx] = dst_register( SVGA3DREG_COLOROUT, - semantic.Index ); + if (emit->unit == PIPE_SHADER_FRAGMENT) { + if (emit->key.fs.white_fragments) { + /* Used for XOR logicop mode */ + emit->output_map[idx] = dst_register( SVGA3DREG_TEMP, + emit->nr_hw_temp++ ); + emit->temp_color_output[idx] = emit->output_map[idx]; + emit->true_color_output[idx] = dst_register(SVGA3DREG_COLOROUT, + semantic.Index); + } + else if (emit->key.fs.write_color0_to_n_cbufs) { + /* We'll write color output [0] to all render targets. + * Prepare all the output registers here, but only when the + * semantic.Index == 0 so we don't do this more than once. + */ + if (semantic.Index == 0) { + unsigned i; + for (i = 0; i < emit->key.fs.write_color0_to_n_cbufs; i++) { + emit->output_map[idx+i] = dst_register(SVGA3DREG_TEMP, + emit->nr_hw_temp++); + emit->temp_color_output[i] = emit->output_map[idx+i]; + emit->true_color_output[i] = dst_register(SVGA3DREG_COLOROUT, + i); + } + } + } + else { + emit->output_map[idx] = + dst_register(SVGA3DREG_COLOROUT, semantic.Index); + } } else { emit->output_map[idx] = dst_register( SVGA3DREG_COLOROUT, @@ -311,7 +372,8 @@ static boolean ps30_output( struct svga_shader_emitter *emit, break; default: assert(0); - reg = dst_register( SVGA3DREG_COLOROUT, 0 ); + /* A wild stab in the dark. */ + emit->output_map[idx] = dst_register( SVGA3DREG_COLOROUT, 0 ); break; } @@ -319,11 +381,14 @@ static boolean ps30_output( struct svga_shader_emitter *emit, } -/* We still make up the input semantics the same as in 2.0 +/** + * Declare a VS input register. + * We still make up the input semantics the same as in 2.0 */ -static boolean vs30_input( struct svga_shader_emitter *emit, - struct tgsi_declaration_semantic semantic, - unsigned idx ) +static boolean +vs30_input(struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx) { SVGA3DOpDclArgs dcl; SVGA3dShaderInstToken opcode; @@ -333,39 +398,28 @@ static boolean vs30_input( struct svga_shader_emitter *emit, dcl.values[0] = 0; dcl.values[1] = 0; - if (emit->key.vkey.zero_stride_vertex_elements & (1 << idx)) { - unsigned i; - unsigned offset = 0; - unsigned start_idx = emit->info.file_max[TGSI_FILE_CONSTANT] + 1; - /* adjust for prescale constants */ - start_idx += emit->key.vkey.need_prescale ? 2 : 0; - /* compute the offset from the start of zero stride constants */ - for (i = 0; i < PIPE_MAX_ATTRIBS && i < idx; ++i) { - if (emit->key.vkey.zero_stride_vertex_elements & (1<input_map[idx] = src_register( SVGA3DREG_CONST, - start_idx + offset ); - } else { - emit->input_map[idx] = src_register( SVGA3DREG_INPUT, idx ); - dcl.dst = dst_register( SVGA3DREG_INPUT, idx ); + emit->input_map[idx] = src_register( SVGA3DREG_INPUT, idx ); + dcl.dst = dst_register( SVGA3DREG_INPUT, idx ); - assert(dcl.dst.reserved0); + assert(dcl.dst.reserved0); - svga_generate_vdecl_semantics( idx, &usage, &index ); + svga_generate_vdecl_semantics( idx, &usage, &index ); - dcl.usage = usage; - dcl.index = index; - dcl.values[0] |= 1<<31; + dcl.usage = usage; + dcl.index = index; + dcl.values[0] |= 1<<31; - return (emit_instruction(emit, opcode) && - svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); - } - return TRUE; + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, ARRAY_SIZE(dcl.values))); } -static boolean vs30_output_emit_depth_fog( struct svga_shader_emitter *emit, - SVGA3dShaderDestToken *out ) + +/** + * Declare VS output for holding depth/fog. + */ +static boolean +vs30_output_emit_depth_fog(struct svga_shader_emitter *emit, + SVGA3dShaderDestToken *out) { SVGA3dShaderDestToken reg; @@ -383,12 +437,16 @@ static boolean vs30_output_emit_depth_fog( struct svga_shader_emitter *emit, return emit_decl( emit, reg, SVGA3D_DECLUSAGE_TEXCOORD, 0 ); } -/* VS3.0 outputs have proper declarations and semantic info for + +/** + * Declare a VS output. + * VS3.0 outputs have proper declarations and semantic info for * matching against PS inputs. */ -static boolean vs30_output( struct svga_shader_emitter *emit, - struct tgsi_declaration_semantic semantic, - unsigned idx ) +static boolean +vs30_output(struct svga_shader_emitter *emit, + struct tgsi_declaration_semantic semantic, + unsigned idx) { SVGA3DOpDclArgs dcl; SVGA3dShaderInstToken opcode; @@ -398,7 +456,7 @@ static boolean vs30_output( struct svga_shader_emitter *emit, 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) @@ -429,7 +487,7 @@ static boolean vs30_output( struct svga_shader_emitter *emit, /* This has the effect of not declaring psiz (below) and not * emitting the final MOV to true_psiz in the postamble. */ - if (!emit->key.vkey.allow_psiz) + if (!emit->key.vs.allow_psiz) return TRUE; emit->true_psiz = dcl.dst; @@ -450,14 +508,34 @@ static boolean vs30_output( struct svga_shader_emitter *emit, emit->output_map[idx] = dcl.dst; } + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, ARRAY_SIZE(dcl.values))); +} + - return (emit_instruction(emit, opcode) && - svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); +/** Translate PIPE_TEXTURE_x to SVGA3DSAMP_x */ +static ubyte +svga_tgsi_sampler_type(const struct svga_shader_emitter *emit, int idx) +{ + switch (emit->sampler_target[idx]) { + case TGSI_TEXTURE_1D: + return SVGA3DSAMP_2D; + case TGSI_TEXTURE_2D: + case TGSI_TEXTURE_RECT: + return SVGA3DSAMP_2D; + case TGSI_TEXTURE_3D: + return SVGA3DSAMP_VOLUME; + case TGSI_TEXTURE_CUBE: + return SVGA3DSAMP_CUBE; + } + + return SVGA3DSAMP_UNKNOWN; } -static boolean ps30_sampler( struct svga_shader_emitter *emit, - struct tgsi_declaration_semantic semantic, - unsigned idx ) + +static boolean +ps30_sampler( struct svga_shader_emitter *emit, + unsigned idx ) { SVGA3DOpDclArgs dcl; SVGA3dShaderInstToken opcode; @@ -470,32 +548,40 @@ static boolean ps30_sampler( struct svga_shader_emitter *emit, dcl.type = svga_tgsi_sampler_type( emit, idx ); dcl.values[0] |= 1<<31; - return (emit_instruction(emit, opcode) && - svga_shader_emit_dwords( emit, dcl.values, Elements(dcl.values))); + return (emit_instruction(emit, opcode) && + svga_shader_emit_dwords( emit, dcl.values, ARRAY_SIZE(dcl.values))); } +boolean +svga_shader_emit_samplers_decl( struct svga_shader_emitter *emit ) +{ + unsigned i; -boolean svga_translate_decl_sm30( struct svga_shader_emitter *emit, - const struct tgsi_full_declaration *decl ) + for (i = 0; i < emit->num_samplers; i++) { + if (!ps30_sampler(emit, i)) + return FALSE; + } + return TRUE; +} + +boolean +svga_translate_decl_sm30( struct svga_shader_emitter *emit, + const struct tgsi_full_declaration *decl ) { unsigned first = decl->Range.First; unsigned last = decl->Range.Last; - unsigned semantic = 0; - unsigned semantic_idx = 0; unsigned idx; - if (decl->Declaration.Semantic) { - semantic = decl->Semantic.Name; - semantic_idx = decl->Semantic.Index; - } - for( idx = first; idx <= last; idx++ ) { - boolean ok; + boolean ok = TRUE; switch (decl->Declaration.File) { case TGSI_FILE_SAMPLER: assert (emit->unit == PIPE_SHADER_FRAGMENT); - ok = ps30_sampler( emit, decl->Semantic, idx ); + /* just keep track of the number of samplers here. + * Will emit the declaration in the helpers function. + */ + emit->num_samplers = MAX2(emit->num_samplers, decl->Range.Last + 1); break; case TGSI_FILE_INPUT: @@ -512,6 +598,14 @@ boolean svga_translate_decl_sm30( struct svga_shader_emitter *emit, ok = ps30_output( emit, decl->Semantic, idx ); break; + case TGSI_FILE_SAMPLER_VIEW: + { + unsigned unit = decl->Range.First; + assert(decl->Range.First == decl->Range.Last); + emit->sampler_target[unit] = decl->SamplerView.Resource; + } + break; + default: /* don't need to declare other vars */ ok = TRUE; @@ -523,6 +617,3 @@ boolean svga_translate_decl_sm30( struct svga_shader_emitter *emit, return TRUE; } - - -