2018-01-19 18:57:30 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2017 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
2018-08-19 00:31:46 -07:00
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2018-01-19 18:57:30 -08:00
|
|
|
*
|
2018-08-19 00:31:46 -07:00
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
|
* in all copies or substantial portions of the Software.
|
2018-01-19 18:57:30 -08:00
|
|
|
*
|
2018-08-19 00:31:46 -07:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2018-01-19 18:57:30 -08:00
|
|
|
*/
|
2018-08-19 00:31:46 -07:00
|
|
|
|
2018-01-19 18:57:30 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include "pipe/p_defines.h"
|
|
|
|
|
#include "pipe/p_state.h"
|
2018-01-20 02:47:04 -08:00
|
|
|
#include "util/ralloc.h"
|
2018-01-19 18:57:30 -08:00
|
|
|
#include "util/u_inlines.h"
|
|
|
|
|
#include "util/u_format.h"
|
|
|
|
|
#include "util/u_upload_mgr.h"
|
2018-01-20 23:11:37 -08:00
|
|
|
#include "i915_drm.h"
|
2018-01-19 18:57:30 -08:00
|
|
|
#include "iris_context.h"
|
|
|
|
|
#include "iris_resource.h"
|
|
|
|
|
#include "iris_screen.h"
|
2018-08-20 23:37:13 -07:00
|
|
|
#include "common/gen_sample_positions.h"
|
2018-01-19 18:57:30 -08:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
iris_flush(struct pipe_context *ctx,
|
|
|
|
|
struct pipe_fence_handle **fence,
|
|
|
|
|
unsigned flags)
|
|
|
|
|
{
|
2018-01-21 17:44:08 -08:00
|
|
|
struct iris_context *ice = (struct iris_context *)ctx;
|
|
|
|
|
|
|
|
|
|
iris_batch_flush(&ice->render_batch);
|
2018-10-19 02:12:29 -07:00
|
|
|
|
|
|
|
|
if (ice->compute_batch.contains_draw)
|
|
|
|
|
iris_batch_flush(&ice->compute_batch);
|
2018-01-21 17:44:08 -08:00
|
|
|
|
2018-07-30 23:49:34 -07:00
|
|
|
// XXX: bogus!!!
|
2018-01-19 18:57:30 -08:00
|
|
|
if (fence)
|
|
|
|
|
*fence = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* For debugging purposes, this returns a time in seconds.
|
|
|
|
|
*/
|
|
|
|
|
double
|
|
|
|
|
get_time(void)
|
|
|
|
|
{
|
|
|
|
|
struct timespec tp;
|
|
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &tp);
|
|
|
|
|
|
|
|
|
|
return tp.tv_sec + tp.tv_nsec / 1000000000.0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 23:49:34 -07:00
|
|
|
/**
|
|
|
|
|
* The pipe->set_debug_callback() driver hook.
|
|
|
|
|
*/
|
2018-01-19 18:57:30 -08:00
|
|
|
static void
|
|
|
|
|
iris_set_debug_callback(struct pipe_context *ctx,
|
|
|
|
|
const struct pipe_debug_callback *cb)
|
|
|
|
|
{
|
|
|
|
|
struct iris_context *ice = (struct iris_context *)ctx;
|
|
|
|
|
|
|
|
|
|
if (cb)
|
|
|
|
|
ice->dbg = *cb;
|
|
|
|
|
else
|
|
|
|
|
memset(&ice->dbg, 0, sizeof(ice->dbg));
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 23:37:13 -07:00
|
|
|
static void
|
|
|
|
|
iris_get_sample_position(struct pipe_context *ctx,
|
|
|
|
|
unsigned sample_count,
|
|
|
|
|
unsigned sample_index,
|
|
|
|
|
float *out_value)
|
|
|
|
|
{
|
|
|
|
|
union {
|
|
|
|
|
struct {
|
|
|
|
|
float x[16];
|
|
|
|
|
float y[16];
|
|
|
|
|
} a;
|
|
|
|
|
struct {
|
|
|
|
|
float _0XOffset, _1XOffset, _2XOffset, _3XOffset,
|
|
|
|
|
_4XOffset, _5XOffset, _6XOffset, _7XOffset,
|
|
|
|
|
_8XOffset, _9XOffset, _10XOffset, _11XOffset,
|
|
|
|
|
_12XOffset, _13XOffset, _14XOffset, _15XOffset;
|
|
|
|
|
float _0YOffset, _1YOffset, _2YOffset, _3YOffset,
|
|
|
|
|
_4YOffset, _5YOffset, _6YOffset, _7YOffset,
|
|
|
|
|
_8YOffset, _9YOffset, _10YOffset, _11YOffset,
|
|
|
|
|
_12YOffset, _13YOffset, _14YOffset, _15YOffset;
|
|
|
|
|
} v;
|
|
|
|
|
} u;
|
|
|
|
|
switch (sample_count) {
|
|
|
|
|
case 1: GEN_SAMPLE_POS_1X(u.v._); break;
|
|
|
|
|
case 2: GEN_SAMPLE_POS_2X(u.v._); break;
|
|
|
|
|
case 4: GEN_SAMPLE_POS_4X(u.v._); break;
|
|
|
|
|
case 8: GEN_SAMPLE_POS_8X(u.v._); break;
|
|
|
|
|
case 16: GEN_SAMPLE_POS_16X(u.v._); break;
|
|
|
|
|
default: unreachable("invalid sample count");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out_value[0] = u.a.x[sample_index];
|
|
|
|
|
out_value[1] = u.a.y[sample_index];
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 23:49:34 -07:00
|
|
|
/**
|
|
|
|
|
* Destroy a context, freeing any associated memory.
|
|
|
|
|
*/
|
2018-01-19 18:57:30 -08:00
|
|
|
static void
|
|
|
|
|
iris_destroy_context(struct pipe_context *ctx)
|
|
|
|
|
{
|
2018-01-20 02:47:04 -08:00
|
|
|
struct iris_context *ice = (struct iris_context *)ctx;
|
|
|
|
|
|
2018-01-19 18:57:30 -08:00
|
|
|
if (ctx->stream_uploader)
|
|
|
|
|
u_upload_destroy(ctx->stream_uploader);
|
|
|
|
|
|
2018-06-16 09:56:59 -07:00
|
|
|
ice->vtbl.destroy_state(ice);
|
2018-01-25 19:43:45 -08:00
|
|
|
iris_destroy_program_cache(ice);
|
2018-04-05 21:48:33 -07:00
|
|
|
u_upload_destroy(ice->state.surface_uploader);
|
|
|
|
|
u_upload_destroy(ice->state.dynamic_uploader);
|
2018-01-25 19:43:45 -08:00
|
|
|
|
2018-07-06 11:29:51 -07:00
|
|
|
slab_destroy_child(&ice->transfer_pool);
|
|
|
|
|
|
2018-01-23 01:23:54 -08:00
|
|
|
iris_batch_free(&ice->render_batch);
|
2018-11-07 09:56:37 -08:00
|
|
|
iris_batch_free(&ice->compute_batch);
|
2018-09-08 19:43:34 -07:00
|
|
|
iris_destroy_binder(&ice->state.binder);
|
2018-01-23 01:23:54 -08:00
|
|
|
|
2018-01-20 02:47:04 -08:00
|
|
|
ralloc_free(ice);
|
2018-01-19 18:57:30 -08:00
|
|
|
}
|
|
|
|
|
|
2018-01-25 01:36:49 -08:00
|
|
|
#define genX_call(devinfo, func, ...) \
|
|
|
|
|
switch (devinfo->gen) { \
|
2018-10-08 06:26:15 -07:00
|
|
|
case 11: \
|
|
|
|
|
gen11_##func(__VA_ARGS__); \
|
|
|
|
|
break; \
|
2018-01-25 01:36:49 -08:00
|
|
|
case 10: \
|
|
|
|
|
gen10_##func(__VA_ARGS__); \
|
|
|
|
|
break; \
|
|
|
|
|
case 9: \
|
|
|
|
|
gen9_##func(__VA_ARGS__); \
|
|
|
|
|
break; \
|
|
|
|
|
default: \
|
|
|
|
|
unreachable("Unknown hardware generation"); \
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 23:49:34 -07:00
|
|
|
/**
|
|
|
|
|
* Create a context.
|
|
|
|
|
*
|
|
|
|
|
* This is where each context begins.
|
|
|
|
|
*/
|
2018-01-19 18:57:30 -08:00
|
|
|
struct pipe_context *
|
2018-01-19 21:55:32 -08:00
|
|
|
iris_create_context(struct pipe_screen *pscreen, void *priv, unsigned flags)
|
2018-01-19 18:57:30 -08:00
|
|
|
{
|
2018-01-19 21:55:32 -08:00
|
|
|
struct iris_screen *screen = (struct iris_screen*)pscreen;
|
2018-01-25 01:36:49 -08:00
|
|
|
const struct gen_device_info *devinfo = &screen->devinfo;
|
2018-01-20 02:47:04 -08:00
|
|
|
struct iris_context *ice = rzalloc(NULL, struct iris_context);
|
2018-01-19 18:57:30 -08:00
|
|
|
|
|
|
|
|
if (!ice)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
struct pipe_context *ctx = &ice->ctx;
|
|
|
|
|
|
2018-01-19 21:55:32 -08:00
|
|
|
ctx->screen = pscreen;
|
2018-01-19 18:57:30 -08:00
|
|
|
ctx->priv = priv;
|
|
|
|
|
|
|
|
|
|
ctx->stream_uploader = u_upload_create_default(ctx);
|
|
|
|
|
if (!ctx->stream_uploader) {
|
|
|
|
|
free(ctx);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
ctx->const_uploader = ctx->stream_uploader;
|
|
|
|
|
|
|
|
|
|
ctx->destroy = iris_destroy_context;
|
|
|
|
|
ctx->flush = iris_flush;
|
|
|
|
|
ctx->set_debug_callback = iris_set_debug_callback;
|
2018-08-20 23:37:13 -07:00
|
|
|
ctx->get_sample_position = iris_get_sample_position;
|
2018-01-19 18:57:30 -08:00
|
|
|
|
2018-01-25 21:23:45 -08:00
|
|
|
ice->shaders.urb_size = devinfo->urb.size;
|
|
|
|
|
|
2018-01-19 18:57:30 -08:00
|
|
|
iris_init_blit_functions(ctx);
|
|
|
|
|
iris_init_clear_functions(ctx);
|
|
|
|
|
iris_init_program_functions(ctx);
|
|
|
|
|
iris_init_resource_functions(ctx);
|
|
|
|
|
iris_init_query_functions(ctx);
|
2018-07-24 21:15:13 -07:00
|
|
|
iris_init_flush_functions(ctx);
|
2018-01-19 18:57:30 -08:00
|
|
|
|
2018-01-20 02:47:04 -08:00
|
|
|
iris_init_program_cache(ice);
|
2018-06-28 02:25:25 -07:00
|
|
|
iris_init_border_color_pool(ice);
|
2018-09-08 19:43:34 -07:00
|
|
|
iris_init_binder(ice);
|
2018-01-20 02:47:04 -08:00
|
|
|
|
2018-07-06 11:29:51 -07:00
|
|
|
slab_create_child(&ice->transfer_pool, &screen->transfer_pool);
|
|
|
|
|
|
2018-04-05 21:48:33 -07:00
|
|
|
ice->state.surface_uploader =
|
2018-09-08 19:43:34 -07:00
|
|
|
u_upload_create(ctx, 16384, PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE,
|
2018-04-05 21:48:33 -07:00
|
|
|
IRIS_RESOURCE_FLAG_SURFACE_MEMZONE);
|
|
|
|
|
ice->state.dynamic_uploader =
|
2018-09-08 19:43:34 -07:00
|
|
|
u_upload_create(ctx, 16384, PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE,
|
2018-04-05 21:48:33 -07:00
|
|
|
IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE);
|
|
|
|
|
|
2018-01-25 01:36:49 -08:00
|
|
|
genX_call(devinfo, init_state, ice);
|
2018-04-21 22:20:32 -07:00
|
|
|
genX_call(devinfo, init_blorp, ice);
|
2018-11-06 21:12:30 -08:00
|
|
|
|
|
|
|
|
struct iris_batch *batches[IRIS_BATCH_COUNT] = {
|
|
|
|
|
&ice->render_batch,
|
|
|
|
|
&ice->compute_batch,
|
|
|
|
|
};
|
2018-11-08 15:32:59 -08:00
|
|
|
const char *batch_names[IRIS_BATCH_COUNT] = { "render", "compute", };
|
2018-11-06 21:12:30 -08:00
|
|
|
|
|
|
|
|
for (int i = 0; i < IRIS_BATCH_COUNT; i++) {
|
|
|
|
|
iris_init_batch(batches[i], screen, &ice->vtbl, &ice->dbg,
|
2018-11-08 15:32:59 -08:00
|
|
|
batches, batch_names[i], I915_EXEC_RENDER);
|
2018-11-06 21:12:30 -08:00
|
|
|
}
|
|
|
|
|
|
2018-04-20 23:28:03 -07:00
|
|
|
ice->vtbl.init_render_context(screen, &ice->render_batch, &ice->vtbl,
|
|
|
|
|
&ice->dbg);
|
2018-07-26 21:59:20 -07:00
|
|
|
ice->vtbl.init_compute_context(screen, &ice->compute_batch, &ice->vtbl,
|
|
|
|
|
&ice->dbg);
|
2018-01-19 21:55:32 -08:00
|
|
|
|
2018-01-19 18:57:30 -08:00
|
|
|
return ctx;
|
|
|
|
|
}
|