Browse Source

Shaders: assume materialId is 0 if MATERIAL_COUNT is 1.

Unlike the drawId optimization before, there's no possibility to
check this anywhere, so the assumption is just documented.

On an Intel 630 this resulted in further significant reduction for the
single-draw single-material case, down to 260 from 440 in the previous
commit, about a 45% reduction compared to the original 550 ms; multidraw
case is still around the 550 there.
pull/518/head
Vladimír Vondruš 5 years ago
parent
commit
78d9694676
  1. 4
      src/Magnum/Shaders/DistanceFieldVector.frag
  2. 5
      src/Magnum/Shaders/DistanceFieldVector.h
  3. 4
      src/Magnum/Shaders/Flat.frag
  4. 6
      src/Magnum/Shaders/Flat.h
  5. 4
      src/Magnum/Shaders/MeshVisualizer.frag
  6. 5
      src/Magnum/Shaders/MeshVisualizer.h
  7. 4
      src/Magnum/Shaders/Phong.frag
  8. 5
      src/Magnum/Shaders/Phong.h
  9. 4
      src/Magnum/Shaders/Vector.frag
  10. 5
      src/Magnum/Shaders/Vector.h

4
src/Magnum/Shaders/DistanceFieldVector.frag

@ -144,7 +144,11 @@ out lowp vec4 fragmentColor;
void main() {
#ifdef UNIFORM_BUFFERS
#if MATERIAL_COUNT > 1
mediump const uint materialId = draws[drawId].draw_materialIdReserved & 0xffffu;
#else
#define materialId 0u
#endif
lowp const float smoothness = materials[materialId].material_smoothness;
lowp const vec4 color = materials[materialId].color;
lowp const vec4 outlineColor = materials[materialId].outlineColor;

5
src/Magnum/Shaders/DistanceFieldVector.h

@ -101,8 +101,9 @@ struct DistanceFieldVectorDrawUniform {
* more than one material is supplied or in a multi-draw scenario. Should
* be less than the material count passed to the
* @ref DistanceFieldVectorGL::DistanceFieldVectorGL(Flags, UnsignedInt, UnsignedInt)
* constructor. Default value is @cpp 0 @ce, meaning the first material
* gets used.
* constructor, if material count is @cpp 1 @ce, this field is assumed to
* be @cpp 0 @ce and isn't even read by the shader. Default value is
* @cpp 0 @ce, meaning the first material gets used.
*/
/* This field is an UnsignedInt in the shader and materialId is extracted

4
src/Magnum/Shaders/Flat.frag

@ -176,7 +176,11 @@ void main() {
#ifdef OBJECT_ID
highp const uint objectId = draws[drawId].draw_objectId;
#endif
#if MATERIAL_COUNT > 1
mediump const uint materialId = draws[drawId].draw_materialIdReserved & 0xffffu;
#else
#define materialId 0u
#endif
lowp const vec4 color = materials[materialId].color;
#ifdef ALPHA_MASK
lowp const float alphaMask = materials[materialId].material_alphaMask;

6
src/Magnum/Shaders/Flat.h

@ -108,8 +108,10 @@ struct FlatDrawUniform {
* References a particular material from a @ref FlatMaterialUniform array.
* Useful when an UBO with more than one material is supplied or in a
* multi-draw scenario. Should be less than the material count passed to
* the @ref FlatGL::FlatGL(Flags, UnsignedInt, UnsignedInt) constructor.
* Default value is @cpp 0 @ce, meaning the first material gets used.
* the @ref FlatGL::FlatGL(Flags, UnsignedInt, UnsignedInt) constructor, if
* material count is @cpp 1 @ce, this field is assumed to be @cpp 0 @ce and
* isn't even read by the shader. Default value is @cpp 0 @ce, meaning the
* first material gets used.
*/
/* This field is an UnsignedInt in the shader and materialId is extracted

4
src/Magnum/Shaders/MeshVisualizer.frag

@ -224,7 +224,11 @@ out lowp vec4 fragmentColor;
void main() {
#ifdef UNIFORM_BUFFERS
#if MATERIAL_COUNT > 1
mediump const uint materialId = draws[drawId].draw_materialIdReserved & 0xffffu;
#else
#define materialId 0u
#endif
#if (defined(WIREFRAME_RENDERING) || defined(INSTANCED_OBJECT_ID) || defined(VERTEX_ID) || defined(PRIMITIVE_ID) || defined(PRIMITIVE_ID_FROM_VERTEX_ID)) && !defined(TBN_DIRECTION)
lowp const vec4 color = materials[materialId].color;
lowp const vec4 wireframeColor = materials[materialId].wireframeColor;

5
src/Magnum/Shaders/MeshVisualizer.h

@ -100,8 +100,9 @@ struct MeshVisualizerDrawUniform2D {
* more than one material is supplied or in a multi-draw scenario. Should
* be less than the material count passed to the @ref MeshVisualizerGL2D::MeshVisualizerGL2D(Flags, UnsignedInt, UnsignedInt)
* / @ref MeshVisualizerGL3D::MeshVisualizerGL3D(Flags, UnsignedInt, UnsignedInt)
* constructor. Default value is @cpp 0 @ce, meaning the first material
* gets used.
* constructor, if material count is @cpp 1 @ce, this field is assumed to
* be @cpp 0 @ce and isn't even read by the shader. Default value is
* @cpp 0 @ce, meaning the first material gets used.
*/
/* This field is an UnsignedInt in the shader and materialId is extracted

4
src/Magnum/Shaders/Phong.frag

@ -339,7 +339,11 @@ void main() {
#ifdef OBJECT_ID
highp const uint objectId = draws[drawId].draw_objectId;
#endif
#if MATERIAL_COUNT > 1
mediump const uint materialId = draws[drawId].draw_materialIdReserved & 0xffffu;
#else
#define materialId 0u
#endif
lowp const vec4 ambientColor = materials[materialId].ambientColor;
#if LIGHT_COUNT
lowp const vec4 diffuseColor = materials[materialId].diffuseColor;

5
src/Magnum/Shaders/Phong.h

@ -141,8 +141,9 @@ struct PhongDrawUniform {
* Useful when a UBO with more than one material is supplied or in a
* multi-draw scenario. Should be less than the material count passed to
* the @ref PhongGL::PhongGL(Flags, UnsignedInt, UnsignedInt, UnsignedInt)
* constructor. Default value is @cpp 0 @ce, meaning the first material
* gets used.
* constructor, if material count is @cpp 1 @ce, this field is assumed to
* be @cpp 0 @ce and isn't even read by the shader. Default value is
* @cpp 0 @ce, meaning the first material gets used.
*/
/* This field is an UnsignedInt in the shader and materialId is extracted

4
src/Magnum/Shaders/Vector.frag

@ -123,7 +123,11 @@ out lowp vec4 fragmentColor;
void main() {
#ifdef UNIFORM_BUFFERS
#if MATERIAL_COUNT > 1
mediump const uint materialId = draws[drawId].draw_materialIdReserved & 0xffffu;
#else
#define materialId 0u
#endif
lowp const vec4 color = materials[materialId].color;
lowp const vec4 backgroundColor = materials[materialId].backgroundColor;
#endif

5
src/Magnum/Shaders/Vector.h

@ -96,8 +96,9 @@ struct VectorDrawUniform {
* array. Useful when an UBO with more than one material is supplied or in
* a multi-draw scenario. Should be less than the material count passed to
* the @ref VectorGL::VectorGL(Flags, UnsignedInt, UnsignedInt)
* constructor. Default value is @cpp 0 @ce, meaning the first material
* gets used.
* constructor, if material count is @cpp 1 @ce, this field is assumed to
* be @cpp 0 @ce and isn't even read by the shader. Default value is
* @cpp 0 @ce, meaning the first material gets used.
*/
/* This field is an UnsignedInt in the shader and materialId is extracted

Loading…
Cancel
Save