static void * svga_create_gs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct svga_context *svga = svga_context(pipe); struct svga_geometry_shader *gs = CALLOC_STRUCT(svga_geometry_shader); if (!gs) return NULL; SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATEGS); gs->base.tokens = tgsi_dup_tokens(templ->tokens); /* Collect basic info that we'll need later: */ tgsi_scan_shader(gs->base.tokens, &gs->base.info); gs->draw_shader = draw_create_geometry_shader(svga->swtnl.draw, templ); gs->base.id = svga->debug.shader_id++; gs->generic_outputs = svga_get_generic_outputs_mask(&gs->base.info); /* check for any stream output declarations */ if (templ->stream_output.num_outputs) { gs->base.stream_output = svga_create_stream_output(svga, &gs->base, &templ->stream_output); } SVGA_STATS_TIME_POP(svga_sws(svga)); return gs; }
static void * svga_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct svga_context *svga = svga_context(pipe); struct svga_screen *svgascreen = svga_screen(pipe->screen); struct svga_fragment_shader *fs; fs = CALLOC_STRUCT(svga_fragment_shader); if (!fs) return NULL; fs->base.tokens = tgsi_dup_tokens(templ->tokens); /* Collect basic info that we'll need later: */ tgsi_scan_shader(fs->base.tokens, &fs->base.info); fs->base.id = svga->debug.shader_id++; fs->base.use_sm30 = svgascreen->use_ps30; if (SVGA_DEBUG & DEBUG_TGSI || 0) { debug_printf("%s id: %u, inputs: %u, outputs: %u\n", __FUNCTION__, fs->base.id, fs->base.info.num_inputs, fs->base.info.num_outputs); } return fs; }
static void * fd2_vp_state_create(struct pipe_context *pctx, const struct pipe_shader_state *cso) { struct fd2_shader_stateobj *so = create_shader(SHADER_VERTEX); if (!so) return NULL; so->tokens = tgsi_dup_tokens(cso->tokens); return so; }
static void * nv50_gp_state_create(struct pipe_context *pipe, const struct pipe_shader_state *cso) { struct nv50_program *p = CALLOC_STRUCT(nv50_program); p->pipe.tokens = tgsi_dup_tokens(cso->tokens); p->type = PIPE_SHADER_GEOMETRY; tgsi_scan_shader(p->pipe.tokens, &p->info); return (void *)p; }
static void * nv30_vp_state_create(struct pipe_context *pipe, const struct pipe_shader_state *cso) { struct nv30_vertprog *vp = CALLOC_STRUCT(nv30_vertprog); if (!vp) return NULL; vp->pipe.tokens = tgsi_dup_tokens(cso->tokens); tgsi_scan_shader(vp->pipe.tokens, &vp->info); return vp; }
static void * nv30_fp_state_create(struct pipe_context *pipe, const struct pipe_shader_state *cso) { struct nv30_fragprog *fp = CALLOC_STRUCT(nv30_fragprog); if (!fp) return NULL; fp->pipe.tokens = tgsi_dup_tokens(cso->tokens); tgsi_scan_shader(fp->pipe.tokens, &fp->info); return fp; }
struct draw_geometry_shader * draw_create_geometry_shader(struct draw_context *draw, const struct pipe_shader_state *state) { struct draw_geometry_shader *gs; int i; gs = CALLOC_STRUCT(draw_geometry_shader); if (!gs) return NULL; gs->draw = draw; gs->state = *state; gs->state.tokens = tgsi_dup_tokens(state->tokens); if (!gs->state.tokens) { FREE(gs); return NULL; } tgsi_scan_shader(state->tokens, &gs->info); /* setup the defaults */ gs->input_primitive = PIPE_PRIM_TRIANGLES; gs->output_primitive = PIPE_PRIM_TRIANGLE_STRIP; gs->max_output_vertices = 32; for (i = 0; i < gs->info.num_properties; ++i) { if (gs->info.properties[i].name == TGSI_PROPERTY_GS_INPUT_PRIM) gs->input_primitive = gs->info.properties[i].data[0]; else if (gs->info.properties[i].name == TGSI_PROPERTY_GS_OUTPUT_PRIM) gs->output_primitive = gs->info.properties[i].data[0]; else if (gs->info.properties[i].name == TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES) gs->max_output_vertices = gs->info.properties[i].data[0]; } gs->machine = draw->gs.tgsi.machine; if (gs) { uint i; for (i = 0; i < gs->info.num_outputs; i++) { if (gs->info.output_semantic_name[i] == TGSI_SEMANTIC_POSITION && gs->info.output_semantic_index[i] == 0) gs->position_output = i; } } return gs; }
static void * nv40_vp_state_create(struct pipe_context *pipe, const struct pipe_shader_state *cso) { struct nv40_context *nv40 = nv40_context(pipe); struct nv40_vertex_program *vp; vp = CALLOC(1, sizeof(struct nv40_vertex_program)); vp->pipe.tokens = tgsi_dup_tokens(cso->tokens); vp->draw = draw_create_vertex_shader(nv40->draw, &vp->pipe); return (void *)vp; }
static void * nv40_fp_state_create(struct pipe_context *pipe, const struct pipe_shader_state *cso) { struct nv40_fragment_program *fp; fp = CALLOC(1, sizeof(struct nv40_fragment_program)); fp->pipe.tokens = tgsi_dup_tokens(cso->tokens); tgsi_scan_shader(fp->pipe.tokens, &fp->info); return (void *)fp; }
void *r600_create_shader_state(struct pipe_context *ctx, const struct pipe_shader_state *state) { struct r600_pipe_shader *shader = CALLOC_STRUCT(r600_pipe_shader); int r; shader->tokens = tgsi_dup_tokens(state->tokens); shader->so = state->stream_output; r = r600_pipe_shader_create(ctx, shader); if (r) { return NULL; } return shader; }
static void * nvc0_sp_state_create(struct pipe_context *pipe, const struct pipe_shader_state *cso, unsigned type) { struct nvc0_program *prog; prog = CALLOC_STRUCT(nvc0_program); if (!prog) return NULL; prog->type = type; prog->pipe.tokens = tgsi_dup_tokens(cso->tokens); return (void *)prog; }
/* Create fragment shader state. */ static void* r300_create_fs_state(struct pipe_context* pipe, const struct pipe_shader_state* shader) { struct r300_fragment_shader* fs = NULL; fs = (struct r300_fragment_shader*)CALLOC_STRUCT(r300_fragment_shader); /* Copy state directly into shader. */ fs->state = *shader; fs->state.tokens = tgsi_dup_tokens(shader->tokens); tgsi_scan_shader(shader->tokens, &fs->info); return (void*)fs; }
void * rbug_shader_create(struct rbug_context *rb_context, const struct pipe_shader_state *state, void *result, enum rbug_shader_type type) { struct rbug_shader *rb_shader = CALLOC_STRUCT(rbug_shader); rb_shader->type = type; rb_shader->shader = result; rb_shader->tokens = tgsi_dup_tokens(state->tokens); /* works on context as well since its just a macro */ rbug_screen_add_to_list(rb_context, shaders, rb_shader); return rb_shader; }
/** * This function overrides the driver's create_fs_state() function and * will typically be called by the state tracker. */ static void * aapoint_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *fs) { struct aapoint_stage *aapoint = aapoint_stage_from_pipe(pipe); struct aapoint_fragment_shader *aafs = CALLOC_STRUCT(aapoint_fragment_shader); if (aafs == NULL) return NULL; aafs->state.tokens = tgsi_dup_tokens(fs->tokens); /* pass-through */ aafs->driver_fs = aapoint->driver_create_fs_state(pipe, fs); return aafs; }
/** * This function overrides the driver's create_fs_state() function and * will typically be called by the state tracker. */ static void * pstip_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *fs) { struct pstip_stage *pstip = pstip_stage_from_pipe(pipe); struct pstip_fragment_shader *pstipfs = CALLOC_STRUCT(pstip_fragment_shader); if (pstipfs) { pstipfs->state.tokens = tgsi_dup_tokens(fs->tokens); /* pass-through */ pstipfs->driver_fs = pstip->driver_create_fs_state(pstip->pipe, fs); } return pstipfs; }
struct trace_shader * trace_shader_create(struct trace_context *tr_ctx, const struct pipe_shader_state *state, void *result, enum trace_shader_type type) { struct trace_shader *tr_shdr = CALLOC_STRUCT(trace_shader); tr_shdr->state = result; tr_shdr->type = type; tr_shdr->tokens = tgsi_dup_tokens(state->tokens); /* works on context as well */ trace_screen_add_to_list(tr_ctx, shaders, tr_shdr); return tr_shdr; }
/** * Create a new fragment shader variant. */ static struct sp_fragment_shader_variant * create_fs_variant(struct softpipe_context *softpipe, struct sp_fragment_shader *fs, const struct sp_fragment_shader_variant_key *key) { struct sp_fragment_shader_variant *var; struct pipe_shader_state *curfs = &fs->shader; /* codegen, create variant object */ var = softpipe_create_fs_variant_exec(softpipe); if (var) { var->key = *key; #if DO_PSTIPPLE_IN_HELPER_MODULE if (key->polygon_stipple) { /* get new shader that implements polygon stippling */ var->tokens = util_pstipple_create_fragment_shader(curfs->tokens, &var->stipple_sampler_unit, 0, TGSI_FILE_INPUT); } else #endif { var->tokens = tgsi_dup_tokens(curfs->tokens); var->stipple_sampler_unit = 0; } tgsi_scan_shader(var->tokens, &var->info); /* See comments elsewhere about draw fragment shaders */ #if 0 /* draw's fs state */ var->draw_shader = draw_create_fragment_shader(softpipe->draw, &fs->shader); if (!var->draw_shader) { var->delete(var); FREE((void *) var->tokens); return NULL; } #endif /* insert variant into linked list */ var->next = fs->variants; fs->variants = var; }
static void *brw_create_fs_state( struct pipe_context *pipe, const struct pipe_shader_state *shader ) { struct brw_context *brw = brw_context(pipe); struct brw_fragment_shader *fs; int i; fs = CALLOC_STRUCT(brw_fragment_shader); if (fs == NULL) return NULL; /* Duplicate tokens, scan shader */ fs->id = brw->program_id++; fs->has_flow_control = has_flow_control(&fs->info); fs->tokens = tgsi_dup_tokens(shader->tokens); if (fs->tokens == NULL) goto fail; tgsi_scan_shader(fs->tokens, &fs->info); scan_immediates(fs->tokens, &fs->info, &fs->immediates); fs->signature.nr_inputs = fs->info.num_inputs; for (i = 0; i < fs->info.num_inputs; i++) { fs->signature.input[i].interp = fs->info.input_interpolate[i]; fs->signature.input[i].semantic = fs->info.input_semantic_name[i]; fs->signature.input[i].semantic_index = fs->info.input_semantic_index[i]; } for (i = 0; i < fs->info.num_inputs; i++) if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_POSITION) fs->uses_depth = 1; if (fs->info.uses_kill) fs->iz_lookup |= IZ_PS_KILL_ALPHATEST_BIT; if (fs->info.writes_z) fs->iz_lookup |= IZ_PS_COMPUTES_DEPTH_BIT; return (void *)fs; fail: FREE(fs); return NULL; }
static void * \ dd_context_create_compute_state(struct pipe_context *_pipe, const struct pipe_compute_state *state) { struct pipe_context *pipe = dd_context(_pipe)->pipe; struct dd_state *hstate = CALLOC_STRUCT(dd_state); if (!hstate) return NULL; hstate->cso = pipe->create_compute_state(pipe, state); hstate->state.shader.type = state->ir_type; if (state->ir_type == PIPE_SHADER_IR_TGSI) hstate->state.shader.tokens = tgsi_dup_tokens(state->prog); return hstate; }
void * llvmpipe_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct lp_fragment_shader *shader; shader = CALLOC_STRUCT(lp_fragment_shader); if (!shader) return NULL; /* get/save the summary info for this shader */ tgsi_scan_shader(templ->tokens, &shader->info); /* we need to keep a local copy of the tokens */ shader->base.tokens = tgsi_dup_tokens(templ->tokens); return shader; }
static void * i915_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct i915_context *i915 = i915_context(pipe); struct i915_fragment_shader *ifs = CALLOC_STRUCT(i915_fragment_shader); if (!ifs) return NULL; ifs->state.tokens = tgsi_dup_tokens(templ->tokens); tgsi_scan_shader(templ->tokens, &ifs->info); /* The shader's compiled to i915 instructions here */ i915_translate_fragment_program(i915, ifs); return ifs; }
static void * llvmpipe_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct lp_fragment_shader *shader; int nr_samplers; shader = CALLOC_STRUCT(lp_fragment_shader); if (!shader) return NULL; shader->no = fs_no++; make_empty_list(&shader->variants); /* get/save the summary info for this shader */ tgsi_scan_shader(templ->tokens, &shader->info); /* we need to keep a local copy of the tokens */ shader->base.tokens = tgsi_dup_tokens(templ->tokens); nr_samplers = shader->info.file_max[TGSI_FILE_SAMPLER] + 1; shader->variant_key_size = Offset(struct lp_fragment_shader_variant_key, sampler[nr_samplers]); if (LP_DEBUG & DEBUG_TGSI) { unsigned attrib; debug_printf("llvmpipe: Create fragment shader #%u %p:\n", shader->no, (void *) shader); tgsi_dump(templ->tokens, 0); debug_printf("usage masks:\n"); for (attrib = 0; attrib < shader->info.num_inputs; ++attrib) { unsigned usage_mask = shader->info.input_usage_mask[attrib]; debug_printf(" IN[%u].%s%s%s%s\n", attrib, usage_mask & TGSI_WRITEMASK_X ? "x" : "", usage_mask & TGSI_WRITEMASK_Y ? "y" : "", usage_mask & TGSI_WRITEMASK_Z ? "z" : "", usage_mask & TGSI_WRITEMASK_W ? "w" : ""); } debug_printf("\n"); } return shader; }
static void * nvc0_cp_state_create(struct pipe_context *pipe, const struct pipe_compute_state *cso) { struct nvc0_program *prog; prog = CALLOC_STRUCT(nvc0_program); if (!prog) return NULL; prog->type = PIPE_SHADER_COMPUTE; prog->cp.smem_size = cso->req_local_mem; prog->cp.lmem_size = cso->req_private_mem; prog->parm_size = cso->req_input_mem; prog->pipe.tokens = tgsi_dup_tokens((const struct tgsi_token *)cso->prog); return (void *)prog; }
static void * svga_create_vs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct svga_context *svga = svga_context(pipe); struct svga_vertex_shader *vs = CALLOC_STRUCT(svga_vertex_shader); if (!vs) return NULL; SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_CREATEVS); /* substitute a debug shader? */ vs->base.tokens = tgsi_dup_tokens(substitute_vs(svga->debug.shader_id, templ->tokens)); /* Collect basic info that we'll need later: */ tgsi_scan_shader(vs->base.tokens, &vs->base.info); { /* Need to do construct a new template in case we substitued a * debug shader. */ struct pipe_shader_state tmp2 = *templ; tmp2.tokens = vs->base.tokens; vs->draw_shader = draw_create_vertex_shader(svga->swtnl.draw, &tmp2); } vs->base.id = svga->debug.shader_id++; vs->generic_outputs = svga_get_generic_outputs_mask(&vs->base.info); /* check for any stream output declarations */ if (templ->stream_output.num_outputs) { vs->base.stream_output = svga_create_stream_output(svga, &vs->base, &templ->stream_output); } SVGA_STATS_TIME_POP(svga_sws(svga)); return vs; }
static void* r300_create_vs_state(struct pipe_context* pipe, const struct pipe_shader_state* shader) { struct r300_context* r300 = r300_context(pipe); if (r300_screen(pipe->screen)->caps->has_tcl) { struct r300_vertex_shader* vs = CALLOC_STRUCT(r300_vertex_shader); /* Copy state directly into shader. */ vs->state = *shader; vs->state.tokens = tgsi_dup_tokens(shader->tokens); tgsi_scan_shader(shader->tokens, &vs->info); /* Appease Draw. */ vs->draw = draw_create_vertex_shader(r300->draw, shader); return (void*)vs; } else { return draw_create_vertex_shader(r300->draw, shader); } }
static void * svga_create_vs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct svga_context *svga = svga_context(pipe); struct svga_screen *svgascreen = svga_screen(pipe->screen); struct svga_vertex_shader *vs = CALLOC_STRUCT(svga_vertex_shader); if (!vs) return NULL; /* substitute a debug shader? */ vs->base.tokens = tgsi_dup_tokens(substitute_vs(svga->debug.shader_id, templ->tokens)); /* Collect basic info that we'll need later: */ tgsi_scan_shader(vs->base.tokens, &vs->base.info); { /* Need to do construct a new template in case we substitued a * debug shader. */ struct pipe_shader_state tmp2 = *templ; tmp2.tokens = vs->base.tokens; vs->draw_shader = draw_create_vertex_shader(svga->swtnl.draw, &tmp2); } vs->base.id = svga->debug.shader_id++; vs->base.use_sm30 = svgascreen->use_vs30; if (SVGA_DEBUG & DEBUG_TGSI || 0) { debug_printf("%s id: %u, inputs: %u, outputs: %u\n", __FUNCTION__, vs->base.id, vs->base.info.num_inputs, vs->base.info.num_outputs); } return vs; }
static void * nv50_sp_state_create(struct pipe_context *pipe, const struct pipe_shader_state *cso, unsigned type) { struct nv50_program *prog; prog = CALLOC_STRUCT(nv50_program); if (!prog) return NULL; prog->type = type; prog->pipe.tokens = tgsi_dup_tokens(cso->tokens); if (cso->stream_output.num_outputs) prog->pipe.stream_output = cso->stream_output; prog->translated = nv50_program_translate( prog, nv50_context(pipe)->screen->base.device->chipset, &nouveau_context(pipe)->debug); return (void *)prog; }
static void * llvmpipe_create_gs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); struct lp_geometry_shader *state; state = CALLOC_STRUCT(lp_geometry_shader); if (state == NULL ) goto fail; /* debug */ if (0) tgsi_dump(templ->tokens, 0); /* copy stream output info */ state->shader = *templ; if (templ->tokens) { /* copy shader tokens, the ones passed in will go away. */ state->shader.tokens = tgsi_dup_tokens(templ->tokens); if (state->shader.tokens == NULL) goto fail; state->draw_data = draw_create_geometry_shader(llvmpipe->draw, templ); if (state->draw_data == NULL) goto fail; } return state; fail: if (state) { FREE( (void *)state->shader.tokens ); FREE( state->draw_data ); FREE( state ); } return NULL; }
/** * Create fragment shader state. * Called via pipe->create_fs_state() */ static void * cell_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { struct cell_context *cell = cell_context(pipe); struct cell_fragment_shader_state *cfs; cfs = CALLOC_STRUCT(cell_fragment_shader_state); if (!cfs) return NULL; cfs->shader.tokens = tgsi_dup_tokens(templ->tokens); if (!cfs->shader.tokens) { FREE(cfs); return NULL; } tgsi_scan_shader(templ->tokens, &cfs->info); cell_gen_fragment_program(cell, cfs->shader.tokens, &cfs->code); return cfs; }
static void * nvc0_cp_state_create(struct pipe_context *pipe, const struct pipe_compute_state *cso) { struct nvc0_program *prog; prog = CALLOC_STRUCT(nvc0_program); if (!prog) return NULL; prog->type = PIPE_SHADER_COMPUTE; prog->cp.smem_size = cso->req_local_mem; prog->cp.lmem_size = cso->req_private_mem; prog->parm_size = cso->req_input_mem; prog->pipe.tokens = tgsi_dup_tokens((const struct tgsi_token *)cso->prog); prog->translated = nvc0_program_translate( prog, nvc0_context(pipe)->screen->base.device->chipset, &nouveau_context(pipe)->debug); return (void *)prog; }