Validate fragment output location doesn't exceed kMaxColorAttachments

This patch adds the validation on the fragment shader output location to
ensure it will never exceed kMaxColorAttachments.

BUG=dawn:202
TEST=dawn_unittests

Change-Id: I4ac4463fd3dfb3c2e9ffecb370f9d9d59393c26d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11580
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Jiawei Shao 2019-09-25 01:21:28 +00:00 committed by Commit Bot service account
parent c3b613296d
commit 05be0ff348
2 changed files with 31 additions and 0 deletions

View File

@ -190,6 +190,18 @@ namespace dawn_native {
return; return;
} }
} }
for (const auto& fragmentOutput : resources.stage_outputs) {
ASSERT(
compiler.get_decoration_bitset(fragmentOutput.id).get(spv::DecorationLocation));
uint32_t location =
compiler.get_decoration(fragmentOutput.id, spv::DecorationLocation);
if (location >= kMaxColorAttachments) {
device->HandleError(dawn::ErrorType::Validation,
"Fragment output location over limits in the SPIRV");
return;
}
}
} }
} }

View File

@ -12,10 +12,14 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "common/Constants.h"
#include "tests/unittests/validation/ValidationTest.h" #include "tests/unittests/validation/ValidationTest.h"
#include "utils/DawnHelpers.h" #include "utils/DawnHelpers.h"
#include <sstream>
class ShaderModuleValidationTest : public ValidationTest { class ShaderModuleValidationTest : public ValidationTest {
}; };
@ -89,3 +93,18 @@ TEST_F(ShaderModuleValidationTest, DISABLED_OpUndef) {
std::string error = GetLastDeviceErrorMessage(); std::string error = GetLastDeviceErrorMessage();
ASSERT_NE(error.find("OpUndef"), std::string::npos); ASSERT_NE(error.find("OpUndef"), std::string::npos);
} }
// Tests that if the output location exceeds kMaxColorAttachments the fragment shader will fail to
// be compiled.
TEST_F(ShaderModuleValidationTest, FragmentOutputLocationExceedsMaxColorAttachments) {
std::ostringstream stream;
stream << R"(#version 450
layout(location = )"
<< kMaxColorAttachments << R"() out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})";
ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment,
stream.str().c_str()));
}