aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys/radeon
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2011-05-07 19:55:45 +0200
committerMarek Olšák <[email protected]>2011-05-15 03:28:32 +0200
commitfdd37af3f76ea3ac32f21e9a9c41979a9b33cc5c (patch)
tree7296c98673124d2bcc39a530c00f75a00567c15e /src/gallium/winsys/radeon
parent904f43f1909256956856665acf072db71fb92092 (diff)
r300g: dynamically ask for and release Hyper-Z access
We ask for Hyper-Z access when clearing a zbuffer. We release it if no zbuffer clear has been done for 2 seconds.
Diffstat (limited to 'src/gallium/winsys/radeon')
-rw-r--r--src/gallium/winsys/radeon/drm/radeon_drm_winsys.c100
-rw-r--r--src/gallium/winsys/radeon/drm/radeon_drm_winsys.h10
-rw-r--r--src/gallium/winsys/radeon/drm/radeon_winsys.h16
3 files changed, 99 insertions, 27 deletions
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index 37f6d18689d..3ac57d25b5e 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -48,22 +48,59 @@
#define RADEON_INFO_WANT_CMASK 8
#endif
-/* Enable/disable feature access. Return TRUE on success. */
-static boolean radeon_set_fd_access(int fd, unsigned request, boolean enable)
+/* Enable/disable feature access for one command stream.
+ * If enable == TRUE, return TRUE on success.
+ * Otherwise, return FALSE.
+ *
+ * We basically do the same thing kernel does, because we have to deal
+ * with multiple contexts (here command streams) backed by one winsys. */
+static boolean radeon_set_fd_access(struct radeon_drm_cs *applier,
+ struct radeon_drm_cs **owner,
+ pipe_mutex *mutex,
+ unsigned request, boolean enable)
{
struct drm_radeon_info info = {0};
unsigned value = enable ? 1 : 0;
+ pipe_mutex_lock(*mutex);
+
+ /* Early exit if we are sure the request will fail. */
+ if (enable) {
+ if (*owner) {
+ pipe_mutex_unlock(*mutex);
+ return FALSE;
+ }
+ } else {
+ if (*owner != applier) {
+ pipe_mutex_unlock(*mutex);
+ return FALSE;
+ }
+ }
+
+ /* Pass through the request to the kernel. */
info.value = (unsigned long)&value;
info.request = request;
-
- if (drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info)) != 0)
+ if (drmCommandWriteRead(applier->ws->fd, DRM_RADEON_INFO,
+ &info, sizeof(info)) != 0) {
+ pipe_mutex_unlock(*mutex);
return FALSE;
+ }
- if (enable && !value)
- return FALSE;
+ /* Update the rights in the winsys. */
+ if (enable) {
+ if (value) {
+ *owner = applier;
+ fprintf(stderr, "radeon: Acquired Hyper-Z.\n");
+ pipe_mutex_unlock(*mutex);
+ return TRUE;
+ }
+ } else {
+ *owner = NULL;
+ fprintf(stderr, "radeon: Released Hyper-Z.\n");
+ }
- return TRUE;
+ pipe_mutex_unlock(*mutex);
+ return FALSE;
}
/* Helper function to do the ioctls needed for setup and init. */
@@ -138,16 +175,6 @@ static void do_ioctls(struct radeon_drm_winsys *winsys)
}
winsys->z_pipes = target;
- if (debug_get_bool_option("RADEON_HYPERZ", FALSE)) {
- winsys->hyperz = radeon_set_fd_access(winsys->fd,
- RADEON_INFO_WANT_HYPERZ, TRUE);
- }
-
- if (debug_get_bool_option("RADEON_CMASK", FALSE)) {
- winsys->aacompress = radeon_set_fd_access(winsys->fd,
- RADEON_INFO_WANT_CMASK, TRUE);
- }
-
retval = drmCommandWriteRead(winsys->fd, DRM_RADEON_GEM_INFO,
&gem_info, sizeof(gem_info));
if (retval) {
@@ -167,6 +194,9 @@ static void radeon_winsys_destroy(struct radeon_winsys *rws)
{
struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)rws;
+ pipe_mutex_destroy(ws->hyperz_owner_mutex);
+ pipe_mutex_destroy(ws->cmask_owner_mutex);
+
ws->cman->destroy(ws->cman);
ws->kman->destroy(ws->kman);
FREE(rws);
@@ -198,14 +228,38 @@ static uint32_t radeon_get_value(struct radeon_winsys *rws,
return ws->drm_major*100 + ws->drm_minor >= 206;
case RADEON_VID_DRM_2_8_0:
return ws->drm_major*100 + ws->drm_minor >= 208;
- case RADEON_VID_CAN_HYPERZ:
- return ws->hyperz;
- case RADEON_VID_CAN_AACOMPRESS:
- return ws->aacompress;
}
return 0;
}
+static boolean radeon_cs_request_feature(struct radeon_winsys_cs *rcs,
+ enum radeon_feature_id fid,
+ boolean enable)
+{
+ struct radeon_drm_cs *cs = radeon_drm_cs(rcs);
+
+ switch (fid) {
+ case RADEON_FID_HYPERZ_RAM_ACCESS:
+ if (debug_get_bool_option("RADEON_HYPERZ", FALSE)) {
+ return radeon_set_fd_access(cs, &cs->ws->hyperz_owner,
+ &cs->ws->hyperz_owner_mutex,
+ RADEON_INFO_WANT_HYPERZ, enable);
+ } else {
+ return FALSE;
+ }
+
+ case RADEON_FID_CMASK_RAM_ACCESS:
+ if (debug_get_bool_option("RADEON_CMASK", FALSE)) {
+ return radeon_set_fd_access(cs, &cs->ws->cmask_owner,
+ &cs->ws->cmask_owner_mutex,
+ RADEON_INFO_WANT_CMASK, enable);
+ } else {
+ return FALSE;
+ }
+ }
+ return FALSE;
+}
+
struct radeon_winsys *radeon_drm_winsys_create(int fd)
{
struct radeon_drm_winsys *ws = CALLOC_STRUCT(radeon_drm_winsys);
@@ -231,10 +285,14 @@ struct radeon_winsys *radeon_drm_winsys_create(int fd)
/* Set functions. */
ws->base.destroy = radeon_winsys_destroy;
ws->base.get_value = radeon_get_value;
+ ws->base.cs_request_feature = radeon_cs_request_feature;
radeon_bomgr_init_functions(ws);
radeon_drm_cs_init_functions(ws);
+ pipe_mutex_init(ws->hyperz_owner_mutex);
+ pipe_mutex_init(ws->cmask_owner_mutex);
+
return &ws->base;
fail:
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h
index e1b9493fc10..d5186bc4d17 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h
@@ -32,6 +32,8 @@
#include "radeon_winsys.h"
+#include "os/os_thread.h"
+
struct radeon_drm_winsys {
struct radeon_winsys base;
@@ -52,10 +54,10 @@ struct radeon_drm_winsys {
unsigned drm_minor;
unsigned drm_patchlevel;
- /* Hyper-Z user */
- boolean hyperz;
- /* AA compression (CMask) */
- boolean aacompress;
+ struct radeon_drm_cs *hyperz_owner;
+ pipe_mutex hyperz_owner_mutex;
+ struct radeon_drm_cs *cmask_owner;
+ pipe_mutex cmask_owner_mutex;
};
static INLINE struct radeon_drm_winsys *
diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h
index ca0e6624138..3a64e4abc35 100644
--- a/src/gallium/winsys/radeon/drm/radeon_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h
@@ -87,9 +87,11 @@ enum radeon_value_id {
* - TBD
*/
RADEON_VID_DRM_2_8_0,
+};
- RADEON_VID_CAN_HYPERZ, /* ZMask + HiZ */
- RADEON_VID_CAN_AACOMPRESS, /* CMask */
+enum radeon_feature_id {
+ RADEON_FID_HYPERZ_RAM_ACCESS, /* ZMask + HiZ */
+ RADEON_FID_CMASK_RAM_ACCESS,
};
struct radeon_winsys {
@@ -314,6 +316,16 @@ struct radeon_winsys {
*/
boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs,
struct radeon_winsys_cs_handle *buf);
+
+ /**
+ * Request access to a feature for a command stream.
+ *
+ * \param cs A command stream.
+ * \param fid A winsys buffer.
+ */
+ boolean (*cs_request_feature)(struct radeon_winsys_cs *cs,
+ enum radeon_feature_id fid,
+ boolean enable);
};
#endif