@@ -27,7 +27,7 @@ class ISwapchain : public IBackendObject
27
27
if (!physDev || !surface || !surface->getSurfaceCapabilitiesForPhysicalDevice (physDev,caps))
28
28
return false ;
29
29
30
- if (!caps.supportedUsageFlags .hasFlags (imageUsage))
30
+ if (!imageUsage. value || ! caps.supportedUsageFlags .hasFlags (imageUsage))
31
31
return false ;
32
32
if (minImageCount<caps.minImageCount )
33
33
return false ;
@@ -46,6 +46,18 @@ class ISwapchain : public IBackendObject
46
46
return false ;
47
47
if (hlsl::bitCount (preTransform.value )!=1 || !caps.supportedTransforms .hasFlags (preTransform))
48
48
return false ;
49
+ {
50
+ const auto & formatUsages = physDev->getImageFormatUsagesOptimalTiling ();
51
+ core::bitflag<IGPUImage::E_USAGE_FLAGS> possibleUsages = IGPUImage::E_USAGE_FLAGS::EUF_NONE;
52
+ for (auto f=0u ; f<asset::EF_COUNT; f++)
53
+ {
54
+ const auto format = static_cast <asset::E_FORMAT>(f);
55
+ if (viewFormats.test (format))
56
+ possibleUsages |= core::bitflag<IGPUImage::E_USAGE_FLAGS>(formatUsages[format]);
57
+ }
58
+ if (!possibleUsages.hasFlags (imageUsage))
59
+ return false ;
60
+ }
49
61
return true ;
50
62
}
51
63
@@ -76,21 +88,7 @@ class ISwapchain : public IBackendObject
76
88
if (!physDev || !surface || !surface->getSurfaceCapabilitiesForPhysicalDevice (physDev,caps))
77
89
return false ;
78
90
79
- if (!imageUsage)
80
- {
81
- const auto formatUsages = physDev->getImageFormatUsagesOptimalTiling ();
82
- // we must be able to at least render to an image with a Graphics Pipeline
83
- core::bitflag<IGPUImage::E_USAGE_FLAGS> extendedUsages = IGPUImage::E_USAGE_FLAGS::EUF_RENDER_ATTACHMENT_BIT;
84
- for (auto f=0u ; f<asset::EF_COUNT; f++)
85
- {
86
- const auto format = static_cast <asset::E_FORMAT>(f);
87
- if (viewFormats.test (format))
88
- extendedUsages |= core::bitflag<IGPUImage::E_USAGE_FLAGS>(formatUsages[format]);
89
- }
90
- // usages need to be trimmed
91
- imageUsage = caps.supportedUsageFlags & extendedUsages;
92
- }
93
- else if (!caps.supportedUsageFlags .hasFlags (imageUsage))
91
+ if (!imageUsage || !caps.supportedUsageFlags .hasFlags (imageUsage))
94
92
return false ;
95
93
96
94
caps.maxImageCount = core::min<uint32_t >(caps.maxImageCount ,MaxImages);
@@ -155,8 +153,20 @@ class ISwapchain : public IBackendObject
155
153
return true ;
156
154
}
157
155
158
- // default means "all supported"
159
- core::bitflag<IGPUImage::E_USAGE_FLAGS> imageUsage = IGPUImage::E_USAGE_FLAGS::EUF_NONE;
156
+ //
157
+ static inline core::vector<ISurface::SFormat> obtainAvailableSurfaceFormats (const IPhysicalDevice* physDev, const ISurface* surface)
158
+ {
159
+ uint32_t availableFormatCount = 0 ;
160
+ surface->getAvailableFormatsForPhysicalDevice (physDev,availableFormatCount,nullptr );
161
+
162
+ core::vector<ISurface::SFormat> availableFormats (availableFormatCount);
163
+ surface->getAvailableFormatsForPhysicalDevice (physDev,availableFormatCount,availableFormats.data ());
164
+
165
+ return availableFormats;
166
+ }
167
+
168
+ // Required to be not NONE, default to Transfer Dst cause thats the easiest way to copy (blit)
169
+ core::bitflag<IGPUImage::E_USAGE_FLAGS> imageUsage = IGPUImage::E_USAGE_FLAGS::EUF_TRANSFER_DST_BIT|IGPUImage::E_USAGE_FLAGS::EUF_RENDER_ATTACHMENT_BIT;
160
170
// can also treat as them as bitflags of valid transforms
161
171
uint8_t minImageCount = 0u ;
162
172
core::bitflag<ISurface::E_PRESENT_MODE> presentMode = ISurface::EPM_ALL_BITS;
@@ -178,13 +188,7 @@ class ISwapchain : public IBackendObject
178
188
if (!sharedParams.valid (physDev,surface.get ()))
179
189
return false ;
180
190
181
- core::vector<ISurface::SFormat> availableFormats;
182
- {
183
- uint32_t availableFormatCount = 0 ;
184
- surface->getAvailableFormatsForPhysicalDevice (physDev,availableFormatCount,nullptr );
185
- availableFormats.resize (availableFormatCount);
186
- surface->getAvailableFormatsForPhysicalDevice (physDev,availableFormatCount,availableFormats.data ());
187
- }
191
+ auto availableFormats = SSharedCreationParams::obtainAvailableSurfaceFormats (physDev,surface.get ());
188
192
return std::find (availableFormats.begin (),availableFormats.end (),surfaceFormat)!=availableFormats.end ();
189
193
}
190
194
@@ -216,13 +220,7 @@ class ISwapchain : public IBackendObject
216
220
std::span<const asset::E_COLOR_PRIMARIES> preferredColorPrimaries=DefaultColorPrimaries
217
221
)
218
222
{
219
- core::vector<ISurface::SFormat> availableFormats;
220
- {
221
- uint32_t availableFormatCount = 0 ;
222
- surface->getAvailableFormatsForPhysicalDevice (physDev,availableFormatCount,nullptr );
223
- availableFormats.resize (availableFormatCount);
224
- surface->getAvailableFormatsForPhysicalDevice (physDev,availableFormatCount,availableFormats.data ());
225
- }
223
+ auto availableFormats = SSharedCreationParams::obtainAvailableSurfaceFormats (physDev,surface.get ());
226
224
227
225
// override preferred if set to known value already
228
226
if (surfaceFormat.format !=asset::EF_UNKNOWN)
@@ -270,6 +268,8 @@ class ISwapchain : public IBackendObject
270
268
val.format = format;
271
269
if (std::binary_search (formatBegin,formatEnd,val,fullComparator))
272
270
{
271
+ // trim usage
272
+
273
273
// Check compatibility against all `viewFormats`
274
274
bool incompatible = false ;
275
275
const auto formatClass = asset::getFormatClass (format);
0 commit comments