-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] update shaders for line property functions #6658
Conversation
@mollymerp, thanks for your PR! By analyzing the history of the files in this pull request, we identified @kkaefer, @jfirebaugh and @ansis to be potential reviewers. |
@@ -33,12 +33,15 @@ var data = data.split('\n').map(function(line) { | |||
} else { | |||
return params[1] + params[3] + 'p ' + params[4] + ' ' + params[5] + ' = u_' + params[5] + ';'; | |||
} | |||
} else if (line.match(pixel_ratio_regex)){ | |||
return '\n#define DEVICE_PIXEL_RATIO 2.0\n' + line; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line replaces any occurrences of /(.*)#define(.*)DEVICE_PIXEL_RATIO(.*)/
in the shader source with #define DEVICE_PIXEL_RATIO 2.0
. Are there occurrences of /(.*)#define(.*)DEVICE_PIXEL_RATIO(.*)/
in the shader source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually inserts the hardcoded definition before (#define DEVICE_PIXEL_RATIO 2.0
) before the matching line in the line-*.vertex shaders. so the output is
#define DEVICE_PIXEL_RATIO 2.0
#define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0
I've confirmed the build-shaders script is producing the .hpp
shaders with the expected result but at least one of the shaders is not compiling and I can't find a helpful error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mollymerp There are some shaders which use the DEVICE_PIXEL_RATIO
outside of #define
statements. I suggest following the precedent set in GL JS and adding this #define
to the top of all shaders.
Ok I fixed a bug in mapbox/mapbox-gl-shaders#24 and now everything is compiling/building, and I think all I have left to do is figure out how to access |
Soooo this is more or less working, but the render tests show that (I think) antialiasing is messed up and maybe color too? I'll need to investigate that more. |
: name(name_), | ||
program(context.createProgram()), | ||
vertexShader(context.createVertexShader()), | ||
fragmentShader(context.createFragmentShader()) { | ||
util::stopwatch stopwatch("shader compilation", Event::Shader); | ||
|
||
if (!compileShader(vertexShader, vertexSource)) { | ||
std::string vertex(vertexSource); | ||
vertex.replace(vertex.find_first_of('\n'), 1,"\n#define DEVICE_PIXEL_RATIO " + std::to_string(shaderParameters.pixelRatio) + "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure hard-coding the device pixel ratio is a good idea. On desktop, we can switch windows between screens with differing pixel ratio. We don't reload any sprites, but we still do a best effort to render them at the correct size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take that back; we are initializing Map
with a constant pixel ratio that can't be changed after the fact anyway.
std::string fragment(fragmentSource); | ||
if (defines & Defines::Overdraw) { | ||
fragment.replace(fragment.find_first_of('\n'), 1,"\n#define DEVICE_PIXEL_RATIO "+ std::to_string(shaderParameters.pixelRatio) + "\n"); | ||
if ((strcmp(name, "collision_box") != 0) & shaderParameters.overdraw) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this hard-coded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I couldn't figure out how to modify things such that the collision_box_shader
is always initialized with overdraw = false
😳
#ifndef NDEBUG | ||
shaderParametersOverdraw = gl::ShaderParameters{ frame.pixelRatio, true }; | ||
overdrawShaders = std::make_unique<Shaders>(context, shaderParametersOverdraw); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if/endif
should not be indented; and the code it surrounds needs to be unindented. You can use clang-format
to apply our standard code formatting.
shaders = std::make_unique<Shaders>(context, shaderParameters); | ||
#ifndef NDEBUG | ||
shaderParametersOverdraw = gl::ShaderParameters{ frame.pixelRatio, true }; | ||
overdrawShaders = std::make_unique<Shaders>(context, shaderParametersOverdraw); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you move this to the render()
method? This means the shaders are initialized on every frame, which isn't efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I put it originally in the Painter
initialization, DEVICE_PIXEL_RATIO
was getting set to 0 all the time 😬
@@ -151,6 +153,8 @@ class Painter : private util::noncopyable { | |||
LineAtlas* lineAtlas = nullptr; | |||
|
|||
FrameHistory frameHistory; | |||
gl::ShaderParameters shaderParameters; | |||
gl::ShaderParameters shaderParametersOverdraw; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShaderParameters
are only used to initialize the shaders; there's no need to keep them around.
@@ -31,7 +32,7 @@ class Shader : private util::noncopyable { | |||
const char* vertex, | |||
const char* fragment, | |||
Context&, | |||
Defines defines = Defines::None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Defines
isn't used anymore, you should also remove the enum
definition.
There seem to be a few commits in here that track your progress rather than individual self-contained changes (and some commented out code added, then removed subsequently). Can you please merge/split commits so that the changes represent self-contained units? Our general rule of thumb is that every commit in gl-native should have all tests passing. This helps bigly when using |
Thanks for the review @kkaefer ! I will squash my commits when this is closer to merging because I don't think any of these commits have all tests passing so far. |
51871b7
to
162da32
Compare
Ok I think this is finally ready for another glance @kkaefer @jfirebaugh 👀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, pretty much just formatting/style nits at this point.
@@ -20,10 +20,9 @@ | |||
"csscolorparser": "^1.0.2", | |||
"ejs": "^2.4.1", | |||
"express": "^4.11.1", | |||
"lodash": "^4.16.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert the lodash removal -- this is still used in a couple places.
@@ -40,7 +40,7 @@ Context::~Context() { | |||
|
|||
UniqueShader Context::createShader(ShaderType type, const std::string& source) { | |||
UniqueShader result { MBGL_CHECK_ERROR(glCreateShader(static_cast<GLenum>(type))), { this } }; | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert the whitespace changes in this file.
@@ -12,13 +12,11 @@ static_assert(sizeof(LineAttributes::Vertex) == 8, "expected LineVertex size"); | |||
|
|||
template <class Values, class...Args> | |||
Values makeValues(const style::LinePaintProperties& properties, | |||
float pixelRatio, | |||
const RenderTile& tile, | |||
const TransformState& state, | |||
Args&&... args) { | |||
// the distance over which the line edge fades out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the comments here; they were attached to the line that was deleted.
std::string fragment = Shaders::fragmentSource; | ||
if (defines == ProgramDefines::Overdraw) { | ||
|
||
fragment.replace(fragment.find_first_of('\n'), 1,"\n#define DEVICE_PIXEL_RATIO "+ std::to_string(programParameters.pixelRatio) + "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of finding the first newline here? Could it instead simply prepend "#define DEVICE_PIXEL_RATIO ...\n"
to the source?
symbolGlyph(context, defines), | ||
debug(context, ProgramDefines::None), | ||
collisionBox(context, ProgramDefines::None) { | ||
Programs(gl::Context& context, ProgramParameters& programParameters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ProgramParameters&
|
||
namespace mbgl { | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this added whitespace.
@@ -21,6 +22,7 @@ | |||
#include <mbgl/geometry/line_atlas.hpp> | |||
#include <mbgl/text/glyph_atlas.hpp> | |||
|
|||
#include <mbgl/programs/program_parameters.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate #include
.
|
||
namespace mbgl { | ||
|
||
class ProgramParameters { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting nits:
class ProgramParameters {
public:
ProgramParameters(float pixelRatio_ = 1.0, bool overdraw_ = false)
: pixelRatio(pixelRatio_),
overdraw(overdraw_) {}
float pixelRatio;
bool overdraw;
};
@@ -151,6 +152,7 @@ class Painter : private util::noncopyable { | |||
|
|||
FrameHistory frameHistory; | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert whitespace change.
: pixelsToGLUnits }, | ||
uniforms::u_devicepixelratio::Value{ frame.pixelRatio }, | ||
}, | ||
: pixelsToGLUnits } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting nit:
: pixelsToGLUnits }
},
*bucket.vertexBuffer,
740dced
to
4e6da9e
Compare
Thanks @jfirebaugh -- fixed and squashed! |
Launch steps:
|
std::string fragment = Shaders::fragmentSource; | ||
if (defines == ProgramDefines::Overdraw) { | ||
|
||
fragment.insert(0, "\n#define DEVICE_PIXEL_RATIO "+ std::to_string(programParameters.pixelRatio) + "\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static std::string pixelRatioDefine(const ProgramParameters& parameters) {
return std::string("#define DEVICE_PIXEL_RATIO ") + std::to_string(parameters.pixelRatio) + "\n";
}
static std::string fragmentSource(const ProgramParameters& parameters) {
std::string source = pixelRatioDefine(parameters) + Shaders::fragmentSource;
...
}
static std::string vertexSource(const ProgramParameters& parameters) {
return pixelRatioDefine(parameters) + Shaders::vertexSource;
}
1e221cd
to
91c64d4
Compare
@kkaefer Have all your requested changes been addressed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup!
@@ -86,9 +87,12 @@ Painter::Painter(gl::Context& context_, const TransformState& state_) | |||
gl::debugging::enable(); | |||
#endif | |||
|
|||
programs = std::make_unique<Programs>(context); | |||
ProgramParameters programParameters = ProgramParameters{ pixelRatio, false }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be shortened to ProgramParameters programParameters{ pixelRatio, false };
update deps, define device pixel ratio for all shaders [core] create ShaderParameter struct to store pixel ratio and overdraw param repair rebase errs update shaders to include pixel ratio make sure collision_box never overdraws update test suite, move shaders to Painter::render so the correct pixel ratio is applied move shader compiling back to the Painter constructor rebase from shader --> program refactor re-factor parameters for collisionBox and debug programs remove unused vars from line-program, move blur math to shader update core files remove unecessary files update shaders PR, remove comments bump test suite sha fix formatting, incorporate feedback refactor program.hpp
Looks like the mapbox-gl-shaders repository branch didn't get into master after this branch got merged? |
attempting to make native work with the shaders update at mapbox/mapbox-gl-shaders#24
Currently the macOS build is 'succeeding' but it freezes/times out and the actual app never opens so I'm definitely doing something wrong -- possibly that you can't🔧 fixed#define
macros like that in OpenGL or something?I'm planning on having the device pixel ratio not be hard-coded in the🔧 fixedbuild-shaders
script, but I figured I'd try to get that working as a first step 💭cc @lucaswoj