Dawn: fix RTHeight adjustment.

When rendering to a BottomUp render target, the SRIR-V codegen
needs a uniform to pass the render target height. (This is kind
of hacky, since it depends on being the last uniform, but it's
the same hack that the Vulkan backend uses.)

Change-Id: I520478d5e26504c7884daa72024fafe943a07294
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/252182
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White 2019-11-01 13:13:03 -04:00 committed by Skia Commit-Bot
parent 0a4681d044
commit 40c47e113d
3 changed files with 18 additions and 8 deletions

View File

@ -15,11 +15,12 @@
#include "src/sksl/SkSLCompiler.h"
static SkSL::String sksl_to_spirv(const GrDawnGpu* gpu, const char* shaderString,
SkSL::Program::Kind kind, bool flipY,
SkSL::Program::Kind kind, bool flipY, uint32_t rtHeightOffset,
SkSL::Program::Inputs* inputs) {
SkSL::Program::Settings settings;
settings.fCaps = gpu->caps()->shaderCaps();
settings.fFlipY = flipY;
settings.fRTHeightOffset = rtHeightOffset;
std::unique_ptr<SkSL::Program> program = gpu->shaderCompiler()->convertProgram(
kind,
shaderString,
@ -308,14 +309,14 @@ sk_sp<GrDawnProgram> GrDawnProgramBuilder::Build(GrDawnGpu* gpu,
builder.finalizeShaders();
SkSL::Program::Inputs vertInputs, fragInputs;
GrDawnUniformHandler::UniformInfoArray& uniforms = builder.fUniformHandler.fUniforms;
uint32_t uniformBufferSize = builder.fUniformHandler.fCurrentUBOOffset;
sk_sp<GrDawnProgram> result(new GrDawnProgram(uniforms, uniformBufferSize));
bool flipY = programInfo.origin() != kTopLeft_GrSurfaceOrigin;
auto vsModule = builder.createShaderModule(builder.fVS, SkSL::Program::kVertex_Kind, flipY,
&vertInputs);
auto fsModule = builder.createShaderModule(builder.fFS, SkSL::Program::kFragment_Kind, flipY,
&fragInputs);
GrDawnUniformHandler::UniformInfoArray& uniforms = builder.fUniformHandler.fUniforms;
uint32_t uniformBufferSize = builder.fUniformHandler.fCurrentUBOOffset;
sk_sp<GrDawnProgram> result(new GrDawnProgram(uniforms, uniformBufferSize));
result->fGeometryProcessor = std::move(builder.fGeometryProcessor);
result->fXferProcessor = std::move(builder.fXferProcessor);
result->fFragmentProcessors = std::move(builder.fFragmentProcessors);
@ -446,7 +447,11 @@ wgpu::ShaderModule GrDawnProgramBuilder::createShaderModule(const GrGLSLShaderBu
printf("converting program:\n%s\n", sksl.c_str());
#endif
SkSL::String spirvSource = sksl_to_spirv(fGpu, source.c_str(), kind, flipY, inputs);
SkSL::String spirvSource = sksl_to_spirv(fGpu, source.c_str(), kind, flipY,
fUniformHandler.getRTHeightOffset(), inputs);
if (inputs->fRTHeight) {
this->addRTHeightUniform(SKSL_RTHEIGHT_NAME);
}
wgpu::ShaderModuleDescriptor desc;
desc.codeSize = spirvSource.size() / 4;

View File

@ -175,9 +175,7 @@ static inline uint32_t grsltype_to_size(GrSLType type) {
SK_ABORT("Unexpected type");
}
uint32_t get_ubo_offset(uint32_t* currentOffset,
GrSLType type,
int arrayCount) {
uint32_t get_ubo_offset(uint32_t* currentOffset, GrSLType type, int arrayCount) {
uint32_t alignmentMask = grsltype_to_alignment_mask(type);
// We want to use the std140 layout here, so we must make arrays align to 16 bytes.
if (arrayCount || type == kFloat2x2_GrSLType) {
@ -306,3 +304,8 @@ void GrDawnUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString
out->appendf("%s\n};\n", uniformsString.c_str());
}
}
uint32_t GrDawnUniformHandler::getRTHeightOffset() const {
uint32_t dummy = fCurrentUBOOffset;
return get_ubo_offset(&dummy, kFloat_GrSLType, 0);
}

View File

@ -30,6 +30,7 @@ public:
kUniformBinding = 0,
kSamplerBindingBase = 1,
};
uint32_t getRTHeightOffset() const;
private:
explicit GrDawnUniformHandler(GrGLSLProgramBuilder* program);
@ -55,6 +56,7 @@ private:
SkTArray<SkString> fSamplerReferences;
uint32_t fCurrentUBOOffset = 0;
uint32_t fRTHeightOffset = 0;
friend class GrDawnProgramBuilder;
typedef GrGLSLUniformHandler INHERITED;