[Mesa-dev] [PATCH 1/4] gallium: add resource normalization flags (v3)

Luca Barbieri luca at luca-barbieri.com
Tue Aug 17 00:09:10 PDT 2010


Changes in v3:
- Rework to use multiple flags

Changes in v2:
- Add a much longer and better comment

This allows:
1. The state tracker to tell the driver which normalizations it needs
2. The driver to tell the state tracker which normalization it prefers
---
 src/gallium/include/pipe/p_defines.h |   80 ++++++++++++++++++++++++++++++---
 1 files changed, 72 insertions(+), 8 deletions(-)

diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h
index 00aa207..1acb54e 100644
--- a/src/gallium/include/pipe/p_defines.h
+++ b/src/gallium/include/pipe/p_defines.h
@@ -281,14 +281,51 @@ enum pipe_transfer_usage {
  */
 #define PIPE_BIND_DEPTH_STENCIL        (1 << 0) /* get_tex_surface */
 #define PIPE_BIND_RENDER_TARGET        (1 << 1) /* get_tex_surface */
-#define PIPE_BIND_SAMPLER_VIEW         (1 << 2) /* get_sampler_view */
-#define PIPE_BIND_VERTEX_BUFFER        (1 << 3) /* set_vertex_buffers */
-#define PIPE_BIND_INDEX_BUFFER         (1 << 4) /* draw_elements */
-#define PIPE_BIND_CONSTANT_BUFFER      (1 << 5) /* set_constant_buffer */
-#define PIPE_BIND_DISPLAY_TARGET       (1 << 8) /* flush_front_buffer */
-#define PIPE_BIND_TRANSFER_WRITE       (1 << 9) /* get_transfer */
-#define PIPE_BIND_TRANSFER_READ        (1 << 10) /* get_transfer */
-#define PIPE_BIND_STREAM_OUTPUT        (1 << 11) /* set_stream_output_buffers */
+
+/* Sampler views can be created based on this texture. Only the
+ * normalization preferred by the driver can be used, unless the other
+ * flags below are set as well. Only clamp wrap modes are allowed. */
+#define PIPE_BIND_SAMPLER_VIEW_ANY     (1 << 2) /* get_sampler_view */
+
+/* State trackers must set this flag if they/the user API need to be able to use
+ * unnormalized coodinates with clamp, clamp-to-edge or clamp-to-border wrap
+ * mode with this resource when a sampler view based on it is bound.
+ *
+ * OpenCL and OpenGL TEXTURE_RECTANGLE textures will have this flag set.
+ */
+#define PIPE_BIND_SAMPLER_VIEW_UNNORMALIZED_CLAMP ((1 << 2) | (1 << 3))
+
+/* State trackers must set this flag if they/the user API need to be able to use
+ * unnormalized coordinates with non-clamp wrap modes with this resource
+ * when a sampler view based on it is bound.
+ *
+ * OpenCL textures will have this flag set.
+ */
+#define PIPE_BIND_SAMPLER_VIEW_UNNORMALIZED_NON_CLAMP ((1 << 2) | (1 << 4))
+
+/* State trackers must set this flag if they/the user API need to be able to use
+ * normalized coordinates with any wrap mode with this resource
+ * when a sampler view based on it is bound.
+ *
+ * OpenCL, OpenGL TEXTURE_2D and D3D11 textures will have this flag set.
+ */
+#define PIPE_BIND_SAMPLER_VIEW_NORMALIZED ((1 << 2) | (1 << 5))
+
+#define PIPE_BIND_SAMPLER_VIEW_ALL \
+		(PIPE_BIND_SAMPLER_VIEW_UNNORMALIZED_CLAMP \
+		| PIPE_BIND_SAMPLER_VIEW_UNNORMALIZED_NON_CLAMP \
+                | PIPE_BIND_SAMPLER_VIEW_NORMALIZED)
+
+/* XXX: this will be removed in the next patch */
+#define PIPE_BIND_SAMPLER_VIEW PIPE_BIND_SAMPLER_VIEW_ALL
+
+#define PIPE_BIND_VERTEX_BUFFER        (1 << 6) /* set_vertex_buffers */
+#define PIPE_BIND_INDEX_BUFFER         (1 << 7) /* draw_elements */
+#define PIPE_BIND_CONSTANT_BUFFER      (1 << 8) /* set_constant_buffer */
+#define PIPE_BIND_DISPLAY_TARGET       (1 << 9) /* flush_front_buffer */
+#define PIPE_BIND_TRANSFER_WRITE       (1 << 10) /* get_transfer */
+#define PIPE_BIND_TRANSFER_READ        (1 << 11) /* get_transfer */
+#define PIPE_BIND_STREAM_OUTPUT        (1 << 12) /* set_stream_output_buffers */
 #define PIPE_BIND_CUSTOM               (1 << 16) /* state-tracker/winsys usages */
 
 /* The first two flags above were previously part of the amorphous
@@ -313,6 +350,27 @@ enum pipe_transfer_usage {
 /* Flags for the driver about resource behaviour:
  */
 #define PIPE_RESOURCE_FLAG_GEN_MIPS    (1 << 0)  /* Driver performs autogen mips */
+
+/* State trackers should support using either normalization in all internal drawing
+ * code, using these flag to tell which one to use.
+ *
+ * If they do not have such support, then they should indicate the
+ * normalization needed using the bind flags, but they should be aware
+ * that if it is different than the API-needed one, some drivers may
+ * fail creation because they only support one normalization at once.
+ *
+ * State trackers must not set these flags.
+ *
+ * Drivers should set these flags to inform the state tracker of the normalization
+ * it should use in internal drawing code, if they prefer any.
+ *
+ * Drivers who need to always have the same normalization used for a given
+ * resource must set these flags according to the bind flags above, and refuse
+ * creation if too many normalization bind flags are set.
+ */
+#define PIPE_RESOURCE_FLAG_PREFER_UNNORMALIZED_COORDS (1 << 1)
+#define PIPE_RESOURCE_FLAG_PREFER_NORMALIZED_COORDS (1 << 2)
+
 #define PIPE_RESOURCE_FLAG_DRV_PRIV    (1 << 16) /* driver/winsys private */
 #define PIPE_RESOURCE_FLAG_ST_PRIV     (1 << 24) /* state-tracker/winsys private */
 
@@ -420,6 +478,12 @@ enum pipe_transfer_usage {
  */
 enum pipe_cap {
    PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS,
+   /* this means that NPOT textures with mipmaps and
+    * PIPE_BIND_SAMPLER_VIEW_NORMALIZED are supported.
+    *
+    * Otherwise, NPOT textures must have no mipmaps and use
+    * PIPE_BIND_SAMPLER_VIEW_UNNORMALIZED_CLAMP.
+    */
    PIPE_CAP_NPOT_TEXTURES,
    PIPE_CAP_TWO_SIDED_STENCIL,
    PIPE_CAP_GLSL,  /* XXX need something better */
-- 
1.7.0.4



More information about the mesa-dev mailing list