[Mesa-dev] [PATCH 28/31] mesa: don't flag _NEW_PROGRAM_CONSTANTS for non-GLSL programs for st/mesa
Marek Olšák
maraeo at gmail.com
Mon Jun 12 16:55:53 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
This has the benefit that we get to set up constants for exactly
the shader stage that needs it.
---
src/mesa/main/arbprogram.c | 30 ++++++++++++++++++++++++------
src/mesa/main/mtypes.h | 3 +++
src/mesa/main/state.c | 14 ++++++++++++--
src/mesa/state_tracker/st_context.c | 10 ++++++++++
4 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/src/mesa/main/arbprogram.c b/src/mesa/main/arbprogram.c
index f3a0a54c..625dc66 100644
--- a/src/mesa/main/arbprogram.c
+++ b/src/mesa/main/arbprogram.c
@@ -34,20 +34,37 @@
#include "main/hash.h"
#include "main/imports.h"
#include "main/macros.h"
#include "main/mtypes.h"
#include "main/arbprogram.h"
#include "main/shaderapi.h"
#include "program/arbprogparse.h"
#include "program/program.h"
#include "program/prog_print.h"
+static void
+flush_vertices_for_program_constants(struct gl_context *ctx, GLenum target)
+{
+ uint64_t new_driver_state;
+
+ if (target == GL_FRAGMENT_PROGRAM_ARB) {
+ new_driver_state =
+ ctx->DriverFlags.NewShaderConstants[MESA_SHADER_FRAGMENT];
+ } else {
+ new_driver_state =
+ ctx->DriverFlags.NewShaderConstants[MESA_SHADER_VERTEX];
+ }
+
+ FLUSH_VERTICES(ctx, new_driver_state ? 0 : _NEW_PROGRAM_CONSTANTS);
+ ctx->NewDriverState |= new_driver_state;
+}
+
/**
* Bind a program (make it current)
* \note Called from the GL API dispatcher by both glBindProgramNV
* and glBindProgramARB.
*/
void GLAPIENTRY
_mesa_BindProgramARB(GLenum target, GLuint id)
{
struct gl_program *curProg, *newProg;
GET_CURRENT_CONTEXT(ctx);
@@ -98,21 +115,22 @@ _mesa_BindProgramARB(GLenum target, GLuint id)
}
/** All error checking is complete now **/
if (curProg->Id == id) {
/* binding same program - no change */
return;
}
/* signal new program (and its new constants) */
- FLUSH_VERTICES(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
+ FLUSH_VERTICES(ctx, _NEW_PROGRAM);
+ flush_vertices_for_program_constants(ctx, target);
/* bind newProg */
if (target == GL_VERTEX_PROGRAM_ARB) {
_mesa_reference_program(ctx, &ctx->VertexProgram.Current, newProg);
}
else if (target == GL_FRAGMENT_PROGRAM_ARB) {
_mesa_reference_program(ctx, &ctx->FragmentProgram.Current, newProg);
}
/* Never null pointers */
@@ -427,21 +445,21 @@ _mesa_ProgramEnvParameter4dvARB(GLenum target, GLuint index,
* \note Called from the GL API dispatcher.
*/
void GLAPIENTRY
_mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
GLfloat x, GLfloat y, GLfloat z, GLfloat w)
{
GLfloat *param;
GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
+ flush_vertices_for_program_constants(ctx, target);
if (get_env_param_pointer(ctx, "glProgramEnvParameter",
target, index, ¶m)) {
ASSIGN_4V(param, x, y, z, w);
}
}
/**
@@ -449,37 +467,37 @@ _mesa_ProgramEnvParameter4fARB(GLenum target, GLuint index,
* \note Called from the GL API dispatcher.
*/
void GLAPIENTRY
_mesa_ProgramEnvParameter4fvARB(GLenum target, GLuint index,
const GLfloat *params)
{
GLfloat *param;
GET_CURRENT_CONTEXT(ctx);
- FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
+ flush_vertices_for_program_constants(ctx, target);
if (get_env_param_pointer(ctx, "glProgramEnvParameter4fv",
target, index, ¶m)) {
memcpy(param, params, 4 * sizeof(GLfloat));
}
}
void GLAPIENTRY
_mesa_ProgramEnvParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
const GLfloat *params)
{
GET_CURRENT_CONTEXT(ctx);
GLfloat * dest;
- FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
+ flush_vertices_for_program_constants(ctx, target);
if (count <= 0) {
_mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(count)");
}
if (target == GL_FRAGMENT_PROGRAM_ARB
&& ctx->Extensions.ARB_fragment_program) {
if ((index + count) > ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxEnvParams) {
_mesa_error(ctx, GL_INVALID_VALUE, "glProgramEnvParameters4fv(index + count)");
return;
@@ -532,21 +550,21 @@ _mesa_GetProgramEnvParameterfvARB(GLenum target, GLuint index,
}
void GLAPIENTRY
_mesa_ProgramLocalParameter4fARB(GLenum target, GLuint index,
GLfloat x, GLfloat y, GLfloat z, GLfloat w)
{
GET_CURRENT_CONTEXT(ctx);
GLfloat *param;
- FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
+ flush_vertices_for_program_constants(ctx, target);
if (get_local_param_pointer(ctx, "glProgramLocalParameterARB",
target, index, ¶m)) {
assert(index < MAX_PROGRAM_LOCAL_PARAMS);
ASSIGN_4V(param, x, y, z, w);
}
}
void GLAPIENTRY
@@ -558,21 +576,21 @@ _mesa_ProgramLocalParameter4fvARB(GLenum target, GLuint index,
}
void GLAPIENTRY
_mesa_ProgramLocalParameters4fvEXT(GLenum target, GLuint index, GLsizei count,
const GLfloat *params)
{
GET_CURRENT_CONTEXT(ctx);
GLfloat *dest;
- FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
+ flush_vertices_for_program_constants(ctx, target);
if (count <= 0) {
_mesa_error(ctx, GL_INVALID_VALUE, "glProgramLocalParameters4fv(count)");
}
if (get_local_param_pointer(ctx, "glProgramLocalParameters4fvEXT",
target, index, &dest)) {
GLuint maxParams = target == GL_FRAGMENT_PROGRAM_ARB ?
ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxLocalParams :
ctx->Const.Program[MESA_SHADER_VERTEX].MaxLocalParams;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 00e8138..e7684c2 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -4452,20 +4452,23 @@ struct gl_driver_flags
uint64_t NewLineState;
/** gl_context::Polygon */
uint64_t NewPolygonState;
/** gl_context::PolygonStipple */
uint64_t NewPolygonStipple;
/** gl_context::ViewportArray */
uint64_t NewViewport;
+
+ /** Shader constants (uniforms, program parameters, state constants) */
+ uint64_t NewShaderConstants[MESA_SHADER_STAGES];
};
struct gl_uniform_buffer_binding
{
struct gl_buffer_object *BufferObject;
/** Start of uniform block data in the buffer */
GLintptr Offset;
/** Size of data allowed to be referenced from the buffer (in bytes) */
GLsizeiptr Size;
/**
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 2b4d8d4..7aec98e 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -223,33 +223,43 @@ update_program(struct gl_context *ctx)
*/
static GLbitfield
update_program_constants(struct gl_context *ctx)
{
GLbitfield new_state = 0x0;
if (ctx->FragmentProgram._Current) {
const struct gl_program_parameter_list *params =
ctx->FragmentProgram._Current->Parameters;
if (params && params->StateFlags & ctx->NewState) {
- new_state |= _NEW_PROGRAM_CONSTANTS;
+ if (ctx->DriverFlags.NewShaderConstants[MESA_SHADER_FRAGMENT]) {
+ ctx->NewDriverState |=
+ ctx->DriverFlags.NewShaderConstants[MESA_SHADER_FRAGMENT];
+ } else {
+ new_state |= _NEW_PROGRAM_CONSTANTS;
+ }
}
}
/* Don't handle tessellation and geometry shaders here. They don't use
* any state constants.
*/
if (ctx->VertexProgram._Current) {
const struct gl_program_parameter_list *params =
ctx->VertexProgram._Current->Parameters;
if (params && params->StateFlags & ctx->NewState) {
- new_state |= _NEW_PROGRAM_CONSTANTS;
+ if (ctx->DriverFlags.NewShaderConstants[MESA_SHADER_VERTEX]) {
+ ctx->NewDriverState |=
+ ctx->DriverFlags.NewShaderConstants[MESA_SHADER_VERTEX];
+ } else {
+ new_state |= _NEW_PROGRAM_CONSTANTS;
+ }
}
}
return new_state;
}
/**
* Compute derived GL state.
* If __struct gl_contextRec::NewState is non-zero then this function \b must
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 5e64e97..e676a48 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -477,24 +477,34 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
}
static void st_init_driver_flags(struct st_context *st)
{
struct gl_driver_flags *f = &st->ctx->DriverFlags;
f->NewArray = ST_NEW_VERTEX_ARRAYS;
f->NewRasterizerDiscard = ST_NEW_RASTERIZER;
f->NewUniformBuffer = ST_NEW_UNIFORM_BUFFER;
f->NewDefaultTessLevels = ST_NEW_TESS_STATE;
+
+ /* Shader resources */
f->NewTextureBuffer = ST_NEW_SAMPLER_VIEWS;
f->NewAtomicBuffer = ST_NEW_ATOMIC_BUFFER;
f->NewShaderStorageBuffer = ST_NEW_STORAGE_BUFFER;
f->NewImageUnits = ST_NEW_IMAGE_UNITS;
+
+ f->NewShaderConstants[MESA_SHADER_VERTEX] = ST_NEW_VS_CONSTANTS;
+ f->NewShaderConstants[MESA_SHADER_TESS_CTRL] = ST_NEW_TCS_CONSTANTS;
+ f->NewShaderConstants[MESA_SHADER_TESS_EVAL] = ST_NEW_TES_CONSTANTS;
+ f->NewShaderConstants[MESA_SHADER_GEOMETRY] = ST_NEW_GS_CONSTANTS;
+ f->NewShaderConstants[MESA_SHADER_FRAGMENT] = ST_NEW_FS_CONSTANTS;
+ f->NewShaderConstants[MESA_SHADER_COMPUTE] = ST_NEW_CS_CONSTANTS;
+
f->NewWindowRectangles = ST_NEW_WINDOW_RECTANGLES;
f->NewFramebufferSRGB = ST_NEW_FRAMEBUFFER;
f->NewScissorRect = ST_NEW_SCISSOR;
f->NewScissorTest = ST_NEW_SCISSOR | ST_NEW_RASTERIZER;
f->NewAlphaTest = ST_NEW_DSA;
f->NewBlend = ST_NEW_BLEND;
f->NewBlendColor = ST_NEW_BLEND; /* TODO: add an atom for blend color */
f->NewColorMask = ST_NEW_BLEND;
f->NewDepth = ST_NEW_DSA;
f->NewLogicOp = ST_NEW_BLEND;
--
2.7.4
More information about the mesa-dev
mailing list