Commit 2fc9351e authored by Vladimir Dergachev's avatar Vladimir Dergachev

Port texture allocation code from R200.

Hook it up, so lesson06 displays red colored textures.
parent 63fd67e5
......@@ -33,6 +33,9 @@ DRIVER_SOURCES = \
r300_state.c \
r300_render.c \
r300_lib.c \
r300_texmem.c \
r300_tex.c \
r300_texstate.c \
\
r200_context.c \
r200_ioctl.c \
......@@ -52,6 +55,7 @@ DRIVER_SOURCES = \
r200_vtxfmt_sse.c \
r200_vtxfmt_x86.c
C_SOURCES = $(COMMON_SOURCES) $(DRIVER_SOURCES)
X86_SOURCES = r200_vtxtmp_x86.S
......
......@@ -46,6 +46,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "radeon_ioctl.h"
#include "r300_context.h"
#include "r300_ioctl.h"
#include "radeon_reg.h"
#include "r300_reg.h"
#include "r300_cmdbuf.h"
......@@ -545,3 +546,65 @@ void r300DestroyCmdBuf(r300ContextPtr r300)
}
}
void r300EmitBlit(r300ContextPtr rmesa,
GLuint color_fmt,
GLuint src_pitch,
GLuint src_offset,
GLuint dst_pitch,
GLuint dst_offset,
GLint srcx, GLint srcy,
GLint dstx, GLint dsty, GLuint w, GLuint h)
{
drm_radeon_cmd_header_t *cmd;
if (RADEON_DEBUG & DEBUG_IOCTL)
fprintf(stderr,
"%s src %x/%x %d,%d dst: %x/%x %d,%d sz: %dx%d\n",
__FUNCTION__, src_pitch, src_offset, srcx, srcy,
dst_pitch, dst_offset, dstx, dsty, w, h);
assert((src_pitch & 63) == 0);
assert((dst_pitch & 63) == 0);
assert((src_offset & 1023) == 0);
assert((dst_offset & 1023) == 0);
assert(w < (1 << 16));
assert(h < (1 << 16));
cmd =
(drm_radeon_cmd_header_t *) r200AllocCmdBuf(rmesa, 8 * sizeof(int),
__FUNCTION__);
cmd[0].header.cmd_type = RADEON_CMD_PACKET3;
cmd[1].i = R200_CP_CMD_BITBLT_MULTI | (5 << 16);
cmd[2].i = (RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
RADEON_GMC_DST_PITCH_OFFSET_CNTL |
RADEON_GMC_BRUSH_NONE |
(color_fmt << 8) |
RADEON_GMC_SRC_DATATYPE_COLOR |
RADEON_ROP3_S |
RADEON_DP_SRC_SOURCE_MEMORY |
RADEON_GMC_CLR_CMP_CNTL_DIS | RADEON_GMC_WR_MSK_DIS);
cmd[3].i = ((src_pitch / 64) << 22) | (src_offset >> 10);
cmd[4].i = ((dst_pitch / 64) << 22) | (dst_offset >> 10);
cmd[5].i = (srcx << 16) | srcy;
cmd[6].i = (dstx << 16) | dsty; /* dst */
cmd[7].i = (w << 16) | h;
}
void r300EmitWait(r300ContextPtr rmesa, GLuint flags)
{
if (rmesa->radeon.dri.drmMinor >= 6) {
drm_radeon_cmd_header_t *cmd;
assert(!(flags & ~(RADEON_WAIT_2D | RADEON_WAIT_3D)));
cmd =
(drm_radeon_cmd_header_t *) r200AllocCmdBuf(rmesa,
1 * sizeof(int),
__FUNCTION__);
cmd[0].i = 0;
cmd[0].wait.cmd_type = RADEON_CMD_WAIT;
cmd[0].wait.flags = flags;
}
}
......@@ -57,6 +57,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "r300_cmdbuf.h"
#include "r300_state.h"
#include "r300_ioctl.h"
#include "r300_tex.h"
#include "vblank.h"
#include "utils.h"
......@@ -147,7 +148,7 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
struct dd_function_table functions;
r300ContextPtr r300;
GLcontext *ctx;
int tcl_mode;
int tcl_mode, i;
assert(glVisual);
assert(driContextPriv);
......@@ -171,7 +172,7 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
_mesa_init_driver_functions(&functions);
r300InitIoctlFuncs(&functions);
r300InitStateFuncs(&functions);
//r200InitTextureFuncs(&functions);
r300InitTextureFuncs(&functions);
if (!radeonInitContext(&r300->radeon, &functions,
glVisual, driContextPriv, sharedContextPrivate)) {
......@@ -180,6 +181,35 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
}
/* Init r300 context data */
r300->dma.buf0_address = r300->radeon.radeonScreen->buffers->list[0].address;
(void)memset(r300->texture_heaps, 0, sizeof(r300->texture_heaps));
make_empty_list(&r300->swapped);
r300->nr_heaps = 1 /* screen->numTexHeaps */ ;
assert(r300->nr_heaps < R200_NR_TEX_HEAPS);
for (i = 0; i < r300->nr_heaps; i++) {
r300->texture_heaps[i] = driCreateTextureHeap(i, r300,
screen->
texSize[i], 12,
RADEON_NR_TEX_REGIONS,
(drmTextureRegionPtr)
r300->radeon.sarea->
tex_list[i],
&r300->radeon.sarea->
tex_age[i],
&r300->swapped,
sizeof
(r300TexObj),
(destroy_texture_object_t
*)
r300DestroyTexObj);
}
r300->texture_depth = driQueryOptioni(&r300->radeon.optionCache,
"texture_depth");
if (r300->texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
r300->texture_depth = (screen->cpp == 4) ?
DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
/* Set the maximum texture size small enough that we can guarentee that
* all texture units can bind a maximal texture and have them both in
......@@ -239,8 +269,8 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
#if 0
/* plug in a few more device driver functions */
/* XXX these should really go right after _mesa_init_driver_functions() */
r200InitPixelFuncs(ctx);
r200InitSwtcl(ctx);
r300InitPixelFuncs(ctx);
r300InitSwtcl(ctx);
#endif
TNL_CONTEXT(ctx)->Driver.RunPipeline = _tnl_run_pipeline;
......
......@@ -66,6 +66,44 @@ static __inline__ uint32_t r300PackFloat32(float fl)
return u.u;
}
/************ DMA BUFFERS **************/
/* Need refcounting on dma buffers:
*/
struct r300_dma_buffer {
int refcount; /* the number of retained regions in buf */
drmBufPtr buf;
};
#define GET_START(rvb) (rmesa->radeon.radeonScreen->gart_buffer_offset + \
(rvb)->address - rmesa->dma.buf0_address + \
(rvb)->start)
/* A retained region, eg vertices for indexed vertices.
*/
struct r300_dma_region {
struct r300_dma_buffer *buf;
char *address; /* == buf->address */
int start, end, ptr; /* offsets from start of buf */
int aos_start;
int aos_stride;
int aos_size;
};
struct r300_dma {
/* Active dma region. Allocations for vertices and retained
* regions come from here. Also used for emitting random vertices,
* these may be flushed by calling flush_current();
*/
struct r300_dma_region current;
void (*flush) (r300ContextPtr);
char *buf0_address; /* start of buf[0], for index calcs */
GLuint nr_released_bufs; /* flush after so many buffers released */
};
/* Texture related */
#define TEX_0 0x1
......@@ -74,8 +112,8 @@ static __inline__ uint32_t r300PackFloat32(float fl)
#define TEX_3 0x8
#define TEX_4 0x10
#define TEX_5 0x20
#define TEX_6 0x20
#define TEX_7 0x20
#define TEX_6 0x40
#define TEX_7 0x80
#define TEX_ALL 0xff
typedef struct r300_tex_obj r300TexObj, *r300TexObjPtr;
......@@ -114,6 +152,17 @@ struct r300_tex_obj {
GLboolean border_fallback;
};
struct r300_texture_env_state {
r300TexObjPtr texobj;
GLenum format;
GLenum envMode;
};
#define R300_MAX_TEXTURE_UNITS 6
struct r300_texture_state {
struct r300_texture_env_state unit[R300_MAX_TEXTURE_UNITS];
};
/**
* A block of hardware state.
......@@ -402,6 +451,7 @@ struct r300_depthbuffer_state {
struct r300_state {
struct r300_depthbuffer_state depth;
struct r300_texture_state texture;
};
......@@ -419,6 +469,38 @@ struct r300_context {
int elt_count; /* size of the buffer for vertices */
int attrib_count; /* size of the buffer for vertex attributes.. Somehow it can be different ? */
/* Vertex buffers
*/
#if 0 /* we'll need it later, but not now */
struct r300_ioctl ioctl;
#endif
struct r300_dma dma;
GLboolean save_on_next_unlock;
/* Texture object bookkeeping
*/
unsigned nr_heaps;
driTexHeap *texture_heaps[R200_NR_TEX_HEAPS];
driTextureObject swapped;
int texture_depth;
float initialMaxAnisotropy;
/* Clientdata textures;
*/
GLuint prefer_gart_client_texturing;
/* TCL stuff
*/
GLmatrix TexGenMatrix[R300_MAX_TEXTURE_UNITS];
GLboolean recheck_texgen[R300_MAX_TEXTURE_UNITS];
GLboolean TexGenNeedNormals[R300_MAX_TEXTURE_UNITS];
GLuint TexMatEnabled;
GLuint TexMatCompSel;
GLuint TexGenEnabled;
GLuint TexGenInputs;
GLuint TexGenCompSel;
GLmatrix tmpmat;
};
#define R300_CONTEXT(ctx) ((r300ContextPtr)(ctx->DriverCtx))
......
......@@ -282,6 +282,195 @@ void r300Flush(GLcontext * ctx)
r300FlushCmdBuf(r300, __FUNCTION__);
}
void r300RefillCurrentDmaRegion(r300ContextPtr rmesa)
{
struct r200_dma_buffer *dmabuf;
int fd = rmesa->radeon.dri.fd;
int index = 0;
int size = 0;
drmDMAReq dma;
int ret;
if (RADEON_DEBUG & (DEBUG_IOCTL | DEBUG_DMA))
fprintf(stderr, "%s\n", __FUNCTION__);
if (rmesa->dma.flush) {
rmesa->dma.flush(rmesa);
}
if (rmesa->dma.current.buf)
r300ReleaseDmaRegion(rmesa, &rmesa->dma.current, __FUNCTION__);
if (rmesa->dma.nr_released_bufs > 4)
r300FlushCmdBuf(rmesa, __FUNCTION__);
dma.context = rmesa->radeon.dri.hwContext;
dma.send_count = 0;
dma.send_list = NULL;
dma.send_sizes = NULL;
dma.flags = 0;
dma.request_count = 1;
dma.request_size = RADEON_BUFFER_SIZE;
dma.request_list = &index;
dma.request_sizes = &size;
dma.granted_count = 0;
LOCK_HARDWARE(&rmesa->radeon); /* no need to validate */
while (1) {
ret = drmDMA(fd, &dma);
if (ret == 0)
break;
if (rmesa->dma.nr_released_bufs) {
r200FlushCmdBufLocked(rmesa, __FUNCTION__);
}
if (rmesa->radeon.do_usleeps) {
UNLOCK_HARDWARE(&rmesa->radeon);
DO_USLEEP(1);
LOCK_HARDWARE(&rmesa->radeon);
}
}
UNLOCK_HARDWARE(&rmesa->radeon);
if (RADEON_DEBUG & DEBUG_DMA)
fprintf(stderr, "Allocated buffer %d\n", index);
dmabuf = CALLOC_STRUCT(r300_dma_buffer);
dmabuf->buf = &rmesa->radeon.radeonScreen->buffers->list[index];
dmabuf->refcount = 1;
rmesa->dma.current.buf = dmabuf;
rmesa->dma.current.address = dmabuf->buf->address;
rmesa->dma.current.end = dmabuf->buf->total;
rmesa->dma.current.start = 0;
rmesa->dma.current.ptr = 0;
}
void r300ReleaseDmaRegion(r300ContextPtr rmesa,
struct r300_dma_region *region, const char *caller)
{
if (RADEON_DEBUG & DEBUG_IOCTL)
fprintf(stderr, "%s from %s\n", __FUNCTION__, caller);
if (!region->buf)
return;
if (rmesa->dma.flush)
rmesa->dma.flush(rmesa);
if (--region->buf->refcount == 0) {
drm_radeon_cmd_header_t *cmd;
if (RADEON_DEBUG & (DEBUG_IOCTL | DEBUG_DMA))
fprintf(stderr, "%s -- DISCARD BUF %d\n", __FUNCTION__,
region->buf->buf->idx);
cmd =
(drm_radeon_cmd_header_t *) r300AllocCmdBuf(rmesa,
sizeof(*cmd),
__FUNCTION__);
cmd->dma.cmd_type = RADEON_CMD_DMA_DISCARD;
cmd->dma.buf_idx = region->buf->buf->idx;
FREE(region->buf);
rmesa->dma.nr_released_bufs++;
}
region->buf = 0;
region->start = 0;
}
/* Allocates a region from rmesa->dma.current. If there isn't enough
* space in current, grab a new buffer (and discard what was left of current)
*/
void r300AllocDmaRegion(r300ContextPtr rmesa,
struct r300_dma_region *region,
int bytes, int alignment)
{
if (RADEON_DEBUG & DEBUG_IOCTL)
fprintf(stderr, "%s %d\n", __FUNCTION__, bytes);
if (rmesa->dma.flush)
rmesa->dma.flush(rmesa);
if (region->buf)
r300ReleaseDmaRegion(rmesa, region, __FUNCTION__);
alignment--;
rmesa->dma.current.start = rmesa->dma.current.ptr =
(rmesa->dma.current.ptr + alignment) & ~alignment;
if (rmesa->dma.current.ptr + bytes > rmesa->dma.current.end)
r300RefillCurrentDmaRegion(rmesa);
region->start = rmesa->dma.current.start;
region->ptr = rmesa->dma.current.start;
region->end = rmesa->dma.current.start + bytes;
region->address = rmesa->dma.current.address;
region->buf = rmesa->dma.current.buf;
region->buf->refcount++;
rmesa->dma.current.ptr += bytes; /* bug - if alignment > 7 */
rmesa->dma.current.start =
rmesa->dma.current.ptr = (rmesa->dma.current.ptr + 0x7) & ~0x7;
assert(rmesa->dma.current.ptr <= rmesa->dma.current.end);
}
/* Called via glXGetMemoryOffsetMESA() */
GLuint r300GetMemoryOffsetMESA(__DRInativeDisplay * dpy, int scrn,
const GLvoid * pointer)
{
GET_CURRENT_CONTEXT(ctx);
r300ContextPtr rmesa;
GLuint card_offset;
if (!ctx || !(rmesa = R300_CONTEXT(ctx))) {
fprintf(stderr, "%s: no context\n", __FUNCTION__);
return ~0;
}
if (!r300IsGartMemory(rmesa, pointer, 0))
return ~0;
if (rmesa->radeon.dri.drmMinor < 6)
return ~0;
card_offset = r300GartOffsetFromVirtual(rmesa, pointer);
return card_offset - rmesa->radeon.radeonScreen->gart_base;
}
GLboolean r300IsGartMemory(r300ContextPtr rmesa, const GLvoid * pointer,
GLint size)
{
int offset =
(char *)pointer - (char *)rmesa->radeon.radeonScreen->gartTextures.map;
int valid = (size >= 0 && offset >= 0
&& offset + size < rmesa->radeon.radeonScreen->gartTextures.size);
if (RADEON_DEBUG & DEBUG_IOCTL)
fprintf(stderr, "r300IsGartMemory( %p ) : %d\n", pointer,
valid);
return valid;
}
GLuint r300GartOffsetFromVirtual(r300ContextPtr rmesa, const GLvoid * pointer)
{
int offset =
(char *)pointer - (char *)rmesa->radeon.radeonScreen->gartTextures.map;
fprintf(stderr, "offset=%08x\n", offset);
if (offset < 0 || offset > rmesa->radeon.radeonScreen->gartTextures.size)
return ~0;
else
return rmesa->radeon.radeonScreen->gart_texture_offset + offset;
}
void r300InitIoctlFuncs(struct dd_function_table *functions)
{
functions->Clear = r300Clear;
......
......@@ -36,6 +36,18 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef __R300_IOCTL_H__
#define __R300_IOCTL_H__
#include "r300_context.h"
#include "radeon_drm.h"
extern GLuint r300GetMemoryOffsetMESA(__DRInativeDisplay * dpy, int scrn,
const GLvoid * pointer);
extern GLboolean r300IsGartMemory(r300ContextPtr rmesa, const GLvoid * pointer,
GLint size);
extern GLuint r300GartOffsetFromVirtual(r300ContextPtr rmesa,
const GLvoid * pointer);
extern void r300Flush(GLcontext * ctx);
extern void r300InitIoctlFuncs(struct dd_function_table *functions);
......
......@@ -458,12 +458,14 @@ static void r300_render_tex_primitive(r300ContextPtr rmesa,
type=r300_get_primitive_type(rmesa, ctx, start, end, prim);
#if 1
fprintf(stderr,"ObjPtr: size=%d stride=%d\n",
VB->ObjPtr->size, VB->ObjPtr->stride);
fprintf(stderr,"ColorPtr[0]: size=%d stride=%d\n",
VB->ColorPtr[0]->size, VB->ColorPtr[0]->stride);
fprintf(stderr,"TexCoordPtr[0]: size=%d stride=%d\n",
VB->TexCoordPtr[0]->size, VB->TexCoordPtr[0]->stride);
#endif
if(type<0)return;
......@@ -508,16 +510,21 @@ static GLboolean r300_run_tex_render(GLcontext *ctx,
AOS_DATA vb_arrays[3];
/* Only do 2d textures */
struct gl_texture_object *to=ctx->Texture.Unit[0].Current2D;
radeonScreenPtr rsp=rmesa->radeon.radeonScreen;
r300TexObjPtr t=to->DriverData;
LOCAL_VARS
/* Update texture state - needs to be done only when actually changed..
All the time for now.. */
r300UpdateTextureState(ctx);
/* Flush state - make sure command buffer is nice and large */
r300Flush(ctx);
//fprintf(stderr, "You can enable texture drawing in %s:%s \n", __FILE__, __FUNCTION__);
//return GL_TRUE;
if (RADEON_DEBUG == DEBUG_PRIMS)
fprintf(stderr, "%s\n", __FUNCTION__);
......@@ -549,8 +556,6 @@ static GLboolean r300_run_tex_render(GLcontext *ctx,
vb_arrays[2].ncomponents=4;
vb_arrays[2].reg=REG_TEX0;
/* Fill texture with some random data */
for(i=0;i<100000;i++)((int *)(rsp->gartTextures.map))[i]=rand();
/* needed before starting 3d operation .. */
reg_start(R300_RB3D_DSTCACHE_CTLSTAT,0);
......@@ -578,8 +583,16 @@ static GLboolean r300_run_tex_render(GLcontext *ctx,
SINGLE_TEXTURE_PIPELINE.vertex_shader.unknown2.body.f[2]=1.0;
SINGLE_TEXTURE_PIPELINE.vertex_shader.unknown2.body.f[3]=0.0;
/* Put it in the beginning of texture memory */
SINGLE_TEXTURE_PIPELINE.texture_unit[0].offset=rsp->gartTextures.handle;
/* Use actual texture offset */
SINGLE_TEXTURE_PIPELINE.texture_unit[0].offset=rmesa->radeon.radeonScreen->fbLocation+t->offset;
#if 0
SINGLE_TEXTURE_PIPELINE.texture_unit[0].format=t->format;
SINGLE_TEXTURE_PIPELINE.texture_unit[0].size=t->size;
#endif
SINGLE_TEXTURE_PIPELINE.texture_unit[0].filter=t->filter;
SINGLE_TEXTURE_PIPELINE.texture_unit[0].unknown1=t->pitch; /* Unknown 1 is pitch ! */
SINGLE_TEXTURE_PIPELINE.texture_unit[0].filter=t->filter;
/* Upload texture, a hack, really we can do a lot better */
......@@ -644,6 +657,7 @@ reg_start(R300_RS_INTERP_0,7);
reg_start(0x4f18,0);
e32(0x00000003);
// exit(-1);
fprintf(stderr, "\n");
return GL_FALSE;
}
......@@ -671,7 +685,7 @@ static GLboolean r300_run_render(GLcontext *ctx,
if(ctx->Texture.Unit[0].Enabled)
return r300_run_tex_render(ctx, stage);
else
return r300_run_flat_render(ctx, stage);
return r300_run_vb_flat_render(ctx, stage);
#else
return GL_TRUE;
#endif
......
This diff is collapsed.
/* $XFree86: xc/lib/GL/mesa/src/drv/r300/r300_tex.h,v 1.1 2002/10/30 12:51:53 alanh Exp $ */
/*
Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
The Weather Channel (TM) funded Tungsten Graphics to develop the
initial release of the Radeon 8500 driver under the XFree86 license.
This notice must be preserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice (including the
next paragraph) shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************/
/*
* Authors:
* Keith Whitwell <keith@tungstengraphics.com>
*/
#ifndef __r300_TEX_H__
#define __r300_TEX_H__
#ifdef GLX_DIRECT_RENDERING
extern void r300UpdateTextureState(GLcontext * ctx);
extern int r300UploadTexImages(r300ContextPtr rmesa, r300TexObjPtr t,
GLuint face);
extern void r300DestroyTexObj(r300ContextPtr rmesa, r300TexObjPtr t);
extern void r300InitTextureFuncs(struct dd_function_table *functions);
#endif
#endif /* __r300_TEX_H__ */
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment