-
-
Notifications
You must be signed in to change notification settings - Fork 345
nv2a: Implement texture LOD bias #2435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
||
{ | ||
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, | ||
|
@@ -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 = | ||
|
||
GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS); | ||
|
||
if (f->linear) { | ||
/* somtimes games try to set mipmap min filters on linear textures. | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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( | ||
|
||
GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MIPMAP_LOD_BIAS)), | ||
.pNext = sampler_next_struct, | ||
}; | ||
|
||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done