1//
2// Copyright (C) 2018 The Android Open Source Project
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
17package {
18    // http://go/android-license-faq
19    // A large-scale-change added 'default_applicable_licenses' to import
20    // the below license kinds from "external_swiftshader_license":
21    //   SPDX-license-identifier-Apache-2.0
22    //   SPDX-license-identifier-BSD
23    default_applicable_licenses: ["external_swiftshader_license"],
24}
25
26cc_defaults {
27    name: "libswiftshader",
28    vendor: true,
29    host_supported: true,
30
31    defaults: [ "swiftshader_common" ],
32
33    cflags: [
34        "-D_GNU_SOURCE",
35        "-D__STDC_LIMIT_MACROS",
36        "-D__STDC_CONSTANT_MACROS",
37        "-D__STDC_FORMAT_MACROS",
38        "-DNO_SANITIZE_FUNCTION=",
39        // FIXME: Use <android/api-level.h> instead?
40        "-DANDROID_PLATFORM_SDK_VERSION=10000",
41        "-Wno-implicit-fallthrough",
42        "-Wno-unused-parameter",
43        "-Wno-unused-local-typedef",
44    ],
45
46    cppflags: [
47        "-Wno-sign-promo",
48        "-Wno-non-virtual-dtor",
49    ],
50
51    local_include_dirs: [ "OpenGL" ],
52
53    target: {
54        android: {
55            cflags: [
56                "-DHAVE_GRALLOC1",
57                "-DHAVE_GRALLOC3",
58                "-DHAVE_GRALLOC4",
59            ],
60            relative_install_path: "egl",
61            header_libs: [
62                "swiftshader_platform_headers",
63                "libnativebase_headers",
64            ],
65            shared_libs: [
66                "android.hardware.graphics.mapper@3.0",
67                "android.hardware.graphics.mapper@4.0",
68                "libnativewindow",
69                "libhardware",
70                "libhidlbase",
71                "libcutils",
72                "libsync",
73                "liblog",
74                "libutils",
75            ],
76            static_libs: [
77                "libarect",
78            ],
79        },
80
81        host: {
82            header_libs: [
83                "swiftshader_host_headers",
84                "swiftshader_platform_headers",
85                "libnativebase_headers",
86            ],
87
88            // Pretend to build for Android
89            cflags: [ "-D__ANDROID__", "-DANDROID_HOST_BUILD" ],
90
91            allow_undefined_symbols: true,
92            host_ldlibs: ["-ldl"],
93        },
94    },
95}
96
97cc_defaults {
98    name: "libswiftshader_release",
99
100    defaults: [ "libswiftshader" ],
101
102    cflags: [
103        "-fomit-frame-pointer",
104        "-ffunction-sections",
105        "-fdata-sections",
106        "-DANGLE_DISABLE_TRACE",
107    ],
108}
109
110cc_defaults {
111    name: "libswiftshader_debug",
112
113    defaults: [ "libswiftshader" ],
114
115    cflags: [
116        "-UNDEBUG",
117        "-g",
118        "-O0",
119        "-DDEFAULT_THREAD_COUNT=1",
120    ],
121}
122
123// Common libraries
124
125cc_defaults {
126    name: "libswiftshader_common_defaults",
127
128    cflags: [
129        "-DLOG_TAG=\"swiftshader\"",
130    ],
131
132    srcs: [
133        "Common/Configurator.cpp",
134        "Common/CPUID.cpp",
135        "Common/DebugAndroid.cpp",
136        "Common/GrallocAndroid.cpp",
137        "Common/Half.cpp",
138        "Common/Math.cpp",
139        "Common/Memory.cpp",
140        "Common/Resource.cpp",
141        "Common/SharedLibrary.cpp",
142        "Common/Socket.cpp",
143        "Common/Thread.cpp",
144        "Common/Timer.cpp",
145        "Main/Config.cpp",
146        "Main/FrameBuffer.cpp",
147        "Main/FrameBufferAndroid.cpp",
148        "Main/SwiftConfig.cpp",
149        "Renderer/Blitter.cpp",
150        "Renderer/Clipper.cpp",
151        "Renderer/Color.cpp",
152        "Renderer/Context.cpp",
153        "Renderer/ETC_Decoder.cpp",
154        "Renderer/Matrix.cpp",
155        "Renderer/PixelProcessor.cpp",
156        "Renderer/Plane.cpp",
157        "Renderer/Point.cpp",
158        "Renderer/QuadRasterizer.cpp",
159        "Renderer/Renderer.cpp",
160        "Renderer/Sampler.cpp",
161        "Renderer/SetupProcessor.cpp",
162        "Renderer/Surface.cpp",
163        "Renderer/TextureStage.cpp",
164        "Renderer/Vector.cpp",
165        "Renderer/VertexProcessor.cpp",
166        "Shader/Constants.cpp",
167        "Shader/PixelPipeline.cpp",
168        "Shader/PixelProgram.cpp",
169        "Shader/PixelRoutine.cpp",
170        "Shader/PixelShader.cpp",
171        "Shader/SamplerCore.cpp",
172        "Shader/SetupRoutine.cpp",
173        "Shader/Shader.cpp",
174        "Shader/ShaderCore.cpp",
175        "Shader/VertexPipeline.cpp",
176        "Shader/VertexProgram.cpp",
177        "Shader/VertexRoutine.cpp",
178        "Shader/VertexShader.cpp",
179        "OpenGL/common/Image.cpp",
180        "OpenGL/common/Object.cpp",
181        "OpenGL/common/MatrixStack.cpp",
182    ],
183
184    target: {
185        host: {
186            exclude_srcs: [ "Common/DebugAndroid.cpp" ],
187            srcs: [ "Common/Debug.cpp" ],
188        },
189    },
190}
191
192cc_defaults {
193    name: "libswiftshader_llvm_defaults",
194
195    defaults: [ "libswiftshader_common_defaults" ],
196
197    header_libs: [
198        "swiftshader_platform_headers",
199    ],
200
201    srcs: [
202        "Reactor/CPUID.cpp",
203        "Reactor/Debug.cpp",
204        "Reactor/EmulatedIntrinsics.cpp",
205        "Reactor/ExecutableMemory.cpp",
206        "Reactor/LLVMJIT.cpp",
207        "Reactor/LLVMReactor.cpp",
208        "Reactor/OptimalIntrinsics.cpp",
209        "Reactor/Reactor.cpp",
210    ],
211
212    cflags: [
213        "-DREACTOR_ANONYMOUS_MMAP_NAME=swiftshader_jit",
214        "-Wno-unused-parameter",
215        "-Wno-implicit-fallthrough",
216    ],
217
218    static_libs: [
219        "libLLVM10_swiftshader",
220    ],
221
222    shared_libs: [
223        "liblog",
224    ],
225}
226
227cc_defaults {
228    name: "libswiftshadervk_llvm_defaults",
229
230    header_libs: [
231        "swiftshader_platform_headers",
232    ],
233
234    srcs: [
235        "Reactor/CPUID.cpp",
236        "Reactor/Debug.cpp",
237        "Reactor/EmulatedIntrinsics.cpp",
238        "Reactor/ExecutableMemory.cpp",
239        "Reactor/LLVMJIT.cpp",
240        "Reactor/LLVMReactor.cpp",
241        "Reactor/OptimalIntrinsics.cpp",
242        "Reactor/Reactor.cpp",
243    ],
244
245    cflags: [
246        "-DREACTOR_ANONYMOUS_MMAP_NAME=swiftshader_jit",
247        "-Wno-unused-parameter",
248        "-Wno-implicit-fallthrough",
249    ],
250
251    static_libs: [
252        "libLLVM10_swiftshader",
253    ],
254
255    shared_libs: [
256        "libcutils",
257        "liblog",
258    ],
259}
260
261cc_defaults {
262    name: "libswiftshader_common",
263
264    defaults: [ "libswiftshader_release", "libswiftshader_common_defaults" ],
265}
266
267cc_defaults {
268    name: "libswiftshader_common_debug",
269
270    srcs: [ "OpenGL/common/debug.cpp" ],
271
272    defaults: [ "libswiftshader_debug", "libswiftshader_common_defaults" ],
273
274    shared_libs: [
275        "libutils",
276    ],
277}
278
279cc_library_static {
280    name: "libswiftshader_llvm",
281    defaults: [ "libswiftshader_common", "libswiftshader_llvm_defaults" ],
282}
283
284cc_library_static {
285    name: "libswiftshader_llvm_debug",
286    defaults: [ "libswiftshader_common_debug", "libswiftshader_llvm_defaults" ],
287}
288
289cc_library_static {
290    name: "libswiftshadervk_llvm",
291    vendor: true,
292    defaults: [ "libswiftshadervk_llvm_defaults" ],
293}
294
295cc_library_static {
296    name: "libswiftshadervk_llvm_debug",
297    vendor: true,
298    defaults: [ "libswiftshadervk_llvm_defaults" ],
299}
300
301// compiler libraries
302
303cc_defaults {
304    name: "libswiftshader_compiler_defaults",
305
306    defaults: [ "libswiftshader" ],
307
308    cflags: [
309        "-DLOG_TAG=\"swiftshader_compiler\"",
310    ],
311
312    srcs: [
313        "OpenGL/compiler/preprocessor/DiagnosticsBase.cpp",
314        "OpenGL/compiler/preprocessor/DirectiveHandlerBase.cpp",
315        "OpenGL/compiler/preprocessor/DirectiveParser.cpp",
316        "OpenGL/compiler/preprocessor/ExpressionParser.cpp",
317        "OpenGL/compiler/preprocessor/Input.cpp",
318        "OpenGL/compiler/preprocessor/Lexer.cpp",
319        "OpenGL/compiler/preprocessor/Macro.cpp",
320        "OpenGL/compiler/preprocessor/MacroExpander.cpp",
321        "OpenGL/compiler/preprocessor/Preprocessor.cpp",
322        "OpenGL/compiler/preprocessor/Token.cpp",
323        "OpenGL/compiler/preprocessor/Tokenizer.cpp",
324        "OpenGL/compiler/AnalyzeCallDepth.cpp",
325        "OpenGL/compiler/Compiler.cpp",
326        "OpenGL/compiler/debug.cpp",
327        "OpenGL/compiler/Diagnostics.cpp",
328        "OpenGL/compiler/DirectiveHandler.cpp",
329        "OpenGL/compiler/glslang_lex.cpp",
330        "OpenGL/compiler/glslang_tab.cpp",
331        "OpenGL/compiler/InfoSink.cpp",
332        "OpenGL/compiler/Initialize.cpp",
333        "OpenGL/compiler/InitializeParseContext.cpp",
334        "OpenGL/compiler/IntermTraverse.cpp",
335        "OpenGL/compiler/Intermediate.cpp",
336        "OpenGL/compiler/intermOut.cpp",
337        "OpenGL/compiler/ossource_posix.cpp",
338        "OpenGL/compiler/OutputASM.cpp",
339        "OpenGL/compiler/parseConst.cpp",
340        "OpenGL/compiler/ParseHelper.cpp",
341        "OpenGL/compiler/PoolAlloc.cpp",
342        "OpenGL/compiler/SymbolTable.cpp",
343        "OpenGL/compiler/TranslatorASM.cpp",
344        "OpenGL/compiler/util.cpp",
345        "OpenGL/compiler/ValidateLimitations.cpp",
346        "OpenGL/compiler/ValidateSwitch.cpp",
347    ],
348}
349
350cc_library_static {
351    name: "libswiftshader_compiler",
352
353    defaults: [ "libswiftshader_release", "libswiftshader_compiler_defaults" ],
354}
355
356cc_library_static {
357    name: "libswiftshader_compiler_debug",
358
359    defaults: [ "libswiftshader_debug", "libswiftshader_compiler_defaults" ],
360}
361
362// libEGL libraries
363
364cc_defaults {
365    name: "swiftshader_client_libraries",
366
367    defaults: [ "libswiftshader_release" ],
368    static_libs: [
369        "libswiftshader_llvm",
370        "libLLVM10_swiftshader",
371    ],
372}
373
374cc_defaults {
375    name: "swiftshader_client_libraries_debug",
376
377    defaults: [ "libswiftshader_debug" ],
378    static_libs: [
379        "libswiftshader_llvm_debug",
380        "libLLVM10_swiftshader_debug",
381    ],
382}
383
384cc_defaults {
385    name: "libEGL_swiftshader_defaults",
386
387    defaults: [ "libswiftshader" ],
388
389    cflags: [
390        "-DLOG_TAG=\"libEGL_swiftshader\"",
391        "-DEGLAPI=",
392        "-DEGL_EGLEXT_PROTOTYPES",
393        "-Wno-format",
394    ],
395
396    srcs: [
397       "OpenGL/libEGL/Config.cpp",
398       "OpenGL/libEGL/Display.cpp",
399       "OpenGL/libEGL/Surface.cpp",
400       "OpenGL/libEGL/libEGL.cpp",
401       "OpenGL/libEGL/main.cpp",
402    ],
403
404    version_script: "OpenGL/libEGL/libEGL.lds",
405}
406
407cc_library_shared {
408    name: "libEGL_swiftshader",
409
410    defaults: [
411        "libEGL_swiftshader_defaults",
412        "swiftshader_client_libraries",
413    ],
414}
415
416cc_library_shared {
417    name: "libEGL_swiftshader_debug",
418
419    defaults: [
420        "libEGL_swiftshader_defaults",
421        "swiftshader_client_libraries_debug",
422    ],
423}
424
425// libGLESv1_CM libraries
426
427cc_defaults {
428    name: "libGLESv1_CM_swiftshader_defaults",
429
430    defaults: [ "libswiftshader" ],
431
432    cflags: [
433        "-DLOG_TAG=\"libGLES_CM_swiftshader\"",
434        "-DEGLAPI=",
435        "-DGL_API=",
436        "-DGL_APICALL=",
437        "-DGL_GLEXT_PROTOTYPES",
438        "-Wno-format",
439    ],
440
441    srcs: [
442        "OpenGL/libGLES_CM/Buffer.cpp",
443        "OpenGL/libGLES_CM/Context.cpp",
444        "OpenGL/libGLES_CM/Device.cpp",
445        "OpenGL/libGLES_CM/Framebuffer.cpp",
446        "OpenGL/libGLES_CM/IndexDataManager.cpp",
447        "OpenGL/libGLES_CM/libGLES_CM.cpp",
448        "OpenGL/libGLES_CM/main.cpp",
449        "OpenGL/libGLES_CM/Renderbuffer.cpp",
450        "OpenGL/libGLES_CM/ResourceManager.cpp",
451        "OpenGL/libGLES_CM/Texture.cpp",
452        "OpenGL/libGLES_CM/utilities.cpp",
453        "OpenGL/libGLES_CM/VertexDataManager.cpp",
454    ],
455
456    version_script: "OpenGL/libGLES_CM/libGLES_CM.lds",
457}
458
459cc_library_shared {
460    name: "libGLESv1_CM_swiftshader",
461
462    defaults: [
463        "libGLESv1_CM_swiftshader_defaults",
464        "swiftshader_client_libraries",
465    ],
466}
467
468cc_library_shared {
469    name: "libGLESv1_CM_swiftshader_debug",
470
471    defaults: [
472        "libGLESv1_CM_swiftshader_defaults",
473        "swiftshader_client_libraries_debug",
474    ],
475}
476
477// libGLESv2 libraries
478
479cc_defaults {
480    name: "libGLESv2_swiftshader_defaults",
481
482    defaults: [ "libswiftshader" ],
483
484    cflags: [
485        "-DLOG_TAG=\"libGLESv2_swiftshader\"",
486        "-DEGLAPI=",
487        "-DGL_API=",
488        "-DGL_APICALL=",
489        "-DGL_GLEXT_PROTOTYPES",
490        "-Wno-format",
491    ],
492
493    srcs: [
494        "OpenGL/libGLESv2/Buffer.cpp",
495        "OpenGL/libGLESv2/Context.cpp",
496        "OpenGL/libGLESv2/Device.cpp",
497        "OpenGL/libGLESv2/Fence.cpp",
498        "OpenGL/libGLESv2/Framebuffer.cpp",
499        "OpenGL/libGLESv2/IndexDataManager.cpp",
500        "OpenGL/libGLESv2/libGLESv2.cpp",
501        "OpenGL/libGLESv2/libGLESv3.cpp",
502        "OpenGL/libGLESv2/main.cpp",
503        "OpenGL/libGLESv2/entry_points.cpp",
504        "OpenGL/libGLESv2/Program.cpp",
505        "OpenGL/libGLESv2/Query.cpp",
506        "OpenGL/libGLESv2/Renderbuffer.cpp",
507        "OpenGL/libGLESv2/ResourceManager.cpp",
508        "OpenGL/libGLESv2/Shader.cpp",
509        "OpenGL/libGLESv2/Texture.cpp",
510        "OpenGL/libGLESv2/TransformFeedback.cpp",
511        "OpenGL/libGLESv2/utilities.cpp",
512        "OpenGL/libGLESv2/VertexArray.cpp",
513        "OpenGL/libGLESv2/VertexDataManager.cpp",
514    ],
515
516    version_script: "OpenGL/libGLESv2/libGLESv2.lds",
517}
518
519cc_library_shared {
520    name: "libGLESv2_swiftshader",
521
522    defaults: [
523        "libGLESv2_swiftshader_defaults",
524        "swiftshader_client_libraries",
525    ],
526
527    static_libs: [ "libswiftshader_compiler" ],
528}
529
530cc_library_shared {
531    name: "libGLESv2_swiftshader_debug",
532
533    defaults: [
534        "libGLESv2_swiftshader_defaults",
535        "swiftshader_client_libraries_debug",
536    ],
537
538    static_libs: [ "libswiftshader_compiler_debug" ],
539}
540
541
542// Vulkan
543
544genrule {
545    name: "commit_header",
546    out: ["commit.h"],
547    tool_files: ["commit_id.py"],
548    cmd: "$(location commit_id.py) gen $(genDir)/commit.h",
549}
550
551cc_defaults {
552    name: "libvk_swiftshader_defaults",
553    vendor: true,
554
555    defaults: [ "swiftshader_common" ],
556
557    cflags: [
558        "-D_GNU_SOURCE",
559        "-D__STDC_LIMIT_MACROS",
560        "-D__STDC_CONSTANT_MACROS",
561        "-D__STDC_FORMAT_MACROS",
562        "-DHAVE_GRALLOC1",
563        "-DHAVE_GRALLOC3",
564        "-DHAVE_GRALLOC4",
565        "-DNO_SANITIZE_FUNCTION=",
566        // FIXME: Use <android/api-level.h> instead?
567        "-DANDROID_PLATFORM_SDK_VERSION=10000",
568        "-Wno-implicit-fallthrough",
569        "-Wno-unused-parameter",
570        "-Wno-unused-local-typedef",
571        "-Wno-missing-field-initializers",
572        // Enable to output commit hash when SwiftShader is initialized
573        //"-DENABLE_BUILD_VERSION_OUTPUT",
574    ],
575
576    cppflags: [
577        "-Wno-sign-promo",
578        "-Wno-non-virtual-dtor",
579    ],
580
581    ldflags: [
582        // -Bsymbolic binds symbol references to their global definitions within
583        // a shared object, thereby preventing symbol preemption.
584        "-Wl,-Bsymbolic",
585    ],
586
587    local_include_dirs: [ "Vulkan" ],
588
589    version_script: "Vulkan/android_vk_swiftshader.lds",
590
591    generated_headers: [ "commit_header" ],
592
593    target: {
594        android: {
595            relative_install_path: "hw",
596            header_libs: [
597                "swiftshader_platform_headers",
598                "vulkan_headers",
599                "hwvulkan_headers",
600            ],
601            shared_libs: [
602                "android.hardware.graphics.mapper@3.0",
603                "android.hardware.graphics.mapper@4.0",
604                "libnativewindow",
605                "libhardware",
606                "libhidlbase",
607                "libcutils",
608                "libsync",
609                "liblog",
610                "libutils",
611            ],
612            static_libs: [
613                "libarect",
614            ],
615        },
616    },
617}
618
619cc_library_static {
620    name: "swiftshader_debug",
621
622    vendor_available: true,
623
624    cflags: [
625        "-DLOG_TAG=\"swiftshader\"",
626    ],
627
628    srcs: [
629        "System/Debug.cpp",
630    ],
631
632    export_include_dirs: [
633        ".",
634    ],
635
636    shared_libs: [
637        "liblog",
638    ],
639}
640
641cc_defaults {
642    name: "libvk_swiftshader_common_defaults",
643
644    cflags: [
645        "-DLOG_TAG=\"swiftshader\"",
646        "-DSWIFTSHADER_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER",
647        "-DSWIFTSHADER_ENABLE_ASTC",  // TODO(b/150130101)
648        "-DSWIFTSHADER_DEVICE_MEMORY_REPORT",
649    ],
650
651    srcs: [
652        "System/Build.cpp",
653        "System/Configurator.cpp",
654        "System/CPUID.cpp",
655        "System/GrallocAndroid.cpp",
656        "System/Half.cpp",
657        "System/Linux/MemFd.cpp",
658        "System/Math.cpp",
659        "System/Memory.cpp",
660        "System/Socket.cpp",
661        "System/Timer.cpp",
662        "Device/*.cpp",
663        "Pipeline/*.cpp",
664        "Vulkan/*.cpp",
665        "WSI/HeadlessSurfaceKHR.cpp",
666        "WSI/VkSurfaceKHR.cpp",
667    ],
668
669    static_libs: [
670        "swiftshader_astc",
671        "swiftshader_debug",
672        "swiftshader_marl",
673        "swiftshader_spirv-tools",
674    ],
675
676    include_dirs: [
677        "external/swiftshader/third_party/SPIRV-Headers/include",
678        "external/swiftshader/include",
679    ],
680}
681
682cc_library_shared {
683    name: "vulkan.pastel",
684
685    static_libs: [
686        "libswiftshadervk_llvm_debug",
687        "libLLVM10_swiftshader",
688    ],
689
690    defaults: [
691        "libvk_swiftshader_common_defaults",
692        "libvk_swiftshader_defaults"
693    ],
694}
695
696cc_library_shared {
697    name: "vulkan.pastel.debug",
698
699    static_libs: [
700        "libswiftshadervk_llvm_debug",
701        "libLLVM10_swiftshader_debug",
702    ],
703
704    cflags: [
705        "-UNDEBUG",
706        "-g",
707        "-O0",
708        "-DDEFAULT_THREAD_COUNT=1",
709    ],
710
711    defaults: [
712        "libvk_swiftshader_common_defaults",
713        "libvk_swiftshader_defaults",
714    ],
715}
716