Skip to content

Commit

Permalink
handle different executable location for multi-config generators
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbaug committed Aug 19, 2024
1 parent 99b62cd commit b91d97b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
33 changes: 29 additions & 4 deletions test_conformance/common/vulkan_wrapper/vulkan_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const VulkanPhysicalDevice &getVulkanPhysicalDevice()
cl_uint num_devices = 0;
cl_uint device_no = 0;
const size_t bufsize = BUFFERSIZE;
char buf[BUFFERSIZE];
const VulkanInstance &instance = getVulkanInstance();
const VulkanPhysicalDeviceList &physicalDeviceList =
instance.getPhysicalDeviceList();
Expand Down Expand Up @@ -753,9 +752,35 @@ std::ostream &operator<<(std::ostream &os, VulkanFormat format)
return os;
}

std::vector<char> readFile(const std::string &filename)
static std::string findFilePath(const std::string& filename, const std::string& startdir)
{
std::ifstream file(filename, std::ios::ate | std::ios::binary);
const char *searchPath[] = {
"/shaders/", // shaders directory, for most builds
"/../shaders/", // one directory up, for multi-config builds
};
for (unsigned int i = 0; i < sizeof(searchPath) / sizeof(char *); ++i)
{
std::string path(startdir);
path += searchPath[i];
path += filename;

FILE *fp;
fp = fopen(path.c_str(), "rb");

if (fp != NULL)
{
fclose(fp);
return path;
}
}
// File not found
return "";
}

std::vector<char> readFile(const std::string &filename, const std::string& startdir = "")
{
std::string filepath = findFilePath(filename, startdir);
std::ifstream file(filepath, std::ios::ate | std::ios::binary);

if (!file.is_open())
{
Expand All @@ -766,6 +791,6 @@ std::vector<char> readFile(const std::string &filename)
file.seekg(0);
file.read(buffer.data(), fileSize);
file.close();
printf("filesize is %d\n", fileSize);
printf("filesize is %zu\n", fileSize);
return buffer;
}
3 changes: 2 additions & 1 deletion test_conformance/common/vulkan_wrapper/vulkan_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ operator<<(std::ostream& os,
VulkanExternalSemaphoreHandleType externalSemaphoreHandleType);
std::ostream& operator<<(std::ostream& os, VulkanFormat format);

std::vector<char> readFile(const std::string& filename);
std::vector<char> readFile(const std::string& filename,
const std::string& startdir);
#endif // _vulkan_utility_hpp_
12 changes: 4 additions & 8 deletions test_conformance/vulkan/test_vulkan_interop_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ int run_test_with_two_queue(

VulkanQueue &vkQueue = vkDevice.getQueue();

std::string filepath = exe_dir() + "/shaders/buffer.spv";
std::vector<char> vkBufferShader = readFile(filepath);
std::vector<char> vkBufferShader = readFile("buffer.spv", exe_dir());

VulkanShaderModule vkBufferShaderModule(vkDevice, vkBufferShader);
VulkanDescriptorSetLayoutBindingList vkDescriptorSetLayoutBindingList;
Expand Down Expand Up @@ -449,8 +448,7 @@ int run_test_with_one_queue(

VulkanQueue &vkQueue = vkDevice.getQueue();

std::string filepath = exe_dir() + "/shaders/buffer.spv";
std::vector<char> vkBufferShader = readFile(filepath);
std::vector<char> vkBufferShader = readFile("buffer.spv", exe_dir());

VulkanShaderModule vkBufferShaderModule(vkDevice, vkBufferShader);
VulkanDescriptorSetLayoutBindingList vkDescriptorSetLayoutBindingList;
Expand Down Expand Up @@ -753,8 +751,7 @@ int run_test_with_multi_import_same_ctx(

VulkanQueue &vkQueue = vkDevice.getQueue();

std::string filepath = exe_dir() + "/shaders/buffer.spv";
std::vector<char> vkBufferShader = readFile(filepath);
std::vector<char> vkBufferShader = readFile("buffer.spv", exe_dir());

VulkanShaderModule vkBufferShaderModule(vkDevice, vkBufferShader);
VulkanDescriptorSetLayoutBindingList vkDescriptorSetLayoutBindingList;
Expand Down Expand Up @@ -1102,8 +1099,7 @@ int run_test_with_multi_import_diff_ctx(

VulkanQueue &vkQueue = vkDevice.getQueue();

std::string filepath = exe_dir() + "/shaders/buffer.spv";
std::vector<char> vkBufferShader = readFile(filepath);
std::vector<char> vkBufferShader = readFile("buffer.spv", exe_dir());

VulkanShaderModule vkBufferShaderModule(vkDevice, vkBufferShader);
VulkanDescriptorSetLayoutBindingList vkDescriptorSetLayoutBindingList(
Expand Down
14 changes: 7 additions & 7 deletions test_conformance/vulkan/test_vulkan_interop_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ int run_test_with_two_queue(
ASSERT_LEQ(elementSize, (uint32_t)MAX_2D_IMAGE_ELEMENT_SIZE);
log_info("elementSize= %d\n", elementSize);

std::string filepath = exe_dir() + "/shaders/image2D_"
std::string fileName = "image2D_"
+ std::string(getVulkanFormatGLSLFormat(vkFormat)) + ".spv";
log_info("Load file: %s\n", filepath.c_str());
vkImage2DShader = readFile(filepath);
log_info("Load file: %s\n", fileName.c_str());
vkImage2DShader = readFile(fileName, exe_dir());
VulkanShaderModule vkImage2DShaderModule(vkDevice, vkImage2DShader);

VulkanComputePipeline vkComputePipeline(vkDevice, vkPipelineLayout,
Expand Down Expand Up @@ -883,10 +883,10 @@ int run_test_with_one_queue(
ASSERT_LEQ(elementSize, (uint32_t)MAX_2D_IMAGE_ELEMENT_SIZE);
log_info("elementSize= %d\n", elementSize);

std::string filepath = exe_dir() + "/shaders/image2D_"
std::string fileName = "image2D_"
+ std::string(getVulkanFormatGLSLFormat(vkFormat)) + ".spv";
log_info("Load file: %s\n", filepath.c_str());
vkImage2DShader = readFile(filepath);
log_info("Load file: %s\n", fileName.c_str());
vkImage2DShader = readFile(fileName, exe_dir());
VulkanShaderModule vkImage2DShaderModule(vkDevice, vkImage2DShader);

VulkanComputePipeline vkComputePipeline(vkDevice, vkPipelineLayout,
Expand Down Expand Up @@ -1475,7 +1475,7 @@ int test_image_common(cl_device_id device_, cl_context context_,
err = setMaxImageDimensions(deviceId, max_width, max_height);
test_error_and_cleanup(err, CLEANUP, "error setting max image dimensions");

log_info("Set max_width to %lu and max_height to %lu\n", max_width,
log_info("Set max_width to %zu and max_height to %zu\n", max_width,
max_height);
context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
NULL, NULL, &err);
Expand Down

0 comments on commit b91d97b

Please sign in to comment.