Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Shrinking pixel formats from 184->106 and vertex formats 62->50.
Browse files Browse the repository at this point in the history
Fixes #37.
  • Loading branch information
benvanik committed Jul 12, 2017
1 parent 5039d2a commit 8791dfd
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 332 deletions.
44 changes: 44 additions & 0 deletions xrtl/gfx/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ XRTL_BITMASK(DeviceType);
// A device available for use by the backend graphics API.
// This may represent a physical device in the system or a logical device as
// exposed by the API.
//
// For more information on device limits on each API/platform, see:
// OpenGL ES 3.0:
// http://opengles.gpuinfo.org/gles_devicefeatures.php
// https://www.g-truc.net/doc/OpenGL%20ES%203%20Hardware%20Matrix.pdf
// Vulkan:
// http://vulkan.gpuinfo.org/listlimits.php
// Metal:
// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
// D3D12:
// https://msdn.microsoft.com/en-us/library/windows/desktop/mt186615(v=vs.85).aspx
class Device : public RefObject<Device> {
public:
virtual ~Device() = default;
Expand All @@ -60,11 +71,44 @@ class Device : public RefObject<Device> {
// When passed to CreateContext it is used to enable specific features on the
// created context.
//
// Key:
// .: not supported
// ~: optional, but practically not supported
// ?: optional, often supported
// ✔: always supported
//
// Maps to:
// https://www.khronos.org/registry/vulkan/specs/1.0/man/html/VkPhysicalDeviceFeatures.html
struct Features {
// TODO(benvanik): robust buffer access, full draw index uint32, extensions.
// TODO(benvanik): render or compute.

// Defines which pixel formats are available for use on the device.
// Any format not covered by the flags below can be assumed always present.
// Note that not all formats support use as a render target.
struct PixelFormats {
// Supports the packed kD24UNormS8UInt format.
// | ES3 ✔ | VK ✔ | MTL ~ | D3D ✔ |
bool packed_depth_stencil = false;
// Supports the BC1, BC2, and BC3 formats.
// | ES3 ~ | VK ✔ | MTL ~ | D3D ✔ |
bool bc1_2_3 = false;
// Supports the BC4, BC5, BC6, and BC7 formats.
// | ES3 . | VK ✔ | MTL ~ | D3D ✔ |
bool bc4_5_6_7 = false;
// Supports the ETC2 compressed texture formats.
// | ES3 ✔ | VK ~ | MTL . | D3D . |
bool etc2 = false;
// Supports the EAC compressed texture formats.
// | ES3 ✔ | VK ~ | MTL ? | D3D . |
bool eac = false;
// Supports the ASTC compressed texture formats.
// | ES3 ~ | VK ~ | MTL ? | D3D . |
bool astc = false;
// Supports the PVRTC(1) compressed texture formats.
// | ES3 ~ | VK . | MTL ✔ | D3D . |
bool pvrtc = false;
} pixel_formats;
};

// Describes a queue family available on the device.
Expand Down
21 changes: 21 additions & 0 deletions xrtl/gfx/es3/es3_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,37 @@

#include "xrtl/gfx/es3/es3_device.h"

#include "xrtl/gfx/es3/es3_common.h"

namespace xrtl {
namespace gfx {
namespace es3 {

bool ES3Device::AdoptCurrentContext() {
// TODO(benvanik): pull renderer/etc.
type_ = DeviceType::kGpu;

// Query limits.
// TODO(benvanik): query limits.

// Query feature support flags.
// TODO(benvanik): other features.
QuerySupportedPixelFormats(&features_.pixel_formats);

return true;
}

void ES3Device::QuerySupportedPixelFormats(
Features::PixelFormats* pixel_formats) {
pixel_formats->packed_depth_stencil = GLAD_GL_OES_packed_depth_stencil == 1;
pixel_formats->bc1_2_3 = GLAD_GL_EXT_texture_compression_s3tc == 1;
pixel_formats->bc4_5_6_7 = false;
pixel_formats->etc2 = true;
pixel_formats->eac = true;
pixel_formats->astc = GLAD_GL_KHR_texture_compression_astc_hdr == 1;
pixel_formats->pvrtc = GLAD_GL_IMG_texture_compression_pvrtc == 1;
}

} // namespace es3
} // namespace gfx
} // namespace xrtl
4 changes: 4 additions & 0 deletions xrtl/gfx/es3/es3_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class ES3Device : public Device {

// Adopts the device parameters of the currently bound GL platform context.
bool AdoptCurrentContext();

private:
// Queries available pixel formats and populates the given struct.
void QuerySupportedPixelFormats(Features::PixelFormats* pixel_formats);
};

} // namespace es3
Expand Down
97 changes: 0 additions & 97 deletions xrtl/gfx/es3/es3_pixel_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,125 +23,52 @@ bool ConvertPixelFormatToTextureParams(PixelFormat pixel_format,
static const ES3TextureParams kTable[] = {
{GL_NONE, GL_NONE, GL_NONE}, // kUndefined
//
{GL_NONE, GL_NONE, GL_NONE}, // kR4G4UNorm
{GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE}, // kR4G4B4A4UNorm
{GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE}, // kB4G4R4A4UNorm
{GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, // kR5G6B5UNorm
{GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, // kB5G6R5UNorm
{GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1}, // kR5G5B5A1UNorm
{GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1}, // kB5G5R5A1UNorm
{GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1}, // kA1R5G5B5UNorm
//
{GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // kR8UNorm
{GL_R8_SNORM, GL_RED, GL_BYTE}, // kR8SNorm
{GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // kR8UScaled
{GL_R8_SNORM, GL_RED, GL_BYTE}, // kR8SScaled
{GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE}, // kR8UInt
{GL_R8I, GL_RED_INTEGER, GL_BYTE}, // kR8SInt
{GL_NONE, GL_NONE, GL_NONE}, // kR8Srgb
//
{GL_RG8, GL_RG, GL_UNSIGNED_BYTE}, // kR8G8UNorm
{GL_RG8_SNORM, GL_RG, GL_BYTE}, // kR8G8SNorm
{GL_RG8, GL_RG, GL_UNSIGNED_BYTE}, // kR8G8UScaled
{GL_RG8_SNORM, GL_RG, GL_BYTE}, // kR8G8SScaled
{GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE}, // kR8G8UInt
{GL_RG8I, GL_RG_INTEGER, GL_BYTE}, // kR8G8SInt
{GL_NONE, GL_NONE, GL_NONE}, // kR8G8Srgb
//
{GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, // kR8G8B8UNorm
{GL_RGB8_SNORM, GL_RGB, GL_BYTE}, // kR8G8B8SNorm
{GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, // kR8G8B8UScaled
{GL_RGB8_SNORM, GL_RGB, GL_BYTE}, // kR8G8B8SScaled
{GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE}, // kR8G8B8UInt
{GL_RGB8I, GL_RGB_INTEGER, GL_BYTE}, // kR8G8B8SInt
{GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE}, // kR8G8B8Srgb
//
{GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, // kB8G8R8UNorm
{GL_RGB8_SNORM, GL_RGB, GL_BYTE}, // kB8G8R8SNorm
{GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE}, // kB8G8R8UScaled
{GL_RGB8_SNORM, GL_RGB, GL_BYTE}, // kB8G8R8SScaled
{GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE}, // kB8G8R8UInt
{GL_RGB8I, GL_RGB_INTEGER, GL_BYTE}, // kB8G8R8SInt
{GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE}, // kB8G8R8Srgb
//
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // kR8G8B8A8UNorm
{GL_RGBA8_SNORM, GL_RGBA, GL_BYTE}, // kR8G8B8A8SNorm
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // kR8G8B8A8UScaled
{GL_RGBA8_SNORM, GL_RGBA, GL_BYTE}, // kR8G8B8A8SScaled
{GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, // kR8G8B8A8UInt
{GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE}, // kR8G8B8A8SInt
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, // kR8G8B8A8Srgb
//
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // kB8G8R8A8UNorm
{GL_RGBA8_SNORM, GL_RGBA, GL_BYTE}, // kB8G8R8A8SNorm
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // kB8G8R8A8UScaled
{GL_RGBA8_SNORM, GL_RGBA, GL_BYTE}, // kB8G8R8A8SScaled
{GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, // kB8G8R8A8UInt
{GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE}, // kB8G8R8A8SInt
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, // kB8G8R8A8Srgb
//
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // kA8B8G8R8UNorm
{GL_RGBA8_SNORM, GL_RGBA, GL_BYTE}, // kA8B8G8R8SNorm
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // kA8B8G8R8UScaled
{GL_RGBA8_SNORM, GL_RGBA, GL_BYTE}, // kA8B8G8R8SScaled
{GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE}, // kA8B8G8R8UInt
{GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE}, // kA8B8G8R8SInt
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE}, // kA8B8G8R8Srgb
//
{GL_RGB10_A2, GL_RGBA, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2R10G10B10UNorm
{GL_RGB10_A2, GL_RGBA, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2R10G10B10SNorm
{GL_RGB10_A2, GL_RGBA, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2R10G10B10UScaled
{GL_RGB10_A2, GL_RGBA, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2R10G10B10SScaled
{GL_RGB10_A2UI, GL_RGBA_INTEGER, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2R10G10B10UInt
{GL_RGB10_A2UI, GL_RGBA_INTEGER, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2R10G10B10SInt
//
{GL_RGB10_A2, GL_RGBA, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2B10G10R10UNorm
{GL_RGB10_A2, GL_RGBA, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2B10G10R10SNorm
{GL_RGB10_A2, GL_RGBA, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2B10G10R10UScaled
{GL_RGB10_A2, GL_RGBA, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2B10G10R10SScaled
{GL_RGB10_A2UI, GL_RGBA_INTEGER, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2B10G10R10UInt
{GL_RGB10_A2UI, GL_RGBA_INTEGER, //
GL_UNSIGNED_INT_2_10_10_10_REV}, // kA2B10G10R10SInt
//
{GL_R16F, GL_RED, GL_HALF_FLOAT}, // kR16UNorm
{GL_R16F, GL_RED, GL_HALF_FLOAT}, // kR16SNorm
{GL_R16F, GL_RED, GL_HALF_FLOAT}, // kR16UScaled
{GL_R16F, GL_RED, GL_HALF_FLOAT}, // kR16SScaled
{GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT}, // kR16UInt
{GL_R16I, GL_RED_INTEGER, GL_SHORT}, // kR16SInt
{GL_R16F, GL_RED, GL_HALF_FLOAT}, // kR16SFloat
//
{GL_RG16F, GL_RG, GL_HALF_FLOAT}, // kR16G16UNorm
{GL_RG16F, GL_RG, GL_HALF_FLOAT}, // kR16G16SNorm
{GL_RG16F, GL_RG, GL_HALF_FLOAT}, // kR16G16UScaled
{GL_RG16F, GL_RG, GL_HALF_FLOAT}, // kR16G16SScaled
{GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT}, // kR16G16UInt
{GL_RG16I, GL_RG_INTEGER, GL_SHORT}, // kR16G16SInt
{GL_RG16F, GL_RG, GL_HALF_FLOAT}, // kR16G16SFloat
//
{GL_RGB16F, GL_RGB, GL_HALF_FLOAT}, // kR16G16B16UNorm
{GL_RGB16F, GL_RGB, GL_HALF_FLOAT}, // kR16G16B16SNorm
{GL_RGB16F, GL_RGB, GL_HALF_FLOAT}, // kR16G16B16UScaled
{GL_RGB16F, GL_RGB, GL_HALF_FLOAT}, // kR16G16B16SScaled
{GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT}, // kR16G16B16UInt
{GL_RGB16I, GL_RGB_INTEGER, GL_SHORT}, // kR16G16B16SInt
{GL_RGB16F, GL_RGB, GL_HALF_FLOAT}, // kR16G16B16SFloat
//
{GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}, // kR16G16B16A16UNorm
{GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}, // kR16G16B16A16SNorm
{GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}, // kR16G16B16A16UScaled
{GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}, // kR16G16B16A16SScaled
{GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT}, // kR16G16B16A16UInt
{GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT}, // kR16G16B16A16SInt
{GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT}, // kR16G16B16A16SFloat
Expand All @@ -162,40 +89,16 @@ bool ConvertPixelFormatToTextureParams(PixelFormat pixel_format,
{GL_RGBA32I, GL_RGBA_INTEGER, GL_INT}, // kR32G32B32A32SInt
{GL_RGBA32F, GL_RGBA, GL_FLOAT}, // kR32G32B32A32SFloat
//
{GL_NONE, GL_NONE, GL_NONE}, // kR64UInt
{GL_NONE, GL_NONE, GL_NONE}, // kR64SInt
{GL_NONE, GL_NONE, GL_NONE}, // kR64SFloat
//
{GL_NONE, GL_NONE, GL_NONE}, // kR64G64UInt
{GL_NONE, GL_NONE, GL_NONE}, // kR64G64SInt
{GL_NONE, GL_NONE, GL_NONE}, // kR64G64SFloat
//
{GL_NONE, GL_NONE, GL_NONE}, // kR64G64B64UInt
{GL_NONE, GL_NONE, GL_NONE}, // kR64G64B64SInt
{GL_NONE, GL_NONE, GL_NONE}, // kR64G64B64SFloat
//
{GL_NONE, GL_NONE, GL_NONE}, // kR64G64B64A64UInt
{GL_NONE, GL_NONE, GL_NONE}, // kR64G64B64A64SInt
{GL_NONE, GL_NONE, GL_NONE}, // kR64G64B64A64SFloat
//
{GL_R11F_G11F_B10F, GL_RGB, //
GL_UNSIGNED_INT_10F_11F_11F_REV}, // kB10G11R11UFloat
{GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV}, // kE5B9G9R9UFloat
//
{GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, //
GL_UNSIGNED_SHORT}, // kD16UNorm
{GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, //
GL_UNSIGNED_INT}, // kX8D24UNorm
{GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT}, // kD32SFloat
{GL_NONE, GL_NONE, GL_NONE}, // kS8UInt
{GL_NONE, GL_NONE, GL_NONE}, // kD16UNormS8UInt
{GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, //
GL_UNSIGNED_INT_24_8}, // kD24UNormS8UInt
{GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, //
GL_FLOAT_32_UNSIGNED_INT_24_8_REV}, // kD32SFloatS8UInt
//
{GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGB, GL_NONE}, // kBC1RGBUNorm
{GL_COMPRESSED_SRGB_S3TC_DXT1_NV, GL_RGB, GL_NONE}, // kBC1RGBSrgb
{GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_RGBA, GL_NONE}, // kBC1RGBAUNorm
{GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_NV, GL_RGBA, //
GL_NONE}, // kBC1RGBASrgb
Expand Down
Loading

0 comments on commit 8791dfd

Please sign in to comment.