mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 07:08:04 +02:00
mesa/drivers: use _mesa_get_format_bytes()
This commit is contained in:
parent
e0bc4533eb
commit
9fbb8884f0
14 changed files with 71 additions and 48 deletions
|
|
@ -92,44 +92,47 @@ static void i810UploadTexLevel( i810ContextPtr imesa,
|
|||
{
|
||||
const struct gl_texture_image *image = t->image[hwlevel].image;
|
||||
int j;
|
||||
GLuint texelBytes;
|
||||
|
||||
if (!image || !image->Data)
|
||||
return;
|
||||
|
||||
if (image->Width * image->TexFormat->TexelBytes == t->Pitch) {
|
||||
texelBytes = _mesa_get_format_bytes(image->TexFormat->MesaFormat);
|
||||
|
||||
if (image->Width * texelBytes == t->Pitch) {
|
||||
GLubyte *dst = (GLubyte *)(t->BufAddr + t->image[hwlevel].offset);
|
||||
GLubyte *src = (GLubyte *)image->Data;
|
||||
|
||||
memcpy( dst, src, t->Pitch * image->Height );
|
||||
}
|
||||
else switch (image->TexFormat->TexelBytes) {
|
||||
case 1:
|
||||
{
|
||||
GLubyte *dst = (GLubyte *)(t->BufAddr + t->image[hwlevel].offset);
|
||||
GLubyte *src = (GLubyte *)image->Data;
|
||||
else {
|
||||
switch (texelBytes) {
|
||||
case 1:
|
||||
{
|
||||
GLubyte *dst = (GLubyte *)(t->BufAddr + t->image[hwlevel].offset);
|
||||
GLubyte *src = (GLubyte *)image->Data;
|
||||
|
||||
for (j = 0 ; j < image->Height ; j++, dst += t->Pitch) {
|
||||
__memcpy(dst, src, image->Width );
|
||||
src += image->Width;
|
||||
}
|
||||
for (j = 0 ; j < image->Height ; j++, dst += t->Pitch) {
|
||||
__memcpy(dst, src, image->Width );
|
||||
src += image->Width;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
GLushort *dst = (GLushort *)(t->BufAddr + t->image[hwlevel].offset);
|
||||
GLushort *src = (GLushort *)image->Data;
|
||||
|
||||
for (j = 0 ; j < image->Height ; j++, dst += (t->Pitch/2)) {
|
||||
__memcpy(dst, src, image->Width * 2 );
|
||||
src += image->Width;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: Not supported texel size %d\n",
|
||||
__FUNCTION__, texelBytes);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
GLushort *dst = (GLushort *)(t->BufAddr + t->image[hwlevel].offset);
|
||||
GLushort *src = (GLushort *)image->Data;
|
||||
|
||||
for (j = 0 ; j < image->Height ; j++, dst += (t->Pitch/2)) {
|
||||
__memcpy(dst, src, image->Width * 2 );
|
||||
src += image->Width;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "%s: Not supported texel size %d\n",
|
||||
__FUNCTION__, image->TexFormat->TexelBytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@ intel_miptree_match_image(struct intel_mipmap_tree *mt,
|
|||
|
||||
if (!image->IsCompressed &&
|
||||
!mt->compressed &&
|
||||
image->TexFormat->TexelBytes != mt->cpp)
|
||||
_mesa_get_format_bytes(image->TexFormat->MesaFormat) != mt->cpp)
|
||||
return GL_FALSE;
|
||||
|
||||
/* Test image dimensions against the base level image adjusted for
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ guess_and_alloc_mipmap_tree(struct intel_context *intel,
|
|||
GLuint depth = intelImage->base.Depth;
|
||||
GLuint l2width, l2height, l2depth;
|
||||
GLuint i, comp_byte = 0;
|
||||
GLuint texelBytes;
|
||||
|
||||
DBG("%s\n", __FUNCTION__);
|
||||
|
||||
|
|
@ -126,6 +127,9 @@ guess_and_alloc_mipmap_tree(struct intel_context *intel,
|
|||
assert(!intelObj->mt);
|
||||
if (intelImage->base.IsCompressed)
|
||||
comp_byte = intel_compressed_num_bytes(intelImage->base.TexFormat->MesaFormat);
|
||||
|
||||
texelBytes = _mesa_get_format_bytes(intelImage->base.TexFormat->MesaFormat);
|
||||
|
||||
intelObj->mt = intel_miptree_create(intel,
|
||||
intelObj->base.Target,
|
||||
intelImage->base._BaseFormat,
|
||||
|
|
@ -135,7 +139,7 @@ guess_and_alloc_mipmap_tree(struct intel_context *intel,
|
|||
width,
|
||||
height,
|
||||
depth,
|
||||
intelImage->base.TexFormat->TexelBytes,
|
||||
texelBytes,
|
||||
comp_byte,
|
||||
expect_accelerated_upload);
|
||||
|
||||
|
|
@ -399,12 +403,14 @@ intelTexImage(GLcontext * ctx,
|
|||
assert(intelImage->mt);
|
||||
} else if (intelImage->base.Border == 0) {
|
||||
int comp_byte = 0;
|
||||
GLuint texelBytes = _mesa_get_format_bytes(intelImage->base.TexFormat->MesaFormat);
|
||||
|
||||
if (intelImage->base.IsCompressed) {
|
||||
comp_byte =
|
||||
intel_compressed_num_bytes(intelImage->base.TexFormat->MesaFormat);
|
||||
}
|
||||
|
||||
|
||||
/* Didn't fit in the object miptree, but it's suitable for inclusion in
|
||||
* a miptree, so create one just for our level and store it in the image.
|
||||
* It'll get moved into the object miptree at validate time.
|
||||
|
|
@ -414,7 +420,7 @@ intelTexImage(GLcontext * ctx,
|
|||
internalFormat,
|
||||
level, level,
|
||||
width, height, depth,
|
||||
intelImage->base.TexFormat->TexelBytes,
|
||||
texelBytes,
|
||||
comp_byte, pixels == NULL);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,7 +169,8 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
|
|||
comp_byte = intel_compressed_num_bytes(firstImage->base.TexFormat->MesaFormat);
|
||||
cpp = comp_byte;
|
||||
}
|
||||
else cpp = firstImage->base.TexFormat->TexelBytes;
|
||||
else
|
||||
cpp = _mesa_get_format_bytes(firstImage->base.TexFormat->MesaFormat);
|
||||
|
||||
/* Check tree can hold all active levels. Check tree matches
|
||||
* target, imageFormat, etc.
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ static void mach64UploadAGPSubImage( mach64ContextPtr mmesa,
|
|||
struct gl_texture_image *image;
|
||||
int texelsPerDword = 0;
|
||||
int dwords;
|
||||
GLuint texelBytes;
|
||||
|
||||
/* Ensure we have a valid texture to upload */
|
||||
if ( ( level < 0 ) || ( level > mmesa->glCtx->Const.MaxTextureLevels ) )
|
||||
|
|
@ -85,7 +86,9 @@ static void mach64UploadAGPSubImage( mach64ContextPtr mmesa,
|
|||
if ( !image )
|
||||
return;
|
||||
|
||||
switch ( image->TexFormat->TexelBytes ) {
|
||||
texelBytes = _mesa_get_format_bytes(image->TexFormat->MesaFormat);
|
||||
|
||||
switch ( texelBytes ) {
|
||||
case 1: texelsPerDword = 4; break;
|
||||
case 2: texelsPerDword = 2; break;
|
||||
case 4: texelsPerDword = 1; break;
|
||||
|
|
@ -118,8 +121,8 @@ static void mach64UploadAGPSubImage( mach64ContextPtr mmesa,
|
|||
{
|
||||
CARD32 *dst = (CARD32 *)((char *)mach64Screen->agpTextures.map + t->base.memBlock->ofs);
|
||||
const GLubyte *src = (const GLubyte *) image->Data +
|
||||
(y * image->Width + x) * image->TexFormat->TexelBytes;
|
||||
const GLuint bytes = width * height * image->TexFormat->TexelBytes;
|
||||
(y * image->Width + x) * texelBytes;
|
||||
const GLuint bytes = width * height * texelBytes;
|
||||
memcpy(dst, src, bytes);
|
||||
}
|
||||
|
||||
|
|
@ -140,6 +143,7 @@ static void mach64UploadLocalSubImage( mach64ContextPtr mmesa,
|
|||
const int maxdwords = (MACH64_BUFFER_MAX_DWORDS - (MACH64_HOSTDATA_BLIT_OFFSET / 4));
|
||||
CARD32 pitch, offset;
|
||||
int i;
|
||||
GLuint texelBytes;
|
||||
|
||||
/* Ensure we have a valid texture to upload */
|
||||
if ( ( level < 0 ) || ( level > mmesa->glCtx->Const.MaxTextureLevels ) )
|
||||
|
|
@ -149,7 +153,9 @@ static void mach64UploadLocalSubImage( mach64ContextPtr mmesa,
|
|||
if ( !image )
|
||||
return;
|
||||
|
||||
switch ( image->TexFormat->TexelBytes ) {
|
||||
texelBytes = _mesa_get_format_bytes(image->TexFormat->MesaFormat);
|
||||
|
||||
switch ( texelBytes ) {
|
||||
case 1: texelsPerDword = 4; break;
|
||||
case 2: texelsPerDword = 2; break;
|
||||
case 4: texelsPerDword = 1; break;
|
||||
|
|
@ -259,7 +265,7 @@ static void mach64UploadLocalSubImage( mach64ContextPtr mmesa,
|
|||
|
||||
{
|
||||
const GLubyte *src = (const GLubyte *) image->Data +
|
||||
(y * image->Width + x) * image->TexFormat->TexelBytes;
|
||||
(y * image->Width + x) * texelBytes;
|
||||
|
||||
mach64FireBlitLocked( mmesa, (void *)src, offset, pitch, format,
|
||||
x, y, width, height );
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ static void mach64SetTexImages( mach64ContextPtr mmesa,
|
|||
|
||||
totalSize = ( baseImage->Height *
|
||||
baseImage->Width *
|
||||
baseImage->TexFormat->TexelBytes );
|
||||
_mesa_get_format_bytes(baseImage->TexFormat->MesaFormat) );
|
||||
|
||||
totalSize = (totalSize + 31) & ~31;
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ mgaSetTexImages( mgaContextPtr mmesa,
|
|||
break;
|
||||
|
||||
size = texImage->Width * texImage->Height *
|
||||
baseImage->TexFormat->TexelBytes;
|
||||
_mesa_get_format_bytes(baseImage->TexFormat->MesaFormat);
|
||||
|
||||
t->offsets[i] = totalSize;
|
||||
t->base.dirty_images[0] |= (1<<i);
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ static void uploadSubImage( r128ContextPtr rmesa, r128TexObjPtr t,
|
|||
if ( !image )
|
||||
return;
|
||||
|
||||
switch ( image->TexFormat->TexelBytes ) {
|
||||
switch ( _mesa_get_format_bytes(image->TexFormat->MesaFormat) ) {
|
||||
case 1: texelsPerDword = 4; break;
|
||||
case 2: texelsPerDword = 2; break;
|
||||
case 4: texelsPerDword = 1; break;
|
||||
|
|
@ -215,9 +215,11 @@ static void uploadSubImage( r128ContextPtr rmesa, r128TexObjPtr t,
|
|||
|
||||
/* Copy the next chunck of the texture image into the blit buffer */
|
||||
{
|
||||
const GLuint texelBytes =
|
||||
_mesa_get_format_bytes(image->TexFormat->MesaFormat);
|
||||
const GLubyte *src = (const GLubyte *) image->Data +
|
||||
(y * image->Width + x) * image->TexFormat->TexelBytes;
|
||||
const GLuint bytes = width * height * image->TexFormat->TexelBytes;
|
||||
(y * image->Width + x) * texelBytes;
|
||||
const GLuint bytes = width * height * texelBytes;
|
||||
memcpy(dst, src, bytes);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ static void r128SetTexImages( r128ContextPtr rmesa,
|
|||
|
||||
totalSize += (tObj->Image[0][i]->Height *
|
||||
tObj->Image[0][i]->Width *
|
||||
tObj->Image[0][i]->TexFormat->TexelBytes);
|
||||
_mesa_get_format_bytes(tObj->Image[0][i]->TexFormat->MesaFormat));
|
||||
|
||||
/* Offsets must be 32-byte aligned for host data blits and tiling */
|
||||
totalSize = (totalSize + 31) & ~31;
|
||||
|
|
|
|||
|
|
@ -1437,7 +1437,7 @@ static void setup_hardware_state(r200ContextPtr rmesa, radeonTexObj *t)
|
|||
log2Width = firstImage->WidthLog2;
|
||||
log2Height = firstImage->HeightLog2;
|
||||
log2Depth = firstImage->DepthLog2;
|
||||
texelBytes = firstImage->TexFormat->TexelBytes;
|
||||
texelBytes = _mesa_get_format_bytes(firstImage->TexFormat->MesaFormat);
|
||||
|
||||
|
||||
if (!t->image_override) {
|
||||
|
|
|
|||
|
|
@ -347,6 +347,7 @@ GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_textu
|
|||
GLuint compressed;
|
||||
GLuint numfaces = 1;
|
||||
GLuint firstLevel, lastLevel;
|
||||
GLuint texelBytes;
|
||||
|
||||
calculate_first_last_level(texObj, &firstLevel, &lastLevel, 0, texObj->BaseLevel);
|
||||
if (texObj->Target == GL_TEXTURE_CUBE_MAP)
|
||||
|
|
@ -354,6 +355,7 @@ GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_textu
|
|||
|
||||
firstImage = texObj->Image[0][firstLevel];
|
||||
compressed = firstImage->IsCompressed ? firstImage->TexFormat->MesaFormat : 0;
|
||||
texelBytes = _mesa_get_format_bytes(firstImage->TexFormat->MesaFormat);
|
||||
|
||||
return (mt->firstLevel == firstLevel &&
|
||||
mt->lastLevel == lastLevel &&
|
||||
|
|
@ -361,7 +363,7 @@ GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_textu
|
|||
mt->height0 == firstImage->Height &&
|
||||
mt->depth0 == firstImage->Depth &&
|
||||
mt->compressed == compressed &&
|
||||
(!mt->compressed ? (mt->bpp == firstImage->TexFormat->TexelBytes) : 1));
|
||||
(!mt->compressed ? (mt->bpp == texelBytes) : 1));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -375,6 +377,7 @@ void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t,
|
|||
GLuint compressed = image->base.IsCompressed ? image->base.TexFormat->MesaFormat : 0;
|
||||
GLuint numfaces = 1;
|
||||
GLuint firstLevel, lastLevel;
|
||||
GLuint texelBytes;
|
||||
|
||||
assert(!t->mt);
|
||||
|
||||
|
|
@ -385,11 +388,13 @@ void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t,
|
|||
if (level != firstLevel || face >= numfaces)
|
||||
return;
|
||||
|
||||
texelBytes = _mesa_get_format_bytes(image->base.TexFormat->MesaFormat);
|
||||
|
||||
t->mt = radeon_miptree_create(rmesa, t, t->base.Target,
|
||||
image->base.InternalFormat,
|
||||
firstLevel, lastLevel,
|
||||
image->base.Width, image->base.Height, image->base.Depth,
|
||||
image->base.TexFormat->TexelBytes, t->tile_bits, compressed);
|
||||
texelBytes, t->tile_bits, compressed);
|
||||
}
|
||||
|
||||
/* Although we use the image_offset[] array to store relative offsets
|
||||
|
|
|
|||
|
|
@ -1031,7 +1031,7 @@ static GLboolean setup_hardware_state(r100ContextPtr rmesa, radeonTexObj *t, int
|
|||
log2Width = firstImage->WidthLog2;
|
||||
log2Height = firstImage->HeightLog2;
|
||||
log2Depth = firstImage->DepthLog2;
|
||||
texelBytes = firstImage->TexFormat->TexelBytes;
|
||||
texelBytes = _mesa_get_format_bytes(firstImage->TexFormat->MesaFormat);
|
||||
|
||||
if (!t->image_override) {
|
||||
if (VALID_FORMAT(firstImage->TexFormat->MesaFormat)) {
|
||||
|
|
|
|||
|
|
@ -900,7 +900,7 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt, radeon_texture_imag
|
|||
srcrowstride = _mesa_compressed_row_stride(image->base.TexFormat->MesaFormat, image->base.Width);
|
||||
} else {
|
||||
height = image->base.Height * image->base.Depth;
|
||||
srcrowstride = image->base.Width * image->base.TexFormat->TexelBytes;
|
||||
srcrowstride = image->base.Width * _mesa_get_format_bytes(image->base.TexFormat->MesaFormat);
|
||||
}
|
||||
|
||||
// if (mt->tilebits)
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ sisAllocTexImage( sisContextPtr smesa, sisTexObjPtr t, int level,
|
|||
}
|
||||
assert(t->format == image->_BaseFormat);
|
||||
|
||||
texel_size = image->TexFormat->TexelBytes;
|
||||
texel_size = _mesa_get_format_bytes(image->TexFormat->MesaFormat);
|
||||
size = image->Width * image->Height * texel_size + TEXTURE_HW_PLUS;
|
||||
|
||||
addr = sisAllocFB( smesa, size, &t->image[level].handle );
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue