Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hw/xbox/nv2a/pgraph/gl/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct TextureBinding {
bool border_color_set;
GLenum gl_target;
GLuint gl_texture;
uint32_t lod_bias;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Prefer to group filter params

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} TextureBinding;

typedef struct ShaderModuleCacheKey {
Expand Down
15 changes: 15 additions & 0 deletions hw/xbox/nv2a/pgraph/gl/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ static bool check_texture_possibly_dirty(NV2AState *d,
return possibly_dirty;
}

static inline float convert_lod_bias(uint32_t lod_bias)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If implementation is identical between renderers, prefer to have this in common code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

{
int sign_extended_bias = lod_bias;
if (lod_bias & (1 << 12)) {
sign_extended_bias |= ~NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS;
}
return (float)sign_extended_bias / 256.f;
}

static void apply_texture_parameters(TextureBinding *binding,
const BasicColorFormatInfo *f,
unsigned int dimensionality,
Expand All @@ -120,6 +129,8 @@ static void apply_texture_parameters(TextureBinding *binding,
unsigned int addru = GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRU);
unsigned int addrv = GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRV);
unsigned int addrp = GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRP);
unsigned int lod_bias =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Prefer to group filter params

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS);

if (f->linear) {
/* somtimes games try to set mipmap min filters on linear textures.
Expand All @@ -146,6 +157,10 @@ static void apply_texture_parameters(TextureBinding *binding,
pgraph_texture_mag_filter_gl_map[mag_filter]);
binding->mag_filter = mag_filter;
}
if (lod_bias != binding->lod_bias) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binding->lod_bias not initialized?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, done.

binding->lod_bias = lod_bias;
glTexParameterf(binding->gl_target, GL_TEXTURE_LOD_BIAS, convert_lod_bias(lod_bias));
}

/* Texture wrapping */
assert(addru < ARRAY_SIZE(pgraph_texture_addr_gl_map));
Expand Down
12 changes: 11 additions & 1 deletion hw/xbox/nv2a/pgraph/vk/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ static VkSamplerAddressMode lookup_texture_address_mode(int idx)
return pgraph_texture_addr_vk_map[idx];
}

static inline float convert_lod_bias(uint32_t lod_bias)
{
int sign_extended_bias = lod_bias;
if (lod_bias & (1 << 12)) {
sign_extended_bias |= ~NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS;
}
return (float)sign_extended_bias / 256.f;
}

// FIXME: Move to common
// FIXME: We can shrink the size of this structure
// FIXME: Use simple allocator
Expand Down Expand Up @@ -1356,7 +1365,8 @@ static void create_texture(PGRAPHState *pg, int texture_idx)
VK_SAMPLER_MIPMAP_MODE_LINEAR,
.minLod = mipmap_en ? MIN(state.min_mipmap_level, state.levels - 1) : 0.0,
.maxLod = mipmap_en ? MIN(state.max_mipmap_level, state.levels - 1) : 0.0,
.mipLodBias = 0.0,
.mipLodBias = convert_lod_bias(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolute value needs to be clamped to device limits (see VkPhysicalDeviceLimits::maxSamplerLodBias)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I think; will need to see if my change builds on CI since I can't build VK locally right now.

GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS)),
.pNext = sampler_next_struct,
};

Expand Down
Loading