From 9eab70e54f40a13f55b29974ca7f765c1164f1be Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg=20Kristensen?= Date: Wed, 3 Jun 2015 23:03:29 -0700 Subject: [PATCH] vk: Create a minimal context for the compiler This avoids the full brw context initialization and just sets up context constants, initializes extensions and sets a few driver vfuncs for the front-end GLSL compiler. --- src/mesa/drivers/dri/i965/brw_context.c | 5 +- src/mesa/drivers/dri/i965/brw_context.h | 3 + src/mesa/drivers/dri/i965/brw_program.c | 2 +- src/mesa/drivers/dri/i965/intel_extensions.c | 18 ++++-- src/vulkan/compiler.cpp | 63 +++++++++++++++----- src/vulkan/device.c | 6 +- src/vulkan/private.h | 2 +- 7 files changed, 70 insertions(+), 29 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index e01a7dbabee..23838056690 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -310,7 +310,7 @@ brw_init_driver_functions(struct brw_context *brw, functions->GetSamplePosition = gen6_get_sample_position; } -static void +void brw_initialize_context_constants(struct brw_context *brw) { struct gl_context *ctx = &brw->ctx; @@ -389,7 +389,8 @@ brw_initialize_context_constants(struct brw_context *brw) int max_samples; const int *msaa_modes = intel_supported_msaa_modes(brw->intelScreen); const int clamp_max_samples = - driQueryOptioni(&brw->optionCache, "clamp_max_samples"); + brw->optionCache.info != NULL ? + driQueryOptioni(&brw->optionCache, "clamp_max_samples") : -1; if (clamp_max_samples < 0) { max_samples = msaa_modes[0]; diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h index 5a35e48a481..cb4cc7fb36b 100644 --- a/src/mesa/drivers/dri/i965/brw_context.h +++ b/src/mesa/drivers/dri/i965/brw_context.h @@ -1988,6 +1988,9 @@ void intel_screen_destroy(struct intel_screen *screen); struct brw_context *intel_context_create(struct intel_screen *screen); void intel_context_destroy(struct brw_context *brw); +void +brw_initialize_context_constants(struct brw_context *brw); + #ifdef __cplusplus } #endif diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c index e5c0d3c7604..b056fbfc427 100644 --- a/src/mesa/drivers/dri/i965/brw_program.c +++ b/src/mesa/drivers/dri/i965/brw_program.c @@ -275,7 +275,7 @@ brw_get_scratch_bo(struct brw_context *brw, void brwInitFragProgFuncs( struct dd_function_table *functions ) { - assert(functions->ProgramStringNotify == _tnl_program_string); + /* assert(functions->ProgramStringNotify == _tnl_program_string); */ functions->NewProgram = brwNewProgram; functions->DeleteProgram = brwDeleteProgram; diff --git a/src/mesa/drivers/dri/i965/intel_extensions.c b/src/mesa/drivers/dri/i965/intel_extensions.c index c3eee31d017..d6da34c7065 100644 --- a/src/mesa/drivers/dri/i965/intel_extensions.c +++ b/src/mesa/drivers/dri/i965/intel_extensions.c @@ -275,9 +275,11 @@ intelInitExtensions(struct gl_context *ctx) ctx->Extensions.EXT_shader_integer_mix = ctx->Const.GLSLVersion >= 130; ctx->Extensions.EXT_timer_query = true; - if (brw->gen == 5 || can_write_oacontrol(brw)) { - ctx->Extensions.AMD_performance_monitor = true; - ctx->Extensions.INTEL_performance_query = true; + if (brw->bufmgr) { + if (brw->gen == 5 || can_write_oacontrol(brw)) { + ctx->Extensions.AMD_performance_monitor = true; + ctx->Extensions.INTEL_performance_query = true; + } } } @@ -285,6 +287,7 @@ intelInitExtensions(struct gl_context *ctx) uint64_t dummy; ctx->Extensions.ARB_blend_func_extended = + brw->optionCache.info == NULL || !driQueryOptionb(&brw->optionCache, "disable_blend_func_extended"); ctx->Extensions.ARB_conditional_render_inverted = true; ctx->Extensions.ARB_draw_buffers_blend = true; @@ -308,7 +311,7 @@ intelInitExtensions(struct gl_context *ctx) ctx->Extensions.OES_depth_texture_cube_map = true; /* Test if the kernel has the ioctl. */ - if (drm_intel_reg_read(brw->bufmgr, TIMESTAMP, &dummy) == 0) + if (brw->bufmgr && drm_intel_reg_read(brw->bufmgr, TIMESTAMP, &dummy) == 0) ctx->Extensions.ARB_timer_query = true; /* Only enable this in core profile because other parts of Mesa behave @@ -328,7 +331,8 @@ intelInitExtensions(struct gl_context *ctx) ctx->Extensions.ARB_texture_compression_bptc = true; ctx->Extensions.ARB_texture_view = true; - if (can_do_pipelined_register_writes(brw)) { + if (brw->bufmgr && + can_do_pipelined_register_writes(brw)) { ctx->Extensions.ARB_draw_indirect = true; ctx->Extensions.ARB_transform_feedback2 = true; ctx->Extensions.ARB_transform_feedback3 = true; @@ -353,7 +357,9 @@ intelInitExtensions(struct gl_context *ctx) if (ctx->API != API_OPENGL_CORE) ctx->Extensions.ARB_color_buffer_float = true; - if (ctx->Mesa_DXTn || driQueryOptionb(&brw->optionCache, "force_s3tc_enable")) + if (ctx->Mesa_DXTn || + (brw->optionCache.info != NULL && + driQueryOptionb(&brw->optionCache, "force_s3tc_enable"))) ctx->Extensions.EXT_texture_compression_s3tc = true; ctx->Extensions.ANGLE_texture_compression_dxt = true; diff --git a/src/vulkan/compiler.cpp b/src/vulkan/compiler.cpp index ead4117479c..a140217c4f4 100644 --- a/src/vulkan/compiler.cpp +++ b/src/vulkan/compiler.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -620,43 +621,73 @@ fail_on_compile_error(int status, const char *msg) struct anv_compiler { struct intel_screen *screen; struct brw_context *brw; + struct gl_pipeline_object pipeline; }; - extern "C" { struct anv_compiler * -anv_compiler_create(int fd) +anv_compiler_create(struct anv_device *device) { + const struct brw_device_info *devinfo = &device->info; struct anv_compiler *compiler; + struct gl_context *ctx; - compiler = (struct anv_compiler *) malloc(sizeof *compiler); + compiler = rzalloc(NULL, struct anv_compiler); if (compiler == NULL) return NULL; - compiler->screen = intel_screen_create(fd); - if (compiler->screen == NULL) { - free(compiler); - return NULL; - } + compiler->screen = rzalloc(compiler, struct intel_screen); + if (compiler->screen == NULL) + goto fail; - compiler->brw = intel_context_create(compiler->screen); - if (compiler->brw == NULL) { - free(compiler); - return NULL; - } + compiler->brw = rzalloc(compiler, struct brw_context); + if (compiler->brw == NULL) + goto fail; + + compiler->brw->optionCache.info = NULL; + compiler->brw->bufmgr = NULL; + compiler->brw->gen = devinfo->gen; + compiler->brw->is_g4x = devinfo->is_g4x; + compiler->brw->is_baytrail = devinfo->is_baytrail; + compiler->brw->is_haswell = devinfo->is_haswell; + compiler->brw->is_cherryview = devinfo->is_cherryview; + compiler->brw->intelScreen = compiler->screen; + compiler->screen->devinfo = &device->info; + + brw_process_intel_debug_variable(compiler->brw); + + if (device->info.gen >= 8 && !(INTEL_DEBUG & DEBUG_VEC4VS)) + compiler->brw->scalar_vs = true; + + ctx = &compiler->brw->ctx; + _mesa_init_shader_object_functions(&ctx->Driver); + + _mesa_init_constants(&ctx->Const, API_OPENGL_CORE); + + brw_initialize_context_constants(compiler->brw); + + intelInitExtensions(ctx); + + /* Set dd::NewShader */ + brwInitFragProgFuncs(&ctx->Driver); + + compiler->screen->compiler = brw_compiler_create(compiler, &device->info); + ctx->_Shader = &compiler->pipeline; compiler->brw->precompile = false; return compiler; + + fail: + ralloc_free(compiler); + return NULL; } void anv_compiler_destroy(struct anv_compiler *compiler) { - intel_context_destroy(compiler->brw); - intel_screen_destroy(compiler->screen); - free(compiler); + ralloc_free(compiler); } /* From gen7_urb.c */ diff --git a/src/vulkan/device.c b/src/vulkan/device.c index 7262481f8b5..3aa1c39aaec 100644 --- a/src/vulkan/device.c +++ b/src/vulkan/device.c @@ -386,11 +386,11 @@ VkResult anv_CreateDevice( anv_state_pool_init(&device->surface_state_pool, &device->surface_state_block_pool); - device->compiler = anv_compiler_create(device->fd); - device->aub_writer = NULL; - device->info = *physicalDevice->info; + device->compiler = anv_compiler_create(device); + device->aub_writer = NULL; + pthread_mutex_init(&device->mutex, NULL); anv_device_init_meta(device); diff --git a/src/vulkan/private.h b/src/vulkan/private.h index 1a6c3e0ca2f..65b81b3e918 100644 --- a/src/vulkan/private.h +++ b/src/vulkan/private.h @@ -710,7 +710,7 @@ anv_pipeline_create(VkDevice device, const struct anv_pipeline_create_info *extra, VkPipeline *pPipeline); -struct anv_compiler *anv_compiler_create(int fd); +struct anv_compiler *anv_compiler_create(struct anv_device *device); void anv_compiler_destroy(struct anv_compiler *compiler); int anv_compiler_run(struct anv_compiler *compiler, struct anv_pipeline *pipeline); void anv_compiler_free(struct anv_pipeline *pipeline); -- 2.30.2