#include "main/imports.h"
#include "main/macros.h"
#include "main/colormac.h"
+#include "main/renderbuffer.h"
+#include "main/framebuffer.h"
#include "intel_batchbuffer.h"
#include "intel_regions.h"
+#include "intel_fbo.h"
#include "brw_context.h"
+#include "brw_program.h"
#include "brw_defines.h"
#include "brw_state.h"
#include "brw_draw.h"
#include "brw_vs.h"
#include "brw_wm.h"
+#include "gen6_blorp.h"
+#include "gen7_blorp.h"
+
+#include "glsl/ralloc.h"
+
static void
dri_bo_release(drm_intel_bo **bo)
{
/**
* called from intelDestroyContext()
*/
-static void brw_destroy_context( struct intel_context *intel )
+static void
+brw_destroy_context(struct brw_context *brw)
{
- struct brw_context *brw = brw_context(&intel->ctx);
- int i;
+ if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
+ /* Force a report. */
+ brw->shader_time.report_time = 0;
- brw_destroy_state(brw);
- brw_draw_destroy( brw );
- brw_clear_validated_bos(brw);
- if (brw->wm.compile_data) {
- free(brw->wm.compile_data->instruction);
- free(brw->wm.compile_data->vreg);
- free(brw->wm.compile_data->refs);
- free(brw->wm.compile_data->prog_instructions);
- free(brw->wm.compile_data);
+ brw_collect_and_report_shader_time(brw);
+ brw_destroy_shader_time(brw);
}
- intel_region_release(&brw->state.depth_region);
+ brw_destroy_state(brw);
+ brw_draw_destroy( brw );
dri_bo_release(&brw->curbe.curbe_bo);
- dri_bo_release(&brw->vs.prog_bo);
- dri_bo_release(&brw->vs.state_bo);
- dri_bo_release(&brw->vs.const_bo);
- dri_bo_release(&brw->gs.prog_bo);
- dri_bo_release(&brw->gs.state_bo);
- dri_bo_release(&brw->clip.prog_bo);
- dri_bo_release(&brw->clip.state_bo);
- dri_bo_release(&brw->sf.prog_bo);
- dri_bo_release(&brw->sf.state_bo);
- for (i = 0; i < BRW_MAX_TEX_UNIT; i++)
- dri_bo_release(&brw->wm.sdc_bo[i]);
- dri_bo_release(&brw->wm.sampler_bo);
- dri_bo_release(&brw->wm.prog_bo);
- dri_bo_release(&brw->wm.state_bo);
+ dri_bo_release(&brw->vs.base.const_bo);
dri_bo_release(&brw->wm.const_bo);
- dri_bo_release(&brw->cc.prog_bo);
- dri_bo_release(&brw->cc.blend_state_bo);
- dri_bo_release(&brw->cc.depth_stencil_state_bo);
- dri_bo_release(&brw->cc.color_calc_state_bo);
free(brw->curbe.last_buf);
free(brw->curbe.next_buf);
-}
-
-
-/**
- * called from intelDrawBuffer()
- */
-static void brw_set_draw_region( struct intel_context *intel,
- struct intel_region *color_regions[],
- struct intel_region *depth_region,
- GLuint num_color_regions)
-{
- struct brw_context *brw = brw_context(&intel->ctx);
- if (brw->state.depth_region != depth_region) {
- brw->state.dirty.brw |= BRW_NEW_DEPTH_BUFFER;
- intel_region_release(&brw->state.depth_region);
- intel_region_reference(&brw->state.depth_region, depth_region);
- }
+ drm_intel_gem_context_destroy(brw->hw_ctx);
}
-
/**
* called from intel_batchbuffer_flush and children before sending a
* batchbuffer off.
+ *
+ * Note that ALL state emitted here must fit in the reserved space
+ * at the end of a batchbuffer. If you add more GPU state, increase
+ * the BATCH_RESERVED macro.
*/
-static void brw_finish_batch(struct intel_context *intel)
+static void
+brw_finish_batch(struct brw_context *brw)
{
- struct brw_context *brw = brw_context(&intel->ctx);
brw_emit_query_end(brw);
if (brw->curbe.curbe_bo) {
/**
* called from intelFlushBatchLocked
*/
-static void brw_new_batch( struct intel_context *intel )
+static void
+brw_new_batch(struct brw_context *brw)
{
- struct brw_context *brw = brw_context(&intel->ctx);
+ /* If the kernel supports hardware contexts, then most hardware state is
+ * preserved between batches; we only need to re-emit state that is required
+ * to be in every batch. Otherwise we need to re-emit all the state that
+ * would otherwise be stored in the context (which for all intents and
+ * purposes means everything).
+ */
+ if (brw->hw_ctx == NULL)
+ brw->state.dirty.brw |= BRW_NEW_CONTEXT;
+
+ brw->state.dirty.brw |= BRW_NEW_BATCH;
- /* Mark all context state as needing to be re-emitted.
- * This is probably not as severe as on 915, since almost all of our state
- * is just in referenced buffers.
+ /* Assume that the last command before the start of our batch was a
+ * primitive, for safety.
*/
- brw->state.dirty.brw |= BRW_NEW_CONTEXT;
+ brw->batch.need_workaround_flush = true;
- brw->state.dirty.mesa |= ~0;
- brw->state.dirty.brw |= ~0;
- brw->state.dirty.cache |= ~0;
+ brw->state_batch_count = 0;
- brw->vb.nr_current_buffers = 0;
-}
+ brw->ib.type = -1;
-static void brw_invalidate_state( struct intel_context *intel, GLuint new_state )
-{
- /* nothing */
-}
+ /* Mark that the current program cache BO has been used by the GPU.
+ * It will be reallocated if we need to put new programs in for the
+ * next batch.
+ */
+ brw->cache.bo_used_by_gpu = true;
+ /* We need to periodically reap the shader time results, because rollover
+ * happens every few seconds. We also want to see results every once in a
+ * while, because many programs won't cleanly destroy our context, so the
+ * end-of-run printout may not happen.
+ */
+ if (INTEL_DEBUG & DEBUG_SHADER_TIME)
+ brw_collect_and_report_shader_time(brw);
+}
void brwInitVtbl( struct brw_context *brw )
{
- brw->intel.vtbl.check_vertex_size = 0;
- brw->intel.vtbl.emit_state = 0;
- brw->intel.vtbl.reduced_primitive_state = 0;
- brw->intel.vtbl.render_start = 0;
- brw->intel.vtbl.update_texture_state = 0;
-
- brw->intel.vtbl.invalidate_state = brw_invalidate_state;
- brw->intel.vtbl.new_batch = brw_new_batch;
- brw->intel.vtbl.finish_batch = brw_finish_batch;
- brw->intel.vtbl.destroy = brw_destroy_context;
- brw->intel.vtbl.set_draw_region = brw_set_draw_region;
- brw->intel.vtbl.debug_batch = brw_debug_batch;
- brw->intel.vtbl.render_target_supported = brw_render_target_supported;
+ brw->vtbl.new_batch = brw_new_batch;
+ brw->vtbl.finish_batch = brw_finish_batch;
+ brw->vtbl.destroy = brw_destroy_context;
+
+ assert(brw->gen >= 4);
+ if (brw->gen >= 7) {
+ gen7_init_vtable_surface_functions(brw);
+ gen7_init_vtable_sampler_functions(brw);
+ brw->vtbl.emit_depth_stencil_hiz = gen7_emit_depth_stencil_hiz;
+ } else if (brw->gen >= 4) {
+ gen4_init_vtable_surface_functions(brw);
+ gen4_init_vtable_sampler_functions(brw);
+ brw->vtbl.emit_depth_stencil_hiz = brw_emit_depth_stencil_hiz;
+ }
}