Skip to content

Commit

Permalink
Add infrastructure for checking for supported DataFormats
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 24, 2017
1 parent 528af8a commit 5d6097d
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 4 deletions.
2 changes: 1 addition & 1 deletion android/ab.cmd
Expand Up @@ -4,6 +4,6 @@ xcopy ..\assets\shaders assets\shaders /s /y <d.txt
copy ..\assets\langregion.ini assets\langregion.ini
copy ..\assets\compat.ini assets\compat.ini
copy ..\assets\*.png assets
SET NDK=C:\AndroidNDK
SET NDK=C:\Android\sdk\ndk-bundle
SET NDK_MODULE_PATH=..\ext;..\ext\native\ext
%NDK%/ndk-build -j9 %*
12 changes: 11 additions & 1 deletion ext/native/thin3d/thin3d.h
Expand Up @@ -181,13 +181,16 @@ enum class DataFormat : uint8_t {

R8G8B8A8_UNORM,
R8G8B8A8_UNORM_SRGB,
B8G8R8A8_UNORM, // D3D style

R8G8B8A8_SNORM,
R8G8B8A8_UINT,
R8G8B8A8_SINT,

R4G4_UNORM,
R4G4B4A4_UNORM,
A4B4G4R4_UNORM, // This is the one OpenGL ES supports
R4G4B4A4_UNORM, // Supported by Vulkan, as is the below
B4G4R4A4_UNORM, // This is the one D3D supports

R16_FLOAT,
R16G16_FLOAT,
Expand Down Expand Up @@ -281,6 +284,12 @@ enum class ShaderLanguage {
METAL_BYTECODE = 1024,
};

enum FormatSupport {
FMT_RENDERTARGET = 1,
FMT_TEXTURE = 2,
FMT_INPUTLAYOUT = 4,
};

enum InfoField {
APINAME,
APIVERSION,
Expand Down Expand Up @@ -480,6 +489,7 @@ class DrawContext : public RefCountedObject {
virtual ~DrawContext();

virtual const DeviceCaps &GetDeviceCaps() const = 0;
virtual uint32_t GetDataFormatSupport(DataFormat fmt) const = 0;
virtual std::vector<std::string> GetFeatureList() const { return std::vector<std::string>(); }

virtual uint32_t GetSupportedShaderLanguages() const = 0;
Expand Down
35 changes: 33 additions & 2 deletions ext/native/thin3d/thin3d_d3d11.cpp
Expand Up @@ -28,6 +28,7 @@ class D3D11DrawContext : public DrawContext {
uint32_t GetSupportedShaderLanguages() const override {
return (uint32_t)ShaderLanguage::HLSL_D3D11 | (uint32_t)ShaderLanguage::HLSL_D3D11_BYTECODE;
}
uint32_t GetDataFormatSupport(DataFormat fmt) const override;

InputLayout *CreateInputLayout(const InputLayoutDesc &desc) override;
DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) override;
Expand Down Expand Up @@ -360,8 +361,6 @@ class D3D11Texture : public Texture {
public:
D3D11Texture() {}
void SetImageData(int x, int y, int z, int width, int height, int depth, int level, int stride, const uint8_t *data) override;
void AutoGenMipmaps() override {}
void Finalize() override {}
};

Texture *D3D11DrawContext::CreateTexture(const TextureDesc &desc) {
Expand Down Expand Up @@ -477,6 +476,38 @@ void D3D11DrawContext::DrawUP(const void *vdata, int vertexCount) {
ApplyCurrentState();
}


uint32_t D3D11DrawContext::GetDataFormatSupport(DataFormat fmt) const {
// TODO: Actually do proper checks
switch (fmt) {
case DataFormat::B8G8R8A8_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE;
case DataFormat::B4G4R4A4_UNORM:
case DataFormat::R4G4B4A4_UNORM:
return 0;
case DataFormat::A4B4G4R4_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE; // native support

case DataFormat::R8G8B8A8_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE | FMT_INPUTLAYOUT;

case DataFormat::R32_FLOAT:
case DataFormat::R32G32_FLOAT:
case DataFormat::R32G32B32_FLOAT:
case DataFormat::R32G32B32A32_FLOAT:
return FMT_INPUTLAYOUT;

case DataFormat::R8_UNORM:
return 0;
case DataFormat::BC1_RGBA_UNORM_BLOCK:
case DataFormat::BC2_UNORM_BLOCK:
case DataFormat::BC3_UNORM_BLOCK:
return FMT_TEXTURE;
default:
return 0;
}
}

#endif

DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context) {
Expand Down
31 changes: 31 additions & 0 deletions ext/native/thin3d/thin3d_d3d9.cpp
Expand Up @@ -518,6 +518,7 @@ class D3D9Context : public DrawContext {
uint32_t GetSupportedShaderLanguages() const override {
return (uint32_t)ShaderLanguage::HLSL_D3D9 | (uint32_t)ShaderLanguage::HLSL_D3D9_BYTECODE;
}
uint32_t GetDataFormatSupport(DataFormat fmt) const override;

ShaderModule *CreateShaderModule(ShaderStage stage, ShaderLanguage language, const uint8_t *data, size_t dataSize) override;
DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) override;
Expand Down Expand Up @@ -937,4 +938,34 @@ DrawContext *T3DCreateDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapt
return new D3D9Context(d3d, d3dEx, adapterId, device, deviceEx);
}

// Only partial implementation!
uint32_t D3D9Context::GetDataFormatSupport(DataFormat fmt) const {
switch (fmt) {
case DataFormat::B8G8R8A8_UNORM:
case DataFormat::B4G4R4A4_UNORM: // native support
return FMT_RENDERTARGET | FMT_TEXTURE;
case DataFormat::A4B4G4R4_UNORM:
return FMT_TEXTURE; // emulated support

case DataFormat::R8G8B8A8_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE | FMT_INPUTLAYOUT;

case DataFormat::R32_FLOAT:
case DataFormat::R32G32_FLOAT:
case DataFormat::R32G32B32_FLOAT:
case DataFormat::R32G32B32A32_FLOAT:
return FMT_INPUTLAYOUT;

case DataFormat::R8_UNORM:
return 0;
case DataFormat::BC1_RGBA_UNORM_BLOCK:
case DataFormat::BC2_UNORM_BLOCK:
case DataFormat::BC3_UNORM_BLOCK:
return FMT_TEXTURE;
default:
return 0;
}
}


} // namespace Draw
31 changes: 31 additions & 0 deletions ext/native/thin3d/thin3d_gl.cpp
Expand Up @@ -503,6 +503,7 @@ class OpenGLContext : public DrawContext {
return (uint32_t)ShaderLanguage::GLSL_ES_200 | (uint32_t)ShaderLanguage::GLSL_410;
#endif
}
uint32_t GetDataFormatSupport(DataFormat fmt) const override;

DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) override;
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
Expand Down Expand Up @@ -1151,4 +1152,34 @@ void OpenGLInputLayout::Unapply() {
}
}

uint32_t OpenGLContext::GetDataFormatSupport(DataFormat fmt) const {
switch (fmt) {
case DataFormat::B8G8R8A8_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE;
case DataFormat::B4G4R4A4_UNORM:
case DataFormat::R4G4B4A4_UNORM:
return 0;
case DataFormat::A4B4G4R4_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE; // native support

case DataFormat::R8G8B8A8_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE | FMT_INPUTLAYOUT;

case DataFormat::R32_FLOAT:
case DataFormat::R32G32_FLOAT:
case DataFormat::R32G32B32_FLOAT:
case DataFormat::R32G32B32A32_FLOAT:
return FMT_INPUTLAYOUT;

case DataFormat::R8_UNORM:
return 0;
case DataFormat::BC1_RGBA_UNORM_BLOCK:
case DataFormat::BC2_UNORM_BLOCK:
case DataFormat::BC3_UNORM_BLOCK:
return FMT_TEXTURE;
default:
return 0;
}
}

} // namespace Draw
32 changes: 32 additions & 0 deletions ext/native/thin3d/thin3d_vulkan.cpp
Expand Up @@ -354,6 +354,7 @@ class VKContext : public DrawContext {
uint32_t GetSupportedShaderLanguages() const override {
return (uint32_t)ShaderLanguage::GLSL_VULKAN | (uint32_t)ShaderLanguage::SPIRV_VULKAN;
}
uint32_t GetDataFormatSupport(DataFormat fmt) const override;

DepthStencilState *CreateDepthStencilState(const DepthStencilStateDesc &desc) override;
BlendState *CreateBlendState(const BlendStateDesc &desc) override;
Expand Down Expand Up @@ -1200,4 +1201,35 @@ std::vector<std::string> VKContext::GetFeatureList() const {
return features;
}

uint32_t VKContext::GetDataFormatSupport(DataFormat fmt) const {
// TODO: Actually do proper checks
switch (fmt) {
case DataFormat::B8G8R8A8_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE;
case DataFormat::B4G4R4A4_UNORM:
case DataFormat::R4G4B4A4_UNORM:
return 0;
case DataFormat::A4B4G4R4_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE; // native support

case DataFormat::R8G8B8A8_UNORM:
return FMT_RENDERTARGET | FMT_TEXTURE | FMT_INPUTLAYOUT;

case DataFormat::R32_FLOAT:
case DataFormat::R32G32_FLOAT:
case DataFormat::R32G32B32_FLOAT:
case DataFormat::R32G32B32A32_FLOAT:
return FMT_INPUTLAYOUT;

case DataFormat::R8_UNORM:
return 0;
case DataFormat::BC1_RGBA_UNORM_BLOCK:
case DataFormat::BC2_UNORM_BLOCK:
case DataFormat::BC3_UNORM_BLOCK:
return FMT_TEXTURE;
default:
return 0;
}
}

} // namespace Draw

0 comments on commit 5d6097d

Please sign in to comment.