Skip to content

Commit c0c922b

Browse files
azhirnovTheMostDiligent
authored andcommitted
Added C-interface for RenderDeviceGLES (fixed include tests), added some structs to CHECK_BASE_STRUCT_ALIGNMENT(), enabled include tests on Android CI
1 parent 7030357 commit c0c922b

File tree

5 files changed

+131
-79
lines changed

5 files changed

+131
-79
lines changed

BuildTools/Android/tests/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ android {
55

66
defaultConfig {
77
applicationId 'DE.Android.Tests'
8-
minSdkVersion 24 // for vulkan
98
targetSdkVersion 28
9+
minSdkVersion 21
1010

1111
ndk {
12-
abiFilters "arm64-v8a"
12+
abiFilters "armeabi-v7a", "arm64-v8a"
1313
}
1414
externalNativeBuild {
1515
cmake {

BuildTools/Android/tests/src/main/jni/CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
33
project(DE.Android)
44

55
add_subdirectory("../../../../../.." Core)
6+
add_subdirectory("../../../../../../Tests/IncludeTest" CoreTests)
67

7-
add_library(native_app_glue STATIC "${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c")
8-
target_include_directories(native_app_glue PUBLIC "${ANDROID_NDK}/sources/android/native_app_glue")
9-
target_link_libraries(native_app_glue PUBLIC android log)
10-
11-
add_library(DETestLauncher STATIC main.cpp)
8+
add_library(DETestLauncher SHARED main.cpp)
129

1310
target_link_libraries(DETestLauncher
1411
PUBLIC
15-
native_app_glue
1612
Diligent-Common
13+
DiligentCore-IncludeTest
1714
Diligent-GraphicsEngineOpenGL-static
18-
Diligent-GraphicsEngineVk-static)
15+
Diligent-GraphicsEngineVk-static
16+
)
1917

2018
set_target_properties(DETestLauncher PROPERTIES LINK_FLAGS "-u ANativeActivity_onCreate")

Graphics/GraphicsEngineOpenGL/interface/RenderDeviceGLES.h

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,45 @@
3434
#include <android/native_window.h>
3535
#include <EGL/egl.h>
3636

37-
namespace Diligent
38-
{
37+
DILIGENT_BEGIN_NAMESPACE(Diligent)
3938

4039
// {F705A0D9-2023-4DE1-8B3C-C56E4CEB8DB7}
41-
static const Diligent::INTERFACE_ID IID_RenderDeviceGLES =
40+
static const INTERFACE_ID IID_RenderDeviceGLES =
4241
{0xf705a0d9, 0x2023, 0x4de1, {0x8b, 0x3c, 0xc5, 0x6e, 0x4c, 0xeb, 0x8d, 0xb7}};
4342

43+
#define DILIGENT_INTERFACE_NAME IRenderDeviceGLES
44+
#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"
45+
46+
#define IRenderDeviceGLESInclusiveMethods \
47+
IRenderDeviceGLInclusiveMethods; \
48+
IRenderDeviceGLESMethods RenderDeviceGLES
49+
50+
// clang-format off
51+
4452
/// Interface to the render device object implemented in OpenGLES
45-
class IRenderDeviceGLES : public Diligent::IRenderDeviceGL
53+
DILIGENT_BEGIN_INTERFACE(IRenderDeviceGLES, IRenderDeviceGL)
4654
{
47-
public:
48-
virtual bool Invalidate() = 0;
55+
VIRTUAL bool METHOD(Invalidate)(THIS) PURE;
4956

50-
virtual void Suspend() = 0;
57+
VIRTUAL void METHOD(Suspend)(THIS) PURE;
5158

52-
virtual EGLint Resume(ANativeWindow* window) = 0;
59+
VIRTUAL EGLint METHOD(Resume)(THIS_
60+
ANativeWindow* window) PURE;
5361
};
62+
DILIGENT_END_INTERFACE
63+
64+
#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h"
65+
66+
#if DILIGENT_C_INTERFACE
67+
68+
// clang-format off
69+
70+
# define IRenderDeviceGLES_Invalidate(This) CALL_IFACE_METHOD(RenderDeviceGLES, Invalidate, This)
71+
# define IRenderDeviceGLES_Suspend(This) CALL_IFACE_METHOD(RenderDeviceGLES, Suspend, This)
72+
# define IRenderDeviceGLES_Resume(This, ...) CALL_IFACE_METHOD(RenderDeviceGLES, Resume, This, __VA_ARGS__)
73+
74+
// clang-format on
75+
76+
#endif
5477

55-
} // namespace Diligent
78+
DILIGENT_END_NAMESPACE // namespace Diligent
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2019-2021 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
#include "DiligentCore/Graphics/GraphicsEngine/interface/GraphicsTypes.h"
28+
#include "DiligentCore/Graphics/GraphicsEngine/interface/Shader.h"
29+
#include "DiligentCore/Graphics/GraphicsEngine/interface/PipelineState.h"
30+
31+
#include <cstddef>
32+
33+
namespace Diligent
34+
{
35+
36+
namespace
37+
{
38+
39+
// In c++11, the following struct is not an aggregate:
40+
// struct S1
41+
// {
42+
// int a = 0;
43+
// };
44+
// S1 is an aggregate in c++14.
45+
//
46+
// Likewise, the following struct is not an aggregate in c++11:
47+
// struct S2 : Aggregate
48+
// {
49+
// int b;
50+
// };
51+
// S2 is an aggregate in c++17
52+
//
53+
// When compiling non-aggregates, the compiler may mess with the member placement.
54+
// For example, consider the example below:
55+
// struct S1
56+
// {
57+
// void* p = nullptr;
58+
// int a = 0;
59+
// // <implicit 4-byte padding>
60+
// };
61+
// struct S2 : S1
62+
// {
63+
// int b = 0;
64+
// };
65+
//
66+
// When compiling S2 with x64 gcc, it will place 'b' right after 'a', not after the end of struct S1.
67+
// We try to catch such issues below
68+
69+
70+
#ifdef __GNUC__
71+
// Disable GCC warnings like this one:
72+
// warning: offsetof within non-standard-layout type ‘Diligent::{anonymous}::DeviceObjectAttribs is conditionally-supported [-Winvalid-offsetof]
73+
# pragma GCC diagnostic ignored "-Winvalid-offsetof"
74+
#endif
75+
76+
#define CHECK_BASE_STRUCT_ALIGNMENT(StructName) \
77+
struct StructName##Test : StructName \
78+
{ \
79+
Uint8 AlignmentTest; \
80+
}; \
81+
static_assert(offsetof(StructName##Test, AlignmentTest) == sizeof(StructName), "Using " #StructName " as a base class may result in misalignment")
82+
83+
CHECK_BASE_STRUCT_ALIGNMENT(DeviceObjectAttribs);
84+
CHECK_BASE_STRUCT_ALIGNMENT(EngineCreateInfo);
85+
CHECK_BASE_STRUCT_ALIGNMENT(TextureFormatAttribs);
86+
CHECK_BASE_STRUCT_ALIGNMENT(TextureFormatInfo);
87+
CHECK_BASE_STRUCT_ALIGNMENT(ShaderResourceDesc);
88+
CHECK_BASE_STRUCT_ALIGNMENT(PipelineStateCreateInfo);
89+
90+
} // namespace
91+
92+
} // namespace Diligent

Tests/IncludeTest/GraphicsEngine/GraphicsTypesH_test.cpp

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,64 +26,3 @@
2626
*/
2727

2828
#include "DiligentCore/Graphics/GraphicsEngine/interface/GraphicsTypes.h"
29-
30-
#include <cstddef>
31-
32-
namespace Diligent
33-
{
34-
35-
namespace
36-
{
37-
38-
// In c++11, the following struct is not an aggregate:
39-
// struct S1
40-
// {
41-
// int a = 0;
42-
// };
43-
// S1 is an aggregate in c++14.
44-
//
45-
// Likewise, the following struct is not an aggregate in c++11:
46-
// struct S2 : Aggregate
47-
// {
48-
// int b;
49-
// };
50-
// S2 is an aggregate in c++17
51-
//
52-
// When compiling non-aggregates, the compiler may mess with the member placement.
53-
// For example, consider the example below:
54-
// struct S1
55-
// {
56-
// void* p = nullptr;
57-
// int a = 0;
58-
// // <implicit 4-byte padding>
59-
// };
60-
// struct S2 : S1
61-
// {
62-
// int b = 0;
63-
// };
64-
//
65-
// When compiling S2 with x64 gcc, it will place 'b' right after 'a', not after the end of struct S1.
66-
// We try to catch such issues below
67-
68-
69-
#ifdef __GNUC__
70-
// Disable GCC warnings like this one:
71-
// warning: offsetof within non-standard-layout type ‘Diligent::{anonymous}::DeviceObjectAttribs is conditionally-supported [-Winvalid-offsetof]
72-
# pragma GCC diagnostic ignored "-Winvalid-offsetof"
73-
#endif
74-
75-
#define CHECK_BASE_STRUCT_ALIGNMENT(StructName) \
76-
struct StructName##Test : StructName \
77-
{ \
78-
Uint8 AlignmentTest; \
79-
}; \
80-
static_assert(offsetof(StructName##Test, AlignmentTest) == sizeof(StructName), "Using " #StructName " as a base class may result in misalignment")
81-
82-
CHECK_BASE_STRUCT_ALIGNMENT(DeviceObjectAttribs);
83-
CHECK_BASE_STRUCT_ALIGNMENT(EngineCreateInfo);
84-
CHECK_BASE_STRUCT_ALIGNMENT(TextureFormatAttribs);
85-
CHECK_BASE_STRUCT_ALIGNMENT(TextureFormatInfo);
86-
87-
} // namespace
88-
89-
} // namespace Diligent

0 commit comments

Comments
 (0)