Fix nv40_miptree_layout pitch
PATCH 1/1 Fix nv40_miptree_layout pitch
This patch fixes two issues in nv40_miptree_layout.
First, pt->width0 is used, which is the size of the whole texture, while width, which is the size of the mipmap level, should be used.
Second, the current code does not 64-byte align the pitch of swizzled textures. However, on my NV40 this causes a pgraph error regarding the pitch register (and sometimes a system lockup too), which is fixed by this patch.
I'm not sure how small mipmaps could have worked with the previous code.
Also the offset code below may need some review.
And furthermore, wide_pitch is set for any kind of texture usage, so maybe it should be made unconditional (what's the point of allocating a texture that the GPU can't use in any way?).
(quoted diff) +0 -0
b/src/gallium/drivers/nv40/nv40_miptree.c
index b974e68..9f54187 100644
src/gallium/drivers/nv40/nv40_miptree.c +0 -2
@@ -31,8 +31,8 @@ nv40_miptree_layout(struct nv40_miptree *mt) }for (l =0 ; l <= pt->last_level; l++) { -if (wide_pitch && (pt->tex_usage &NOUVEAU_TEXTURE_USAGE_LINEAR )) - mt->level[l].pitch = align(util_format_get_stride(pt->format,
pt->width0), 64);
+ if (wide_pitch)
+ mt->level[l].pitch = align(util_format_get_stride(pt->format, width), 64);
else
mt->level[l].pitch = util_format_get_stride(pt->format, width);
A message that is not in the archive (sent off-list or not yet received): ff13bc9a0912251659v27b69ea5he53c912cf86939b7-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 30 lines · Luca Barbieri
This patch fixes two issues in
nv40_miptree_layout.First,
pt->width0is used, which is the size of the whole texture, while width, which is the size of the mipmap level, should be used.Second, the current code does not 64-byte align the pitch of swizzled textures. However, on my NV40 this causes a pgraph error regarding the pitch register (and sometimes a system lockup too), which is fixed by this patch.
I'm not sure how small mipmaps could have worked with the previous code.Also the offset code below may need some review.
And furthermore,wide_pitchis set for any kind of texture usage, so maybe it should be made unconditional (what's the point of allocating a texture that the GPU can't use in any way?).src/gallium/drivers/nv40/nv40_miptree.c +2
-2@@ -31,8 +31,8 @@ nv40_miptree_layout(struct nv40_miptree *mt) } for (l = 0; l <= pt->last_level; l++) { - if (wide_pitch && (pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)) - mt->level[l].pitch = align(util_format_get_stride(pt->format, pt->width0), 64); + if (wide_pitch) + mt->level[l].pitch = align(util_format_get_stride(pt->format, width), 64);
Quoted 2 lines
else
mt->level[l].pitch =util_format_get_stride(pt->format, width);
Hi,
Width0 is actually the correct value as far as I know. All mip levels of a linear texture are padded out to the pitch of the base level so they can be used by the 3D engine. I haven't run into the 64-byte pitch error for swizzled textures myself, if you can reproduce it and have a patch for it it would be appreciated.
The wide_pitch flag is set for textures the 3D engine will sample from or render to, but for temporary textures that are used to do swizzled texture transfers the 2D engine doesn't care (or will complain, I don't remember), so it saves a bit of memory.
A message that is not in the archive (sent off-list or not yet received): 586c2acd0912251833x1665b258ica2a55ccfff629f6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
You are right. The patch is wrong. Both changes fix my program, but do break OpenGL (e.g. redbook/mipmap).
I managed to reproduce the problem with perf/genmipmap.
When run, it causes several instances of one of these 3 errors (using swizzled textures):
[12949.125732] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - nSource: DATA_ERROR, nStatus: BAD_ARGUMENT [12949.125738] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - Ch 3/7 Class 0x4097 Mthd 0x020c Data 0x00000000:0x00000008 [12949.214750] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - nSource: DATA_ERROR, nStatus: BAD_ARGUMENT [12949.214757] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - Ch 3/7 Class 0x4097 Mthd 0x020c Data 0x00000000:0x00000010 [12951.752081] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - nSource: DATA_ERROR, nStatus: BAD_ARGUMENT [12951.752088] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - Ch 3/7 Class
0x4097 Mthd 0x020c Data 0x00000000:0x00000020
It seems they are due to PGRAPH not liking an 8/16/32 pitch. In my program I got these as well and narrowed it down to doing mipmap generation on the small levels that have pitch set that way.
This patch does make them go away but breaks progs/mipmap (both changes are wrong).
Apparently the miptree layout is correct, but the lowest mipmap levels cannot be rendered to with the current code (that however tries to, resulting in the errors), possibly due to an hardware limitation.
I guess a possible solution could be to modify nv40_miptree_surface_new to allocate temporary surfaces for pitch <64 levels (i.e. 8x, 4x and 1x mipmap levels for RGBA) and then do a copy with the 2D engine in nv40_miptree_surface_del.
Alternatively, for square Pot textures, it may be possible to map the 8x8, 4x4, 2x2 and 1x1 mipmaps as a single 16x16 pitch 64 swizzled texture in which they should appear as rectangles, and then restrict drawing to the rectangle by adjusting the viewport (and finding a way to make bypass work too). Not sure if this works and whether it can be generalized to non-square-pot textures.
How does the nVidia driver implement glGenerateMipmap?
A message that is not in the archive (sent off-list or not yet received): ff13bc9a0912251937i3c32e044kc84f0c70ff1e9547-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 36 lines · Luca Barbieri
You are right. The patch is wrong. Both changes fix my program, but do break OpenGL (e.g. redbook/mipmap).
I managed to reproduce the problem with perf/genmipmap.
When run, it causes several instances of one of these 3 errors (using swizzled textures):
[12949.125732] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - nSource: DATA_ERROR, nStatus: BAD_ARGUMENT [12949.125738] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - Ch 3/7 Class 0x4097 Mthd 0x020c Data 0x00000000:0x00000008 [12949.214750] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - nSource: DATA_ERROR, nStatus: BAD_ARGUMENT [12949.214757] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - Ch 3/7 Class 0x4097 Mthd 0x020c Data 0x00000000:0x00000010 [12951.752081] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - nSource: DATA_ERROR, nStatus: BAD_ARGUMENT [12951.752088] [drm] nouveau 0000:01:00.0: PGRAPH_ERROR - Ch 3/7 Class
0x4097Mthd0x020cData 0x00000000:0x00000020It seems they are due to PGRAPH not liking an 8/16/32 pitch. In my program I got these as well and narrowed it down to doing mipmap generation on the small levels that have pitch set that way.
This patch does make them go away but breaks progs/mipmap (both changes are wrong).
Apparently the miptree layout is correct, but the lowest mipmap levels cannot be rendered to with the current code (that however tries to, resulting in the errors), possibly due to an hardware limitation.
I guess a possible solution could be to modify
nv40_miptree_surface_newto allocate temporary surfaces for pitch <64 levels (i.e. 8x, 4x and 1x mipmap levels for RGBA) and then do a copy with the 2D engine innv40_miptree_surface_del.
Quoted 9 lines
Alternatively, for square Pot textures, it may be possible to map the 8x8, 4x4, 2x2 and 1x1 mipmaps as a single 16x16 pitch 64 swizzled texture in which they should appear as rectangles, and then restrict drawing to the rectangle by adjusting the viewport (and finding a way to make bypass work too). Not sure if this works and whether it can be generalized to non-square-pot textures.
How does the nVidia driver implement glGenerateMipmap?
Hi,
Yes this is a known problem. The hardware has two incompatible constraints; the layout of swizzled mipmaps makes rendering directly to the last few levels impossible as you saw. Personally I think the first approach is cleaner; in nv40_miptree_surface_new() if the PIPE_BUFFER_USAGE_GPU_WRITE flag is set but the offset & pitch of the surface doesn't allow it to be used as a render target create a temp. I have an old patch that does this that I will try to dig up if you have a program that suffers from this limitation.
The Nvidia driver uses the 2D engine to generate the mipmap chain IIRC. For us this is handled by shared code in Mesa, which tries to generate the mipmap chain by using the 3D engine to render each level. This works fine for linear textures, not so well for swizzled, and currently the driver framework does not let us generate the mipmap chain using the 2D engine (at least without ugly hacks).
A message that is not in the archive (sent off-list or not yet received): 586c2acd0912252032t69dc63cej51472ecacc17d05f-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
I just coded a patch that does this and seems to work fine. It must be fixed since it breaks OpenGL (or the state tracker can be changed, but it seems better to do it in the driver).
The patch also fixes NV20 and NV30 in the same way. They compile but are untested.
I would guess that using the 3D engine is faster for the larger levels, but the 2D engine is faster for the smaller ones (and lacks this issue).
(quoted diff) +0 -0
b/src/gallium/drivers/nouveau/nouveau_winsys.h
index 42c77e5..4c3e08a 100644
src/gallium/drivers/nouveau/nouveau_winsys.h +3 -0
@@ -23,6 +23,9 @@#define NOUVEAU_BUFFER_USAGE_ZETA (1 << 17)#define NOUVEAU_BUFFER_USAGE_TRANSFER (1 << 18) +/* use along GPU_WRITE for 2D-only writes */ +#define NOUVEAU_BUFFER_USAGE_NO_RENDER (1 << 19) +extern struct pipe_screen *nv04_screen_create (struct pipe_winsys *ws,struct nouveau_device *);
(quoted diff) +0 -0
b/src/gallium/drivers/nv04/nv04_surface_2d.c
index 12df7fd..16e8379 100644
src/gallium/drivers/nv04/nv04_surface_2d.c +3 -0
@@ -491,3 +501,49 @@ nv04_surface_2d_init(struct nouveau_screen *screen) ctx->fill = nv04_surface_fill;return ctx; } + +struct nv04_surface * +nv04_surface_wrap_for_render(struct pipe_screen *pscreen, struct
nv04_surface_2d* eng2d, struct nv04_surface* ns)
+{
+ int temp_flags;
+
+ // printf("creating temp, flags is %i!\n", flags);
+
+ if(ns->base.usage & PIPE_BUFFER_USAGE_DISCARD)
+ {
+ temp_flags = ns->base.usage | PIPE_BUFFER_USAGE_GPU_READ;
+ ns->base.usage = PIPE_BUFFER_USAGE_GPU_WRITE |NOUVEAU_BUFFER_USAGE_NO_RENDER | PIPE_BUFFER_USAGE_DISCARD;
+ }
+ else
+ {
+ temp_flags = ns->base.usage | PIPE_BUFFER_USAGE_GPU_READ |PIPE_BUFFER_USAGE_GPU_WRITE;
+ ns->base.usage = PIPE_BUFFER_USAGE_GPU_WRITE |NOUVEAU_BUFFER_USAGE_NO_RENDER | PIPE_BUFFER_USAGE_GPU_READ;
+ }
+
+ struct nv40_screen* screen = (struct nv40_screen*)pscreen;
+ ns->base.usage = PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE;
+
+ struct pipe_texture templ;
+ memset(&templ, 0, sizeof(templ));
+ templ.format = ns->base.texture->format;
+ templ.target = PIPE_TEXTURE_2D;
+ templ.width0 = ns->base.width;
+ templ.height0 = ns->base.height;
+ templ.depth0 = 1;
+ templ.last_level = 0;
+
+ // TODO: this is probably wrong and we should specifically handle
multisampling somehow once it is implemented
+ templ.nr_samples = ns->base.texture->nr_samples;
+
+ templ.tex_usage = ns->base.texture->tex_usage |PIPE_TEXTURE_USAGE_RENDER_TARGET;
+
+ struct pipe_texture* temp_tex = pscreen->texture_create(pscreen, &templ);
+ struct nv04_surface* temp_ns = (struct
nv04_surface*)pscreen->get_tex_surface(pscreen, temp_tex, 0, 0, 0, temp_flags);
+ temp_ns->backing = ns;
+
+ if(ns->base.usage & PIPE_BUFFER_USAGE_GPU_READ)
+ eng2d->copy(eng2d, &temp_ns->backing->base, 0, 0, &ns->base, 0, 0,ns->base.width, ns->base.height);
+
+ return temp_ns;
+}
+
(quoted diff) +0 -0
b/src/gallium/drivers/nv04/nv04_surface_2d.h
index 02b3f56..ce696a1 100644
src/gallium/drivers/nv04/nv04_surface_2d.h +3 -0
@@ -4,6 +4,7 @@struct nv04_surface {struct pipe_surface base;unsigned pitch; +struct nv04_surface * backing; };struct nv04_surface_2d {
@@ -30,4 +31,7 @@ nv04_surface_2d_init(struct nouveau_screen *screen);void nv04_surface_2d_takedown (struct nv04_surface_2d **); +struct nv04_surface * +nv04_surface_wrap_for_render(struct pipe_screen *pscreen, struct
nv04_surface_2d* eng2d, struct nv04_surface* ns);
+
#endif
(quoted diff) +0 -0
b/src/gallium/drivers/nv20/nv20_miptree.c
index d1291a9..8f7538e 100644
src/gallium/drivers/nv20/nv20_miptree.c +1 -0
@@ -6,6 +6,7 @@#include "nv20_context.h" #include "nv20_screen.h" +#include "../nv04/nv04_surface_2d.h" static void nv20_miptree_layout (struct nv20_miptree *nv20mt)
@@ -127,6 +128,12 @@ nv20_miptree_create(struct pipe_screen *screen,
const struct pipe_texture *pt)
if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
buf_usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE;
+ /* apparently we can't render to swizzled surfaces smaller than 64
bytes, so make them linear.
+ * If the user did not ask for a render target, they can still
render to it, but it will cost them an extra copy.
+ * This also happens for small mipmaps of large textures. */
+ if (pt->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET &&util_format_get_stride(pt->format, pt->width0) < 64)
+ mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+
nv20_miptree_layout(mt);
mt->buffer = screen->buffer_create(screen, 256, buf_usage, mt->total_size);
@@ -183,12 +190,27 @@ nv20_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt,
ns->base.offset = nv20mt->level[level].image_offset[0];
}
+ /* create a linear temporary that we can render into if necessary.
+ * Note that ns->pitch is always a multiple of 64 for linear
surfaces and swizzled surfaces are POT, so
+ * ns->pitch & 63 is equivalent to (ns->pitch < 64 && swizzled)*/
+ if((ns->pitch & 63) && (ns->base.usage &
(PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER)) == PIPE_BUFFER_USAGE_GPU_WRITE)
+ return &nv04_surface_wrap_for_render(screen, ((struct
nv20_screen*)screen)->eng2d, ns)->base;
+
return &ns->base;
}
static void nv20_miptree_surface_destroy(struct pipe_surface *ps) {
+ struct nv04_surface* ns = (struct nv04_surface*)ps;
+ if(ns->backing)
+ {
+ struct nv20_screen* screen = (struct nv20_screen*)ps->texture->screen;
+ if(ns->backing->base.usage & PIPE_BUFFER_USAGE_GPU_WRITE)
+ screen->eng2d->copy(screen->eng2d, &ns->backing->base, 0, 0, ps,
0, 0, ns->base.width, ns->base.height);
+ nv20_miptree_surface_destroy(&ns->backing->base);
+ }
+
pipe_texture_reference(&ps->texture, NULL); FREE(ps);
}
(quoted diff) +0 -0
b/src/gallium/drivers/nv20/nv20_transfer.c
index 69b79c8..7b51188 100644
src/gallium/drivers/nv20/nv20_transfer.c +1 -1
@@ -126,7 +126,7 @@ nv20_transfer_del(struct pipe_transfer *ptx) dst = pscreen->get_tex_surface(pscreen, ptx->texture, ptx->face, ptx->level, ptx->zslice, -PIPE_BUFFER_USAGE_GPU_WRITE ); + PIPE_BUFFER_USAGE_GPU_WRITE |
NOUVEAU_BUFFER_USAGE_NO_RENDER);
/* TODO: Check if SIFM can deal with x,y,w,h when swizzling */ nvscreen->eng2d->copy(nvscreen->eng2d,
(quoted diff) +0 -0
b/src/gallium/drivers/nv30/nv30_miptree.c
index ce95d97..8fbba38 100644
src/gallium/drivers/nv30/nv30_miptree.c +1 -0
@@ -5,6 +5,7 @@#include "util/u_math.h" #include "nv30_context.h" +#include "../nv04/nv04_surface_2d.h" static void nv30_miptree_layout (struct nv30_miptree *nv30mt)
@@ -108,6 +109,12 @@ nv30_miptree_create(struct pipe_screen *pscreen,
const struct pipe_texture *pt)
if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
buf_usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE;
+ /* apparently we can't render to swizzled surfaces smaller than 64
bytes, so make them linear.
+ * If the user did not ask for a render target, they can still
render to it, but it will cost them an extra copy.
+ * This also happens for small mipmaps of large textures. */
+ if (pt->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET &&util_format_get_stride(pt->format, pt->width0) < 64)
+ mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+
nv30_miptree_layout(mt);
mt->buffer = pscreen->buffer_create(pscreen, 256, buf_usage,
@@ -196,12 +203,27 @@ nv30_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
ns->base.offset = nv30mt->level[level].image_offset[0];
}
+ /* create a linear temporary that we can render into if necessary.
+ * Note that ns->pitch is always a multiple of 64 for linear
surfaces and swizzled surfaces are POT, so
+ * ns->pitch & 63 is equivalent to (ns->pitch < 64 && swizzled)*/
+ if((ns->pitch & 63) && (ns->base.usage &
(PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER)) == PIPE_BUFFER_USAGE_GPU_WRITE)
+ return &nv04_surface_wrap_for_render(pscreen, ((struct
nv30_screen*)pscreen)->eng2d, ns)->base;
+
return &ns->base;
}
static void nv30_miptree_surface_del(struct pipe_surface *ps) {
+ struct nv04_surface* ns = (struct nv04_surface*)ps;
+ if(ns->backing)
+ {
+ struct nv30_screen* screen = (struct nv30_screen*)ps->texture->screen;
+ if(ns->backing->base.usage & PIPE_BUFFER_USAGE_GPU_WRITE)
+ screen->eng2d->copy(screen->eng2d, &ns->backing->base, 0, 0, ps,
0, 0, ns->base.width, ns->base.height);
+ nv30_miptree_surface_del(&ns->backing->base);
+ }
+
pipe_texture_reference(&ps->texture, NULL); FREE(ps);
}
(quoted diff) +0 -0
b/src/gallium/drivers/nv30/nv30_transfer.c
index 2255a02..68047c4 100644
src/gallium/drivers/nv30/nv30_transfer.c +1 -1
@@ -126,7 +126,7 @@ nv30_transfer_del(struct pipe_transfer *ptx) dst = pscreen->get_tex_surface(pscreen, ptx->texture, ptx->face, ptx->level, ptx->zslice, -PIPE_BUFFER_USAGE_GPU_WRITE ); + PIPE_BUFFER_USAGE_GPU_WRITE |
NOUVEAU_BUFFER_USAGE_NO_RENDER);
/* TODO: Check if SIFM can deal with x,y,w,h when swizzling */ nvscreen->eng2d->copy(nvscreen->eng2d,
(quoted diff) +0 -0
b/src/gallium/drivers/nv40/nv40_miptree.c
index b5a193e..89bd155 100644
src/gallium/drivers/nv40/nv40_miptree.c +1 -0
@@ -5,6 +5,7 @@#include "util/u_math.h" #include "nv40_context.h" +#include "../nv04/nv04_surface_2d.h"
@@ -108,6 +106,12 @@ nv40_miptree_create(struct pipe_screen *pscreen,
const struct pipe_texture *pt)
if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
buf_usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE;
+ /* apparently we can't render to swizzled surfaces smaller than 64
bytes, so make them linear.
+ * If the user did not ask for a render target, they can still
render to it, but it will cost them an extra copy.
+ * This also happens for small mipmaps of large textures. */
+ if (pt->tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET &&util_format_get_stride(pt->format, pt->width0) < 64)
+ mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+
nv40_miptree_layout(mt);
mt->buffer = pscreen->buffer_create(pscreen, 256, buf_usage, mt->total_size);
@@ -194,12 +198,27 @@ nv40_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
ns->base.offset = mt->level[level].image_offset[0];
}
+ /* create a linear temporary that we can render into if necessary.
+ * Note that ns->pitch is always a multiple of 64 for linear
surfaces and swizzled surfaces are POT, so
+ * ns->pitch & 63 is equivalent to (ns->pitch < 64 && swizzled)*/
+ if((ns->pitch & 63) && (ns->base.usage &
(PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER)) == PIPE_BUFFER_USAGE_GPU_WRITE)
+ return &nv04_surface_wrap_for_render(pscreen, ((struct
nv40_screen*)pscreen)->eng2d, ns)->base;
+
return &ns->base;
}
static void nv40_miptree_surface_del(struct pipe_surface *ps) {
+ struct nv04_surface* ns = (struct nv04_surface*)ps;
+ if(ns->backing)
+ {
+ struct nv40_screen* screen = (struct nv40_screen*)ps->texture->screen;
+ if(ns->backing->base.usage & PIPE_BUFFER_USAGE_GPU_WRITE)
+ screen->eng2d->copy(screen->eng2d, &ns->backing->base, 0, 0, ps,
0, 0, ns->base.width, ns->base.height);
+ nv40_miptree_surface_del(&ns->backing->base);
+ }
+
pipe_texture_reference(&ps->texture, NULL); FREE(ps);
}
(quoted diff) +0 -0
b/src/gallium/drivers/nv40/nv40_transfer.c
index b084a38..adfd035 100644
src/gallium/drivers/nv40/nv40_transfer.c +1 -1
@@ -126,7 +126,7 @@ nv40_transfer_del(struct pipe_transfer *ptx) dst = pscreen->get_tex_surface(pscreen, ptx->texture, ptx->face, ptx->level, ptx->zslice, -PIPE_BUFFER_USAGE_GPU_WRITE ); + PIPE_BUFFER_USAGE_GPU_WRITE |
NOUVEAU_BUFFER_USAGE_NO_RENDER);
/* TODO: Check if SIFM can deal with x,y,w,h when swizzling */ nvscreen->eng2d->copy(nvscreen->eng2d,
A message that is not in the archive (sent off-list or not yet received): ff13bc9a0912252222t7ed30b00q3b5081a8ee6586c4-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 10 lines · Luca Barbieri
I just coded a patch that does this and seems to work fine. It must be fixed since it breaks OpenGL (or the state tracker can be changed, but it seems better to do it in the driver).
The patch also fixes NV20 and NV30 in the same way. They compile but are untested.
I would guess that using the 3D engine is faster for the larger levels, but the 2D engine is faster for the smaller ones (and lacks this issue).
Hi, this patch and the other swizzle related one seem to have been mangled, they're wrapped with hard line breaks so I can't apply them. Can you resend? The cmp/scs one applied fine.
A message that is not in the archive (sent off-list or not yet received): 586c2acd0912261725sd8f48c9n5b0191319b505382-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 8 lines · Younes Manton
Quoted 7 lines · Luca Barbieri
I just coded a patch that does this and seems to work fine. It must be fixed since it breaks OpenGL (or the state tracker can be changed, but it seems better to do it in the driver).
The patch also fixes NV20 and NV30 in the same way. They compile but are untested.
Quoted 8 lines
Quoted 3 lines
I would guess that using the 3D engine is faster for the larger levels, but the 2D engine is faster for the smaller ones (and lacks this issue).
Hi, this patch and the other swizzle related one seem to have been mangled, they're wrapped with hard line breaks so I can't apply them. Can you resend? The cmp/scs one applied fine.
Sorry, I hoped gmail wouldn't mangle it, but apparently was wrong.
Attached the patch, will test once I get the message back.
I'll post the other patch in reply to the other message.
src/gallium/drivers/nouveau/nouveau_winsys.h +3 -0
@@ -23,6 +23,9 @@#define NOUVEAU_BUFFER_USAGE_ZETA (1 << 17)#define NOUVEAU_BUFFER_USAGE_TRANSFER (1 << 18) +/* use along with GPU_WRITE for 2D-only writes */ +#define NOUVEAU_BUFFER_USAGE_NO_RENDER (1 << 19) +extern struct pipe_screen *nv04_screen_create (struct pipe_winsys *ws,struct nouveau_device *);
src/gallium/drivers/nv04/nv04_surface_2d.c +46 -0
49 lines not on this page · raw message
src/gallium/drivers/nv04/nv04_surface_2d.h +4 -0
@@ -4,6 +4,7 @@struct nv04_surface {struct pipe_surface base;unsigned pitch; +struct nv04_surface * backing; };struct nv04_surface_2d {
@@ -30,4 +31,7 @@ nv04_surface_2d_init(struct nouveau_screen *screen);void nv04_surface_2d_takedown (struct nv04_surface_2d **); +struct nv04_surface * +nv04_surface_wrap_for_render (struct pipe_screen *pscreen,struct nv04_surface_2d * eng2d,struct nv04_surface * ns); +#endif
src/gallium/drivers/nv20/nv20_miptree.c +22 -0
@@ -6,6 +6,7 @@#include "nv20_context.h" #include "nv20_screen.h" +#include "../nv04/nv04_surface_2d.h" static void nv20_miptree_layout (struct nv20_miptree *nv20mt)
@@ -127,6 +128,12 @@ nv20_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt)if (pt->tex_usage &PIPE_TEXTURE_USAGE_DYNAMIC ) buf_usage |=PIPE_BUFFER_USAGE_CPU_READ_WRITE ; +/* apparently we can't render to swizzled surfaces smaller than 64 bytes, so make them linear. +* If the user did not ask for a render target, they can still render to it, but it will cost them an extra copy. +* This also happens for small mipmaps of large textures. */ +if (pt->tex_usage &PIPE_TEXTURE_USAGE_RENDER_TARGET &&util_format_get_stride (pt->format, pt->width0) <64 ) + mt->base.tex_usage |=NOUVEAU_TEXTURE_USAGE_LINEAR ; +nv20_miptree_layout (mt); mt->buffer = screen->buffer_create (screen,256 , buf_usage, mt->total_size);
@@ -183,12 +190,27 @@ nv20_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt, ns->base.offset = nv20mt->level[level].image_offset[0 ]; } +/* create a linear temporary that we can render into if necessary. +* Note that ns->pitch is always a multiple of 64 for linear surfaces and swizzled surfaces are POT, so +* ns->pitch & 63 is equivalent to (ns->pitch < 64 && swizzled)*/ +if ((ns->pitch &63 ) && (ns->base.usage & (PIPE_BUFFER_USAGE_GPU_WRITE |NOUVEAU_BUFFER_USAGE_NO_RENDER )) ==PIPE_BUFFER_USAGE_GPU_WRITE ) +return &nv04_surface_wrap_for_render (screen, ((struct nv20_screen *)screen)->eng2d, ns)->base; +return &ns->base; }static void nv20_miptree_surface_destroy (struct pipe_surface *ps) { +struct nv04_surface * ns = (struct nv04_surface *)ps; +if (ns->backing) + { +struct nv20_screen * screen = (struct nv20_screen *)ps->texture->screen; +if (ns->backing->base.usage &PIPE_BUFFER_USAGE_GPU_WRITE ) + screen->eng2d->copy (screen->eng2d, &ns->backing->base,0 ,0 , ps,0 ,0 , ns->base.width, ns->base.height); +nv20_miptree_surface_destroy (&ns->backing->base); + } +pipe_texture_reference (&ps->texture,NULL );FREE (ps); }
src/gallium/drivers/nv20/nv20_transfer.c +1 -1
@@ -126,7 +126,7 @@ nv20_transfer_del(struct pipe_transfer *ptx) dst = pscreen->get_tex_surface (pscreen, ptx->texture, ptx->face, ptx->level, ptx->zslice, -PIPE_BUFFER_USAGE_GPU_WRITE ); +PIPE_BUFFER_USAGE_GPU_WRITE |NOUVEAU_BUFFER_USAGE_NO_RENDER );/* TODO: Check if SIFM can deal with x,y,w,h when swizzling */ nvscreen->eng2d->copy(nvscreen->eng2d,
src/gallium/drivers/nv30/nv30_miptree.c +22 -0
@@ -5,6 +5,7 @@#include "util/u_math.h" #include "nv30_context.h" +#include "../nv04/nv04_surface_2d.h" static void nv30_miptree_layout (struct nv30_miptree *nv30mt)
@@ -108,6 +109,12 @@ nv30_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)if (pt->tex_usage &PIPE_TEXTURE_USAGE_DYNAMIC ) buf_usage |=PIPE_BUFFER_USAGE_CPU_READ_WRITE ; +/* apparently we can't render to swizzled surfaces smaller than 64 bytes, so make them linear. +* If the user did not ask for a render target, they can still render to it, but it will cost them an extra copy. +* This also happens for small mipmaps of large textures. */ +if (pt->tex_usage &PIPE_TEXTURE_USAGE_RENDER_TARGET &&util_format_get_stride (pt->format, pt->width0) <64 ) + mt->base.tex_usage |=NOUVEAU_TEXTURE_USAGE_LINEAR ; +nv30_miptree_layout (mt); mt->buffer = pscreen->buffer_create(pscreen, 256, buf_usage,
@@ -196,12 +203,27 @@ nv30_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, ns->base.offset = nv30mt->level[level].image_offset[0 ]; } +/* create a linear temporary that we can render into if necessary. +* Note that ns->pitch is always a multiple of 64 for linear surfaces and swizzled surfaces are POT, so +* ns->pitch & 63 is equivalent to (ns->pitch < 64 && swizzled)*/ +if ((ns->pitch &63 ) && (ns->base.usage & (PIPE_BUFFER_USAGE_GPU_WRITE |NOUVEAU_BUFFER_USAGE_NO_RENDER )) ==PIPE_BUFFER_USAGE_GPU_WRITE ) +return &nv04_surface_wrap_for_render (pscreen, ((struct nv30_screen *)pscreen)->eng2d, ns)->base; +return &ns->base; }static void nv30_miptree_surface_del (struct pipe_surface *ps) { +struct nv04_surface * ns = (struct nv04_surface *)ps; +if (ns->backing) + { +struct nv30_screen * screen = (struct nv30_screen *)ps->texture->screen; +if (ns->backing->base.usage &PIPE_BUFFER_USAGE_GPU_WRITE ) + screen->eng2d->copy (screen->eng2d, &ns->backing->base,0 ,0 , ps,0 ,0 , ns->base.width, ns->base.height); +nv30_miptree_surface_del (&ns->backing->base); + } +pipe_texture_reference (&ps->texture,NULL );FREE (ps); }
src/gallium/drivers/nv30/nv30_transfer.c +1 -1
@@ -126,7 +126,7 @@ nv30_transfer_del(struct pipe_transfer *ptx) dst = pscreen->get_tex_surface (pscreen, ptx->texture, ptx->face, ptx->level, ptx->zslice, -PIPE_BUFFER_USAGE_GPU_WRITE ); +PIPE_BUFFER_USAGE_GPU_WRITE |NOUVEAU_BUFFER_USAGE_NO_RENDER );/* TODO: Check if SIFM can deal with x,y,w,h when swizzling */ nvscreen->eng2d->copy(nvscreen->eng2d,
src/gallium/drivers/nv40/nv40_miptree.c +22 -3
@@ -5,6 +5,7 @@#include "util/u_math.h" #include "nv40_context.h" +#include "../nv04/nv04_surface_2d.h"
@@ -36,9 +37,6 @@ nv40_miptree_layout(struct nv40_miptree *mt)else mt->level[l].pitch =util_format_get_stride (pt->format, width); -if (wide_pitch && mt->level[l].pitch <64 ) - mt->level[l].pitch =64 ; - mt->level[l].image_offset =CALLOC (nr_faces,sizeof (unsigned ));
@@ -108,6 +106,12 @@ nv40_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)if (pt->tex_usage &PIPE_TEXTURE_USAGE_DYNAMIC ) buf_usage |=PIPE_BUFFER_USAGE_CPU_READ_WRITE ; +/* apparently we can't render to swizzled surfaces smaller than 64 bytes, so make them linear. +* If the user did not ask for a render target, they can still render to it, but it will cost them an extra copy. +* This also happens for small mipmaps of large textures. */ +if (pt->tex_usage &PIPE_TEXTURE_USAGE_RENDER_TARGET &&util_format_get_stride (pt->format, pt->width0) <64 ) + mt->base.tex_usage |=NOUVEAU_TEXTURE_USAGE_LINEAR ; +nv40_miptree_layout (mt); mt->buffer = pscreen->buffer_create (pscreen,256 , buf_usage, mt->total_size);
@@ -194,12 +198,27 @@ nv40_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt, ns->base.offset = mt->level[level].image_offset[0 ]; } +/* create a linear temporary that we can render into if necessary. +* Note that ns->pitch is always a multiple of 64 for linear surfaces and swizzled surfaces are POT, so +* ns->pitch & 63 is equivalent to (ns->pitch < 64 && swizzled)*/ +if ((ns->pitch &63 ) && (ns->base.usage & (PIPE_BUFFER_USAGE_GPU_WRITE |NOUVEAU_BUFFER_USAGE_NO_RENDER )) ==PIPE_BUFFER_USAGE_GPU_WRITE ) +return &nv04_surface_wrap_for_render (pscreen, ((struct nv40_screen *)pscreen)->eng2d, ns)->base; +return &ns->base; }static void nv40_miptree_surface_del (struct pipe_surface *ps) { +struct nv04_surface * ns = (struct nv04_surface *)ps; +if (ns->backing) + { +struct nv40_screen * screen = (struct nv40_screen *)ps->texture->screen; +if (ns->backing->base.usage &PIPE_BUFFER_USAGE_GPU_WRITE ) + screen->eng2d->copy (screen->eng2d, &ns->backing->base,0 ,0 , ps,0 ,0 , ns->base.width, ns->base.height); +nv40_miptree_surface_del (&ns->backing->base); + } +pipe_texture_reference (&ps->texture,NULL );FREE (ps); }
src/gallium/drivers/nv40/nv40_transfer.c +1 -1
@@ -126,7 +126,7 @@ nv40_transfer_del(struct pipe_transfer *ptx) dst = pscreen->get_tex_surface (pscreen, ptx->texture, ptx->face, ptx->level, ptx->zslice, -PIPE_BUFFER_USAGE_GPU_WRITE ); +PIPE_BUFFER_USAGE_GPU_WRITE |NOUVEAU_BUFFER_USAGE_NO_RENDER );/* TODO: Check if SIFM can deal with x,y,w,h when swizzling */ nvscreen->eng2d->copy(nvscreen->eng2d,
_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
A message that is not in the archive (sent off-list or not yet received): ff13bc9a0912261904x1ccc4ce9y3f6bb5c9283376bf-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 18 lines · Luca Barbieri
Quoted 8 lines · Younes Manton
Quoted 7 lines · Luca Barbieri
I just coded a patch that does this and seems to work fine. It must be fixed since it breaks OpenGL (or the state tracker can be changed, but it seems better to do it in the driver).
The patch also fixes NV20 and NV30 in the same way. They compile but are untested.
Quoted 8 lines
Quoted 3 lines
I would guess that using the 3D engine is faster for the larger levels, but the 2D engine is faster for the smaller ones (and lacks this issue).
Hi, this patch and the other swizzle related one seem to have been mangled, they're wrapped with hard line breaks so I can't apply them. Can you resend? The cmp/scs one applied fine.
Quoted 6 lines
Sorry, I hoped gmail wouldn't mangle it, but apparently was wrong.
Attached the patch, will test once I get the message back.
I'll post the other patch in reply to the other message.
Pushed. Thanks.