static enum pipe_error upload_sf_vp(struct brw_context *brw) { const struct pipe_viewport_state *vp = &brw->curr.viewport; const struct pipe_scissor_state *scissor = &brw->curr.scissor; struct brw_sf_viewport sfv; enum pipe_error ret; memset(&sfv, 0, sizeof(sfv)); /* PIPE_NEW_VIEWPORT, PIPE_NEW_SCISSOR */ sfv.viewport.m00 = vp->scale[0]; sfv.viewport.m11 = vp->scale[1]; sfv.viewport.m22 = vp->scale[2]; sfv.viewport.m30 = vp->translate[0]; sfv.viewport.m31 = vp->translate[1]; sfv.viewport.m32 = vp->translate[2]; sfv.scissor.xmin = scissor->minx; sfv.scissor.xmax = scissor->maxx - 1; /* ? */ sfv.scissor.ymin = scissor->miny; sfv.scissor.ymax = scissor->maxy - 1; /* ? */ ret = brw_cache_data( &brw->cache, BRW_SF_VP, &sfv, NULL, 0, &brw->sf.vp_bo ); if (ret) return ret; return PIPE_OK; }
static unsigned upload_default_color( struct brw_context *brw, const float *color ) { struct brw_sampler_default_color sdc; COPY_4V(sdc.color, color); return brw_cache_data( &brw->cache[BRW_SAMPLER_DEFAULT_COLOR], &sdc ); }
static dri_bo *upload_default_color( struct brw_context *brw, const GLfloat *color ) { struct brw_sampler_default_color sdc; COPY_4V(sdc.color, color); return brw_cache_data( &brw->cache, BRW_SAMPLER_DEFAULT_COLOR, &sdc, NULL, 0 ); }
static void upload_cc_vp( struct brw_context *brw ) { struct brw_cc_viewport ccv; memset(&ccv, 0, sizeof(ccv)); ccv.min_depth = 0.0; ccv.max_depth = 1.0; brw->cc.vp_gs_offset = brw_cache_data( &brw->cache[BRW_CC_VP], &ccv ); }
static void upload_vs_unit( struct brw_context *brw ) { struct brw_vs_unit_state vs; memset(&vs, 0, sizeof(vs)); /* CACHE_NEW_VS_PROG */ vs.thread0.kernel_start_pointer = brw->vs.prog_gs_offset >> 6; vs.thread0.grf_reg_count = ALIGN(brw->vs.prog_data->total_grf, 16) / 16 - 1; vs.thread3.urb_entry_read_length = brw->vs.prog_data->urb_read_length; vs.thread3.const_urb_entry_read_length = brw->vs.prog_data->curb_read_length; vs.thread3.dispatch_grf_start_reg = 1; /* BRW_NEW_URB_FENCE */ vs.thread4.nr_urb_entries = brw->urb.nr_vs_entries; vs.thread4.urb_entry_allocation_size = brw->urb.vsize - 1; vs.thread4.max_threads = MIN2( MAX2(0, (brw->urb.nr_vs_entries - 6) / 2 - 1), 15); if (INTEL_DEBUG & DEBUG_SINGLE_THREAD) vs.thread4.max_threads = 0; /* BRW_NEW_CURBE_OFFSETS, _NEW_TRANSFORM */ if (brw->attribs.Transform->ClipPlanesEnabled) { /* Note that we read in the userclip planes as well, hence * clip_start: */ vs.thread3.const_urb_entry_read_offset = brw->curbe.clip_start * 2; } else { vs.thread3.const_urb_entry_read_offset = brw->curbe.vs_start * 2; } vs.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; vs.thread3.urb_entry_read_offset = 0; /* No samplers for ARB_vp programs: */ vs.vs5.sampler_count = 0; if (INTEL_DEBUG & DEBUG_STATS) vs.thread4.stats_enable = 1; /* Vertex program always enabled: */ vs.vs6.vs_enable = 1; brw->vs.state_gs_offset = brw_cache_data( &brw->cache[BRW_VS_UNIT], &vs ); }
static void prepare_cc_vp( struct brw_context *brw ) { struct brw_cc_viewport ccv; memset(&ccv, 0, sizeof(ccv)); ccv.min_depth = 0.0; ccv.max_depth = 1.0; dri_bo_unreference(brw->cc.vp_bo); brw->cc.vp_bo = brw_cache_data( &brw->cache, BRW_CC_VP, &ccv, NULL, 0 ); }
static void upload_clip_unit( struct brw_context *brw ) { struct brw_clip_unit_state clip; memset(&clip, 0, sizeof(clip)); /* CACHE_NEW_CLIP_PROG */ clip.thread0.grf_reg_count = ALIGN(brw->clip.prog_data->total_grf, 16) / 16 - 1; clip.thread0.kernel_start_pointer = brw->clip.prog_gs_offset >> 6; clip.thread3.urb_entry_read_length = brw->clip.prog_data->urb_read_length; clip.thread3.const_urb_entry_read_length = brw->clip.prog_data->curb_read_length; clip.clip5.clip_mode = brw->clip.prog_data->clip_mode; /* BRW_NEW_CURBE_OFFSETS */ clip.thread3.const_urb_entry_read_offset = brw->curbe.clip_start * 2; /* BRW_NEW_URB_FENCE */ clip.thread4.nr_urb_entries = brw->urb.nr_clip_entries; clip.thread4.urb_entry_allocation_size = brw->urb.vsize - 1; clip.thread4.max_threads = 1; /* 2 threads */ if (INTEL_DEBUG & DEBUG_STATS) clip.thread4.stats_enable = 1; /* CONSTANT */ clip.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; clip.thread1.single_program_flow = 1; clip.thread3.dispatch_grf_start_reg = 1; clip.thread3.urb_entry_read_offset = 0; clip.clip5.userclip_enable_flags = 0x7f; clip.clip5.userclip_must_clip = 1; clip.clip5.guard_band_enable = 0; clip.clip5.viewport_z_clip_enable = 1; clip.clip5.viewport_xy_clip_enable = 1; clip.clip5.vertex_position_space = BRW_CLIP_NDCSPACE; clip.clip5.api_mode = BRW_CLIP_API_OGL; if (BRW_IS_GM45(brw) || BRW_IS_G4X(brw)) clip.clip5.negative_w_clip_test = 1; clip.clip6.clipper_viewport_state_ptr = 0; clip.viewport_xmin = -1; clip.viewport_xmax = 1; clip.viewport_ymin = -1; clip.viewport_ymax = 1; brw->clip.state_gs_offset = brw_cache_data( &brw->cache[BRW_CLIP_UNIT], &clip ); }
static void prepare_cc_vp( struct brw_context *brw ) { GLcontext *ctx = &brw->intel.ctx; struct brw_cc_viewport ccv; memset(&ccv, 0, sizeof(ccv)); /* _NEW_TRANSOFORM */ if (ctx->Transform.DepthClamp) { /* _NEW_VIEWPORT */ ccv.min_depth = MIN2(ctx->Viewport.Near, ctx->Viewport.Far); ccv.max_depth = MAX2(ctx->Viewport.Near, ctx->Viewport.Far); } else { ccv.min_depth = 0.0; ccv.max_depth = 1.0; } dri_bo_unreference(brw->cc.vp_bo); brw->cc.vp_bo = brw_cache_data(&brw->cache, BRW_CC_VP, &ccv, sizeof(ccv), NULL, 0); }
static void upload_sf_vp(struct brw_context *brw) { struct brw_sf_viewport sfv; memset(&sfv, 0, sizeof(sfv)); if (brw->intel.driDrawable) { /* _NEW_VIEWPORT, BRW_NEW_METAOPS */ if (!brw->metaops.active) { const GLfloat *v = brw->intel.ctx.Viewport._WindowMap.m; sfv.viewport.m00 = v[MAT_SX]; sfv.viewport.m11 = - v[MAT_SY]; sfv.viewport.m22 = v[MAT_SZ] * brw->intel.depth_scale; sfv.viewport.m30 = v[MAT_TX]; sfv.viewport.m31 = - v[MAT_TY] + brw->intel.driDrawable->h; sfv.viewport.m32 = v[MAT_TZ] * brw->intel.depth_scale; } else { sfv.viewport.m00 = 1; sfv.viewport.m11 = - 1; sfv.viewport.m22 = 1; sfv.viewport.m30 = 0; sfv.viewport.m31 = brw->intel.driDrawable->h; sfv.viewport.m32 = 0; } } /* XXX: what state for this? */ if (brw->intel.driDrawable) { intelScreenPrivate *screen = brw->intel.intelScreen; /* _NEW_SCISSOR */ GLint x = brw->attribs.Scissor->X; GLint y = brw->attribs.Scissor->Y; GLuint w = brw->attribs.Scissor->Width; GLuint h = brw->attribs.Scissor->Height; GLint x1 = x; GLint y1 = brw->intel.driDrawable->h - (y + h); GLint x2 = x + w - 1; GLint y2 = y1 + h - 1; if (x1 < 0) x1 = 0; if (y1 < 0) y1 = 0; if (x2 < 0) x2 = 0; if (y2 < 0) y2 = 0; if (x2 >= screen->width) x2 = screen->width-1; if (y2 >= screen->height) y2 = screen->height-1; if (x1 >= screen->width) x1 = screen->width-1; if (y1 >= screen->height) y1 = screen->height-1; sfv.scissor.xmin = x1; sfv.scissor.xmax = x2; sfv.scissor.ymin = y1; sfv.scissor.ymax = y2; } brw->sf.vp_gs_offset = brw_cache_data( &brw->cache[BRW_SF_VP], &sfv ); }
static void upload_sf_unit( struct brw_context *brw ) { struct brw_sf_unit_state sf; memset(&sf, 0, sizeof(sf)); /* CACHE_NEW_SF_PROG */ sf.thread0.grf_reg_count = ((brw->sf.prog_data->total_grf-1) & ~15) / 16; sf.thread0.kernel_start_pointer = brw->sf.prog_gs_offset >> 6; sf.thread3.urb_entry_read_length = brw->sf.prog_data->urb_read_length; sf.thread1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; sf.thread3.dispatch_grf_start_reg = 3; sf.thread3.urb_entry_read_offset = 1; /* BRW_NEW_URB_FENCE */ sf.thread4.nr_urb_entries = brw->urb.nr_sf_entries; sf.thread4.urb_entry_allocation_size = brw->urb.sfsize - 1; sf.thread4.max_threads = MIN2(12, brw->urb.nr_sf_entries / 2) - 1; if (INTEL_DEBUG & DEBUG_SINGLE_THREAD) sf.thread4.max_threads = 0; if (INTEL_DEBUG & DEBUG_STATS) sf.thread4.stats_enable = 1; /* CACHE_NEW_SF_VP */ sf.sf5.sf_viewport_state_offset = brw->sf.vp_gs_offset >> 5; sf.sf5.viewport_transform = 1; /* _NEW_SCISSOR */ if (brw->attribs.Scissor->Enabled) sf.sf6.scissor = 1; /* _NEW_POLYGON */ if (brw->attribs.Polygon->FrontFace == GL_CCW) sf.sf5.front_winding = BRW_FRONTWINDING_CCW; else sf.sf5.front_winding = BRW_FRONTWINDING_CW; if (brw->attribs.Polygon->CullFlag) { switch (brw->attribs.Polygon->CullFaceMode) { case GL_FRONT: sf.sf6.cull_mode = BRW_CULLMODE_FRONT; break; case GL_BACK: sf.sf6.cull_mode = BRW_CULLMODE_BACK; break; case GL_FRONT_AND_BACK: sf.sf6.cull_mode = BRW_CULLMODE_BOTH; break; default: assert(0); break; } } else sf.sf6.cull_mode = BRW_CULLMODE_NONE; /* _NEW_LINE */ /* XXX use ctx->Const.Min/MaxLineWidth here */ sf.sf6.line_width = CLAMP(brw->attribs.Line->Width, 1.0, 5.0) * (1<<1); sf.sf6.line_endcap_aa_region_width = 1; if (brw->attribs.Line->SmoothFlag) sf.sf6.aa_enable = 1; else if (sf.sf6.line_width <= 0x2) sf.sf6.line_width = 0; /* _NEW_POINT */ sf.sf6.point_rast_rule = 1; /* opengl conventions */ /* XXX clamp max depends on AA vs. non-AA */ sf.sf7.point_size = CLAMP(brw->attribs.Point->Size, 1.0, 3.0) * (1<<3); sf.sf7.use_point_size_state = !brw->attribs.Point->_Attenuated; /* might be BRW_NEW_PRIMITIVE if we have to adjust pv for polygons: */ sf.sf7.trifan_pv = 2; sf.sf7.linestrip_pv = 1; sf.sf7.tristrip_pv = 2; sf.sf7.line_last_pixel_enable = 0; /* Set bias for OpenGL rasterization rules: */ sf.sf6.dest_org_vbias = 0x8; sf.sf6.dest_org_hbias = 0x8; brw->sf.state_gs_offset = brw_cache_data( &brw->cache[BRW_SF_UNIT], &sf ); }
static void upload_wm_surfaces(struct brw_context *brw ) { GLcontext *ctx = &brw->intel.ctx; struct intel_context *intel = &brw->intel; GLuint i; { struct brw_surface_state surf; struct intel_region *region = brw->state.draw_region; memset(&surf, 0, sizeof(surf)); if (region->cpp == 4) surf.ss0.surface_format = BRW_SURFACEFORMAT_B8G8R8A8_UNORM; else surf.ss0.surface_format = BRW_SURFACEFORMAT_B5G6R5_UNORM; surf.ss0.surface_type = BRW_SURFACE_2D; /* _NEW_COLOR */ surf.ss0.color_blend = (!brw->attribs.Color->_LogicOpEnabled && brw->attribs.Color->BlendEnabled); surf.ss0.writedisable_red = !brw->attribs.Color->ColorMask[0]; surf.ss0.writedisable_green = !brw->attribs.Color->ColorMask[1]; surf.ss0.writedisable_blue = !brw->attribs.Color->ColorMask[2]; surf.ss0.writedisable_alpha = !brw->attribs.Color->ColorMask[3]; /* BRW_NEW_LOCK */ surf.ss1.base_addr = bmBufferOffset(&brw->intel, region->buffer); surf.ss2.width = region->pitch - 1; /* XXX: not really! */ surf.ss2.height = region->height - 1; surf.ss3.tile_walk = BRW_TILEWALK_XMAJOR; surf.ss3.tiled_surface = region->tiled; surf.ss3.pitch = (region->pitch * region->cpp) - 1; brw->wm.bind.surf_ss_offset[0] = brw_cache_data( &brw->cache[BRW_SS_SURFACE], &surf ); brw->wm.nr_surfaces = 1; } for (i = 0; i < BRW_MAX_TEX_UNIT; i++) { struct gl_texture_unit *texUnit = &brw->attribs.Texture->Unit[i]; /* _NEW_TEXTURE, BRW_NEW_TEXDATA */ if (texUnit->_ReallyEnabled && intel_finalize_mipmap_tree(intel,texUnit->_Current)) { struct brw_surface_state surf; brw_update_texture_surface(ctx, i, &surf); brw->wm.bind.surf_ss_offset[i+1] = brw_cache_data( &brw->cache[BRW_SS_SURFACE], &surf ); brw->wm.nr_surfaces = i+2; } else if( texUnit->_ReallyEnabled && texUnit->_Current == intel->frame_buffer_texobj ) { brw->wm.bind.surf_ss_offset[i+1] = brw->wm.bind.surf_ss_offset[0]; brw->wm.nr_surfaces = i+2; } else { brw->wm.bind.surf_ss_offset[i+1] = 0; } } brw->wm.bind_ss_offset = brw_cache_data( &brw->cache[BRW_SS_SURF_BIND], &brw->wm.bind ); }
static void upload_cc_unit( struct brw_context *brw ) { struct brw_cc_unit_state cc; memset(&cc, 0, sizeof(cc)); /* BRW_NEW_DEPTH_STENCIL */ if (brw->attribs.DepthStencil->stencil[0].enabled) { cc.cc0.stencil_enable = brw->attribs.DepthStencil->stencil[0].enabled; cc.cc0.stencil_func = brw_translate_compare_func(brw->attribs.DepthStencil->stencil[0].func); cc.cc0.stencil_fail_op = brw_translate_stencil_op(brw->attribs.DepthStencil->stencil[0].fail_op); cc.cc0.stencil_pass_depth_fail_op = brw_translate_stencil_op( brw->attribs.DepthStencil->stencil[0].zfail_op); cc.cc0.stencil_pass_depth_pass_op = brw_translate_stencil_op( brw->attribs.DepthStencil->stencil[0].zpass_op); cc.cc1.stencil_ref = brw->attribs.DepthStencil->stencil[0].ref_value; cc.cc1.stencil_write_mask = brw->attribs.DepthStencil->stencil[0].write_mask; cc.cc1.stencil_test_mask = brw->attribs.DepthStencil->stencil[0].value_mask; if (brw->attribs.DepthStencil->stencil[1].enabled) { cc.cc0.bf_stencil_enable = brw->attribs.DepthStencil->stencil[1].enabled; cc.cc0.bf_stencil_func = brw_translate_compare_func( brw->attribs.DepthStencil->stencil[1].func); cc.cc0.bf_stencil_fail_op = brw_translate_stencil_op( brw->attribs.DepthStencil->stencil[1].fail_op); cc.cc0.bf_stencil_pass_depth_fail_op = brw_translate_stencil_op( brw->attribs.DepthStencil->stencil[1].zfail_op); cc.cc0.bf_stencil_pass_depth_pass_op = brw_translate_stencil_op( brw->attribs.DepthStencil->stencil[1].zpass_op); cc.cc1.bf_stencil_ref = brw->attribs.DepthStencil->stencil[1].ref_value; cc.cc2.bf_stencil_write_mask = brw->attribs.DepthStencil->stencil[1].write_mask; cc.cc2.bf_stencil_test_mask = brw->attribs.DepthStencil->stencil[1].value_mask; } /* Not really sure about this: */ if (brw->attribs.DepthStencil->stencil[0].write_mask || brw->attribs.DepthStencil->stencil[1].write_mask) cc.cc0.stencil_write_enable = 1; } /* BRW_NEW_BLEND */ if (brw->attribs.Blend->logicop_enable) { cc.cc2.logicop_enable = 1; cc.cc5.logicop_func = brw_translate_logic_op( brw->attribs.Blend->logicop_func ); } else if (brw->attribs.Blend->blend_enable) { int eqRGB = brw->attribs.Blend->rgb_func; int eqA = brw->attribs.Blend->alpha_func; int srcRGB = brw->attribs.Blend->rgb_src_factor; int dstRGB = brw->attribs.Blend->rgb_dst_factor; int srcA = brw->attribs.Blend->alpha_src_factor; int dstA = brw->attribs.Blend->alpha_dst_factor; if (eqRGB == PIPE_BLEND_MIN || eqRGB == PIPE_BLEND_MAX) { srcRGB = dstRGB = PIPE_BLENDFACTOR_ONE; } if (eqA == PIPE_BLEND_MIN || eqA == PIPE_BLEND_MAX) { srcA = dstA = PIPE_BLENDFACTOR_ONE; } cc.cc6.dest_blend_factor = brw_translate_blend_factor(dstRGB); cc.cc6.src_blend_factor = brw_translate_blend_factor(srcRGB); cc.cc6.blend_function = brw_translate_blend_equation( eqRGB ); cc.cc5.ia_dest_blend_factor = brw_translate_blend_factor(dstA); cc.cc5.ia_src_blend_factor = brw_translate_blend_factor(srcA); cc.cc5.ia_blend_function = brw_translate_blend_equation( eqA ); cc.cc3.blend_enable = 1; cc.cc3.ia_blend_enable = (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB); } /* BRW_NEW_ALPHATEST */ if (brw->attribs.DepthStencil->alpha.enabled) { cc.cc3.alpha_test = 1; cc.cc3.alpha_test_func = brw_translate_compare_func(brw->attribs.DepthStencil->alpha.func); cc.cc7.alpha_ref.ub[0] = float_to_ubyte(brw->attribs.DepthStencil->alpha.ref); cc.cc3.alpha_test_format = BRW_ALPHATEST_FORMAT_UNORM8; } if (brw->attribs.Blend->dither) { cc.cc5.dither_enable = 1; cc.cc6.y_dither_offset = 0; cc.cc6.x_dither_offset = 0; } if (brw->attribs.DepthStencil->depth.enabled) { cc.cc2.depth_test = brw->attribs.DepthStencil->depth.enabled; cc.cc2.depth_test_function = brw_translate_compare_func(brw->attribs.DepthStencil->depth.func); cc.cc2.depth_write_enable = brw->attribs.DepthStencil->depth.writemask; } /* CACHE_NEW_CC_VP */ cc.cc4.cc_viewport_state_offset = brw->cc.vp_gs_offset >> 5; if (BRW_DEBUG & DEBUG_STATS) cc.cc5.statistics_enable = 1; brw->cc.state_gs_offset = brw_cache_data( &brw->cache[BRW_CC_UNIT], &cc ); }