vk: Create a minimal context for the compiler
authorKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Thu, 4 Jun 2015 06:03:29 +0000 (23:03 -0700)
committerKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Mon, 8 Jun 2015 15:51:40 +0000 (08:51 -0700)
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
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_program.c
src/mesa/drivers/dri/i965/intel_extensions.c
src/vulkan/compiler.cpp
src/vulkan/device.c
src/vulkan/private.h

index e01a7dbabee2cba0f4044c2c83cb2fd7b9c35bd6..23838056690fa5a1422cab8c3e803fd3212737c7 100644 (file)
@@ -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];
index 5a35e48a48137fca5032df03bc5ddddac24b0748..cb4cc7fb36b0dacafb06d72c28adf792d8c1e36e 100644 (file)
@@ -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
index e5c0d3c760457c86e8e8fdbdfe3defb6dc8fcee2..b056fbfc4275018b3f6e04894139de060302be9c 100644 (file)
@@ -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;
index c3eee31d017173349bd7299db7c97fc5d32d50e0..d6da34c7065acf675717e1f47f97db2194664969 100644 (file)
@@ -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;
index ead4117479c4ed6d02f020fbb8d15ff1aaf62c44..a140217c4f4348eb8c8f3cbb37918d20d15653de 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <mesa/main/shaderobj.h>
 #include <mesa/main/fbobject.h>
+#include <mesa/main/context.h>
 #include <mesa/program/program.h>
 #include <glsl/program.h>
 
@@ -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 */
index 7262481f8b58e8f80e6d5a90698da4f98a2a6f7e..3aa1c39aaec91bca914fe416ab0f30e3d58c6aed 100644 (file)
@@ -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);
index 1a6c3e0ca2f7d83e9208cb8b311672ff585bb825..65b81b3e918dd9a523d7f9c53bf9849f790bf73f 100644 (file)
@@ -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);