1 /*-------------------------------------------------------------------------
5 * Copyright (c) 2015 Google Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and/or associated documentation files (the
9 * "Materials"), to deal in the Materials without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Materials, and to
12 * permit persons to whom the Materials are furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice(s) and this permission notice shall be
16 * included in all copies or substantial portions of the Materials.
18 * The Materials are Confidential Information as defined by the
19 * Khronos Membership Agreement until designated non-confidential by
20 * Khronos, at which point this condition clause shall be removed.
22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
32 * \brief SPIR-V assembly to binary.
33 *//*--------------------------------------------------------------------*/
35 #include "vkSpirVAsm.hpp"
36 #include "vkSpirVProgram.hpp"
37 #include "deArrayUtil.hpp"
40 #include "qpDebugOut.h"
42 #if defined(DEQP_HAVE_SPIRV_TOOLS)
43 # include "deSingleton.h"
45 # include "libspirv/libspirv.h"
54 #if defined(DEQP_HAVE_SPIRV_TOOLS)
57 void assembleSpirV (const SpirVAsmSource* program, std::vector<deUint8>* dst, SpirVProgramInfo* buildInfo)
59 spv_context context = spvContextCreate();
61 const std::string& spvSource = program->program.str();
62 spv_binary binary = DE_NULL;
63 spv_diagnostic diagnostic = DE_NULL;
64 const deUint64 compileStartTime = deGetMicroseconds();
65 const spv_result_t compileOk = spvTextToBinary(context, spvSource.c_str(), spvSource.size(), &binary, &diagnostic);
68 buildInfo->source = program;
69 buildInfo->infoLog = diagnostic? diagnostic->error : ""; // \todo [2015-07-13 pyry] Include debug log?
70 buildInfo->compileTimeUs = deGetMicroseconds() - compileStartTime;
71 buildInfo->compileOk = (compileOk == SPV_SUCCESS);
74 if (compileOk != SPV_SUCCESS)
75 TCU_FAIL("Failed to compile shader");
77 dst->resize((int)binary->wordCount * sizeof(deUint32));
78 #if (DE_ENDIANNESS == DE_LITTLE_ENDIAN)
79 deMemcpy(&(*dst)[0], &binary->code[0], dst->size());
81 # error "Big-endian not supported"
83 spvBinaryDestroy(binary);
84 spvDiagnosticDestroy(diagnostic);
85 spvContextDestroy(context);
89 #else // defined(DEQP_HAVE_SPIRV_TOOLS)
91 void assembleSpirV (const SpirVAsmSource*, std::vector<deUint8>*, SpirVProgramInfo*)
93 TCU_THROW(NotSupportedError, "SPIR-V assembly not supported (DEQP_HAVE_SPIRV_TOOLS not defined)");