Skip to content

Commit

Permalink
Change various calls to use raw pointer rather than ref pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
ccummingsNV committed Aug 12, 2024
1 parent 952888c commit c298278
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/sgl/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,15 +673,15 @@ ref<MutableShaderObject> Device::create_mutable_shader_object(const ShaderProgra
return shader_object;
}

ref<MutableShaderObject> Device::create_mutable_shader_object(ref<const TypeLayoutReflection> type_layout)
ref<MutableShaderObject> Device::create_mutable_shader_object(const TypeLayoutReflection* type_layout)
{
return make_ref<MutableShaderObject>(ref<Device>(this), type_layout);
}

ref<MutableShaderObject> Device::create_mutable_shader_object(ReflectionCursor cursor)
{
SGL_CHECK(cursor.is_valid(), "Invalid reflection cursor");
return create_mutable_shader_object(cursor.type_layout());
return create_mutable_shader_object(cursor.type_layout().get());
}

ref<ComputePipeline> Device::create_compute_pipeline(ComputePipelineDesc desc)
Expand Down
2 changes: 1 addition & 1 deletion src/sgl/device/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class SGL_API Device : public Object {

ref<MutableShaderObject> create_mutable_shader_object(const ShaderProgram* shader_program);

ref<MutableShaderObject> create_mutable_shader_object(ref<const TypeLayoutReflection> type_layout);
ref<MutableShaderObject> create_mutable_shader_object(const TypeLayoutReflection* type_layout);

ref<MutableShaderObject> create_mutable_shader_object(ReflectionCursor cursor);

Expand Down
9 changes: 5 additions & 4 deletions src/sgl/device/reflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ ReflectionCursor::ReflectionCursor(ref<const EntryPointLayout> entry_point_layou
{
}

ReflectionCursor::ReflectionCursor(ref<const TypeLayoutReflection> type_layout)
ReflectionCursor::ReflectionCursor(const TypeLayoutReflection* type_layout)
: m_type_layout(type_layout)
, m_valid(m_type_layout != nullptr)
{
Expand All @@ -312,7 +312,8 @@ ReflectionCursor ReflectionCursor::find_field(std::string_view name) const
{
if (m_shader_program) {
// Try to find field in global variables.
if (auto global_field = ReflectionCursor(m_shader_program->layout()->globals_type_layout()).find_field(name);
if (auto global_field
= ReflectionCursor(m_shader_program->layout()->globals_type_layout().get()).find_field(name);
global_field.is_valid())
return global_field;
// Try to find an entry point.
Expand All @@ -324,7 +325,7 @@ ReflectionCursor ReflectionCursor::find_field(std::string_view name) const
// Try to find parameter in entry point.
for (uint32_t i = 0; i < m_entry_point_layout->parameter_count(); ++i) {
if (m_entry_point_layout->get_parameter_by_index(i)->name() == name)
return ReflectionCursor(m_entry_point_layout->get_parameter_by_index(i)->type_layout());
return ReflectionCursor(m_entry_point_layout->get_parameter_by_index(i)->type_layout().get());
}
} else if (m_type_layout) {
// If type is a constant buffer or parameter block, try to find field in element type.
Expand All @@ -336,7 +337,7 @@ ReflectionCursor ReflectionCursor::find_field(std::string_view name) const
int32_t field_index = type_layout->find_field_index_by_name(name.data(), name.data() + name.size());
if (field_index >= 0) {
ref<const VariableLayoutReflection> field_layout = type_layout->get_field_by_index(field_index);
return ReflectionCursor(field_layout->type_layout());
return ReflectionCursor(field_layout->type_layout().get());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sgl/device/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ class SGL_API ReflectionCursor {

ReflectionCursor(const ShaderProgram* shader_program);
ReflectionCursor(ref<const EntryPointLayout> entry_point_layout);
ReflectionCursor(ref<const TypeLayoutReflection> type_layout);
ReflectionCursor(const TypeLayoutReflection* type_layout);

ref<const TypeLayoutReflection> type_layout() const { return m_type_layout; }
ref<const TypeReflection> type() const { return m_type_layout->type(); }
Expand Down
16 changes: 8 additions & 8 deletions src/sgl/device/shader_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ ShaderCursor ShaderCursor::find_entry_point(uint32_t index) const
// Resource binding
//

inline bool is_parameter_block(ref<const TypeReflection> type)
inline bool is_parameter_block(const TypeReflection* type)
{
return type->kind() == TypeReflection::Kind::parameter_block;
}

inline bool is_resource_type(ref<const TypeReflection> type)
inline bool is_resource_type(const TypeReflection* type)
{
switch (type->kind()) {
case TypeReflection::Kind::constant_buffer:
Expand All @@ -325,7 +325,7 @@ inline bool is_resource_type(ref<const TypeReflection> type)
}
}

inline bool is_buffer_resource_type(ref<const TypeReflection> type)
inline bool is_buffer_resource_type(const TypeReflection* type)
{
switch (type->kind()) {
case TypeReflection::Kind::constant_buffer:
Expand All @@ -348,7 +348,7 @@ inline bool is_buffer_resource_type(ref<const TypeReflection> type)
}
}

inline bool is_texture_resource_type(ref<const TypeReflection> type)
inline bool is_texture_resource_type(const TypeReflection* type)
{
switch (type->kind()) {
case TypeReflection::Kind::resource:
Expand All @@ -367,22 +367,22 @@ inline bool is_texture_resource_type(ref<const TypeReflection> type)
}
}

inline bool is_sampler_type(ref<const TypeReflection> type)
inline bool is_sampler_type(const TypeReflection* type)
{
return type->kind() == TypeReflection::Kind::sampler_state;
}

inline bool is_shader_resource_type(ref<const TypeReflection> type)
inline bool is_shader_resource_type(const TypeReflection* type)
{
return type->resource_access() == TypeReflection::ResourceAccess::read;
}

inline bool is_unordered_access_type(ref<const TypeReflection> type)
inline bool is_unordered_access_type(const TypeReflection* type)
{
return type->resource_access() == TypeReflection::ResourceAccess::read_write;
}

inline bool is_acceleration_structure_resource_type(ref<const TypeReflection> type)
inline bool is_acceleration_structure_resource_type(const TypeReflection* type)
{
return type->kind() == TypeReflection::Kind::resource
&& type->resource_shape() == TypeReflection::ResourceShape::acceleration_structure;
Expand Down
2 changes: 1 addition & 1 deletion src/sgl/device/shader_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ MutableShaderObject::MutableShaderObject(ref<Device> device, const ShaderProgram
m_device->gfx_device()->createMutableRootShaderObject(shader_program->gfx_shader_program(), &m_shader_object);
}

MutableShaderObject::MutableShaderObject(ref<Device> device, ref<const TypeLayoutReflection> type_layout)
MutableShaderObject::MutableShaderObject(ref<Device> device, const TypeLayoutReflection* type_layout)
: ShaderObject(std::move(device), nullptr)
{
m_device->gfx_device()->createMutableShaderObjectFromTypeLayout(
Expand Down
2 changes: 1 addition & 1 deletion src/sgl/device/shader_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SGL_API MutableShaderObject : public ShaderObject {
public:
MutableShaderObject(ref<Device> device, gfx::IShaderObject* shader_object);
MutableShaderObject(ref<Device> device, const ShaderProgram* shader_program);
MutableShaderObject(ref<Device> device, ref<const TypeLayoutReflection> type_layout);
MutableShaderObject(ref<Device> device, const TypeLayoutReflection* type_layout);
~MutableShaderObject();

virtual ref<ShaderObject> get_entry_point(uint32_t index) override;
Expand Down

0 comments on commit c298278

Please sign in to comment.