Skip to content

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

hw/xbox/nv2a/pgraph/gl/renderer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typedef struct TextureBinding {
8080
bool border_color_set;
8181
GLenum gl_target;
8282
GLuint gl_texture;
83+
uint32_t lod_bias;
8384
} TextureBinding;
8485

8586
typedef struct ShaderModuleCacheKey {

hw/xbox/nv2a/pgraph/gl/texture.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ static bool check_texture_possibly_dirty(NV2AState *d,
107107
return possibly_dirty;
108108
}
109109

110+
static inline float convert_lod_bias(uint32_t lod_bias)
111+
{
112+
int sign_extended_bias = lod_bias;
113+
if (lod_bias & (1 << 12)) {
114+
sign_extended_bias |= ~NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS;
115+
}
116+
return (float)sign_extended_bias / 256.f;
117+
}
118+
110119
static void apply_texture_parameters(TextureBinding *binding,
111120
const BasicColorFormatInfo *f,
112121
unsigned int dimensionality,
@@ -120,6 +129,8 @@ static void apply_texture_parameters(TextureBinding *binding,
120129
unsigned int addru = GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRU);
121130
unsigned int addrv = GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRV);
122131
unsigned int addrp = GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRP);
132+
unsigned int lod_bias =
133+
GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS);
123134

124135
if (f->linear) {
125136
/* somtimes games try to set mipmap min filters on linear textures.
@@ -146,6 +157,10 @@ static void apply_texture_parameters(TextureBinding *binding,
146157
pgraph_texture_mag_filter_gl_map[mag_filter]);
147158
binding->mag_filter = mag_filter;
148159
}
160+
if (lod_bias != binding->lod_bias) {
161+
binding->lod_bias = lod_bias;
162+
glTexParameterf(binding->gl_target, GL_TEXTURE_LOD_BIAS, convert_lod_bias(lod_bias));
163+
}
149164

150165
/* Texture wrapping */
151166
assert(addru < ARRAY_SIZE(pgraph_texture_addr_gl_map));

hw/xbox/nv2a/pgraph/vk/texture.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ static VkSamplerAddressMode lookup_texture_address_mode(int idx)
5151
return pgraph_texture_addr_vk_map[idx];
5252
}
5353

54+
static inline float convert_lod_bias(uint32_t lod_bias)
55+
{
56+
int sign_extended_bias = lod_bias;
57+
if (lod_bias & (1 << 12)) {
58+
sign_extended_bias |= ~NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS;
59+
}
60+
return (float)sign_extended_bias / 256.f;
61+
}
62+
5463
// FIXME: Move to common
5564
// FIXME: We can shrink the size of this structure
5665
// FIXME: Use simple allocator
@@ -1356,7 +1365,8 @@ static void create_texture(PGRAPHState *pg, int texture_idx)
13561365
VK_SAMPLER_MIPMAP_MODE_LINEAR,
13571366
.minLod = mipmap_en ? MIN(state.min_mipmap_level, state.levels - 1) : 0.0,
13581367
.maxLod = mipmap_en ? MIN(state.max_mipmap_level, state.levels - 1) : 0.0,
1359-
.mipLodBias = 0.0,
1368+
.mipLodBias = convert_lod_bias(
1369+
GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS)),
13601370
.pNext = sampler_next_struct,
13611371
};
13621372

0 commit comments

Comments
 (0)