tint/writer: Do not attempt to use invalid programs
Attempting to emit shader code from an invalid program is unsafe. The WGSL writer is used for dumping information which is valuable for debugging bad programs, so this has not been changed. Bug: chromium:1327461 Change-Id: I4497fcb19d126ef6c872e2bcda8e9b79044aeb68 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91163 Reviewed-by: David Neto <dneto@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
34f4e1ecd3
commit
8f4f449540
|
@ -30,6 +30,10 @@ Result::Result(const Result&) = default;
|
||||||
|
|
||||||
Result Generate(const Program* program, const Options& options, const std::string& entry_point) {
|
Result Generate(const Program* program, const Options& options, const std::string& entry_point) {
|
||||||
Result result;
|
Result result;
|
||||||
|
if (!program->IsValid()) {
|
||||||
|
result.error = "input program is not valid";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Sanitize the program.
|
// Sanitize the program.
|
||||||
auto sanitized_result = Sanitize(program, options, entry_point);
|
auto sanitized_result = Sanitize(program, options, entry_point);
|
||||||
|
|
|
@ -19,6 +19,15 @@ namespace {
|
||||||
|
|
||||||
using GlslGeneratorImplTest = TestHelper;
|
using GlslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
|
TEST_F(GlslGeneratorImplTest, InvalidProgram) {
|
||||||
|
Diagnostics().add_error(diag::System::Writer, "make the program invalid");
|
||||||
|
ASSERT_FALSE(IsValid());
|
||||||
|
auto program = std::make_unique<Program>(std::move(*this));
|
||||||
|
ASSERT_FALSE(program->IsValid());
|
||||||
|
auto result = Generate(program.get(), Options{}, "");
|
||||||
|
EXPECT_EQ(result.error, "input program is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(GlslGeneratorImplTest, Generate) {
|
TEST_F(GlslGeneratorImplTest, Generate) {
|
||||||
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, ast::AttributeList{});
|
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, ast::AttributeList{});
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,10 @@ Result::Result(const Result&) = default;
|
||||||
|
|
||||||
Result Generate(const Program* program, const Options& options) {
|
Result Generate(const Program* program, const Options& options) {
|
||||||
Result result;
|
Result result;
|
||||||
|
if (!program->IsValid()) {
|
||||||
|
result.error = "input program is not valid";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Sanitize the program.
|
// Sanitize the program.
|
||||||
auto sanitized_result = Sanitize(program, options);
|
auto sanitized_result = Sanitize(program, options);
|
||||||
|
|
|
@ -19,6 +19,15 @@ namespace {
|
||||||
|
|
||||||
using HlslGeneratorImplTest = TestHelper;
|
using HlslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
|
TEST_F(HlslGeneratorImplTest, InvalidProgram) {
|
||||||
|
Diagnostics().add_error(diag::System::Writer, "make the program invalid");
|
||||||
|
ASSERT_FALSE(IsValid());
|
||||||
|
auto program = std::make_unique<Program>(std::move(*this));
|
||||||
|
ASSERT_FALSE(program->IsValid());
|
||||||
|
auto result = Generate(program.get(), Options{});
|
||||||
|
EXPECT_EQ(result.error, "input program is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest, Generate) {
|
TEST_F(HlslGeneratorImplTest, Generate) {
|
||||||
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, ast::AttributeList{});
|
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{}, ast::AttributeList{});
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,10 @@ Result::Result(const Result&) = default;
|
||||||
|
|
||||||
Result Generate(const Program* program, const Options& options) {
|
Result Generate(const Program* program, const Options& options) {
|
||||||
Result result;
|
Result result;
|
||||||
|
if (!program->IsValid()) {
|
||||||
|
result.error = "input program is not valid";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Sanitize the program.
|
// Sanitize the program.
|
||||||
auto sanitized_result = Sanitize(program, options);
|
auto sanitized_result = Sanitize(program, options);
|
||||||
|
|
|
@ -22,6 +22,15 @@ namespace {
|
||||||
|
|
||||||
using MslGeneratorImplTest = TestHelper;
|
using MslGeneratorImplTest = TestHelper;
|
||||||
|
|
||||||
|
TEST_F(MslGeneratorImplTest, InvalidProgram) {
|
||||||
|
Diagnostics().add_error(diag::System::Writer, "make the program invalid");
|
||||||
|
ASSERT_FALSE(IsValid());
|
||||||
|
auto program = std::make_unique<Program>(std::move(*this));
|
||||||
|
ASSERT_FALSE(program->IsValid());
|
||||||
|
auto result = Generate(program.get(), Options{});
|
||||||
|
EXPECT_EQ(result.error, "input program is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, Generate) {
|
TEST_F(MslGeneratorImplTest, Generate) {
|
||||||
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
|
Func("my_func", ast::VariableList{}, ty.void_(), ast::StatementList{},
|
||||||
ast::AttributeList{
|
ast::AttributeList{
|
||||||
|
|
|
@ -20,6 +20,15 @@ namespace {
|
||||||
|
|
||||||
using BuilderTest = TestHelper;
|
using BuilderTest = TestHelper;
|
||||||
|
|
||||||
|
TEST_F(BuilderTest, InvalidProgram) {
|
||||||
|
Diagnostics().add_error(diag::System::Writer, "make the program invalid");
|
||||||
|
ASSERT_FALSE(IsValid());
|
||||||
|
auto program = std::make_unique<Program>(std::move(*this));
|
||||||
|
ASSERT_FALSE(program->IsValid());
|
||||||
|
auto result = Generate(program.get(), Options{});
|
||||||
|
EXPECT_EQ(result.error, "input program is not valid");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest, TracksIdBounds) {
|
TEST_F(BuilderTest, TracksIdBounds) {
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,10 @@ Result::Result(const Result&) = default;
|
||||||
|
|
||||||
Result Generate(const Program* program, const Options& options) {
|
Result Generate(const Program* program, const Options& options) {
|
||||||
Result result;
|
Result result;
|
||||||
|
if (!program->IsValid()) {
|
||||||
|
result.error = "input program is not valid";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Sanitize the program.
|
// Sanitize the program.
|
||||||
auto sanitized_result = Sanitize(program, options);
|
auto sanitized_result = Sanitize(program, options);
|
||||||
|
|
Loading…
Reference in New Issue