static void * i915_create_depth_stencil_state(struct pipe_context *pipe, const struct pipe_depth_stencil_alpha_state *depth_stencil) { struct i915_depth_stencil_state *cso = CALLOC_STRUCT( i915_depth_stencil_state ); { int testmask = depth_stencil->stencil[0].valuemask & 0xff; int writemask = depth_stencil->stencil[0].writemask & 0xff; cso->stencil_modes4 |= (_3DSTATE_MODES_4_CMD | ENABLE_STENCIL_TEST_MASK | STENCIL_TEST_MASK(testmask) | ENABLE_STENCIL_WRITE_MASK | STENCIL_WRITE_MASK(writemask)); } if (depth_stencil->stencil[0].enabled) { int test = i915_translate_compare_func(depth_stencil->stencil[0].func); int fop = i915_translate_stencil_op(depth_stencil->stencil[0].fail_op); int dfop = i915_translate_stencil_op(depth_stencil->stencil[0].zfail_op); int dpop = i915_translate_stencil_op(depth_stencil->stencil[0].zpass_op); cso->stencil_LIS5 |= (S5_STENCIL_TEST_ENABLE | S5_STENCIL_WRITE_ENABLE | (test << S5_STENCIL_TEST_FUNC_SHIFT) | (fop << S5_STENCIL_FAIL_SHIFT) | (dfop << S5_STENCIL_PASS_Z_FAIL_SHIFT) | (dpop << S5_STENCIL_PASS_Z_PASS_SHIFT)); } if (depth_stencil->stencil[1].enabled) { int test = i915_translate_compare_func(depth_stencil->stencil[1].func); int fop = i915_translate_stencil_op(depth_stencil->stencil[1].fail_op); int dfop = i915_translate_stencil_op(depth_stencil->stencil[1].zfail_op); int dpop = i915_translate_stencil_op(depth_stencil->stencil[1].zpass_op); int tmask = depth_stencil->stencil[1].valuemask & 0xff; int wmask = depth_stencil->stencil[1].writemask & 0xff; cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | BFO_ENABLE_STENCIL_FUNCS | BFO_ENABLE_STENCIL_TWO_SIDE | BFO_ENABLE_STENCIL_REF | BFO_STENCIL_TWO_SIDE | (test << BFO_STENCIL_TEST_SHIFT) | (fop << BFO_STENCIL_FAIL_SHIFT) | (dfop << BFO_STENCIL_PASS_Z_FAIL_SHIFT) | (dpop << BFO_STENCIL_PASS_Z_PASS_SHIFT)); cso->bfo[1] = (_3DSTATE_BACKFACE_STENCIL_MASKS | BFM_ENABLE_STENCIL_TEST_MASK | BFM_ENABLE_STENCIL_WRITE_MASK | (tmask << BFM_STENCIL_TEST_MASK_SHIFT) | (wmask << BFM_STENCIL_WRITE_MASK_SHIFT)); } else { /* This actually disables two-side stencil: The bit set is a * modify-enable bit to indicate we are changing the two-side * setting. Then there is a symbolic zero to show that we are * setting the flag to zero/off. */ cso->bfo[0] = (_3DSTATE_BACKFACE_STENCIL_OPS | BFO_ENABLE_STENCIL_TWO_SIDE | 0); cso->bfo[1] = 0; } if (depth_stencil->depth.enabled) { int func = i915_translate_compare_func(depth_stencil->depth.func); cso->depth_LIS6 |= (S6_DEPTH_TEST_ENABLE | (func << S6_DEPTH_TEST_FUNC_SHIFT)); if (depth_stencil->depth.writemask) cso->depth_LIS6 |= S6_DEPTH_WRITE_ENABLE; } if (depth_stencil->alpha.enabled) { int test = i915_translate_compare_func(depth_stencil->alpha.func); ubyte refByte = float_to_ubyte(depth_stencil->alpha.ref_value); cso->depth_LIS6 |= (S6_ALPHA_TEST_ENABLE | (test << S6_ALPHA_TEST_FUNC_SHIFT) | (((unsigned) refByte) << S6_ALPHA_REF_SHIFT)); } return cso; }
static void * i915_create_sampler_state(struct pipe_context *pipe, const struct pipe_sampler_state *sampler) { struct i915_sampler_state *cso = CALLOC_STRUCT( i915_sampler_state ); const unsigned ws = sampler->wrap_s; const unsigned wt = sampler->wrap_t; const unsigned wr = sampler->wrap_r; unsigned minFilt, magFilt; unsigned mipFilt; cso->templ = sampler; mipFilt = translate_mip_filter(sampler->min_mip_filter); minFilt = translate_img_filter( sampler->min_img_filter ); magFilt = translate_img_filter( sampler->mag_img_filter ); if (sampler->max_anisotropy > 2.0) { cso->state[0] |= SS2_MAX_ANISO_4; } { int b = (int) (sampler->lod_bias * 16.0); b = CLAMP(b, -256, 255); cso->state[0] |= ((b << SS2_LOD_BIAS_SHIFT) & SS2_LOD_BIAS_MASK); } /* Shadow: */ if (sampler->compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) { cso->state[0] |= (SS2_SHADOW_ENABLE | i915_translate_compare_func(sampler->compare_func)); minFilt = FILTER_4X4_FLAT; magFilt = FILTER_4X4_FLAT; } cso->state[0] |= ((minFilt << SS2_MIN_FILTER_SHIFT) | (mipFilt << SS2_MIP_FILTER_SHIFT) | (magFilt << SS2_MAG_FILTER_SHIFT)); cso->state[1] |= ((translate_wrap_mode(ws) << SS3_TCX_ADDR_MODE_SHIFT) | (translate_wrap_mode(wt) << SS3_TCY_ADDR_MODE_SHIFT) | (translate_wrap_mode(wr) << SS3_TCZ_ADDR_MODE_SHIFT)); if (sampler->normalized_coords) cso->state[1] |= SS3_NORMALIZED_COORDS; { int minlod = (int) (16.0 * sampler->min_lod); int maxlod = (int) (16.0 * sampler->max_lod); minlod = CLAMP(minlod, 0, 16 * 11); maxlod = CLAMP(maxlod, 0, 16 * 11); if (minlod > maxlod) maxlod = minlod; cso->minlod = minlod; cso->maxlod = maxlod; } { ubyte r = float_to_ubyte(sampler->border_color[0]); ubyte g = float_to_ubyte(sampler->border_color[1]); ubyte b = float_to_ubyte(sampler->border_color[2]); ubyte a = float_to_ubyte(sampler->border_color[3]); cso->state[2] = I915PACKCOLOR8888(r, g, b, a); } return cso; }