i965/wm: emit null buffer surfaces when null buffers are attached
authorSamuel Iglesias Gonsalvez <siglesias@igalia.com>
Thu, 16 Apr 2015 11:18:01 +0000 (13:18 +0200)
committerSamuel Iglesias Gonsalvez <siglesias@igalia.com>
Fri, 25 Sep 2015 06:39:21 +0000 (08:39 +0200)
Otherwise we can expect odd things to happen if, for example, we ask
for the size of the attached buffer from shader code, since that
might query this value from the surface we uploaded and get random
results.

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
src/mesa/drivers/dri/i965/brw_wm_surface_state.c

index 24ff2d6a44319ffc8f5432c5a700267899ae8d52..61031d29db30b64bd31345d73c9373a75a2026a7 100644 (file)
@@ -939,28 +939,36 @@ brw_upload_ubo_surfaces(struct brw_context *brw,
          struct gl_uniform_buffer_binding *binding;
          binding =
             &ctx->UniformBufferBindings[shader->UniformBlocks[i].Binding];
-         intel_bo = intel_buffer_object(binding->BufferObject);
-         drm_intel_bo *bo =
-            intel_bufferobj_buffer(brw, intel_bo,
-                                   binding->Offset,
-                                   binding->BufferObject->Size - binding->Offset);
-         brw_create_constant_surface(brw, bo, binding->Offset,
-                                     bo->size - binding->Offset,
-                                     &surf_offsets[i],
-                                     dword_pitch);
+         if (binding->BufferObject == ctx->Shared->NullBufferObj) {
+            brw->vtbl.emit_null_surface_state(brw, 1, 1, 1, &surf_offsets[i]);
+         } else {
+            intel_bo = intel_buffer_object(binding->BufferObject);
+            drm_intel_bo *bo =
+               intel_bufferobj_buffer(brw, intel_bo,
+                                      binding->Offset,
+                                      binding->BufferObject->Size - binding->Offset);
+            brw_create_constant_surface(brw, bo, binding->Offset,
+                                        bo->size - binding->Offset,
+                                        &surf_offsets[i],
+                                        dword_pitch);
+         }
       } else {
          struct gl_shader_storage_buffer_binding *binding;
          binding =
             &ctx->ShaderStorageBufferBindings[shader->UniformBlocks[i].Binding];
-         intel_bo = intel_buffer_object(binding->BufferObject);
-         drm_intel_bo *bo =
-            intel_bufferobj_buffer(brw, intel_bo,
-                                   binding->Offset,
-                                   binding->BufferObject->Size - binding->Offset);
-         brw_create_buffer_surface(brw, bo, binding->Offset,
-                                   bo->size - binding->Offset,
-                                   &surf_offsets[i],
-                                   dword_pitch);
+         if (binding->BufferObject == ctx->Shared->NullBufferObj) {
+            brw->vtbl.emit_null_surface_state(brw, 1, 1, 1, &surf_offsets[i]);
+         } else {
+            intel_bo = intel_buffer_object(binding->BufferObject);
+            drm_intel_bo *bo =
+               intel_bufferobj_buffer(brw, intel_bo,
+                                      binding->Offset,
+                                      binding->BufferObject->Size - binding->Offset);
+            brw_create_buffer_surface(brw, bo, binding->Offset,
+                                      bo->size - binding->Offset,
+                                      &surf_offsets[i],
+                                      dword_pitch);
+         }
       }
    }