Commit 0b4bc585 by Ben Clayton

Style: clang-format the tests source too

Move the `.clang-format` rule up one level from `./src` to `.`. Add a `.clang-format` file to `./third_party` that disables formatting. Update `./src/clang-format-all.sh` to include `./tests`. Format all source files in `./tests`. Bug: b/144825072 Change-Id: I01c7ae37a7b1fe8d63ee143107da8acefba20e76 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39873 Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAntonio Maiorano <amaiorano@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 4be96b5f
SRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" SRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ROOT_DIR="$( cd "${SRC_DIR}/.." >/dev/null 2>&1 && pwd )"
TESTS_DIR="$( cd "${ROOT_DIR}/tests" >/dev/null 2>&1 && pwd )"
CLANG_FORMAT=${CLANG_FORMAT:-clang-format} CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
for DIR in "Device" "Pipeline" "Reactor" "System" "Vulkan" "WSI" for DIR in "${SRC_DIR}/Device" "${SRC_DIR}/Pipeline" "${SRC_DIR}/Reactor" "${SRC_DIR}/System" "${SRC_DIR}/Vulkan" "${SRC_DIR}/WSI" "${TESTS_DIR}"
do do
# Double clang-format, as it seems that one pass isn't always enough # Double clang-format, as it seems that one pass isn't always enough
find ${SRC_DIR}/${DIR} -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.inl" | xargs ${CLANG_FORMAT} -i -style=file find ${DIR} -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.inl" | xargs ${CLANG_FORMAT} -i -style=file
find ${SRC_DIR}/${DIR} -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.inl" | xargs ${CLANG_FORMAT} -i -style=file find ${DIR} -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.inl" | xargs ${CLANG_FORMAT} -i -style=file
done done
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "System/Half.hpp" #include "System/Half.hpp"
#include <gtest/gtest.h>
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <cstdlib> #include <cstdlib>
...@@ -48,9 +48,9 @@ unsigned int RGB9E5_reference(float r, float g, float b) ...@@ -48,9 +48,9 @@ unsigned int RGB9E5_reference(float r, float g, float b)
constexpr int g_sharedexp_maxexponent = 31; constexpr int g_sharedexp_maxexponent = 31;
constexpr float g_sharedexp_max = constexpr float g_sharedexp_max =
((static_cast<float>(1 << g_sharedexp_mantissabits) - 1) / ((static_cast<float>(1 << g_sharedexp_mantissabits) - 1) /
static_cast<float>(1 << g_sharedexp_mantissabits)) * static_cast<float>(1 << g_sharedexp_mantissabits)) *
static_cast<float>(1 << (g_sharedexp_maxexponent - g_sharedexp_bias)); static_cast<float>(1 << (g_sharedexp_maxexponent - g_sharedexp_bias));
const float red_c = clamp0hi(r, g_sharedexp_max); const float red_c = clamp0hi(r, g_sharedexp_max);
const float green_c = clamp0hi(g, g_sharedexp_max); const float green_c = clamp0hi(g, g_sharedexp_max);
......
...@@ -14,34 +14,37 @@ ...@@ -14,34 +14,37 @@
#include "System/Memory.hpp" #include "System/Memory.hpp"
#ifdef __linux__ #ifdef __linux__
#include "System/Linux/MemFd.hpp" # include "System/Linux/MemFd.hpp"
#endif #endif
#include <gtest/gtest.h>
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <cstdlib> #include <cstdlib>
using namespace sw; using namespace sw;
#ifdef __linux__ #ifdef __linux__
TEST(MemFd, DefaultConstructor) { TEST(MemFd, DefaultConstructor)
{
LinuxMemFd memfd; LinuxMemFd memfd;
ASSERT_FALSE(memfd.isValid()); ASSERT_FALSE(memfd.isValid());
ASSERT_EQ(-1, memfd.exportFd()); ASSERT_EQ(-1, memfd.exportFd());
} }
TEST(MemFd, AllocatingConstructor) { TEST(MemFd, AllocatingConstructor)
{
const size_t kRegionSize = sw::memoryPageSize() * 8; const size_t kRegionSize = sw::memoryPageSize() * 8;
LinuxMemFd memfd("test-region", kRegionSize); LinuxMemFd memfd("test-region", kRegionSize);
ASSERT_TRUE(memfd.isValid()); ASSERT_TRUE(memfd.isValid());
ASSERT_GE(memfd.fd(), 0); ASSERT_GE(memfd.fd(), 0);
void* addr = memfd.mapReadWrite(0, kRegionSize); void *addr = memfd.mapReadWrite(0, kRegionSize);
ASSERT_TRUE(addr); ASSERT_TRUE(addr);
memfd.unmap(addr, kRegionSize); memfd.unmap(addr, kRegionSize);
} }
TEST(MemFd, ExplicitAllocation) { TEST(MemFd, ExplicitAllocation)
{
const size_t kRegionSize = sw::memoryPageSize() * 8; const size_t kRegionSize = sw::memoryPageSize() * 8;
LinuxMemFd memfd; LinuxMemFd memfd;
ASSERT_FALSE(memfd.isValid()); ASSERT_FALSE(memfd.isValid());
...@@ -50,7 +53,8 @@ TEST(MemFd, ExplicitAllocation) { ...@@ -50,7 +53,8 @@ TEST(MemFd, ExplicitAllocation) {
ASSERT_TRUE(memfd.isValid()); ASSERT_TRUE(memfd.isValid());
} }
TEST(MemFd, Close) { TEST(MemFd, Close)
{
const size_t kRegionSize = sw::memoryPageSize() * 8; const size_t kRegionSize = sw::memoryPageSize() * 8;
LinuxMemFd memfd("test-region", kRegionSize); LinuxMemFd memfd("test-region", kRegionSize);
ASSERT_TRUE(memfd.isValid()); ASSERT_TRUE(memfd.isValid());
...@@ -61,12 +65,13 @@ TEST(MemFd, Close) { ...@@ -61,12 +65,13 @@ TEST(MemFd, Close) {
::close(fd); ::close(fd);
} }
TEST(MemFd, ExportImportFd) { TEST(MemFd, ExportImportFd)
{
const size_t kRegionSize = sw::memoryPageSize() * 8; const size_t kRegionSize = sw::memoryPageSize() * 8;
LinuxMemFd memfd("test-region1", kRegionSize); LinuxMemFd memfd("test-region1", kRegionSize);
auto* addr = reinterpret_cast<uint8_t*>(memfd.mapReadWrite(0, kRegionSize)); auto *addr = reinterpret_cast<uint8_t *>(memfd.mapReadWrite(0, kRegionSize));
ASSERT_TRUE(addr); ASSERT_TRUE(addr);
for (size_t n = 0; n < kRegionSize; ++n) for(size_t n = 0; n < kRegionSize; ++n)
{ {
addr[n] = static_cast<uint8_t>(n); addr[n] = static_cast<uint8_t>(n);
} }
...@@ -77,9 +82,9 @@ TEST(MemFd, ExportImportFd) { ...@@ -77,9 +82,9 @@ TEST(MemFd, ExportImportFd) {
LinuxMemFd memfd2; LinuxMemFd memfd2;
memfd2.importFd(fd); memfd2.importFd(fd);
ASSERT_TRUE(memfd2.isValid()); ASSERT_TRUE(memfd2.isValid());
addr = reinterpret_cast<uint8_t*>(memfd2.mapReadWrite(0, kRegionSize)); addr = reinterpret_cast<uint8_t *>(memfd2.mapReadWrite(0, kRegionSize));
ASSERT_TRUE(addr); ASSERT_TRUE(addr);
for (size_t n = 0; n < kRegionSize; ++n) for(size_t n = 0; n < kRegionSize; ++n)
{ {
ASSERT_EQ(addr[n], static_cast<uint8_t>(n)) << "# " << n; ASSERT_EQ(addr[n], static_cast<uint8_t>(n)) << "# " << n;
} }
......
...@@ -35,7 +35,7 @@ public: ...@@ -35,7 +35,7 @@ public:
// returned (as there was no Vulkan error), but calling Device::IsValid() // returned (as there was no Vulkan error), but calling Device::IsValid()
// on this device will return false. // on this device will return false.
static VkResult CreateComputeDevice( static VkResult CreateComputeDevice(
Driver const *driver, VkInstance instance, std::unique_ptr<Device>& out); Driver const *driver, VkInstance instance, std::unique_ptr<Device> &out);
// IsValid returns true if the Device is initialized and can be used. // IsValid returns true if the Device is initialized and can be used.
bool IsValid() const; bool IsValid() const;
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
// VK_BUFFER_USAGE_STORAGE_BUFFER_BIT usage, and // VK_BUFFER_USAGE_STORAGE_BUFFER_BIT usage, and
// VK_SHARING_MODE_EXCLUSIVE sharing mode. // VK_SHARING_MODE_EXCLUSIVE sharing mode.
VkResult CreateStorageBuffer(VkDeviceMemory memory, VkDeviceSize size, VkResult CreateStorageBuffer(VkDeviceMemory memory, VkDeviceSize size,
VkDeviceSize offset, VkBuffer *out) const; VkDeviceSize offset, VkBuffer *out) const;
// DestroyBuffer destroys a VkBuffer. // DestroyBuffer destroys a VkBuffer.
void DestroyBuffer(VkBuffer buffer) const; void DestroyBuffer(VkBuffer buffer) const;
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
// CreateShaderModule creates a new shader module with the given SPIR-V // CreateShaderModule creates a new shader module with the given SPIR-V
// code. // code.
VkResult CreateShaderModule(const std::vector<uint32_t> &spirv, VkResult CreateShaderModule(const std::vector<uint32_t> &spirv,
VkShaderModule *out) const; VkShaderModule *out) const;
// DestroyShaderModule destroys a VkShaderModule. // DestroyShaderModule destroys a VkShaderModule.
void DestroyShaderModule(VkShaderModule shaderModule) const; void DestroyShaderModule(VkShaderModule shaderModule) const;
...@@ -60,15 +60,15 @@ public: ...@@ -60,15 +60,15 @@ public:
// CreateDescriptorSetLayout creates a new descriptor set layout with the // CreateDescriptorSetLayout creates a new descriptor set layout with the
// given bindings. // given bindings.
VkResult CreateDescriptorSetLayout( VkResult CreateDescriptorSetLayout(
const std::vector<VkDescriptorSetLayoutBinding> &bindings, const std::vector<VkDescriptorSetLayoutBinding> &bindings,
VkDescriptorSetLayout *out) const; VkDescriptorSetLayout *out) const;
// DestroyDescriptorSetLayout destroys a VkDescriptorSetLayout. // DestroyDescriptorSetLayout destroys a VkDescriptorSetLayout.
void DestroyDescriptorSetLayout(VkDescriptorSetLayout descriptorSetLayout) const; void DestroyDescriptorSetLayout(VkDescriptorSetLayout descriptorSetLayout) const;
// CreatePipelineLayout creates a new single set descriptor set layout. // CreatePipelineLayout creates a new single set descriptor set layout.
VkResult CreatePipelineLayout(VkDescriptorSetLayout layout, VkResult CreatePipelineLayout(VkDescriptorSetLayout layout,
VkPipelineLayout *out) const; VkPipelineLayout *out) const;
// DestroyPipelineLayout destroys a VkPipelineLayout. // DestroyPipelineLayout destroys a VkPipelineLayout.
void DestroyPipelineLayout(VkPipelineLayout pipelineLayout) const; void DestroyPipelineLayout(VkPipelineLayout pipelineLayout) const;
...@@ -76,8 +76,8 @@ public: ...@@ -76,8 +76,8 @@ public:
// CreateComputePipeline creates a new compute pipeline with the entry point // CreateComputePipeline creates a new compute pipeline with the entry point
// "main". // "main".
VkResult CreateComputePipeline(VkShaderModule module, VkResult CreateComputePipeline(VkShaderModule module,
VkPipelineLayout pipelineLayout, VkPipelineLayout pipelineLayout,
VkPipeline *out) const; VkPipeline *out) const;
// DestroyPipeline destroys a graphics or compute pipeline. // DestroyPipeline destroys a graphics or compute pipeline.
void DestroyPipeline(VkPipeline pipeline) const; void DestroyPipeline(VkPipeline pipeline) const;
...@@ -85,7 +85,7 @@ public: ...@@ -85,7 +85,7 @@ public:
// CreateStorageBufferDescriptorPool creates a new descriptor pool that can // CreateStorageBufferDescriptorPool creates a new descriptor pool that can
// hold descriptorCount storage buffers. // hold descriptorCount storage buffers.
VkResult CreateStorageBufferDescriptorPool(uint32_t descriptorCount, VkResult CreateStorageBufferDescriptorPool(uint32_t descriptorCount,
VkDescriptorPool *out) const; VkDescriptorPool *out) const;
// DestroyDescriptorPool destroys the VkDescriptorPool. // DestroyDescriptorPool destroys the VkDescriptorPool.
void DestroyDescriptorPool(VkDescriptorPool descriptorPool) const; void DestroyDescriptorPool(VkDescriptorPool descriptorPool) const;
...@@ -93,38 +93,38 @@ public: ...@@ -93,38 +93,38 @@ public:
// AllocateDescriptorSet allocates a single descriptor set with the given // AllocateDescriptorSet allocates a single descriptor set with the given
// layout from pool. // layout from pool.
VkResult AllocateDescriptorSet(VkDescriptorPool pool, VkResult AllocateDescriptorSet(VkDescriptorPool pool,
VkDescriptorSetLayout layout, VkDescriptorSetLayout layout,
VkDescriptorSet *out) const; VkDescriptorSet *out) const;
// UpdateStorageBufferDescriptorSets updates the storage buffers in // UpdateStorageBufferDescriptorSets updates the storage buffers in
// descriptorSet with the given list of VkDescriptorBufferInfos. // descriptorSet with the given list of VkDescriptorBufferInfos.
void UpdateStorageBufferDescriptorSets(VkDescriptorSet descriptorSet, void UpdateStorageBufferDescriptorSets(VkDescriptorSet descriptorSet,
const std::vector<VkDescriptorBufferInfo> &bufferInfos) const; const std::vector<VkDescriptorBufferInfo> &bufferInfos) const;
// AllocateMemory allocates size bytes from a memory heap that has all the // AllocateMemory allocates size bytes from a memory heap that has all the
// given flag bits set. // given flag bits set.
// If memory could not be allocated from any heap then // If memory could not be allocated from any heap then
// VK_ERROR_OUT_OF_DEVICE_MEMORY is returned. // VK_ERROR_OUT_OF_DEVICE_MEMORY is returned.
VkResult AllocateMemory(size_t size, VkMemoryPropertyFlags flags, VkDeviceMemory* out) const; VkResult AllocateMemory(size_t size, VkMemoryPropertyFlags flags, VkDeviceMemory *out) const;
// FreeMemory frees the VkDeviceMemory. // FreeMemory frees the VkDeviceMemory.
void FreeMemory(VkDeviceMemory memory) const; void FreeMemory(VkDeviceMemory memory) const;
// MapMemory wraps vkMapMemory, supplying the first VkDevice parameter. // MapMemory wraps vkMapMemory, supplying the first VkDevice parameter.
VkResult MapMemory(VkDeviceMemory memory, VkDeviceSize offset, VkResult MapMemory(VkDeviceMemory memory, VkDeviceSize offset,
VkDeviceSize size, VkMemoryMapFlags flags, void **ppData) const; VkDeviceSize size, VkMemoryMapFlags flags, void **ppData) const;
// UnmapMemory wraps vkUnmapMemory, supplying the first VkDevice parameter. // UnmapMemory wraps vkUnmapMemory, supplying the first VkDevice parameter.
void UnmapMemory(VkDeviceMemory memory) const; void UnmapMemory(VkDeviceMemory memory) const;
// CreateCommandPool creates a new command pool. // CreateCommandPool creates a new command pool.
VkResult CreateCommandPool(VkCommandPool* out) const; VkResult CreateCommandPool(VkCommandPool *out) const;
// DestroyCommandPool destroys a VkCommandPool. // DestroyCommandPool destroys a VkCommandPool.
void DestroyCommandPool(VkCommandPool commandPool) const; void DestroyCommandPool(VkCommandPool commandPool) const;
// AllocateCommandBuffer creates a new command buffer with a primary level. // AllocateCommandBuffer creates a new command buffer with a primary level.
VkResult AllocateCommandBuffer(VkCommandPool pool, VkCommandBuffer* out) const; VkResult AllocateCommandBuffer(VkCommandPool pool, VkCommandBuffer *out) const;
// FreeCommandBuffer frees the VkCommandBuffer. // FreeCommandBuffer frees the VkCommandBuffer.
void FreeCommandBuffer(VkCommandPool pool, VkCommandBuffer buffer); void FreeCommandBuffer(VkCommandPool pool, VkCommandBuffer buffer);
...@@ -137,19 +137,18 @@ public: ...@@ -137,19 +137,18 @@ public:
VkResult QueueSubmitAndWait(VkCommandBuffer commandBuffer) const; VkResult QueueSubmitAndWait(VkCommandBuffer commandBuffer) const;
static VkResult GetPhysicalDevices( static VkResult GetPhysicalDevices(
Driver const *driver, VkInstance instance, Driver const *driver, VkInstance instance,
std::vector<VkPhysicalDevice> &out); std::vector<VkPhysicalDevice> &out);
static int GetComputeQueueFamilyIndex( static int GetComputeQueueFamilyIndex(
Driver const *driver, VkPhysicalDevice device); Driver const *driver, VkPhysicalDevice device);
private: private:
Device(Driver const *driver, VkDevice device, VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex); Device(Driver const *driver, VkDevice device, VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex);
static std::vector<VkQueueFamilyProperties> static std::vector<VkQueueFamilyProperties>
GetPhysicalDeviceQueueFamilyProperties( GetPhysicalDeviceQueueFamilyProperties(
Driver const *driver, VkPhysicalDevice device); Driver const *driver, VkPhysicalDevice device);
Driver const *driver; Driver const *driver;
VkDevice device; VkDevice device;
......
...@@ -15,26 +15,27 @@ ...@@ -15,26 +15,27 @@
#include "Driver.hpp" #include "Driver.hpp"
#if defined(_WIN32) #if defined(_WIN32)
# include "Windows.h" # include "Windows.h"
# define OS_WINDOWS 1 # define OS_WINDOWS 1
#elif defined(__APPLE__) #elif defined(__APPLE__)
# include "dlfcn.h" # include "dlfcn.h"
# define OS_MAC 1 # define OS_MAC 1
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
# include "dlfcn.h" # include "dlfcn.h"
# define OS_ANDROID 1 # define OS_ANDROID 1
#elif defined(__linux__) #elif defined(__linux__)
# include "dlfcn.h" # include "dlfcn.h"
# define OS_LINUX 1 # define OS_LINUX 1
#elif defined(__Fuchsia__) #elif defined(__Fuchsia__)
# include <zircon/dlfcn.h> # include <zircon/dlfcn.h>
# define OS_FUCHSIA 1 # define OS_FUCHSIA 1
#else #else
# error Unimplemented platform # error Unimplemented platform
#endif #endif
Driver::Driver() : vk_icdGetInstanceProcAddr(nullptr), dll(nullptr) Driver::Driver()
{ : vk_icdGetInstanceProcAddr(nullptr)
, dll(nullptr){
#define VK_GLOBAL(N, R, ...) N = nullptr #define VK_GLOBAL(N, R, ...) N = nullptr
#include "VkGlobalFuncs.hpp" #include "VkGlobalFuncs.hpp"
#undef VK_GLOBAL #undef VK_GLOBAL
...@@ -42,43 +43,43 @@ Driver::Driver() : vk_icdGetInstanceProcAddr(nullptr), dll(nullptr) ...@@ -42,43 +43,43 @@ Driver::Driver() : vk_icdGetInstanceProcAddr(nullptr), dll(nullptr)
#define VK_INSTANCE(N, R, ...) N = nullptr #define VK_INSTANCE(N, R, ...) N = nullptr
#include "VkInstanceFuncs.hpp" #include "VkInstanceFuncs.hpp"
#undef VK_INSTANCE #undef VK_INSTANCE
} }
Driver::~Driver() Driver::~Driver()
{ {
unload(); unload();
} }
bool Driver::loadSwiftShader() bool Driver::loadSwiftShader()
{ {
#if OS_WINDOWS #if OS_WINDOWS
#if !defined(STANDALONE) # if !defined(STANDALONE)
// The DLL is delay loaded (see BUILD.gn), so we can load // The DLL is delay loaded (see BUILD.gn), so we can load
// the correct ones from Chrome's swiftshader subdirectory. // the correct ones from Chrome's swiftshader subdirectory.
HMODULE libvulkan = LoadLibraryA("swiftshader\\libvulkan.dll"); HMODULE libvulkan = LoadLibraryA("swiftshader\\libvulkan.dll");
EXPECT_NE((HMODULE)NULL, libvulkan); EXPECT_NE((HMODULE)NULL, libvulkan);
return true; return true;
#elif defined(NDEBUG) # elif defined(NDEBUG)
#if defined(_WIN64) # if defined(_WIN64)
return load("./build/Release_x64/vk_swiftshader.dll") || return load("./build/Release_x64/vk_swiftshader.dll") ||
load("./build/Release/vk_swiftshader.dll") || load("./build/Release/vk_swiftshader.dll") ||
load("./vk_swiftshader.dll"); load("./vk_swiftshader.dll");
#else # else
return load("./build/Release_Win32/vk_swiftshader.dll") || return load("./build/Release_Win32/vk_swiftshader.dll") ||
load("./build/Release/vk_swiftshader.dll") || load("./build/Release/vk_swiftshader.dll") ||
load("./vk_swiftshader.dll"); load("./vk_swiftshader.dll");
#endif # endif
#else # else
#if defined(_WIN64) # if defined(_WIN64)
return load("./build/Debug_x64/vk_swiftshader.dll") || return load("./build/Debug_x64/vk_swiftshader.dll") ||
load("./build/Debug/vk_swiftshader.dll") || load("./build/Debug/vk_swiftshader.dll") ||
load("./vk_swiftshader.dll"); load("./vk_swiftshader.dll");
#else # else
return load("./build/Debug_Win32/vk_swiftshader.dll") || return load("./build/Debug_Win32/vk_swiftshader.dll") ||
load("./build/Debug/vk_swiftshader.dll") || load("./build/Debug/vk_swiftshader.dll") ||
load("./vk_swiftshader.dll"); load("./vk_swiftshader.dll");
#endif # endif
#endif # endif
#elif OS_MAC #elif OS_MAC
return load("./build/Darwin/libvk_swiftshader.dylib") || return load("./build/Darwin/libvk_swiftshader.dylib") ||
load("swiftshader/libvk_swiftshader.dylib") || load("swiftshader/libvk_swiftshader.dylib") ||
...@@ -91,65 +92,65 @@ bool Driver::loadSwiftShader() ...@@ -91,65 +92,65 @@ bool Driver::loadSwiftShader()
#elif OS_ANDROID || OS_FUCHSIA #elif OS_ANDROID || OS_FUCHSIA
return load("libvk_swiftshader.so"); return load("libvk_swiftshader.so");
#else #else
#error Unimplemented platform # error Unimplemented platform
#endif #endif
} }
bool Driver::loadSystem() bool Driver::loadSystem()
{ {
#if OS_LINUX #if OS_LINUX
return load("libvulkan.so.1"); return load("libvulkan.so.1");
#else #else
return false; return false;
#endif #endif
} }
bool Driver::load(const char* path) bool Driver::load(const char *path)
{ {
#if OS_WINDOWS #if OS_WINDOWS
dll = LoadLibraryA(path); dll = LoadLibraryA(path);
#elif(OS_MAC || OS_LINUX || OS_ANDROID || OS_FUCHSIA) #elif(OS_MAC || OS_LINUX || OS_ANDROID || OS_FUCHSIA)
dll = dlopen(path, RTLD_LAZY | RTLD_LOCAL); dll = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
#else #else
return false; return false;
#endif #endif
if(dll == nullptr) if(dll == nullptr)
{ {
return false; return false;
} }
// Is the driver an ICD? // Is the driver an ICD?
if(!lookup(&vk_icdGetInstanceProcAddr, "vk_icdGetInstanceProcAddr")) if(!lookup(&vk_icdGetInstanceProcAddr, "vk_icdGetInstanceProcAddr"))
{ {
// Nope, attempt to use the loader version. // Nope, attempt to use the loader version.
if(!lookup(&vk_icdGetInstanceProcAddr, "vkGetInstanceProcAddr")) if(!lookup(&vk_icdGetInstanceProcAddr, "vkGetInstanceProcAddr"))
{ {
return false; return false;
} }
} }
#define VK_GLOBAL(N, R, ...) \ #define VK_GLOBAL(N, R, ...) \
if(auto pfn = vk_icdGetInstanceProcAddr(nullptr, #N)) \ if(auto pfn = vk_icdGetInstanceProcAddr(nullptr, #N)) \
{ \ { \
N = reinterpret_cast<decltype(N)>(pfn); \ N = reinterpret_cast<decltype(N)>(pfn); \
} }
#include "VkGlobalFuncs.hpp" #include "VkGlobalFuncs.hpp"
#undef VK_GLOBAL #undef VK_GLOBAL
return true; return true;
} }
void Driver::unload() void Driver::unload()
{ {
if(!isLoaded()) if(!isLoaded())
{ {
return; return;
} }
#if OS_WINDOWS #if OS_WINDOWS
FreeLibrary((HMODULE)dll); FreeLibrary((HMODULE)dll);
#elif (OS_LINUX || OS_FUCHSIA) #elif(OS_LINUX || OS_FUCHSIA)
dlclose(dll); dlclose(dll);
#endif #endif
#define VK_GLOBAL(N, R, ...) N = nullptr #define VK_GLOBAL(N, R, ...) N = nullptr
...@@ -163,38 +164,38 @@ void Driver::unload() ...@@ -163,38 +164,38 @@ void Driver::unload()
bool Driver::isLoaded() const bool Driver::isLoaded() const
{ {
return dll != nullptr; return dll != nullptr;
} }
bool Driver::resolve(VkInstance instance) bool Driver::resolve(VkInstance instance)
{ {
if(!isLoaded()) if(!isLoaded())
{ {
return false; return false;
} }
#define VK_INSTANCE(N, R, ...) \ #define VK_INSTANCE(N, R, ...) \
if(auto pfn = vk_icdGetInstanceProcAddr(instance, #N)) \ if(auto pfn = vk_icdGetInstanceProcAddr(instance, #N)) \
{ \ { \
N = reinterpret_cast<decltype(N)>(pfn); \ N = reinterpret_cast<decltype(N)>(pfn); \
} \ } \
else \ else \
{ \ { \
return false; \ return false; \
} }
#include "VkInstanceFuncs.hpp" #include "VkInstanceFuncs.hpp"
#undef VK_INSTANCE #undef VK_INSTANCE
return true; return true;
} }
void* Driver::lookup(const char* name) void *Driver::lookup(const char *name)
{ {
#if OS_WINDOWS #if OS_WINDOWS
return GetProcAddress((HMODULE)dll, name); return GetProcAddress((HMODULE)dll, name);
#elif(OS_MAC || OS_LINUX || OS_ANDROID || OS_FUCHSIA) #elif(OS_MAC || OS_LINUX || OS_ANDROID || OS_FUCHSIA)
return dlsym(dll, name); return dlsym(dll, name);
#else #else
return nullptr; return nullptr;
#endif #endif
} }
...@@ -20,69 +20,69 @@ ...@@ -20,69 +20,69 @@
class Driver class Driver
{ {
public: public:
Driver(); Driver();
~Driver(); ~Driver();
// loadSwiftShader attempts to load the SwiftShader vulkan driver. // loadSwiftShader attempts to load the SwiftShader vulkan driver.
// returns true on success, false on failure. // returns true on success, false on failure.
bool loadSwiftShader(); bool loadSwiftShader();
// loadSystem attempts to load the system's vulkan driver. // loadSystem attempts to load the system's vulkan driver.
// returns true on success, false on failure. // returns true on success, false on failure.
bool loadSystem(); bool loadSystem();
// load attempts to load the vulkan driver from the given path. // load attempts to load the vulkan driver from the given path.
// returns true on success, false on failure. // returns true on success, false on failure.
bool load(const char* path); bool load(const char *path);
// unloads the currently loaded driver. // unloads the currently loaded driver.
// No-op if no driver is currently loaded. // No-op if no driver is currently loaded.
void unload(); void unload();
// isLoaded returns true if the driver is currently loaded. // isLoaded returns true if the driver is currently loaded.
bool isLoaded() const; bool isLoaded() const;
// resolve all the functions for the given VkInstance. // resolve all the functions for the given VkInstance.
bool resolve(VkInstance); bool resolve(VkInstance);
VKAPI_ATTR PFN_vkVoidFunction(VKAPI_CALL* vk_icdGetInstanceProcAddr)(VkInstance instance, const char* pName); VKAPI_ATTR PFN_vkVoidFunction(VKAPI_CALL *vk_icdGetInstanceProcAddr)(VkInstance instance, const char *pName);
// Global vulkan function pointers. // Global vulkan function pointers.
#define VK_GLOBAL(N, R, ...) VKAPI_ATTR R (VKAPI_CALL *N)(__VA_ARGS__) #define VK_GLOBAL(N, R, ...) VKAPI_ATTR R(VKAPI_CALL *N)(__VA_ARGS__)
#include "VkGlobalFuncs.hpp" #include "VkGlobalFuncs.hpp"
#undef VK_GLOBAL #undef VK_GLOBAL
// Per-instance vulkan function pointers. // Per-instance vulkan function pointers.
#define VK_INSTANCE(N, R, ...) VKAPI_ATTR R (VKAPI_CALL *N)(__VA_ARGS__) #define VK_INSTANCE(N, R, ...) VKAPI_ATTR R(VKAPI_CALL *N)(__VA_ARGS__)
#include "VkInstanceFuncs.hpp" #include "VkInstanceFuncs.hpp"
#undef VK_INSTANCE #undef VK_INSTANCE
private: private:
Driver(const Driver&) = delete; Driver(const Driver &) = delete;
Driver(Driver&&) = delete; Driver(Driver &&) = delete;
Driver& operator=(const Driver&) = delete; Driver &operator=(const Driver &) = delete;
// lookup searches the loaded driver for a symbol with the given name, // lookup searches the loaded driver for a symbol with the given name,
// returning the address of this symbol if found, otherwise nullptr. // returning the address of this symbol if found, otherwise nullptr.
void* lookup(const char* name); void *lookup(const char *name);
// Helper function to lookup a symbol and cast it to the appropriate type. // Helper function to lookup a symbol and cast it to the appropriate type.
// Returns true if the symbol was found and assigned to ptr, otherwise // Returns true if the symbol was found and assigned to ptr, otherwise
// returns false. // returns false.
template<typename T> template<typename T>
inline bool lookup(T* ptr, const char* name); inline bool lookup(T *ptr, const char *name);
void* dll; void *dll;
}; };
template<typename T> template<typename T>
bool Driver::lookup(T* ptr, const char* name) bool Driver::lookup(T *ptr, const char *name)
{ {
void* sym = lookup(name); void *sym = lookup(name);
if(sym == nullptr) if(sym == nullptr)
{ {
return false; return false;
} }
*ptr = reinterpret_cast<T>(sym); *ptr = reinterpret_cast<T>(sym);
return true; return true;
} }
\ No newline at end of file
...@@ -17,5 +17,5 @@ ...@@ -17,5 +17,5 @@
// TODO: Generate this list. // TODO: Generate this list.
// VK_GLOBAL(<function name>, <return type>, <arguments>...) // VK_GLOBAL(<function name>, <return type>, <arguments>...)
VK_GLOBAL(vkCreateInstance, VkResult, const VkInstanceCreateInfo*, const VkAllocationCallbacks*, VkInstance*); VK_GLOBAL(vkCreateInstance, VkResult, const VkInstanceCreateInfo *, const VkAllocationCallbacks *, VkInstance *);
VK_GLOBAL(vkEnumerateInstanceVersion, VkResult, uint32_t*); VK_GLOBAL(vkEnumerateInstanceVersion, VkResult, uint32_t *);
...@@ -17,53 +17,53 @@ ...@@ -17,53 +17,53 @@
// TODO: Generate this list. // TODO: Generate this list.
// VK_INSTANCE(<function name>, <return type>, <arguments>...) // VK_INSTANCE(<function name>, <return type>, <arguments>...)
VK_INSTANCE(vkAllocateCommandBuffers, VkResult, VkDevice, const VkCommandBufferAllocateInfo*, VkCommandBuffer*); VK_INSTANCE(vkAllocateCommandBuffers, VkResult, VkDevice, const VkCommandBufferAllocateInfo *, VkCommandBuffer *);
VK_INSTANCE(vkAllocateDescriptorSets, VkResult, VkDevice, const VkDescriptorSetAllocateInfo*, VkDescriptorSet*); VK_INSTANCE(vkAllocateDescriptorSets, VkResult, VkDevice, const VkDescriptorSetAllocateInfo *, VkDescriptorSet *);
VK_INSTANCE(vkAllocateMemory, VkResult, VkDevice, const VkMemoryAllocateInfo*, const VkAllocationCallbacks*, VK_INSTANCE(vkAllocateMemory, VkResult, VkDevice, const VkMemoryAllocateInfo *, const VkAllocationCallbacks *,
VkDeviceMemory*); VkDeviceMemory *);
VK_INSTANCE(vkBeginCommandBuffer, VkResult, VkCommandBuffer, const VkCommandBufferBeginInfo*); VK_INSTANCE(vkBeginCommandBuffer, VkResult, VkCommandBuffer, const VkCommandBufferBeginInfo *);
VK_INSTANCE(vkBindBufferMemory, VkResult, VkDevice, VkBuffer, VkDeviceMemory, VkDeviceSize); VK_INSTANCE(vkBindBufferMemory, VkResult, VkDevice, VkBuffer, VkDeviceMemory, VkDeviceSize);
VK_INSTANCE(vkCmdBindDescriptorSets, void, VkCommandBuffer, VkPipelineBindPoint, VkPipelineLayout, uint32_t, uint32_t, VK_INSTANCE(vkCmdBindDescriptorSets, void, VkCommandBuffer, VkPipelineBindPoint, VkPipelineLayout, uint32_t, uint32_t,
const VkDescriptorSet*, uint32_t, const uint32_t*); const VkDescriptorSet *, uint32_t, const uint32_t *);
VK_INSTANCE(vkCmdBindPipeline, void, VkCommandBuffer, VkPipelineBindPoint, VkPipeline); VK_INSTANCE(vkCmdBindPipeline, void, VkCommandBuffer, VkPipelineBindPoint, VkPipeline);
VK_INSTANCE(vkCmdDispatch, void, VkCommandBuffer, uint32_t, uint32_t, uint32_t); VK_INSTANCE(vkCmdDispatch, void, VkCommandBuffer, uint32_t, uint32_t, uint32_t);
VK_INSTANCE(vkCreateBuffer, VkResult, VkDevice, const VkBufferCreateInfo*, const VkAllocationCallbacks*, VkBuffer*); VK_INSTANCE(vkCreateBuffer, VkResult, VkDevice, const VkBufferCreateInfo *, const VkAllocationCallbacks *, VkBuffer *);
VK_INSTANCE(vkCreateCommandPool, VkResult, VkDevice, const VkCommandPoolCreateInfo*, const VkAllocationCallbacks*, VK_INSTANCE(vkCreateCommandPool, VkResult, VkDevice, const VkCommandPoolCreateInfo *, const VkAllocationCallbacks *,
VkCommandPool*); VkCommandPool *);
VK_INSTANCE(vkCreateComputePipelines, VkResult, VkDevice, VkPipelineCache, uint32_t, const VkComputePipelineCreateInfo*, VK_INSTANCE(vkCreateComputePipelines, VkResult, VkDevice, VkPipelineCache, uint32_t, const VkComputePipelineCreateInfo *,
const VkAllocationCallbacks*, VkPipeline*); const VkAllocationCallbacks *, VkPipeline *);
VK_INSTANCE(vkCreateDescriptorPool, VkResult, VkDevice, const VkDescriptorPoolCreateInfo*, const VkAllocationCallbacks*, VK_INSTANCE(vkCreateDescriptorPool, VkResult, VkDevice, const VkDescriptorPoolCreateInfo *, const VkAllocationCallbacks *,
VkDescriptorPool*); VkDescriptorPool *);
VK_INSTANCE(vkCreateDescriptorSetLayout, VkResult, VkDevice, const VkDescriptorSetLayoutCreateInfo*, VK_INSTANCE(vkCreateDescriptorSetLayout, VkResult, VkDevice, const VkDescriptorSetLayoutCreateInfo *,
const VkAllocationCallbacks*, VkDescriptorSetLayout*); const VkAllocationCallbacks *, VkDescriptorSetLayout *);
VK_INSTANCE(vkCreateDevice, VkResult, VkPhysicalDevice, const VkDeviceCreateInfo*, const VkAllocationCallbacks*, VK_INSTANCE(vkCreateDevice, VkResult, VkPhysicalDevice, const VkDeviceCreateInfo *, const VkAllocationCallbacks *,
VkDevice*); VkDevice *);
VK_INSTANCE(vkCreatePipelineLayout, VkResult, VkDevice, const VkPipelineLayoutCreateInfo*, const VkAllocationCallbacks*, VK_INSTANCE(vkCreatePipelineLayout, VkResult, VkDevice, const VkPipelineLayoutCreateInfo *, const VkAllocationCallbacks *,
VkPipelineLayout*); VkPipelineLayout *);
VK_INSTANCE(vkCreateShaderModule, VkResult, VkDevice, const VkShaderModuleCreateInfo*, const VkAllocationCallbacks*, VK_INSTANCE(vkCreateShaderModule, VkResult, VkDevice, const VkShaderModuleCreateInfo *, const VkAllocationCallbacks *,
VkShaderModule*); VkShaderModule *);
VK_INSTANCE(vkDestroyBuffer, void, VkDevice, VkBuffer, const VkAllocationCallbacks*); VK_INSTANCE(vkDestroyBuffer, void, VkDevice, VkBuffer, const VkAllocationCallbacks *);
VK_INSTANCE(vkDestroyCommandPool, void, VkDevice, VkCommandPool, const VkAllocationCallbacks*); VK_INSTANCE(vkDestroyCommandPool, void, VkDevice, VkCommandPool, const VkAllocationCallbacks *);
VK_INSTANCE(vkDestroyDescriptorPool, void, VkDevice, VkDescriptorPool, const VkAllocationCallbacks*); VK_INSTANCE(vkDestroyDescriptorPool, void, VkDevice, VkDescriptorPool, const VkAllocationCallbacks *);
VK_INSTANCE(vkDestroyDescriptorSetLayout, void, VkDevice, VkDescriptorSetLayout, const VkAllocationCallbacks*); VK_INSTANCE(vkDestroyDescriptorSetLayout, void, VkDevice, VkDescriptorSetLayout, const VkAllocationCallbacks *);
VK_INSTANCE(vkDestroyDevice, VkResult, VkDevice, const VkAllocationCallbacks*); VK_INSTANCE(vkDestroyDevice, VkResult, VkDevice, const VkAllocationCallbacks *);
VK_INSTANCE(vkDestroyInstance, void, VkInstance, const VkAllocationCallbacks*); VK_INSTANCE(vkDestroyInstance, void, VkInstance, const VkAllocationCallbacks *);
VK_INSTANCE(vkDestroyPipeline, void, VkDevice, VkPipeline, const VkAllocationCallbacks*); VK_INSTANCE(vkDestroyPipeline, void, VkDevice, VkPipeline, const VkAllocationCallbacks *);
VK_INSTANCE(vkDestroyPipelineLayout, void, VkDevice, VkPipelineLayout, const VkAllocationCallbacks*); VK_INSTANCE(vkDestroyPipelineLayout, void, VkDevice, VkPipelineLayout, const VkAllocationCallbacks *);
VK_INSTANCE(vkDestroyShaderModule, void, VkDevice, VkShaderModule, const VkAllocationCallbacks*); VK_INSTANCE(vkDestroyShaderModule, void, VkDevice, VkShaderModule, const VkAllocationCallbacks *);
VK_INSTANCE(vkEndCommandBuffer, VkResult, VkCommandBuffer); VK_INSTANCE(vkEndCommandBuffer, VkResult, VkCommandBuffer);
VK_INSTANCE(vkEnumeratePhysicalDevices, VkResult, VkInstance, uint32_t*, VkPhysicalDevice*); VK_INSTANCE(vkEnumeratePhysicalDevices, VkResult, VkInstance, uint32_t *, VkPhysicalDevice *);
VK_INSTANCE(vkFreeCommandBuffers, void, VkDevice, VkCommandPool, uint32_t, const VkCommandBuffer*); VK_INSTANCE(vkFreeCommandBuffers, void, VkDevice, VkCommandPool, uint32_t, const VkCommandBuffer *);
VK_INSTANCE(vkFreeMemory, void, VkDevice, VkDeviceMemory, const VkAllocationCallbacks*); VK_INSTANCE(vkFreeMemory, void, VkDevice, VkDeviceMemory, const VkAllocationCallbacks *);
VK_INSTANCE(vkGetDeviceQueue, void, VkDevice, uint32_t, uint32_t, VkQueue*); VK_INSTANCE(vkGetDeviceQueue, void, VkDevice, uint32_t, uint32_t, VkQueue *);
VK_INSTANCE(vkGetPhysicalDeviceMemoryProperties, void, VkPhysicalDevice, VkPhysicalDeviceMemoryProperties*); VK_INSTANCE(vkGetPhysicalDeviceMemoryProperties, void, VkPhysicalDevice, VkPhysicalDeviceMemoryProperties *);
VK_INSTANCE(vkGetPhysicalDeviceProperties, void, VkPhysicalDevice, VkPhysicalDeviceProperties*); VK_INSTANCE(vkGetPhysicalDeviceProperties, void, VkPhysicalDevice, VkPhysicalDeviceProperties *);
VK_INSTANCE(vkGetPhysicalDeviceProperties2, void, VkPhysicalDevice, VkPhysicalDeviceProperties2*); VK_INSTANCE(vkGetPhysicalDeviceProperties2, void, VkPhysicalDevice, VkPhysicalDeviceProperties2 *);
VK_INSTANCE(vkGetPhysicalDeviceQueueFamilyProperties, void, VkPhysicalDevice, uint32_t*, VkQueueFamilyProperties*); VK_INSTANCE(vkGetPhysicalDeviceQueueFamilyProperties, void, VkPhysicalDevice, uint32_t *, VkQueueFamilyProperties *);
VK_INSTANCE(vkMapMemory, VkResult, VkDevice, VkDeviceMemory, VkDeviceSize, VkDeviceSize, VkMemoryMapFlags, void**); VK_INSTANCE(vkMapMemory, VkResult, VkDevice, VkDeviceMemory, VkDeviceSize, VkDeviceSize, VkMemoryMapFlags, void **);
VK_INSTANCE(vkQueueSubmit, VkResult, VkQueue, uint32_t, const VkSubmitInfo*, VkFence); VK_INSTANCE(vkQueueSubmit, VkResult, VkQueue, uint32_t, const VkSubmitInfo *, VkFence);
VK_INSTANCE(vkQueueWaitIdle, VkResult, VkQueue); VK_INSTANCE(vkQueueWaitIdle, VkResult, VkQueue);
VK_INSTANCE(vkUnmapMemory, void, VkDevice, VkDeviceMemory); VK_INSTANCE(vkUnmapMemory, void, VkDevice, VkDeviceMemory);
VK_INSTANCE(vkUpdateDescriptorSets, void, VkDevice, uint32_t, const VkWriteDescriptorSet*, uint32_t, VK_INSTANCE(vkUpdateDescriptorSets, void, VkDevice, uint32_t, const VkWriteDescriptorSet *, uint32_t,
const VkCopyDescriptorSet*); const VkCopyDescriptorSet *);
VK_INSTANCE(vkDeviceWaitIdle, VkResult, VkDevice); VK_INSTANCE(vkDeviceWaitIdle, VkResult, VkDevice);
\ No newline at end of file
...@@ -24,52 +24,60 @@ ...@@ -24,52 +24,60 @@
#include "Renderer/VertexProcessor.hpp" #include "Renderer/VertexProcessor.hpp"
#include "Shader/VertexProgram.hpp" #include "Shader/VertexProgram.hpp"
#include <cassert>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <cassert>
namespace { namespace {
// TODO(cwallez@google.com): Like in ANGLE, disable most of the pool allocator for fuzzing // TODO(cwallez@google.com): Like in ANGLE, disable most of the pool allocator for fuzzing
// This is a helper class to make sure all the resources used by the compiler are initialized // This is a helper class to make sure all the resources used by the compiler are initialized
class ScopedPoolAllocatorAndTLS { class ScopedPoolAllocatorAndTLS
public: {
ScopedPoolAllocatorAndTLS() { public:
InitializeParseContextIndex(); ScopedPoolAllocatorAndTLS()
InitializePoolIndex(); {
SetGlobalPoolAllocator(&allocator); InitializeParseContextIndex();
} InitializePoolIndex();
~ScopedPoolAllocatorAndTLS() { SetGlobalPoolAllocator(&allocator);
SetGlobalPoolAllocator(nullptr); }
FreePoolIndex(); ~ScopedPoolAllocatorAndTLS()
FreeParseContextIndex(); {
} SetGlobalPoolAllocator(nullptr);
FreePoolIndex();
FreeParseContextIndex();
}
private: private:
TPoolAllocator allocator; TPoolAllocator allocator;
}; };
// Trivial implementation of the glsl::Shader interface that fakes being an API-level // Trivial implementation of the glsl::Shader interface that fakes being an API-level
// shader object. // shader object.
class FakeVS : public glsl::Shader { class FakeVS : public glsl::Shader
public: {
FakeVS(sw::VertexShader* bytecode) : bytecode(bytecode) { public:
} FakeVS(sw::VertexShader *bytecode)
: bytecode(bytecode)
{
}
sw::Shader *getShader() const override { sw::Shader *getShader() const override
return bytecode; {
} return bytecode;
sw::VertexShader *getVertexShader() const override { }
return bytecode; sw::VertexShader *getVertexShader() const override
} {
return bytecode;
}
private: private:
sw::VertexShader* bytecode; sw::VertexShader *bytecode;
}; };
} // anonymous namespace } // anonymous namespace
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{ {
// Data layout: // Data layout:
// //
...@@ -111,8 +119,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) ...@@ -111,8 +119,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
resources.MaxTextureImageUnits = sw::TEXTURE_IMAGE_UNITS; resources.MaxTextureImageUnits = sw::TEXTURE_IMAGE_UNITS;
resources.MaxFragmentUniformVectors = sw::FRAGMENT_UNIFORM_VECTORS - 3; resources.MaxFragmentUniformVectors = sw::FRAGMENT_UNIFORM_VECTORS - 3;
resources.MaxDrawBuffers = sw::RENDERTARGETS; resources.MaxDrawBuffers = sw::RENDERTARGETS;
resources.MaxVertexOutputVectors = 16; // ??? resources.MaxVertexOutputVectors = 16; // ???
resources.MaxFragmentInputVectors = 15; // ??? resources.MaxFragmentInputVectors = 15; // ???
resources.MinProgramTexelOffset = sw::MIN_PROGRAM_TEXEL_OFFSET; resources.MinProgramTexelOffset = sw::MIN_PROGRAM_TEXEL_OFFSET;
resources.MaxProgramTexelOffset = sw::MAX_PROGRAM_TEXEL_OFFSET; resources.MaxProgramTexelOffset = sw::MAX_PROGRAM_TEXEL_OFFSET;
resources.OES_standard_derivatives = 1; resources.OES_standard_derivatives = 1;
...@@ -125,8 +133,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) ...@@ -125,8 +133,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
glslCompiler->Init(resources); glslCompiler->Init(resources);
const char* glslSource = reinterpret_cast<const char*>(data + kHeaderSize); const char *glslSource = reinterpret_cast<const char *>(data + kHeaderSize);
if (!glslCompiler->compile(&glslSource, 1, SH_OBJECT_CODE)) if(!glslCompiler->compile(&glslSource, 1, SH_OBJECT_CODE))
{ {
return 0; return 0;
} }
...@@ -146,7 +154,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) ...@@ -146,7 +154,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
state.transformFeedbackEnabled = (data[0] & 0x10) != 0; state.transformFeedbackEnabled = (data[0] & 0x10) != 0;
state.verticesPerPrimitive = 1 + ((data[0] & 0x20) != 0) + ((data[0] & 0x40) != 0); state.verticesPerPrimitive = 1 + ((data[0] & 0x20) != 0) + ((data[0] & 0x40) != 0);
if((data[0] & 0x80) != 0) // Unused/reserved. if((data[0] & 0x80) != 0) // Unused/reserved.
{ {
return 0; return 0;
} }
...@@ -163,7 +171,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) ...@@ -163,7 +171,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
for(int i = 0; i < sw::MAX_VERTEX_INPUTS; i++) for(int i = 0; i < sw::MAX_VERTEX_INPUTS; i++)
{ {
sw::StreamType type = (sw::StreamType)data[1 + 2 * i + 0]; sw::StreamType type = (sw::StreamType)data[1 + 2 * i + 0];
Stream stream = (Stream&)data[1 + 2 * i + 1]; Stream stream = (Stream &)data[1 + 2 * i + 1];
if(type > sw::STREAMTYPE_LAST) return 0; if(type > sw::STREAMTYPE_LAST) return 0;
if(stream.count > MAX_ATTRIBUTE_COMPONENTS) return 0; if(stream.count > MAX_ATTRIBUTE_COMPONENTS) return 0;
...@@ -178,10 +186,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) ...@@ -178,10 +186,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
for(unsigned int i = 0; i < sw::VERTEX_TEXTURE_IMAGE_UNITS; i++) for(unsigned int i = 0; i < sw::VERTEX_TEXTURE_IMAGE_UNITS; i++)
{ {
// TODO // TODO
// if(bytecodeShader->usesSampler(i)) // if(bytecodeShader->usesSampler(i))
// { // {
// state.samplerState[i] = context->sampler[sw::TEXTURE_IMAGE_UNITS + i].samplerState(); // state.samplerState[i] = context->sampler[sw::TEXTURE_IMAGE_UNITS + i].samplerState();
// } // }
for(int j = 0; j < 32; j++) for(int j = 0; j < 32; j++)
{ {
...@@ -206,7 +214,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) ...@@ -206,7 +214,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
auto routine = program("VertexRoutine"); auto routine = program("VertexRoutine");
assert(routine); assert(routine);
const void *entry = routine->getEntry(); const void *entry = routine->getEntry();
assert(entry); (void)entry; assert(entry);
(void)entry;
return 0; return 0;
} }
...@@ -219,7 +228,7 @@ int main(int argc, char *argv[]) ...@@ -219,7 +228,7 @@ int main(int argc, char *argv[])
fseek(file, 0L, SEEK_END); fseek(file, 0L, SEEK_END);
long numbytes = ftell(file); long numbytes = ftell(file);
fseek(file, 0L, SEEK_SET); fseek(file, 0L, SEEK_SET);
uint8_t *buffer = (uint8_t*)calloc(numbytes, sizeof(uint8_t)); uint8_t *buffer = (uint8_t *)calloc(numbytes, sizeof(uint8_t));
fread(buffer, sizeof(char), numbytes, file); fread(buffer, sizeof(char), numbytes, file);
fclose(file); fclose(file);
......
---
Language: Cpp
DisableFormat: true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment