Skip to content

Commit

Permalink
fbsource//xplat/graphics/igl/public/shell/renderSessions [A]
Browse files Browse the repository at this point in the history
Reviewed By: nlutsenko

Differential Revision: D69432617

fbshipit-source-id: 35b3fbf4d628653be4c7e4ade3a71da92aa7b22b
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Feb 11, 2025
1 parent 119b408 commit fc003b2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
42 changes: 21 additions & 21 deletions shell/renderSessions/GPUStressSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ layout(push_constant) uniform PushConstants {
})";
}

std::unique_ptr<IShaderStages> getShaderStagesForBackend(igl::IDevice& device) noexcept {
std::unique_ptr<IShaderStages> getShaderStagesForBackend(IDevice& device) noexcept {
const bool bMultiView = device.hasFeature(DeviceFeatures::Multiview);
switch (device.getBackendType()) {
// @fb-only
Expand Down Expand Up @@ -709,11 +709,11 @@ void GPUStressSession::setModelViewMatrix(float angle,
}

void GPUStressSession::initState(const igl::SurfaceTextures& surfaceTextures) {
igl::Result ret;
Result ret;

// TODO: fix framebuffers so you can update the resolve texture
if (framebuffer_ == nullptr) {
igl::FramebufferDesc framebufferDesc;
FramebufferDesc framebufferDesc;
framebufferDesc.colorAttachments[0].texture = surfaceTextures.color;
framebufferDesc.depthAttachment.texture = surfaceTextures.depth;
framebufferDesc.mode = surfaceTextures.color->getNumLayers() > 1 ? FramebufferMode::Stereo
Expand Down Expand Up @@ -796,7 +796,7 @@ void GPUStressSession::initState(const igl::SurfaceTextures& surfaceTextures) {
}

void GPUStressSession::drawCubes(const igl::SurfaceTextures& surfaceTextures,
std::shared_ptr<igl::IRenderCommandEncoder> commands) {
std::shared_ptr<IRenderCommandEncoder> commands) {
static float angle = 0.0f;
static int frameCount = 0;
frameCount++;
Expand Down Expand Up @@ -861,20 +861,20 @@ void GPUStressSession::drawCubes(const igl::SurfaceTextures& surfaceTextures,
iglu::ManagedUniformBufferInfo info;
info.index = 1;
info.length = sizeof(VertexFormat);
info.uniforms = std::vector<igl::UniformDesc>{
igl::UniformDesc{"projectionMatrix",
-1,
igl::UniformType::Mat4x4,
1,
offsetof(VertexFormat, projectionMatrix),
0},
igl::UniformDesc{"modelViewMatrix",
-1,
igl::UniformType::Mat4x4,
1,
offsetof(VertexFormat, modelViewMatrix),
0},
igl::UniformDesc{
info.uniforms = std::vector<UniformDesc>{
UniformDesc{"projectionMatrix",
-1,
igl::UniformType::Mat4x4,
1,
offsetof(VertexFormat, projectionMatrix),
0},
UniformDesc{"modelViewMatrix",
-1,
igl::UniformType::Mat4x4,
1,
offsetof(VertexFormat, modelViewMatrix),
0},
UniformDesc{
"scaleZ", -1, igl::UniformType::Float, 1, offsetof(VertexFormat, scaleZ), 0}};

vertUniformBuffer = std::make_shared<iglu::ManagedUniformBuffer>(device, info);
Expand All @@ -889,7 +889,7 @@ void GPUStressSession::drawCubes(const igl::SurfaceTextures& surfaceTextures,
}
}

void GPUStressSession::update(igl::SurfaceTextures surfaceTextures) noexcept {
void GPUStressSession::update(SurfaceTextures surfaceTextures) noexcept {
auto& device = getPlatform().getDevice();
if (!isDeviceCompatible(device)) {
return;
Expand All @@ -910,10 +910,10 @@ void GPUStressSession::update(igl::SurfaceTextures surfaceTextures) noexcept {

// Command buffers (1-N per thread): create, submit and forget
auto buffer = commandQueue_->createCommandBuffer(CommandBufferDesc{}, nullptr);
const std::shared_ptr<igl::IRenderCommandEncoder> commands =
const std::shared_ptr<IRenderCommandEncoder> commands =
buffer->createRenderCommandEncoder(renderPass_, framebuffer_);

igl::FramebufferDesc framebufferDesc;
FramebufferDesc framebufferDesc;
framebufferDesc.colorAttachments[0].texture = framebuffer_->getColorAttachment(0);
framebufferDesc.depthAttachment.texture = framebuffer_->getDepthAttachment();

Expand Down
24 changes: 12 additions & 12 deletions shell/renderSessions/HelloOpenXRSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ std::string getVulkanVertexShaderSource(bool stereoRendering) {
}

[[nodiscard]] std::unique_ptr<IShaderStages> getShaderStagesForBackend(
igl::IDevice& device,
IDevice& device,
const iglu::ShaderCross& shaderCross,
bool stereoRendering) noexcept {
switch (device.getBackendType()) {
Expand All @@ -118,7 +118,7 @@ std::string getVulkanVertexShaderSource(bool stereoRendering) {
"",
nullptr);
case igl::BackendType::OpenGL: {
igl::Result res;
Result res;
const auto vs = shaderCross.crossCompileFromVulkanSource(
getVulkanVertexShaderSource(stereoRendering).c_str(), igl::ShaderStage::Vertex, &res);
IGL_DEBUG_ASSERT(res.isOk(), res.message.c_str());
Expand Down Expand Up @@ -276,7 +276,7 @@ void HelloOpenXRSession::updateUniformBlock() {
ub_.scaleZ = scaleZ;
}

void HelloOpenXRSession::update(igl::SurfaceTextures surfaceTextures) noexcept {
void HelloOpenXRSession::update(SurfaceTextures surfaceTextures) noexcept {
auto& device = getPlatform().getDevice();
if (!isDeviceCompatible(device)) {
return;
Expand All @@ -287,9 +287,9 @@ void HelloOpenXRSession::update(igl::SurfaceTextures surfaceTextures) noexcept {
IGL_DEBUG_ASSERT(!shellParams().viewParams.empty());
const auto viewIndex = shellParams().viewParams[0].viewIndex;

igl::Result ret;
Result ret;
if (framebuffer_[viewIndex] == nullptr) {
igl::FramebufferDesc framebufferDesc;
FramebufferDesc framebufferDesc;
framebufferDesc.colorAttachments[0].texture = surfaceTextures.color;
framebufferDesc.depthAttachment.texture = surfaceTextures.depth;

Expand Down Expand Up @@ -323,35 +323,35 @@ void HelloOpenXRSession::update(igl::SurfaceTextures surfaceTextures) noexcept {

// Command buffers (1-N per thread): create, submit and forget
auto buffer = commandQueue_->createCommandBuffer(CommandBufferDesc{}, nullptr);
const std::shared_ptr<igl::IRenderCommandEncoder> commands =
const std::shared_ptr<IRenderCommandEncoder> commands =
buffer->createRenderCommandEncoder(renderPass_, framebuffer_[viewIndex]);
commands->pushDebugGroupLabel("HelloOpenXRSession Commands", igl::Color(0.0f, 1.0f, 0.0f));
commands->pushDebugGroupLabel("HelloOpenXRSession Commands", Color(0.0f, 1.0f, 0.0f));

commands->bindVertexBuffer(0, *vb0_);

iglu::ManagedUniformBufferInfo info;
info.index = 1;
info.length = sizeof(UniformBlock);
info.uniforms = std::vector<igl::UniformDesc>{
igl::UniformDesc{
info.uniforms = std::vector<UniformDesc>{
UniformDesc{
"modelMatrix", -1, igl::UniformType::Mat4x4, 1, offsetof(UniformBlock, modelMatrix), 0},
igl::UniformDesc{
UniformDesc{
"viewProjectionMatrix",
-1,
igl::UniformType::Mat4x4,
2,
offsetof(UniformBlock, viewProjectionMatrix),
sizeof(glm::mat4),
},
igl::UniformDesc{
UniformDesc{
"scaleZ",
-1,
igl::UniformType::Float,
1,
offsetof(UniformBlock, scaleZ),
0,
},
igl::UniformDesc{
UniformDesc{
"viewId",
-1,
igl::UniformType::Int,
Expand Down
5 changes: 3 additions & 2 deletions shell/renderSessions/HelloOpenXRSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ struct UniformBlock {

class HelloOpenXRSession : public RenderSession {
public:
HelloOpenXRSession(std::shared_ptr<Platform> platform) : RenderSession(std::move(platform)) {}
explicit HelloOpenXRSession(std::shared_ptr<Platform> platform) :
RenderSession(std::move(platform)) {}
void initialize() noexcept override;
void update(igl::SurfaceTextures surfaceTextures) noexcept override;
void update(SurfaceTextures surfaceTextures) noexcept override;

private:
std::shared_ptr<ICommandQueue> commandQueue_;
Expand Down

0 comments on commit fc003b2

Please sign in to comment.