Path: blob/21.2-virgl/src/gallium/drivers/crocus/gen4_blorp_exec.h
4570 views
/*1* Copyright © 2016 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223static inline struct blorp_address24dynamic_state_address(struct blorp_batch *blorp_batch, uint32_t offset)25{26struct crocus_batch *batch = blorp_batch->driver_batch;2728return (struct blorp_address) {29.buffer = batch->state.bo,30.offset = offset,31};3233}3435static inline struct blorp_address36instruction_state_address(struct blorp_batch *blorp_batch, uint32_t offset)37{38struct crocus_batch *batch = blorp_batch->driver_batch;3940return (struct blorp_address) {41.buffer = batch->ice->shaders.cache_bo,42.offset = offset,43};44}4546static struct blorp_address47blorp_emit_vs_state(struct blorp_batch *blorp_batch)48{49struct crocus_batch *batch = blorp_batch->driver_batch;5051uint32_t offset;52blorp_emit_dynamic(blorp_batch, GENX(VS_STATE), vs, 64, &offset) {53vs.Enable = false;54vs.URBEntryAllocationSize = batch->ice->urb.vsize - 1;55#if GFX_VER == 556vs.NumberofURBEntries = batch->ice->urb.nr_vs_entries >> 2;57#else58vs.NumberofURBEntries = batch->ice->urb.nr_vs_entries;59#endif60}6162return dynamic_state_address(blorp_batch, offset);63}6465static struct blorp_address66blorp_emit_sf_state(struct blorp_batch *blorp_batch,67const struct blorp_params *params)68{69struct crocus_batch *batch = blorp_batch->driver_batch;70const struct brw_sf_prog_data *prog_data = params->sf_prog_data;7172uint32_t offset;73blorp_emit_dynamic(blorp_batch, GENX(SF_STATE), sf, 64, &offset) {74#if GFX_VER == 475sf.KernelStartPointer =76instruction_state_address(blorp_batch, params->sf_prog_kernel);77#else78sf.KernelStartPointer = params->sf_prog_kernel;79#endif80sf.GRFRegisterCount = DIV_ROUND_UP(prog_data->total_grf, 16) - 1;81sf.VertexURBEntryReadLength = prog_data->urb_read_length;82sf.VertexURBEntryReadOffset = BRW_SF_URB_ENTRY_READ_OFFSET;83sf.DispatchGRFStartRegisterForURBData = 3;84sf.URBEntryAllocationSize = batch->ice->urb.sfsize - 1;85sf.NumberofURBEntries = batch->ice->urb.nr_sf_entries;8687#if GFX_VER == 588sf.MaximumNumberofThreads = MIN2(48, batch->ice->urb.nr_sf_entries) - 1;89#else90sf.MaximumNumberofThreads = MIN2(24, batch->ice->urb.nr_sf_entries) - 1;91#endif92sf.ViewportTransformEnable = false;9394sf.CullMode = CULLMODE_NONE;95}9697return dynamic_state_address(blorp_batch, offset);98}99100static struct blorp_address101blorp_emit_wm_state(struct blorp_batch *blorp_batch,102const struct blorp_params *params)103{104const struct brw_wm_prog_data *prog_data = params->wm_prog_data;105106uint32_t offset;107blorp_emit_dynamic(blorp_batch, GENX(WM_STATE), wm, 64, &offset) {108if (params->src.enabled) {109/* Iron Lake can't do sampler prefetch */110wm.SamplerCount = (GFX_VER != 5);111wm.BindingTableEntryCount = 2;112uint32_t sampler = blorp_emit_sampler_state(blorp_batch);113wm.SamplerStatePointer = dynamic_state_address(blorp_batch, sampler);114}115116if (prog_data) {117wm.DispatchGRFStartRegisterForConstantSetupData0 =118prog_data->base.dispatch_grf_start_reg;119wm.SetupURBEntryReadLength = prog_data->num_varying_inputs * 2;120wm.SetupURBEntryReadOffset = 0;121122wm.DepthCoefficientURBReadOffset = 1;123wm.PixelShaderKillsPixel = prog_data->uses_kill;124wm.ThreadDispatchEnable = true;125wm.EarlyDepthTestEnable = true;126127wm._8PixelDispatchEnable = prog_data->dispatch_8;128wm._16PixelDispatchEnable = prog_data->dispatch_16;129wm._32PixelDispatchEnable = prog_data->dispatch_32;130131#if GFX_VER == 4132wm.KernelStartPointer0 =133instruction_state_address(blorp_batch, params->wm_prog_kernel);134wm.GRFRegisterCount0 = brw_wm_prog_data_reg_blocks(prog_data, wm, 0);135#else136wm.KernelStartPointer0 = params->wm_prog_kernel +137brw_wm_prog_data_prog_offset(prog_data, wm, 0);138wm.KernelStartPointer1 = params->wm_prog_kernel +139brw_wm_prog_data_prog_offset(prog_data, wm, 1);140wm.KernelStartPointer2 = params->wm_prog_kernel +141brw_wm_prog_data_prog_offset(prog_data, wm, 2);142wm.GRFRegisterCount0 = brw_wm_prog_data_reg_blocks(prog_data, wm, 0);143wm.GRFRegisterCount1 = brw_wm_prog_data_reg_blocks(prog_data, wm, 1);144wm.GRFRegisterCount2 = brw_wm_prog_data_reg_blocks(prog_data, wm, 2);145#endif146}147148wm.MaximumNumberofThreads =149blorp_batch->blorp->compiler->devinfo->max_wm_threads - 1;150}151152return dynamic_state_address(blorp_batch, offset);153}154155static struct blorp_address156blorp_emit_color_calc_state(struct blorp_batch *blorp_batch)157{158uint32_t cc_viewport = blorp_emit_cc_viewport(blorp_batch);159160uint32_t offset;161blorp_emit_dynamic(blorp_batch, GENX(COLOR_CALC_STATE), cc, 64, &offset) {162cc.CCViewportStatePointer = dynamic_state_address(blorp_batch, cc_viewport);163}164165return dynamic_state_address(blorp_batch, offset);166}167168static void169blorp_emit_pipeline(struct blorp_batch *blorp_batch,170const struct blorp_params *params)171{172struct crocus_batch *batch = blorp_batch->driver_batch;173174emit_urb_config(blorp_batch, params, NULL);175176blorp_emit(blorp_batch, GENX(3DSTATE_PIPELINED_POINTERS), pp) {177pp.PointertoVSState = blorp_emit_vs_state(blorp_batch);178pp.GSEnable = false;179pp.ClipEnable = false;180pp.PointertoSFState = blorp_emit_sf_state(blorp_batch, params);181pp.PointertoWMState = blorp_emit_wm_state(blorp_batch, params);182pp.PointertoColorCalcState = blorp_emit_color_calc_state(blorp_batch);183}184185batch->screen->vtbl.upload_urb_fence(batch);186187blorp_emit(blorp_batch, GENX(CS_URB_STATE), curb);188blorp_emit(blorp_batch, GENX(CONSTANT_BUFFER), curb);189}190191192