Skip to content

Commit 16dff44

Browse files
committed
Add cubic FilterMode;
1 parent 6d89932 commit 16dff44

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

src/api/l_graphics.c

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ StringEntry lovrDataType[] = {
117117
StringEntry lovrFilterMode[] = {
118118
[FILTER_NEAREST] = ENTRY("nearest"),
119119
[FILTER_LINEAR] = ENTRY("linear"),
120+
[FILTER_CUBIC] = ENTRY("cubic"),
120121
{ 0 }
121122
};
122123

@@ -175,6 +176,7 @@ StringEntry lovrTextureFeature[] = {
175176
[1] = ENTRY("render"),
176177
[2] = ENTRY("storage"),
177178
[3] = ENTRY("blit"),
179+
[4] = ENTRY("cubic"),
178180
{ 0 }
179181
};
180182

@@ -462,6 +464,7 @@ static int l_lovrGraphicsGetFeatures(lua_State* L) {
462464
lua_pushboolean(L, features.float64), lua_setfield(L, -2, "float64");
463465
lua_pushboolean(L, features.int64), lua_setfield(L, -2, "int64");
464466
lua_pushboolean(L, features.int16), lua_setfield(L, -2, "int16");
467+
lua_pushboolean(L, features.cubic), lua_setfield(L, -2, "cubic");
465468
return 1;
466469
}
467470

src/core/gpu.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ bool gpu_surface_present(void);
190190

191191
typedef enum {
192192
GPU_FILTER_NEAREST,
193-
GPU_FILTER_LINEAR
193+
GPU_FILTER_LINEAR,
194+
GPU_FILTER_CUBIC
194195
} gpu_filter;
195196

196197
typedef enum {
@@ -667,7 +668,8 @@ enum {
667668
GPU_FEATURE_SAMPLE = (1 << 0),
668669
GPU_FEATURE_RENDER = (1 << 1),
669670
GPU_FEATURE_STORAGE = (1 << 2),
670-
GPU_FEATURE_BLIT = (1 << 3)
671+
GPU_FEATURE_BLIT = (1 << 3),
672+
GPU_FEATURE_CUBIC = (1 << 4)
671673
};
672674

673675
typedef struct {
@@ -685,6 +687,7 @@ typedef struct {
685687
bool float64;
686688
bool int64;
687689
bool int16;
690+
bool cubic;
688691
} gpu_features;
689692

690693
typedef struct {

src/core/gpu_vk.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ typedef struct {
184184
bool scalarBlockLayout;
185185
bool foveation;
186186
bool pipelineCacheControl;
187+
bool cubicFilter;
187188
} gpu_extensions;
188189

189190
// State
@@ -1023,7 +1024,8 @@ bool gpu_surface_present(void) {
10231024
bool gpu_sampler_init(gpu_sampler* sampler, gpu_sampler_info* info) {
10241025
static const VkFilter filters[] = {
10251026
[GPU_FILTER_NEAREST] = VK_FILTER_NEAREST,
1026-
[GPU_FILTER_LINEAR] = VK_FILTER_LINEAR
1027+
[GPU_FILTER_LINEAR] = VK_FILTER_LINEAR,
1028+
[GPU_FILTER_CUBIC] = VK_FILTER_CUBIC_IMG
10271029
};
10281030

10291031
static const VkSamplerMipmapMode mipFilters[] = {
@@ -2658,7 +2660,8 @@ bool gpu_init(gpu_config* config) {
26582660
{ "VK_KHR_dynamic_rendering", true, &state.extensions.dynamicRendering },
26592661
{ "VK_EXT_scalar_block_layout", true, &state.extensions.scalarBlockLayout },
26602662
{ "VK_EXT_fragment_density_map", true, &state.extensions.foveation },
2661-
{ "VK_EXT_pipeline_creation_cache_control", true, &state.extensions.pipelineCacheControl }
2663+
{ "VK_EXT_pipeline_creation_cache_control", true, &state.extensions.pipelineCacheControl },
2664+
{ "VK_IMG_filter_cubic", true, &state.extensions.cubicFilter }
26622665
};
26632666

26642667
uint32_t extensionCount = 0;
@@ -2818,6 +2821,7 @@ bool gpu_init(gpu_config* config) {
28182821
config->features->float64 = enabled.features.shaderFloat64;
28192822
config->features->int64 = enabled.features.shaderInt64;
28202823
config->features->int16 = enabled.features.shaderInt16;
2824+
config->features->cubic = state.extensions.cubicFilter;
28212825

28222826
// Formats
28232827
for (uint32_t i = 0; i < GPU_FORMAT_COUNT; i++) {
@@ -2831,13 +2835,15 @@ bool gpu_init(gpu_config* config) {
28312835
uint32_t sampleMask = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
28322836
uint32_t renderMask = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
28332837
uint32_t blitMask = VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT;
2838+
uint32_t cubicMask = VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG;
28342839
uint32_t flags = formatProperties.optimalTilingFeatures;
28352840
config->features->formats[i][j] =
28362841
((flags & sampleMask) ? GPU_FEATURE_SAMPLE : 0) |
28372842
((flags & renderMask) == renderMask ? GPU_FEATURE_RENDER : 0) |
28382843
((flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) ? GPU_FEATURE_RENDER : 0) |
28392844
((flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? GPU_FEATURE_STORAGE : 0) |
2840-
((flags & blitMask) == blitMask ? GPU_FEATURE_BLIT : 0);
2845+
((flags & blitMask) == blitMask ? GPU_FEATURE_BLIT : 0) |
2846+
((flags & cubicMask) == cubicMask ? GPU_FEATURE_CUBIC : 0);
28412847
}
28422848
}
28432849
}

src/modules/graphics/graphics.c

+15-4
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ void lovrGraphicsGetFeatures(GraphicsFeatures* features) {
969969
features->float64 = state.features.float64;
970970
features->int64 = state.features.int64;
971971
features->int16 = state.features.int16;
972+
features->cubic = state.features.cubic;
972973
}
973974

974975
void lovrGraphicsGetLimits(GraphicsLimits* limits) {
@@ -1015,7 +1016,8 @@ uint32_t lovrGraphicsGetFormatSupport(uint32_t format, uint32_t features) {
10151016
(((~features & TEXTURE_FEATURE_SAMPLE) || (supports & GPU_FEATURE_SAMPLE)) &&
10161017
((~features & TEXTURE_FEATURE_RENDER) || (supports & GPU_FEATURE_RENDER)) &&
10171018
((~features & TEXTURE_FEATURE_STORAGE) || (supports & GPU_FEATURE_STORAGE)) &&
1018-
((~features & TEXTURE_FEATURE_BLIT) || (supports & GPU_FEATURE_BLIT))) << i;
1019+
((~features & TEXTURE_FEATURE_BLIT) || (supports & GPU_FEATURE_BLIT)) &&
1020+
((~features & TEXTURE_FEATURE_CUBIC) || (supports & GPU_FEATURE_CUBIC))) << i;
10191021
} else {
10201022
support |= !!supports << i;
10211023
}
@@ -2945,10 +2947,19 @@ Sampler* lovrSamplerCreate(const SamplerInfo* info) {
29452947
sampler->gpu = (gpu_sampler*) (sampler + 1);
29462948
sampler->info = *info;
29472949

2950+
if (sampler->info.mip == FILTER_CUBIC) {
2951+
sampler->info.mip = FILTER_LINEAR;
2952+
}
2953+
2954+
if (!state.features.cubic) {
2955+
sampler->info.min = sampler->info.min == FILTER_CUBIC ? FILTER_LINEAR : sampler->info.min;
2956+
sampler->info.mag = sampler->info.mag == FILTER_CUBIC ? FILTER_LINEAR : sampler->info.mag;
2957+
}
2958+
29482959
gpu_sampler_info gpu = {
2949-
.min = (gpu_filter) info->min,
2950-
.mag = (gpu_filter) info->mag,
2951-
.mip = (gpu_filter) info->mip,
2960+
.min = (gpu_filter) sampler->info.min,
2961+
.mag = (gpu_filter) sampler->info.mag,
2962+
.mip = (gpu_filter) sampler->info.mip,
29522963
.wrap[0] = (gpu_wrap) info->wrap[0],
29532964
.wrap[1] = (gpu_wrap) info->wrap[1],
29542965
.wrap[2] = (gpu_wrap) info->wrap[2],

src/modules/graphics/graphics.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef struct {
5050
bool float64;
5151
bool int64;
5252
bool int16;
53+
bool cubic;
5354
} GraphicsFeatures;
5455

5556
typedef struct {
@@ -89,7 +90,8 @@ enum {
8990
TEXTURE_FEATURE_SAMPLE = (1 << 0),
9091
TEXTURE_FEATURE_RENDER = (1 << 1),
9192
TEXTURE_FEATURE_STORAGE = (1 << 2),
92-
TEXTURE_FEATURE_BLIT = (1 << 3)
93+
TEXTURE_FEATURE_BLIT = (1 << 3),
94+
TEXTURE_FEATURE_CUBIC = (1 << 4)
9395
};
9496

9597
bool lovrGraphicsInit(GraphicsConfig* config);
@@ -233,7 +235,8 @@ typedef struct {
233235

234236
typedef enum {
235237
FILTER_NEAREST,
236-
FILTER_LINEAR
238+
FILTER_LINEAR,
239+
FILTER_CUBIC
237240
} FilterMode;
238241

239242
bool lovrGraphicsGetWindowTexture(Texture** texture);

0 commit comments

Comments
 (0)