#include <stdbool.h>
+#include <c99_alloca.h>
#include "main/glheader.h"
#include "main/context.h"
-#include "main/dispatch.h"
#include "main/enums.h"
+#include "main/glspirv.h"
#include "main/hash.h"
#include "main/mtypes.h"
#include "main/pipelineobj.h"
#include "main/program_binary.h"
#include "main/shaderapi.h"
#include "main/shaderobj.h"
+#include "main/state.h"
#include "main/transformfeedback.h"
#include "main/uniforms.h"
#include "compiler/glsl/glsl_parser_extras.h"
#include "util/hash_table.h"
#include "util/mesa-sha1.h"
#include "util/crc32.h"
+#include "util/os_file.h"
/**
* Return mask of GLSL_x flags by examining the MESA_GLSL env var.
{
for (int i = 0; i < MESA_SHADER_STAGES; i++) {
_mesa_reference_program(ctx, &ctx->Shader.CurrentProgram[i], NULL);
+ _mesa_reference_shader_program(ctx,
+ &ctx->Shader.ReferencedPrograms[i],
+ NULL);
}
_mesa_reference_shader_program(ctx, &ctx->Shader.ActiveProgram, NULL);
shProg->Shaders = newList;
shProg->NumShaders = n - 1;
-#ifdef DEBUG
+#ifndef NDEBUG
/* sanity check - make sure the new list's entries are sensible */
for (j = 0; j < shProg->NumShaders; j++) {
assert(shProg->Shaders[j]->Stage == MESA_SHADER_VERTEX ||
/* True if geometry shaders (of the form that was adopted into GLSL 1.50
* and GL 3.2) are available in this context
*/
- const bool has_core_gs = _mesa_has_geometry_shaders(ctx);
+ const bool has_gs = _mesa_has_geometry_shaders(ctx);
const bool has_tess = _mesa_has_tessellation(ctx);
/* Are uniform buffer objects available in this context?
case GL_DELETE_STATUS:
*params = shProg->DeletePending;
return;
+ case GL_COMPLETION_STATUS_ARB:
+ if (ctx->Driver.GetShaderProgramCompletionStatus)
+ *params = ctx->Driver.GetShaderProgramCompletionStatus(ctx, shProg);
+ else
+ *params = GL_TRUE;
+ return;
case GL_LINK_STATUS:
*params = shProg->data->LinkStatus ? GL_TRUE : GL_FALSE;
return;
*params = shProg->TransformFeedback.BufferMode;
return;
case GL_GEOMETRY_VERTICES_OUT:
- if (!has_core_gs)
+ if (!has_gs)
break;
if (check_gs_query(ctx, shProg)) {
*params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->
}
return;
case GL_GEOMETRY_SHADER_INVOCATIONS:
- if (!has_core_gs || !ctx->Extensions.ARB_gpu_shader5)
+ if (!has_gs || !ctx->Extensions.ARB_gpu_shader5)
break;
if (check_gs_query(ctx, shProg)) {
*params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->
}
return;
case GL_GEOMETRY_INPUT_TYPE:
- if (!has_core_gs)
+ if (!has_gs)
break;
if (check_gs_query(ctx, shProg)) {
*params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->
}
return;
case GL_GEOMETRY_OUTPUT_TYPE:
- if (!has_core_gs)
+ if (!has_gs)
break;
if (check_gs_query(ctx, shProg)) {
*params = shProg->_LinkedShaders[MESA_SHADER_GEOMETRY]->
if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
break;
- *params = shProg->BinaryRetreivableHint;
+ *params = shProg->BinaryRetrievableHint;
return;
case GL_PROGRAM_BINARY_LENGTH:
- if (ctx->Const.NumProgramBinaryFormats == 0) {
+ if (ctx->Const.NumProgramBinaryFormats == 0 || !shProg->data->LinkStatus) {
*params = 0;
} else {
_mesa_get_program_binary_length(ctx, shProg, params);
}
case GL_PROGRAM_SEPARABLE:
/* If the program has not been linked, return initial value 0. */
- *params = (shProg->data->LinkStatus == linking_failure) ? 0 : shProg->SeparateShader;
+ *params = (shProg->data->LinkStatus == LINKING_FAILURE) ? 0 : shProg->SeparateShader;
return;
/* ARB_tessellation_shader */
case GL_DELETE_STATUS:
*params = shader->DeletePending;
break;
+ case GL_COMPLETION_STATUS_ARB:
+ /* _mesa_glsl_compile_shader is not offloaded to other threads. */
+ *params = GL_TRUE;
+ return;
case GL_COMPILE_STATUS:
*params = shader->CompileStatus ? GL_TRUE : GL_FALSE;
break;
case GL_SHADER_SOURCE_LENGTH:
*params = shader->Source ? strlen((char *) shader->Source) + 1 : 0;
break;
+ case GL_SPIR_V_BINARY_ARB:
+ *params = (shader->spirv_data != NULL);
+ break;
default:
_mesa_error(ctx, GL_INVALID_ENUM, "glGetShaderiv(pname)");
return;
{
assert(sh);
- if (sh->CompileStatus == compile_skipped && !sh->FallbackSource) {
+ /* The GL_ARB_gl_spirv spec adds the following to the end of the description
+ * of ShaderSource:
+ *
+ * "If <shader> was previously associated with a SPIR-V module (via the
+ * ShaderBinary command), that association is broken. Upon successful
+ * completion of this command the SPIR_V_BINARY_ARB state of <shader>
+ * is set to FALSE."
+ */
+ _mesa_shader_spirv_data_reference(&sh->spirv_data, NULL);
+
+ if (sh->CompileStatus == COMPILE_SKIPPED && !sh->FallbackSource) {
/* If shader was previously compiled back-up the source in case of cache
* fallback.
*/
if (!sh)
return;
+ /* The GL_ARB_gl_spirv spec says:
+ *
+ * "Add a new error for the CompileShader command:
+ *
+ * An INVALID_OPERATION error is generated if the SPIR_V_BINARY_ARB
+ * state of <shader> is TRUE."
+ */
+ if (sh->spirv_data) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glCompileShader(SPIR-V)");
+ return;
+ }
+
if (!sh->Source) {
/* If the user called glCompileShader without first calling
* glShaderSource, we should fail to compile, but not raise a GL_ERROR.
*/
- sh->CompileStatus = compile_failure;
+ sh->CompileStatus = COMPILE_FAILURE;
} else {
if (ctx->_Shader->Flags & GLSL_DUMP) {
_mesa_log("GLSL source for %s shader %d:\n",
/* Capture .shader_test files. */
const char *capture_path = _mesa_get_shader_capture_path();
if (shProg->Name != 0 && shProg->Name != ~0 && capture_path != NULL) {
- FILE *file;
- char *filename = ralloc_asprintf(NULL, "%s/%u.shader_test",
+ /* Find an unused filename. */
+ FILE *file = NULL;
+ char *filename = NULL;
+ for (unsigned i = 0;; i++) {
+ if (i) {
+ filename = ralloc_asprintf(NULL, "%s/%u-%u.shader_test",
+ capture_path, shProg->Name, i);
+ } else {
+ filename = ralloc_asprintf(NULL, "%s/%u.shader_test",
capture_path, shProg->Name);
- file = fopen(filename, "w");
+ }
+ file = os_file_create_unique(filename, 0644);
+ if (file)
+ break;
+ ralloc_free(filename);
+ }
if (file) {
fprintf(file, "[require]\nGLSL%s >= %u.%02u\n",
shProg->IsES ? " ES" : "",
ralloc_free(filename);
}
- if (shProg->data->LinkStatus == linking_failure &&
+ if (shProg->data->LinkStatus == LINKING_FAILURE &&
(ctx->_Shader->Flags & GLSL_REPORT_ERRORS)) {
_mesa_debug(ctx, "Error linking program %u:\n%s\n",
shProg->Name, shProg->data->InfoLog);
}
+ _mesa_update_vertex_processing_mode(ctx);
+
+ shProg->BinaryRetrievableHint = shProg->BinaryRetrievableHintPending;
+
/* debug code */
if (0) {
GLuint i;
* following format:
*
* <path>/<stage prefix>_<CHECKSUM>.glsl
+ * <path>/<stage prefix>_<CHECKSUM>.arb
*/
static char *
construct_name(const gl_shader_stage stage, const char *source,
"VS", "TC", "TE", "GS", "FS", "CS",
};
+ const char *format = strncmp(source, "!!ARB", 5) ? "glsl" : "arb";
+
generate_sha1(source, sha);
- return ralloc_asprintf(NULL, "%s/%s_%s.glsl", path, types[stage], sha);
+ return ralloc_asprintf(NULL, "%s/%s_%s.%s", path, types[stage], sha, format);
}
/**
* Write given shader source to a file in MESA_SHADER_DUMP_PATH.
*/
-static void
-dump_shader(const gl_shader_stage stage, const char *source)
+void
+_mesa_dump_shader_source(const gl_shader_stage stage, const char *source)
{
static bool path_exists = true;
char *dump_path;
* Read shader source code from a file.
* Useful for debugging to override an app's shader.
*/
-static GLcharARB *
-read_shader(const gl_shader_stage stage, const char *source)
+GLcharARB *
+_mesa_read_shader_source(const gl_shader_stage stage, const char *source)
{
char *read_path;
static bool path_exists = true;
/* Dump original shader source to MESA_SHADER_DUMP_PATH and replace
* if corresponding entry found from MESA_SHADER_READ_PATH.
*/
- dump_shader(sh->Stage, source);
+ _mesa_dump_shader_source(sh->Stage, source);
- replacement = read_shader(sh->Stage, source);
+ replacement = _mesa_read_shader_source(sh->Stage, source);
if (replacement) {
free(source);
source = replacement;
_mesa_BindProgramPipeline(ctx->Pipeline.Current->Name);
}
}
+
+ _mesa_update_vertex_processing_mode(ctx);
}
const void* binary, GLint length)
{
GET_CURRENT_CONTEXT(ctx);
- (void) shaders;
- (void) binaryformat;
- (void) binary;
+ struct gl_shader **sh;
/* Page 68, section 7.2 'Shader Binaries" of the of the OpenGL ES 3.1, and
* page 88 of the OpenGL 4.5 specs state:
return;
}
+ /* Get all shader objects at once so we can make the operation
+ * all-or-nothing.
+ */
+ if (n > SIZE_MAX / sizeof(*sh)) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderBinary(count)");
+ return;
+ }
+
+ sh = alloca(sizeof(*sh) * (size_t)n);
+ if (!sh) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderBinary");
+ return;
+ }
+
+ for (int i = 0; i < n; ++i) {
+ sh[i] = _mesa_lookup_shader_err(ctx, shaders[i], "glShaderBinary");
+ if (!sh[i])
+ return;
+ }
+
+ if (binaryformat == GL_SHADER_BINARY_FORMAT_SPIR_V_ARB) {
+ if (!ctx->Extensions.ARB_gl_spirv) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "glShaderBinary(SPIR-V)");
+ } else if (n > 0) {
+ _mesa_spirv_shader_binary(ctx, (unsigned) n, sh, binary,
+ (size_t) length);
+ }
+
+ return;
+ }
+
_mesa_error(ctx, GL_INVALID_ENUM, "glShaderBinary(format)");
}
* Since any value of binaryFormat passed "is not one of those specified as
* allowable for [this] command, an INVALID_ENUM error is generated."
*/
- shProg->data->LinkStatus = linking_failure;
+ shProg->data->LinkStatus = LINKING_FAILURE;
_mesa_error(ctx, GL_INVALID_ENUM, "glProgramBinary");
} else {
_mesa_program_binary(ctx, shProg, binaryFormat, binary, length);
* will not be in effect until the next time LinkProgram or
* ProgramBinary has been called successfully."
*
- * The resloution of issue 9 in the extension spec also says:
+ * The resolution of issue 9 in the extension spec also says:
*
* "The application may use the PROGRAM_BINARY_RETRIEVABLE_HINT hint
* to indicate to the GL implementation that this program will
* changes made to the program before being saved such that when it
* is loaded again a recompile can be avoided."
*/
- shProg->BinaryRetreivableHint = value;
+ shProg->BinaryRetrievableHintPending = value;
return;
case GL_PROGRAM_SEPARABLE:
&shTarget->ReferencedPrograms[stage],
shProg);
_mesa_reference_program(ctx, target, prog);
+ if (stage == MESA_SHADER_VERTEX)
+ _mesa_update_vertex_processing_mode(ctx);
return;
}
/* Possibly... */
if (active-user-defined-varyings-in-linked-program) {
append-error-to-info-log;
- shProg->data->LinkStatus = linking_failure;
+ shProg->data->LinkStatus = LINKING_FAILURE;
}
#endif
}