[Piglit] [PATCH 1/4] util: Add a utility to assemble SPIR-V sources
Alejandro PiƱeiro
apinheiro at igalia.com
Fri Jul 20 15:16:09 UTC 2018
From: Neil Roberts <nroberts at igalia.com>
Adds piglit_assemble_spirv which invokes spirv-as to assemble a SPIR-V
source. The function is based on a static helper function that was in
shader_runner.
---
tests/shaders/shader_runner.c | 45 ++++++-------------------------------------
tests/util/piglit-shader.c | 37 +++++++++++++++++++++++++++++++++++
tests/util/piglit-shader.h | 3 +++
3 files changed, 46 insertions(+), 39 deletions(-)
diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 63cffdc19..00f13ec70 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -720,8 +720,8 @@ program_binary_save_restore(bool script_command)
}
static enum piglit_result
-load_and_specialize_spirv(GLenum target,
- const char *binary, unsigned size)
+specialize_spirv(GLenum target,
+ GLuint shader)
{
if (glsl_in_use) {
printf("Cannot mix SPIR-V and non-SPIR-V shaders\n");
@@ -730,11 +730,6 @@ load_and_specialize_spirv(GLenum target,
spirv_in_use = true;
- GLuint shader = glCreateShader(target);
-
- glShaderBinary(1, &shader, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB,
- binary, size);
-
const struct specialization_list *specs;
switch (target) {
@@ -822,15 +817,6 @@ assemble_spirv(GLenum target)
return PIGLIT_SKIP;
}
- char *arguments[] = {
- getenv("PIGLIT_SPIRV_AS_BINARY"),
- "-o", "-",
- NULL
- };
-
- if (arguments[0] == NULL)
- arguments[0] = "spirv-as";
-
/* Strip comments from the source */
char *stripped_source = malloc(shader_string_size);
char *p = stripped_source;
@@ -853,32 +839,13 @@ assemble_spirv(GLenum target)
}
}
- uint8_t *binary_source;
- size_t binary_source_length;
- bool res = piglit_subprocess(arguments,
- p - stripped_source,
- (const uint8_t *)
- stripped_source,
- &binary_source_length,
- &binary_source);
+ GLuint shader = piglit_assemble_spirv(target,
+ p - stripped_source,
+ stripped_source);
free(stripped_source);
- if (!res) {
- fprintf(stderr, "spirv-as failed\n");
- return PIGLIT_FAIL;
- }
-
- enum piglit_result ret;
-
- ret = load_and_specialize_spirv(target,
- (const char *)
- binary_source,
- binary_source_length);
-
- free(binary_source);
-
- return ret;
+ return specialize_spirv(target, shader);
}
static enum piglit_result
diff --git a/tests/util/piglit-shader.c b/tests/util/piglit-shader.c
index 7ac5df14d..1938b1576 100644
--- a/tests/util/piglit-shader.c
+++ b/tests/util/piglit-shader.c
@@ -24,6 +24,7 @@
#include <errno.h>
#include "piglit-util-gl.h"
+#include "piglit-subprocess.h"
void piglit_get_glsl_version(bool *es, int* major, int* minor)
{
@@ -464,6 +465,42 @@ piglit_build_simple_program_multiple_shaders(GLenum target1,
return prog;
}
+GLuint
+piglit_assemble_spirv(GLenum target,
+ size_t source_length,
+ const char *source)
+{
+ char *arguments[] = {
+ getenv("PIGLIT_SPIRV_AS_BINARY"),
+ "-o", "-",
+ NULL
+ };
+
+ if (arguments[0] == NULL)
+ arguments[0] = "spirv-as";
+
+ uint8_t *binary_source;
+ size_t binary_source_length;
+ bool res = piglit_subprocess(arguments,
+ source_length,
+ (const uint8_t *) source,
+ &binary_source_length,
+ &binary_source);
+
+ if (!res) {
+ fprintf(stderr, "spirv-as failed\n");
+ piglit_report_result(PIGLIT_FAIL);
+ }
+
+ GLuint shader = glCreateShader(target);
+ glShaderBinary(1, &shader, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB,
+ binary_source, binary_source_length);
+
+ free(binary_source);
+
+ return shader;
+}
+
void
piglit_require_GLSL(void)
{
diff --git a/tests/util/piglit-shader.h b/tests/util/piglit-shader.h
index 9208451a8..aa29d0994 100644
--- a/tests/util/piglit-shader.h
+++ b/tests/util/piglit-shader.h
@@ -49,6 +49,9 @@ GLint piglit_build_simple_program_unlinked_multiple_shaders(GLenum target1,
GLint piglit_build_simple_program_multiple_shaders(GLenum target1,
const char *source1,
...);
+GLuint piglit_assemble_spirv(GLenum target,
+ size_t source_length,
+ const char *source);
extern GLboolean piglit_program_pipeline_check_status(GLuint pipeline);
extern GLboolean piglit_program_pipeline_check_status_quiet(GLuint pipeline);
--
2.14.1
More information about the Piglit
mailing list