/////////////////////////////////////////////////////////////////////// // Class : CStochastic // Method : CStochastic // Description : /// \brief Ctor // Return Value : - // Comments : CStochastic::CStochastic(int thread) : CReyes(thread), COcclusionCuller(), apertureGenerator(CRenderer::frame) { int i,j; float *cExtraSample; CPixel *cPixel; // The maximum width/height we should handle totalWidth = CRenderer::pixelXsamples*CRenderer::bucketWidth + 2*CRenderer::xSampleOffset; totalHeight = CRenderer::pixelYsamples*CRenderer::bucketHeight + 2*CRenderer::ySampleOffset; // Allocate the framebuffer for extra samples (checkpointed) if (CRenderer::numExtraSamples > 0) extraSampleMemory = (float *) ralloc(totalWidth*totalHeight*CRenderer::numExtraSamples*sizeof(float),CRenderer::globalMemory); else extraSampleMemory = NULL; // Allocate the pixels (checkpointed) cExtraSample = extraSampleMemory; fb = (CPixel **) ralloc(totalHeight*sizeof(CPixel *),CRenderer::globalMemory); for (i=0;i<totalHeight;i++) { cPixel = fb[i] = (CPixel *) ralloc(totalWidth*sizeof(CPixel),CRenderer::globalMemory); for (j=totalWidth;j>0;j--,cPixel++,cExtraSample+=CRenderer::numExtraSamples) { cPixel->last.extraSamples = cExtraSample; cPixel->first.extraSamples = NULL; } } // Init the fragment buffer freeFragments = NULL; numFragments = 0; // Initialize the occlusion culler initCuller(max(totalWidth,totalHeight), &maxDepth); }
/* * Append more text to a constant string, adding the same thing as 'str' */ cptr string_append(cptr base, cptr str) { huge len = 0; cptr t = base; char *s, *res; /* Simple sillyness */ if (!str) return (str); /* Get the number of chars in the string, including terminator */ while (base[len++]) /* loop */ ; while (str[len++]) /* loop */ ; /* Allocate space for the string */ s = res = (char *)(ralloc(len)); /* Copy the string (with terminator) */ while ((*s++ = *t++) != 0) /* loop */ ; s--; t = str; while ((*s++ = *t++) != 0) /* loop */ ; s = '\0'; /* Return the allocated, initialized, string */ return (res); }
static void genspill(Symbol r, Node last, Symbol tmp) { Node p, q; Symbol s; unsigned ty; debug(fprint(stderr, "(spilling %s to local %s)\n", r->x.name, tmp->x.name)); debug(fprint(stderr, "(genspill: ")); debug(dumptree(last)); debug(fprint(stderr, ")\n")); ty = opkind(last->op); NEW0(s, FUNC); s->sclass = REGISTER; s->name = s->x.name = r->x.name; s->x.regnode = r->x.regnode; q = newnode(ADDRL+P + sizeop(IR->ptrmetric.size), NULL, NULL, s); q = newnode(INDIR + ty, q, NULL, NULL); p = newnode(ADDRL+P + sizeop(IR->ptrmetric.size), NULL, NULL, tmp); p = newnode(ASGN + ty, p, q, NULL); p->x.spills = 1; rewrite(p); prune(p, &q); q = last->x.next; linearize(p, q); for (p = last->x.next; p != q; p = p->x.next) { ralloc(p); assert(!p->x.listed || !NeedsReg[opindex(p->op)] || !(*IR->x.rmap)(opkind(p->op))); } }
/* change number of samples allocated in ring buffer */ void changeSmpls(Expr **p, int nsmpls) { Expr *x = *p; Metric *m; int i; if (nsmpls == x->nsmpls) return; x = (Expr *) ralloc(x, sizeof(Expr) + (nsmpls - 1) * sizeof(Sample)); x->nsmpls = nsmpls; x->nvals = x->tspan * nsmpls; x->valid = 0; if (x->op == CND_FETCH) { /* node relocated, fix pointers from associated Metric structures */ m = x->metrics; for (i = 0; i < x->hdom; i++) { m->expr = x; m++; } } /* * we have relocated node from *p to x ... need to fix the * parent pointers in any descendent nodes */ if (x->arg1 != NULL) x->arg1->parent = x; if (x->arg2 != NULL) x->arg2->parent = x; *p = x; newRingBfr(x); }
Shader_Arg *alloc_Shader_argv( region_p R, int argc, Shader_Param *params ) { int size = sizeof(GLint); // Terminate the buffer w/ a -1 sentinel // First figure out total size for( int i=0; i<argc; i++ ) size += sizeof(Shader_Arg) + sizeof_Shade_Type(params[i].type); // Allocate argv and initialize structure Shader_Arg *argv = ralloc( R, size ); // Terminate the buffer with a negative location *(GLint*)((pointer)argv + size - sizeof(GLint)) = -1; Shader_Arg *arg = argv; for( int i=0; i<argc; i++ ) { arg->loc = params[i].loc; arg->type = params[i].type; arg->var = NULL; // Initialize the const value to some the type default pointer defaultValue = get_shader_default_initializer( arg->type.glType ); int elementSize = sizeof_Shade_Type( arg->type) / arg->type.count; for( int j=0; j<arg->type.count; j++ ) memcpy( arg->value + j*elementSize, defaultValue, elementSize ); arg = _next_Shader_Arg_unchecked( arg ); } return argv; }
Font *font_load(const char *filename) { Font *font; if (fontlib == NULL) { if (FT_Init_FreeType(&fontlib) != 0) { log_err("Error initializing FreeType 2\n"); return NULL; } atexit(fontlib_destroy); } if ((font = ralloc(NULL, Font)) == NULL) { log_err("Out of memory\n"); return NULL; } if (FT_New_Face(fontlib, filename, 0, &font->face) != 0) { log_err("Error initializing font %s\n", filename); ralloc_free(font); return NULL; } log_dbg("Loaded font with %ld glyphs\n", font->face->num_glyphs); return font; }
struct slab *sl_new(struct pool * p, uint size) { struct slab *s = ralloc(p, &sl_class); s->size = size; init_list(&s->objs); return s; }
forceinline T* Heap::alloc(long unsigned int n) { T* p = static_cast<T*>(ralloc(sizeof(T)*n)); for (long unsigned int i=n; i--; ) (void) new (p+i) T(); return p; }
struct timer2 * tm2_new(struct pool *p) { struct timer2 *t = ralloc(p, &tm2_class); t->index = -1; return t; }
/* * Allocate some memory and remember the pointer used. */ static vptr safe_malloc(huge len) { vptr *np = get_alloc_pointer(NULL); *np = ralloc(len); return *np; }
static void worklist_push(struct exec_list *worklist, nir_instr *instr) { worklist_elem *elem = ralloc(worklist, worklist_elem); elem->instr = instr; instr->pass_flags = 1; exec_list_push_tail(worklist, &elem->node); }
// Create a single rectanglular region t_region *create_rect_region(long x, long y, long right, long bottom) { t_region *region; region = ralloc(NULL); SetRect(®ion->rcRegion, x, y, right, bottom); return region; }
slab * sl_new(pool *p, unsigned size) { slab *s = ralloc(p, &sl_class); s->size = size; init_list(&s->objs); return s; }
int extractFrame(CWProtocolMessage ** frame, unsigned char *buffer, int len) //len: frame length including prism header { if (!(*frame = ralloc(NULL, CWProtocolMessage))) return 0; CWProtocolMessage *auxPtr = *frame; CW_CREATE_PROTOCOL_MESSAGE(ctx, *auxPtr, len - PRISMH_LEN, return 0; );
void bufaddc(buf_s *b, char c) { b->size++; if(b->size > b->bsize) { b->bsize *= 2; b->buf = ralloc(b->buf, b->size); } b->buf[b->size - 1] = c; }
Scene* new_Scene( region_p R ) { Scene* sc = ralloc( R, sizeof(Scene) ); sc->R = R; sc->buckets = new_Map( ZONE_heap, hashSize ); return sc; }
void x86_block::x86_buffer_ensure(u32 size) { if (this->x86_size<(size+x86_indx)) { verify(do_realloc!=false); u32 old_size=x86_size; x86_size+=128; x86_size*=2; x86_buff=(u8*)ralloc(x86_buff,old_size,x86_size); } }
forceinline T* Heap::realloc(T* b, long unsigned int n, long unsigned int m) { if (n == m) return b; T* p = static_cast<T*>(ralloc(sizeof(T)*m)); for (long unsigned int i=std::min(n,m); i--; ) (void) new (p+i) T(b[i]); for (long unsigned int i=n; i<m; i++) (void) new (p+i) T(); free<T>(b,n); return p; }
void bufaddstr(buf_s *b, char *str, size_t len) { b->size += len; if(b->size > b->bsize) { do { b->bsize *= 2; } while(b->size > b->bsize); b->buf = ralloc(b->buf, b->bsize); } strcpy(&b->buf[b->size - len], str); }
static nir_constant * read_constant(read_ctx *ctx, nir_variable *nvar) { nir_constant *c = ralloc(nvar, nir_constant); blob_copy_bytes(ctx->blob, (uint8_t *)c->values, sizeof(c->values)); c->num_elements = blob_read_uint32(ctx->blob); c->elements = ralloc_array(nvar, nir_constant *, c->num_elements); for (unsigned i = 0; i < c->num_elements; i++) c->elements[i] = read_constant(ctx, nvar); return c; }
static void extend_cur_line() { char *new_line; /* extent input line length */ new_line=ralloc(cur_line, line_len+MAXBUF, NULL); if(!new_line) { reset_termio(); int_error("Can't extend readline length", NO_CARET); } cur_line=new_line; line_len+=MAXBUF; }
nir_constant * nir_constant_clone(const nir_constant *c, nir_variable *nvar) { nir_constant *nc = ralloc(nvar, nir_constant); memcpy(nc->values, c->values, sizeof(nc->values)); nc->num_elements = c->num_elements; nc->elements = ralloc_array(nvar, nir_constant *, c->num_elements); for (unsigned i = 0; i < c->num_elements; i++) { nc->elements[i] = nir_constant_clone(c->elements[i], nvar); } return nc; }
static nir_src get_deref_reg_src(nir_deref_instr *deref, struct locals_to_regs_state *state) { nir_builder *b = &state->builder; nir_src src; src.is_ssa = false; src.reg.reg = get_reg_for_deref(deref, state); src.reg.base_offset = 0; src.reg.indirect = NULL; /* It is possible for a user to create a shader that has an array with a * single element and then proceed to access it indirectly. Indirectly * accessing a non-array register is not allowed in NIR. In order to * handle this case we just convert it to a direct reference. */ if (src.reg.reg->num_array_elems == 0) return src; unsigned inner_array_size = 1; for (const nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) { if (d->deref_type != nir_deref_type_array) continue; if (nir_src_is_const(d->arr.index) && !src.reg.indirect) { src.reg.base_offset += nir_src_as_uint(d->arr.index) * inner_array_size; } else { if (src.reg.indirect) { assert(src.reg.base_offset == 0); } else { src.reg.indirect = ralloc(b->shader, nir_src); *src.reg.indirect = nir_src_for_ssa(nir_imm_int(b, src.reg.base_offset)); src.reg.base_offset = 0; } assert(src.reg.indirect->is_ssa); nir_ssa_def *index = nir_i2i(b, nir_ssa_for_src(b, d->arr.index, 1), 32); src.reg.indirect->ssa = nir_iadd(b, src.reg.indirect->ssa, nir_imul(b, index, nir_imm_int(b, inner_array_size))); } inner_array_size *= glsl_get_length(nir_deref_instr_parent(d)->type); } return src; }
void gen6_gs_visitor::visit(ir_end_primitive *) { this->current_annotation = "gen6 end primitive"; /* Calling EndPrimitive() is optional for point output. In this case we set * the PrimEnd flag when we process EmitVertex(). */ if (c->gp->program.OutputType == GL_POINTS) return; /* Otherwise we know that the last vertex we have processed was the last * vertex in the primitive and we need to set its PrimEnd flag, so do this * unless we haven't emitted that vertex at all (vertex_count != 0). * * Notice that we have already incremented vertex_count when we processed * the last emit_vertex, so we need to take that into account in the * comparison below (hence the num_output_vertices + 1 in the comparison * below). */ unsigned num_output_vertices = c->gp->program.VerticesOut; emit(CMP(dst_null_d(), this->vertex_count, src_reg(num_output_vertices + 1), BRW_CONDITIONAL_L)); vec4_instruction *inst = emit(CMP(dst_null_d(), this->vertex_count, 0u, BRW_CONDITIONAL_NEQ)); inst->predicate = BRW_PREDICATE_NORMAL; emit(IF(BRW_PREDICATE_NORMAL)); { /* vertex_output_offset is already pointing at the first entry of the * next vertex. So subtract 1 to modify the flags for the previous * vertex. */ src_reg offset(this, glsl_type::uint_type); emit(ADD(dst_reg(offset), this->vertex_output_offset, src_reg(-1))); src_reg dst(this->vertex_output); dst.reladdr = ralloc(mem_ctx, src_reg); memcpy(dst.reladdr, &offset, sizeof(src_reg)); emit(OR(dst_reg(dst), dst, URB_WRITE_PRIM_END)); emit(ADD(dst_reg(this->prim_count), this->prim_count, 1u)); /* Set the first vertex flag to indicate that the next vertex will start * a primitive. */ emit(MOV(dst_reg(this->first_vertex), URB_WRITE_PRIM_START)); } emit(BRW_OPCODE_ENDIF); }
/* pragmatics analysis */ void pragmatics(Symbol rule, RealTime delta) { Expr *x = symValue(rule); Task *t; if (x->op != NOP) { t = findTask(delta); bundle(t, x); t->nrules++; t->rules = (Symbol *) ralloc(t->rules, t->nrules * sizeof(Symbol)); t->rules[t->nrules-1] = symCopy(rule); perf->eval_expected += (float)1/delta; } }
Drawable* new_Drawable_indexed( region_p R, uint count, Vindex* els, Varray* geo, drawMode_e mode ) { Drawable* dr = ralloc( R, sizeof(Drawable) ); dr->mode = mode; dr->count = count; dr->els = els; dr->geo = geo; return dr; }
/* * Allocate a constant string, containing the same thing as 'str' */ cptr string_make(cptr str) { char *res; /* Simple sillyness */ if (!str) return (str); /* Allocate space for the string including terminator */ res = ralloc(strlen(str) + 1); /* Copy the string (with terminator) */ strcpy(res, str); /* Return the allocated and initialized string */ return (res); }
Node gen(Node forest) { int i; struct node sentinel; Node dummy, p; head = forest; for (p = forest; p; p = p->link) { assert(p->count == 0); if (generic(p->op) == CALL) docall(p); else if ( generic(p->op) == ASGN && generic(p->kids[1]->op) == CALL) docall(p->kids[1]); else if (generic(p->op) == ARG) (*IR->x.doarg)(p); rewrite(p); p->x.listed = 1; } for (p = forest; p; p = p->link) prune(p, &dummy); relink(&sentinel, &sentinel); for (p = forest; p; p = p->link) linearize(p, &sentinel); forest = sentinel.x.next; assert(forest); sentinel.x.next->x.prev = NULL; sentinel.x.prev->x.next = NULL; for (p = forest; p; p = p->x.next) for (i = 0; i < NELEMS(p->x.kids) && p->x.kids[i]; i++) { assert(p->x.kids[i]->syms[RX]); if (p->x.kids[i]->syms[RX]->temporary) { p->x.kids[i]->x.prevuse = p->x.kids[i]->syms[RX]->x.lastuse; p->x.kids[i]->syms[RX]->x.lastuse = p->x.kids[i]; } } for (p = forest; p; p = p->x.next) { ralloc(p); if (p->x.listed && NeedsReg[opindex(p->op)] && (*IR->x.rmap)(opkind(p->op))) { assert(generic(p->op) == CALL || generic(p->op) == LOAD); putreg(p->syms[RX]); } } return forest; }
void ppir_node_add_dep(ppir_node *succ, ppir_node *pred) { /* don't add dep for two nodes from different block */ if (succ->block != pred->block) return; /* don't add duplicated dep */ ppir_node_foreach_pred(succ, dep) { if (dep->pred == pred) return; } ppir_dep *dep = ralloc(succ, ppir_dep); dep->pred = pred; dep->succ = succ; list_addtail(&dep->pred_link, &succ->pred_list); list_addtail(&dep->succ_link, &pred->succ_list); }
Visual* link_Scene( Scene* sc, pointer tag, uint32 mask, Drawable* dr, Shader_Arg* argv ) { struct Bucket* bucket = lookup_Map( sc->buckets, sizeof( tag ), &tag ); if( NULL == bucket ) { // Create a new bucket bucket = ralloc( sc->R, sizeof(struct Bucket) ); bucket->visuals = new_Vector( ZONE_heap, sizeof(Visual), bucketSize ); bucket->freelist = NULL; put_Map( sc->buckets, sizeof(tag), &tag, bucket ); } // Stick it in the bucket Visual* vis = NULL; if( bucket->freelist ) { vis = bucket->freelist; bucket->freelist = vis->next; } else vis = (Visual*)push_back_Vector( bucket->visuals ); vis->tag = tag; vis->mask = mask; vis->draw = dr; vis->argv = argv; vis->next = NULL; return vis; }