Add renderer texture usage contract
This commit is contained in:
@@ -101,8 +101,8 @@ pp::foundation::Status RecordingCommandContext::begin_render_pass(
|
||||
}
|
||||
|
||||
active_target_ = target.color_desc();
|
||||
if (!active_target_.render_target) {
|
||||
return pp::foundation::Status::invalid_argument("render target texture must be flagged as render_target");
|
||||
if (!has_texture_usage(active_target_.usage, TextureUsage::render_target)) {
|
||||
return pp::foundation::Status::invalid_argument("render target texture must allow render_target usage");
|
||||
}
|
||||
|
||||
const auto size_status = texture_byte_size(active_target_);
|
||||
@@ -256,6 +256,10 @@ pp::foundation::Status RecordingCommandContext::bind_texture(
|
||||
}
|
||||
|
||||
const auto desc = texture.desc();
|
||||
if (!has_texture_usage(desc.usage, TextureUsage::sampled)) {
|
||||
return pp::foundation::Status::invalid_argument("bound texture must allow sampled usage");
|
||||
}
|
||||
|
||||
const auto size_status = texture_byte_size(desc);
|
||||
if (!size_status.ok()) {
|
||||
return size_status.status();
|
||||
@@ -351,6 +355,10 @@ pp::foundation::Status RecordingCommandContext::read_texture(
|
||||
}
|
||||
|
||||
const auto desc = texture.desc();
|
||||
if (!has_texture_usage(desc.usage, TextureUsage::readback_source)) {
|
||||
return pp::foundation::Status::invalid_argument("readback texture must allow readback_source usage");
|
||||
}
|
||||
|
||||
const auto bytes = readback_byte_size(desc, region);
|
||||
if (!bytes) {
|
||||
return bytes.status();
|
||||
@@ -379,6 +387,10 @@ pp::foundation::Status RecordingCommandContext::upload_texture(
|
||||
}
|
||||
|
||||
const auto desc = texture.desc();
|
||||
if (!has_texture_usage(desc.usage, TextureUsage::upload_destination)) {
|
||||
return pp::foundation::Status::invalid_argument("texture upload destination must allow upload_destination usage");
|
||||
}
|
||||
|
||||
const auto bytes = readback_byte_size(desc, region);
|
||||
if (!bytes) {
|
||||
return bytes.status();
|
||||
@@ -560,6 +572,11 @@ const char* RecordingRenderDevice::backend_name() const noexcept
|
||||
pp::foundation::Result<std::unique_ptr<ITexture2D>> RecordingRenderDevice::create_texture(
|
||||
TextureDesc desc) noexcept
|
||||
{
|
||||
const auto desc_status = validate_texture_desc(desc);
|
||||
if (!desc_status.ok()) {
|
||||
return pp::foundation::Result<std::unique_ptr<ITexture2D>>::failure(desc_status);
|
||||
}
|
||||
|
||||
const auto bytes = texture_byte_size(desc);
|
||||
if (!bytes.ok()) {
|
||||
return pp::foundation::Result<std::unique_ptr<ITexture2D>>::failure(bytes.status());
|
||||
@@ -571,9 +588,14 @@ pp::foundation::Result<std::unique_ptr<ITexture2D>> RecordingRenderDevice::creat
|
||||
pp::foundation::Result<std::unique_ptr<IRenderTarget>> RecordingRenderDevice::create_render_target(
|
||||
TextureDesc color_desc) noexcept
|
||||
{
|
||||
if (!color_desc.render_target) {
|
||||
if (!has_texture_usage(color_desc.usage, TextureUsage::render_target)) {
|
||||
return pp::foundation::Result<std::unique_ptr<IRenderTarget>>::failure(
|
||||
pp::foundation::Status::invalid_argument("render target texture must be flagged as render_target"));
|
||||
pp::foundation::Status::invalid_argument("render target texture must allow render_target usage"));
|
||||
}
|
||||
|
||||
const auto desc_status = validate_texture_desc(color_desc);
|
||||
if (!desc_status.ok()) {
|
||||
return pp::foundation::Result<std::unique_ptr<IRenderTarget>>::failure(desc_status);
|
||||
}
|
||||
|
||||
const auto bytes = texture_byte_size(color_desc);
|
||||
|
||||
Reference in New Issue
Block a user