-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image file writing, with test. #255
Merged
lilike-adsk
merged 4 commits into
dev
from
tremblp/HYDRA-1405/hydra_disk_rendering_spike
Feb 25, 2025
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# ----------------------------------------------------------------------------- | ||
# sources | ||
# ----------------------------------------------------------------------------- | ||
target_sources(${TARGET_NAME} | ||
PRIVATE | ||
fvpImageBufferWriter.cpp | ||
fvpTextureBufferWriter.cpp | ||
fvpRenderBufferWriter.cpp | ||
fvpImageBufferWriterFactory.cpp | ||
) | ||
|
||
set(HEADERS | ||
fvpImageBufferWriter.h | ||
fvpTextureBufferWriter.h | ||
fvpRenderBufferWriter.h | ||
) | ||
|
||
# ----------------------------------------------------------------------------- | ||
# promoted headers | ||
# ----------------------------------------------------------------------------- | ||
mayaUsd_promoteHeaderList( | ||
HEADERS | ||
${HEADERS} | ||
BASEDIR | ||
${TARGET_NAME}/imageWriter | ||
) | ||
|
||
# ----------------------------------------------------------------------------- | ||
# install | ||
# ----------------------------------------------------------------------------- | ||
install(FILES ${HEADERS} | ||
DESTINATION | ||
${CMAKE_INSTALL_PREFIX}/include/flowViewport/imageWriter | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// Copyright 2025 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#include <flowViewport/imageWriter/fvpImageBufferWriter.h> | ||
|
||
#include <pxr/base/tf/scoped.h> | ||
#include <pxr/imaging/hdx/types.h> | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
std::string ImageBufferWriter::_fileName{}; | ||
|
||
bool ImageBufferWriter::ValidSource() const | ||
{ | ||
return ValidHandle() && | ||
(Width() != 0) && (Height() != 0) && | ||
(Format() != HioFormatInvalid); | ||
} | ||
|
||
bool ImageBufferWriter::Write(const std::string& fileName) | ||
{ | ||
if (!ValidSource()) { | ||
return false; | ||
} | ||
|
||
HioImage::StorageSpec storage; | ||
storage.width = Width(); | ||
storage.height = Height(); | ||
storage.format = Format(); | ||
storage.flipped = true; | ||
storage.data = Map(); | ||
|
||
if (!storage.data) { | ||
return false; | ||
} | ||
|
||
TfScoped unmapGuard([this](){ Unmap(); }); | ||
|
||
const auto image = HioImage::OpenForWriting(fileName); | ||
return image && image->Write(storage); | ||
} | ||
|
||
/* static */ | ||
bool ImageBufferWriter::Write( | ||
const PXR_NS::VtDictionary& args, | ||
const std::string& fileName, | ||
const PXR_NS::TfToken& aov | ||
) | ||
{ | ||
auto writer = Create(args, aov); | ||
return (writer ? writer->Write(fileName) : false); | ||
} | ||
|
||
/* static */ | ||
bool ImageBufferWriter::Write( | ||
const std::string& fileName, | ||
const HioImage::StorageSpec& storageSpec | ||
) | ||
{ | ||
if (!storageSpec.data) { | ||
return false; | ||
} | ||
|
||
const auto image = HioImage::OpenForWriting(fileName); | ||
return image && image->Write(storageSpec); | ||
} | ||
|
||
/* static */ | ||
void ImageBufferWriter::SetFileName(const std::string& fileName) | ||
{ | ||
_fileName = fileName; | ||
} | ||
|
||
/* static */ | ||
std::string ImageBufferWriter::GetFileName() | ||
{ | ||
return _fileName; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// | ||
// Copyright 2025 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef FVP_IMAGE_BUFFER_WRITER_H | ||
#define FVP_IMAGE_BUFFER_WRITER_H | ||
|
||
#include <flowViewport/api.h> | ||
|
||
#include <pxr/pxr.h> | ||
#include <pxr/imaging/hio/types.h> | ||
#include <pxr/imaging/hio/image.h> | ||
#include <pxr/imaging/hd/tokens.h> | ||
|
||
#include <memory> // shared_ptr | ||
#include <string> | ||
|
||
PXR_NAMESPACE_OPEN_SCOPE | ||
class HdEngine; | ||
class TfToken; | ||
class VtDictionary; | ||
PXR_NAMESPACE_CLOSE_SCOPE | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
/// \class ImageBufferWriter | ||
/// | ||
/// Base class for writing Hydra images to files. | ||
|
||
class ImageBufferWriter | ||
{ | ||
public: | ||
|
||
using Ptr = std::shared_ptr<ImageBufferWriter>; | ||
|
||
FVP_API | ||
virtual ~ImageBufferWriter() = default; | ||
|
||
//! Factory method to create an image buffer writer. | ||
FVP_API | ||
static Ptr Create( | ||
const PXR_NS::VtDictionary& args, | ||
const PXR_NS::TfToken& aov = PXR_NS::HdAovTokens->color | ||
); | ||
|
||
//! Create an image buffer writer and use it to write to the file | ||
//! path passed in as argument. Returns false if the file name is | ||
//! empty. | ||
//! \return true for success. | ||
FVP_API | ||
static bool Write( | ||
const PXR_NS::VtDictionary& args, | ||
const std::string& fileName, | ||
const PXR_NS::TfToken& aov = PXR_NS::HdAovTokens->color | ||
); | ||
|
||
//! Utility method to write the content of the image buffer | ||
//! described by the StorageSpec to the file path passed in as argument. | ||
//! \return true for success. | ||
FVP_API | ||
static bool Write( | ||
const std::string& fileName, | ||
const PXR_NS::HioImage::StorageSpec& storageSpec | ||
); | ||
|
||
//! Utility modifier and accessor for file name to be used when calling | ||
//! Write() overload which takes a file argument. Useful as a central | ||
//! storage location for a file name, mostly for testing purposes, as | ||
//! this is not thread-safe or multi-viewport ready. | ||
FVP_API | ||
static void SetFileName(const std::string& fileName); | ||
FVP_API | ||
static std::string GetFileName(); | ||
|
||
//! Write the content of the image buffer writer to the | ||
//! file path passed in as argument. | ||
//! \return true for success. | ||
FVP_API | ||
bool Write(const std::string& fileName); | ||
|
||
FVP_API | ||
virtual unsigned int Width() const = 0; | ||
FVP_API | ||
virtual unsigned int Height() const = 0; | ||
|
||
FVP_API | ||
virtual PXR_NS::HioFormat Format() const = 0; | ||
|
||
FVP_API | ||
bool ValidSource() const; | ||
|
||
FVP_API | ||
virtual bool ValidHandle() const = 0; | ||
|
||
FVP_API | ||
virtual void* Map() = 0; | ||
|
||
FVP_API | ||
virtual void Unmap() = 0; | ||
|
||
protected: | ||
|
||
FVP_API | ||
ImageBufferWriter() = default; | ||
|
||
private: | ||
|
||
static std::string _fileName; | ||
}; | ||
|
||
} | ||
|
||
#endif |
39 changes: 39 additions & 0 deletions
39
lib/flowViewport/imageWriter/fvpImageBufferWriterFactory.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// Copyright 2025 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#include <flowViewport/imageWriter/fvpTextureBufferWriter.h> | ||
#include <flowViewport/imageWriter/fvpRenderBufferWriter.h> | ||
|
||
#include <pxr/base/vt/dictionary.h> | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
/* static */ | ||
ImageBufferWriter::Ptr ImageBufferWriter::Create( | ||
const PXR_NS::VtDictionary& args, | ||
const PXR_NS::TfToken& aov | ||
) | ||
{ | ||
// Can't use ternary operator because of differing std::shared_ptr types. | ||
if (args.find("hgi") == args.end()) { | ||
return std::make_shared<RenderBufferWriter>(args, aov); | ||
} | ||
else { | ||
return std::make_shared<TextureBufferWriter>(args, aov); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// Copyright 2025 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#include <flowViewport/imageWriter/fvpRenderBufferWriter.h> | ||
|
||
#include <pxr/imaging/hdSt/hioConversions.h> | ||
#include <pxr/imaging/hdx/taskController.h> | ||
#include <pxr/imaging/hd/renderBuffer.h> | ||
#include <pxr/base/vt/dictionary.h> | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
namespace { | ||
|
||
HdRenderBuffer* getRenderBuffer( | ||
const VtDictionary& args, | ||
const PXR_NS::TfToken& aovToken | ||
) | ||
{ | ||
auto found = args.find("taskController"); | ||
if (found == args.end() || !found->second.IsHolding<HdxTaskController*>()) { | ||
return nullptr; | ||
} | ||
|
||
auto taskController = found->second.Get<HdxTaskController*>(); | ||
return taskController ? taskController->GetRenderOutput(aovToken) : nullptr; | ||
} | ||
|
||
} | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
RenderBufferWriter::RenderBufferWriter( | ||
const PXR_NS::VtDictionary& args, | ||
const TfToken& aov | ||
) : ImageBufferWriter(), _renderBuffer(getRenderBuffer(args, aov)) | ||
{} | ||
|
||
unsigned int RenderBufferWriter::Width() const | ||
{ | ||
return _renderBuffer ? _renderBuffer->GetWidth() : 0; | ||
} | ||
|
||
unsigned int RenderBufferWriter::Height() const | ||
{ | ||
return _renderBuffer ? _renderBuffer->GetHeight() : 0; | ||
} | ||
|
||
HioFormat RenderBufferWriter::Format() const | ||
{ | ||
return _renderBuffer ? HdStHioConversions::GetHioFormat( | ||
_renderBuffer->GetFormat()) : HioFormatInvalid; | ||
} | ||
|
||
bool RenderBufferWriter::ValidHandle() const | ||
{ | ||
return bool(_renderBuffer); | ||
} | ||
|
||
void* RenderBufferWriter::Map() | ||
{ | ||
return _renderBuffer ? _renderBuffer->Map() : nullptr; | ||
} | ||
|
||
void RenderBufferWriter::Unmap() | ||
{ | ||
if (_renderBuffer) { | ||
_renderBuffer->Unmap(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think it would be worth explaining more why you're looking for hgi andthe differences it will do unless it is explained somewhere else ?