Skip to content

Commit

Permalink
sokol_app.h, sokol_gfx.h wgpu: support bc and etc2 compressed texture…
Browse files Browse the repository at this point in the history
… formats
  • Loading branch information
floooh committed Sep 2, 2023
1 parent 9d18ccc commit 08e258a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
13 changes: 11 additions & 2 deletions sokol_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -5743,12 +5743,21 @@ _SOKOL_PRIVATE void _sapp_emsc_wgpu_request_adapter_cb(WGPURequestAdapterStatus
}
SOKOL_ASSERT(adapter);
_sapp.wgpu.adapter = adapter;
const WGPUFeatureName requiredFeatures[1] = {
size_t cur_feature_index = 1;
WGPUFeatureName requiredFeatures[8] = {
WGPUFeatureName_Depth32FloatStencil8,
};
// check for optional features we're interested in
// FIXME: ASTC texture compression
if (wgpuAdapterHasFeature(adapter, WGPUFeatureName_TextureCompressionBC)) {
requiredFeatures[cur_feature_index++] = WGPUFeatureName_TextureCompressionBC;
} else if (wgpuAdapterHasFeature(adapter, WGPUFeatureName_TextureCompressionETC2)) {
requiredFeatures[cur_feature_index++] = WGPUFeatureName_TextureCompressionETC2;
}

WGPUDeviceDescriptor dev_desc;
_sapp_clear(&dev_desc, sizeof(dev_desc));
dev_desc.requiredFeaturesCount = 1,
dev_desc.requiredFeaturesCount = cur_feature_index;
dev_desc.requiredFeatures = requiredFeatures,
wgpuAdapterRequestDevice(adapter, &dev_desc, _sapp_emsc_wgpu_request_device_cb, 0);
}
Expand Down
33 changes: 20 additions & 13 deletions sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12341,6 +12341,7 @@ _SOKOL_PRIVATE void _sg_wgpu_init_caps(void) {
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_R8SN]);
_sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R8UI]);
_sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R8SI]);
// NOTE: no WGPUTextureFormat_R16Unorm
_sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R16UI]);
_sg_pixelformat_srm(&_sg.formats[SG_PIXELFORMAT_R16SI]);
_sg_pixelformat_all(&_sg.formats[SG_PIXELFORMAT_R16F]);
Expand Down Expand Up @@ -12373,19 +12374,25 @@ _SOKOL_PRIVATE void _sg_wgpu_init_caps(void) {
_sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH]);
_sg_pixelformat_srmd(&_sg.formats[SG_PIXELFORMAT_DEPTH_STENCIL]);

/* FIXME FIXME FIXME: need to check if BC texture compression is
actually supported, currently the WebGPU C-API doesn't allow this
*/
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC1_RGBA]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC2_RGBA]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC3_RGBA]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_R]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_RSN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RG]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RGSN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBF]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBUF]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC7_RGBA]);
if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_TextureCompressionBC)) {
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC1_RGBA]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC2_RGBA]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC3_RGBA]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_R]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC4_RSN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RG]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC5_RGSN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBF]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC6H_RGBUF]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_BC7_RGBA]);
}
if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_TextureCompressionETC2)) {
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11SN]);
}
}

_SOKOL_PRIVATE void _sg_wgpu_uniform_buffer_init(const sg_desc* desc) {
Expand Down

0 comments on commit 08e258a

Please sign in to comment.