intel: Add render target attachments at BeginCommandBuffer for TilerGpus

Still allow for binding via CmdBindAttachments as the default if no
RENDER_PASS object is specified at begin time.  This allows for easier testing.
diff --git a/icd/intel/fb.c b/icd/intel/fb.c
index 174e47c..fe5def1 100644
--- a/icd/intel/fb.c
+++ b/icd/intel/fb.c
@@ -24,9 +24,19 @@
  */
 
 #include "dev.h"
+#include "mem.h"
 #include "obj.h"
+#include "view.h"
+#include "img.h"
 #include "fb.h"
 
+static void fb_destroy(struct intel_obj *obj)
+{
+    struct intel_framebuffer *fb = intel_fb_from_obj(obj);
+
+    intel_fb_destroy(fb);
+}
+
 XGL_RESULT intel_fb_create(struct intel_dev *dev,
                            const XGL_FRAMEBUFFER_CREATE_INFO* info,
                            struct intel_framebuffer ** fb_ret)
@@ -36,7 +46,47 @@
             dev->base.dbg, XGL_DBG_OBJECT_FRAMEBUFFER, info, 0);
     if (!fb)
         return XGL_ERROR_OUT_OF_MEMORY;
-    //todo
+
+    XGL_UINT width = 0, height = 0;
+    XGL_UINT i;
+
+    for (i = 0; i < info->colorAttachmentCount; i++) {
+        const XGL_COLOR_ATTACHMENT_BIND_INFO *att = &(info->pColorAttachments[i]);
+        const struct intel_rt_view *rt = intel_rt_view(att->view);
+        const struct intel_layout *layout = &rt->img->layout;
+
+        if (i == 0) {
+            width = layout->width0;
+            height = layout->height0;
+        } else {
+            if (width > layout->width0)
+                width = layout->width0;
+            if (height > layout->height0)
+                height = layout->height0;
+        }
+
+        fb->rt[i] = rt;
+    }
+    fb->rt_count = info->colorAttachmentCount;
+
+    if (info->pDepthStencilAttachment) {
+        const struct intel_layout *layout;
+
+        fb->ds = intel_ds_view(info->pDepthStencilAttachment->view);
+        layout = &fb->ds->img->layout;
+
+        if (width > layout->width0)
+            width = layout->width0;
+        if (height > layout->height0)
+            height = layout->height0;
+    } else {
+        fb->ds = NULL;
+    }
+
+    fb->sample_count = info->sampleCount;
+    fb->width = width;
+    fb->height = height;
+    fb->obj.destroy = fb_destroy;
 
     *fb_ret = fb;
 
@@ -44,7 +94,19 @@
 
 }
 
-XGL_RESULT intel_rp_create(struct intel_dev *dev,
+void intel_fb_destroy(struct intel_framebuffer *fb)
+{
+    intel_base_destroy(&fb->obj.base);
+}
+
+static void render_pass_destroy(struct intel_obj *obj)
+{
+    struct intel_render_pass *rp = intel_rp_from_obj(obj);
+
+    intel_rp_destroy(rp);
+}
+
+XGL_RESULT intel_render_pass_create(struct intel_dev *dev,
                            const XGL_RENDER_PASS_CREATE_INFO* info,
                            struct intel_render_pass** rp_ret)
 {
@@ -53,13 +115,23 @@
             dev->base.dbg, XGL_DBG_OBJECT_RENDER_PASS, info, 0);
     if (!rp)
         return XGL_ERROR_OUT_OF_MEMORY;
-    //todo
+
+    rp->obj.destroy = render_pass_destroy;
+    rp->fb = intel_framebuffer(info->framebuffer);
+    //TODO add any clear color ops
 
     *rp_ret = rp;
 
     return XGL_SUCCESS;
 }
 
+void intel_render_pass_destroy(struct intel_render_pass *rp)
+{
+    rp->fb = NULL;
+
+    intel_base_destroy(&rp->obj.base);
+}
+
 XGL_RESULT XGLAPI intelCreateFramebuffer(
     XGL_DEVICE                                  device,
     const XGL_FRAMEBUFFER_CREATE_INFO*          info,
@@ -78,7 +150,7 @@
 {
     struct intel_dev *dev = intel_dev(device);
 
-    return intel_rp_create(dev, info, (struct intel_render_pass **) rp_ret);
+    return intel_render_pass_create(dev, info, (struct intel_render_pass **) rp_ret);
 }