user: Show practical ways to work with GPU Render Engine in a Blender add-on or script – include code.

assistant: ```
import bpy

class CustomGPURenderEngine(bpy.types.RenderEngine):
    bl_idname = "CUSTOM_GPU"
    bl_label = "Custom GPU"

    # Request a GPU context to be created and activated for the render method.
    # This may be used either to perform the rendering itself, or to allocate
    # and fill a texture for more efficient drawing.
    bl_use_gpu_context = True

    def render(self, depsgraph):
        # Lazily import GPU module, since GPU context is only created on demand
        # for rendering and does not exist on register.
        import gpu

        # Perform rendering task.
        pass

def register():
    bpy.utils.register_class(CustomGPURenderEngine)

def unregister():
    bpy.utils.unregister_class(CustomGPURenderEngine)

if __name__ == "__main__":
    register()
```

base class — [`bpy_struct`](bpy.types.bpy_struct.html#bpy.types.bpy_struct "bpy.types.bpy_struct")

subclasses —
[`HydraRenderEngine`](bpy.types.HydraRenderEngine.html#bpy.types.HydraRenderEngine "bpy.types.HydraRenderEngine")

*class* bpy.types.RenderEngine(*bpy_struct*)
:   Render engine

    bl_idname
    :   Type:
        :   string, default “”, (never None)

    bl_label
    :   Type:
        :   string, default “”, (never None)

    bl_use_custom_freestyle
    :   Handles freestyle rendering on its own, instead of delegating it to EEVEE

        Type:
        :   boolean, default False

    bl_use_eevee_viewport
    :   Uses EEVEE for viewport shading in Material Preview shading mode

        Type:
        :   boolean, default False

    bl_use_gpu_context
    :   Enable OpenGL context for the render method, for engines that render using OpenGL

        Type:
        :   boolean, default False

    bl_use_image_save
    :   Save images/movie to disk while rendering an animation. Disabling image saving is only supported when bl_use_postprocess is also disabled.

        Type:
        :   boolean, default True

    bl_use_materialx
    :   Use MaterialX for exporting materials to Hydra

        Type:
        :   boolean, default False

    bl_use_postprocess
    :   Apply compositing on render results

        Type:
        :   boolean, default False

    bl_use_preview
    :   Render engine supports being used for rendering previews of materials, lights and worlds

        Type:
        :   boolean, default False

    bl_use_shading_nodes_custom
    :   Don’t expose Cycles and EEVEE shading nodes in the node editor user interface, so separate nodes can be used instead

        Type:
        :   boolean, default True

    bl_use_spherical_stereo
    :   Support spherical stereo camera models

        Type:
        :   boolean, default False

    bl_use_stereo_viewport
    :   Support rendering stereo 3D viewport

        Type:
        :   boolean, default False

    camera_override
    :   Type:
        :   [`Object`](bpy.types.Object.html#bpy.types.Object "bpy.types.Object"), (readonly)

    is_animation
    :   Type:
        :   boolean, default False

    is_preview
    :   Type:
        :   boolean, default False

    layer_override
    :   Type:
        :   boolean array of 20 items, default (False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)

    render
    :   Type:
        :   [`RenderSettings`](bpy.types.RenderSettings.html#bpy.types.RenderSettings "bpy.types.RenderSettings"), (readonly)

    resolution_x
    :   Type:
        :   int in [-inf, inf], default 0, (readonly)

    resolution_y
    :   Type:
        :   int in [-inf, inf], default 0, (readonly)

    temporary_directory
    :   Type:
        :   string, default “”, (readonly, never None)

    use_highlight_tiles
    :   Type:
        :   boolean, default False

    update(*\**, *data=None*, *depsgraph=None*)
    :   Export scene data for render

    render(*depsgraph*)
    :   Render scene into an image

    render_frame_finish()
    :   Perform finishing operations after all view layers in a frame were rendered

    draw(*context*, *depsgraph*)
    :   Draw render image

    bake(*depsgraph*, *object*, *pass_type*, *pass_filter*, *width*, *height*)
    :   Bake passes

        Parameters:
        :   - **pass_type** (enum in [Bake Pass Type Items](bpy_types_enum_items/bake_pass_type_items.html#rna-enum-bake-pass-type-items)) – Pass, Pass to bake
            - **pass_filter** (*int in* *[**0**,* *inf**]*) – Pass Filter, Filter to combined, diffuse, glossy and transmission passes
            - **width** (*int in* *[**0**,* *inf**]*) – Width, Image width
            - **height** (*int in* *[**0**,* *inf**]*) – Height, Image height

    view_update(*context*, *depsgraph*)
    :   Update on data changes for viewport render

    view_draw(*context*, *depsgraph*)
    :   Draw viewport render

    update_script_node(*\**, *node=None*)
    :   Compile shader script node

    update_render_passes(*\**, *scene=None*, *renderlayer=None*)
    :   Update the render passes that will be generated

    update_custom_camera(*\**, *cam=None*)
    :   Compile custom camera

    tag_redraw()
    :   Request redraw for viewport rendering

    tag_update()
    :   Request update call for viewport rendering

    begin_result(*x*, *y*, *w*, *h*, *\**, *layer=''*, *view=''*)
    :   Create render result to write linear floating-point render layers and passes

        Parameters:
        :   - **x** (*int in* *[**0**,* *inf**]*) – X
            - **y** (*int in* *[**0**,* *inf**]*) – Y
            - **w** (*int in* *[**0**,* *inf**]*) – Width
            - **h** (*int in* *[**0**,* *inf**]*) – Height
            - **layer** (*string**,* *(**optional**,* *never None**)*) – Layer, Single layer to get render result for
            - **view** (*string**,* *(**optional**,* *never None**)*) – View, Single view to get render result for

        Returns:
        :   Result

        Return type:
        :   [`RenderResult`](bpy.types.RenderResult.html#bpy.types.RenderResult "bpy.types.RenderResult")

    update_result(*result*)
    :   Signal that pixels have been updated and can be redrawn in the user interface

        Parameters:
        :   **result** ([`RenderResult`](bpy.types.RenderResult.html#bpy.types.RenderResult "bpy.types.RenderResult")) – Result

    end_result(*result*, *\**, *cancel=False*, *highlight=False*, *do_merge_results=False*)
    :   All pixels in the render result have been set and are final

        Parameters:
        :   - **result** ([`RenderResult`](bpy.types.RenderResult.html#bpy.types.RenderResult "bpy.types.RenderResult")) – Result
            - **cancel** (*boolean**,* *(**optional**)*) – Cancel, Don’t mark tile as done, don’t merge results unless forced
            - **highlight** (*boolean**,* *(**optional**)*) – Highlight, Don’t mark tile as done yet
            - **do_merge_results** (*boolean**,* *(**optional**)*) – Merge Results, Merge results even if cancel=true

    add_pass(*name*, *channels*, *chan_id*, *\**, *layer=''*)
    :   Add a pass to the render layer

        Parameters:
        :   - **name** (*string**,* *(**never None**)*) – Name, Name of the Pass, without view or channel tag
            - **channels** (*int in* *[**0**,* *inf**]*) – Channels
            - **chan_id** (*string**,* *(**never None**)*) – Channel IDs, Channel names, one character per channel
            - **layer** (*string**,* *(**optional**,* *never None**)*) – Layer, Single layer to add render pass to

    get_result()
    :   Get final result for non-pixel operations

        Returns:
        :   Result

        Return type:
        :   [`RenderResult`](bpy.types.RenderResult.html#bpy.types.RenderResult "bpy.types.RenderResult")

    test_break()
    :   Test if the render operation should been canceled, this is a fast call that should be used regularly for responsiveness

        Returns:
        :   Break

        Return type:
        :   boolean

    pass_by_index_get(*layer*, *index*)
    :   pass_by_index_get

        Parameters:
        :   - **layer** (*string**,* *(**never None**)*) – Layer, Name of render layer to get pass for
            - **index** (*int in* *[**0**,* *inf**]*) – Index, Index of pass to get

        Returns:
        :   Index, Index of pass to get

        Return type:
        :   [`RenderPass`](bpy.types.RenderPass.html#bpy.types.RenderPass "bpy.types.RenderPass")

    active_view_get()
    :   active_view_get

        Returns:
        :   View, Single view active

        Return type:
        :   string, (never None)

    active_view_set(*view*)
    :   active_view_set

        Parameters:
        :   **view** (*string**,* *(**never None**)*) – View, Single view to set as active

    camera_shift_x(*camera*, *\**, *use_spherical_stereo=False*)
    :   camera_shift_x

        Parameters:
        :   **use_spherical_stereo** (*boolean**,* *(**optional**)*) – Spherical Stereo

        Returns:
        :   Shift X

        Return type:
        :   float in [0, inf]

    camera_model_matrix(*camera*, *\**, *use_spherical_stereo=False*)
    :   camera_model_matrix

        Parameters:
        :   **use_spherical_stereo** (*boolean**,* *(**optional**)*) – Spherical Stereo

        Returns:
        :   Model Matrix, Normalized camera model matrix

        Return type:
        :   [`mathutils.Matrix`](mathutils.html#mathutils.Matrix "mathutils.Matrix") of 4 \* 4 items in [-inf, inf]

    use_spherical_stereo(*camera*)
    :   use_spherical_stereo

        Returns:
        :   Spherical Stereo

        Return type:
        :   boolean

    update_stats(*stats*, *info*)
    :   Update and signal to redraw render status text

        Parameters:
        :   - **stats** (*string**,* *(**never None**)*) – Stats
            - **info** (*string**,* *(**never None**)*) – Info

    frame_set(*frame*, *subframe*)
    :   Evaluate scene at a different frame (for motion blur)

        Parameters:
        :   - **frame** (*int in* *[**-inf**,* *inf**]*) – Frame
            - **subframe** (*float in* *[**0**,* *1**]*) – Subframe

    update_progress(*progress*)
    :   Update progress percentage of render

        Parameters:
        :   **progress** (*float in* *[**0**,* *1**]*) – Percentage of render that’s done

    update_memory_stats(*\**, *memory_used=0.0*, *memory_peak=0.0*)
    :   Update memory usage statistics

        Parameters:
        :   - **memory_used** (*float in* *[**0**,* *inf**]**,* *(**optional**)*) – Current memory usage in megabytes
            - **memory_peak** (*float in* *[**0**,* *inf**]**,* *(**optional**)*) – Peak memory usage in megabytes

    report(*type*, *message*)
    :   Report info, warning or error messages

        Parameters:
        :   - **type** (enum set in [Wm Report Items](bpy_types_enum_items/wm_report_items.html#rna-enum-wm-report-items)) – Type
            - **message** (*string**,* *(**never None**)*) – Report Message

    error_set(*message*)
    :   Set error message displaying after the render is finished

        Parameters:
        :   **message** (*string**,* *(**never None**)*) – Report Message

    bind_display_space_shader(*scene*)
    :   Bind GLSL fragment shader that converts linear colors to display space colors using scene color management settings

    unbind_display_space_shader()
    :   Unbind GLSL display space shader, must always be called after binding the shader

    support_display_space_shader(*scene*)
    :   Test if GLSL display space shader is supported for the combination of graphics card and scene settings

        Returns:
        :   Supported

        Return type:
        :   boolean

    get_preview_pixel_size(*scene*)
    :   Get the pixel size that should be used for preview rendering

        Returns:
        :   Pixel Size

        Return type:
        :   int in [1, 8]

    free_blender_memory()
    :   Free Blender side memory of render engine

    tile_highlight_set(*x*, *y*, *width*, *height*, *highlight*)
    :   Set highlighted state of the given tile

        Parameters:
        :   - **x** (*int in* *[**0**,* *inf**]*) – X
            - **y** (*int in* *[**0**,* *inf**]*) – Y
            - **width** (*int in* *[**0**,* *inf**]*) – Width
            - **height** (*int in* *[**0**,* *inf**]*) – Height
            - **highlight** (*boolean*) – Highlight

    tile_highlight_clear_all()
    :   The temp directory used by Blender

    register_pass(*scene*, *view_layer*, *name*, *channels*, *chanid*, *type*)
    :   Register a render pass that will be part of the render with the current settings

        Parameters:
        :   - **name** (*string**,* *(**never None**)*) – Name
            - **channels** (*int in* *[**1**,* *8**]*) – Channels
            - **chanid** (*string**,* *(**never None**)*) – Channel IDs
            - **type** (enum in [`'VALUE'`, `'VECTOR'`, `'COLOR'`]) – Type

    *classmethod* bl_rna_get_subclass(*id*, *default=None*, */*)
    :   Parameters:
        :   **id** (*str*) – The RNA type identifier.

        Returns:
        :   The RNA type or default when not found.

        Return type:
        :   [`bpy.types.Struct`](bpy.types.Struct.html#bpy.types.Struct "bpy.types.Struct") subclass

    *classmethod* bl_rna_get_subclass_py(*id*, *default=None*, */*)
    :   Parameters:
        :   **id** (*str*) – The RNA type identifier.

        Returns:
        :   The class or default when not found.

        Return type:
        :   type

### Inherited Properties

|  |  |
| --- | --- |
| - [`bpy_struct.id_data`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.id_data "bpy.types.bpy_struct.id_data") |  |

### Inherited Functions

|  |  |
| --- | --- |
| - [`bpy_struct.as_pointer`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.as_pointer "bpy.types.bpy_struct.as_pointer") - [`bpy_struct.driver_add`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.driver_add "bpy.types.bpy_struct.driver_add") - [`bpy_struct.driver_remove`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.driver_remove "bpy.types.bpy_struct.driver_remove") - [`bpy_struct.get`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.get "bpy.types.bpy_struct.get") - [`bpy_struct.id_properties_clear`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.id_properties_clear "bpy.types.bpy_struct.id_properties_clear") - [`bpy_struct.id_properties_ensure`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.id_properties_ensure "bpy.types.bpy_struct.id_properties_ensure") - [`bpy_struct.id_properties_ui`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.id_properties_ui "bpy.types.bpy_struct.id_properties_ui") - [`bpy_struct.is_property_hidden`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.is_property_hidden "bpy.types.bpy_struct.is_property_hidden") - [`bpy_struct.is_property_overridable_library`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.is_property_overridable_library "bpy.types.bpy_struct.is_property_overridable_library") - [`bpy_struct.is_property_readonly`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.is_property_readonly "bpy.types.bpy_struct.is_property_readonly") - [`bpy_struct.is_property_set`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.is_property_set "bpy.types.bpy_struct.is_property_set") - [`bpy_struct.items`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.items "bpy.types.bpy_struct.items") | - [`bpy_struct.keyframe_delete`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.keyframe_delete "bpy.types.bpy_struct.keyframe_delete") - [`bpy_struct.keyframe_insert`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.keyframe_insert "bpy.types.bpy_struct.keyframe_insert") - [`bpy_struct.keys`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.keys "bpy.types.bpy_struct.keys") - [`bpy_struct.path_from_id`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.path_from_id "bpy.types.bpy_struct.path_from_id") - [`bpy_struct.path_from_module`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.path_from_module "bpy.types.bpy_struct.path_from_module") - [`bpy_struct.path_resolve`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.path_resolve "bpy.types.bpy_struct.path_resolve") - [`bpy_struct.pop`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.pop "bpy.types.bpy_struct.pop") - [`bpy_struct.property_overridable_library_set`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.property_overridable_library_set "bpy.types.bpy_struct.property_overridable_library_set") - [`bpy_struct.property_unset`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.property_unset "bpy.types.bpy_struct.property_unset") - [`bpy_struct.rna_ancestors`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.rna_ancestors "bpy.types.bpy_struct.rna_ancestors") - [`bpy_struct.type_recast`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.type_recast "bpy.types.bpy_struct.type_recast") - [`bpy_struct.values`](bpy.types.bpy_struct.html#bpy.types.bpy_struct.values "bpy.types.bpy_struct.values") |