Skip to content
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

fix Program from sh_string_type #103

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
name = "GLAbstraction"
uuid = "ca6e7d0a-b0c9-59ca-8aba-aebf11497e1c"
repo = "https://github.com/JuliaGL/GLAbstraction.jl.git"
version = "0.7.0"
version = "0.8.1"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
ModernGL = "66fc600b-dfda-50eb-8b99-91cfa97b1301"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
ThreadPools = "b189fb0b-2eb5-4ed4-bc0c-d34c51242431"

[compat]
FixedPointNumbers = "^0.8"
ModernGL = "^1"
StaticArrays = "^1"
ThreadPools = "^2"
julia = "^1"

[extras]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Expand All @@ -19,12 +28,5 @@ Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
FixedPointNumbers = "^0.8"
ModernGL = "^1"
StaticArrays = "^1"
ThreadPools = "^2"
julia = "^1"

[targets]
test = ["Test", "GeometryBasics", "GLFW", "ColorTypes", "Images", "LinearAlgebra", "Downloads"]
61 changes: 21 additions & 40 deletions src/AbstractGPUArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import Base: eltype
import Base: ndims
import Base: size

abstract type GPUArray{T, NDim} <: AbstractArray{T, NDim} end
abstract type GPUArray{T,NDim} <: AbstractArray{T,NDim} end

length(A::GPUArray) = prod(size(A))
eltype(b::GPUArray{T, NDim}) where {T, NDim} = T
eltype(b::GPUArray{T,NDim}) where {T,NDim} = T
endof(A::GPUArray) = length(A)
ndims(A::GPUArray{T, NDim}) where {T, NDim} = NDim
ndims(A::GPUArray{T,NDim}) where {T,NDim} = NDim
size(A::GPUArray) = (A.len,)
size(A::GPUArray, i::Integer) = i <= ndims(A) ? A.size[i] : 1

function checkdimensions(value::Array, ranges::Union{Integer, UnitRange}...)
array_size = size(value)
function checkdimensions(value::Array, ranges::Union{Integer,UnitRange}...)
array_size = size(value)
indexes_size = map(length, ranges)
(array_size != indexes_size) && throw(DimensionMismatch("asigning a $array_size to a $(indexes_size) location"))
true
Expand All @@ -33,26 +33,26 @@ function to_range(index)
@error "Indexing only defined for integers or ranges. Found: $val"
end
end
setindex!(A::GPUArray{T, N}, value::Union{T, Array{T, N}}) where {T, N} = (A[1] = value)
setindex!(A::GPUArray{T,N}, value::Union{T,Array{T,N}}) where {T,N} = (A[1] = value)

function setindex!(A::GPUArray{T, N}, value, indexes...) where {T, N}
function setindex!(A::GPUArray{T,N}, value, indexes...) where {T,N}
ranges = to_range(indexes)
v = isa(value, T) ? [value] : convert(Array{T,N}, value)
setindex!(A, v, ranges...)
nothing
end

setindex!(A::GPUArray{T, 2}, value::Vector{T}, i::Integer, range::UnitRange) where {T} =
(A[i, range] = reshape(value, (length(value),1)))
setindex!(A::GPUArray{T,2}, value::Vector{T}, i::Integer, range::UnitRange) where {T} =
(A[i, range] = reshape(value, (length(value), 1)))

function setindex!(A::GPUArray{T, N}, value::Array{T, N}, ranges::UnitRange...) where {T, N}
function setindex!(A::GPUArray{T,N}, value::Array{T,N}, ranges::UnitRange...) where {T,N}
checkbounds(A, ranges...)
checkdimensions(value, ranges...)
gpu_setindex!(A, value, ranges...)
nothing
end

function update!(A::GPUArray{T, N}, value::Array{T, N}) where {T, N}
function update!(A::GPUArray{T,N}, value::Array{T,N}) where {T,N}
if length(A) != length(value)
if isa(A, Buffer)
resize!(A, length(value))
Expand All @@ -62,37 +62,37 @@ function update!(A::GPUArray{T, N}, value::Array{T, N}) where {T, N}
@error "Dynamic resizing not implemented for $(typeof(A))"
end
end
dims = map(x->1:x, size(A))
dims = map(x -> 1:x, size(A))
A[dims...] = value
nothing
end

function getindex(A::GPUArray{T, N}, i::Int) where {T, N}
function getindex(A::GPUArray{T,N}, i::Int) where {T,N}
checkbounds(A, i)
gpu_getindex(A, i:i)[1] # not as bad as its looks, as so far gpu data must be loaded into an array anyways
end
function getindex(A::GPUArray{T, N}, ranges::UnitRange...) where {T, N}
function getindex(A::GPUArray{T,N}, ranges::UnitRange...) where {T,N}
checkbounds(A, ranges...)
gpu_getindex(A, ranges...)
end

resize!(A::GPUArray{T, NDim}, dims::Int...) where {T, NDim} = resize!(A, dims)
function resize!(A::GPUArray{T, NDim}, newdims::NTuple{NDim, Int}) where {T, NDim}
resize!(A::GPUArray{T,NDim}, dims::Int...) where {T,NDim} = resize!(A, dims)
function resize!(A::GPUArray{T,NDim}, newdims::NTuple{NDim,Int}) where {T,NDim}
newdims == size(A) && return A
gpu_resize!(A, newdims)
A
end


copy!(a::GPUArray, a_offset::Int, b::Vector, b_offset::Int, amount::Int) = _copy!(a, a_offset, b, b_offset, amount)
copy!(a::Vector, a_offset::Int, b::GPUArray, b_offset::Int, amount::Int) = _copy!(a, a_offset, b, b_offset, amount)
copy!(a::GPUArray, a_offset::Int, b::Vector, b_offset::Int, amount::Int) = _copy!(a, a_offset, b, b_offset, amount)
copy!(a::Vector, a_offset::Int, b::GPUArray, b_offset::Int, amount::Int) = _copy!(a, a_offset, b, b_offset, amount)
copy!(a::GPUArray, a_offset::Int, b::GPUArray, b_offset::Int, amount::Int) = _copy!(a, a_offset, b, b_offset, amount)

#don't overwrite Base.copy! with a::Vector, b::Vector
function _copy!(a::Union{Vector, GPUArray}, a_offset::Int, b::Union{Vector, GPUArray}, b_offset::Int, amount::Int)
function _copy!(a::Union{Vector,GPUArray}, a_offset::Int, b::Union{Vector,GPUArray}, b_offset::Int, amount::Int)
(amount <= 0) && return nothing
@assert a_offset > 0 && (a_offset-1) + amount <= length(a) "a_offset $a_offset, amount $amount, lengtha $(length(a))"
@assert b_offset > 0 && (b_offset-1) + amount <= length(b) "b_offset $b_offset, amount $amount, lengthb $(length(b))"
@assert a_offset > 0 && (a_offset - 1) + amount <= length(a) "a_offset $a_offset, amount $amount, lengtha $(length(a))"
@assert b_offset > 0 && (b_offset - 1) + amount <= length(b) "b_offset $b_offset, amount $amount, lengthb $(length(b))"
unsafe_copy!(a, a_offset, b, b_offset, amount)
return nothing
end
Expand All @@ -104,25 +104,6 @@ gpu_getindex(t) = @error "gpu_getindex not implemented for: $(typeof(t)). This h
gpu_setindex!(t) = @error "gpu_setindex! not implemented for: $(typeof(t)). This happens, when you call setindex! on an array, without implementing the GPUArray interface"
max_dim(t) = @error "max_dim not implemented for: $(typeof(t)). This happens, when you call setindex! on an array, without implementing the GPUArray interface"


# const BaseSerializer = if isdefined(Base, :AbstractSerializer)
# Base.AbstractSerializer
# elseif isdefined(Base, :SerializationState)
# Base.SerializationState
# else
# error("No Serialization type found. Probably unsupported Julia version")
# end

# function Base.serialize(s::BaseSerializer, t::T) where T<:GPUArray
# Base.serialize_type(s, T)
# serialize(s, Array(t))
# end
# function Base.deserialize(s::BaseSerializer, ::Type{T}) where T<:GPUArray
# A = deserialize(s)
# T(A)
# end


export data
export resize
export GPUArray
Expand Down
5 changes: 3 additions & 2 deletions src/GLAbstraction.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
module GLAbstraction

using ColorTypes
using ModernGL
using FixedPointNumbers
using Printf
using StaticArrays
using ThreadPools
using Base.Threads
using Logging

import FixedPointNumbers: N0f8, N0f16, N0f8, Normed

import Base: merge, resize!, similar, length, getindex, setindex!
import Base: merge, resize!, similar, length, getindex, setindex!

include("context.jl")

Expand Down Expand Up @@ -40,7 +42,6 @@ include("utils.jl")
include("buffer.jl")
include("texture.jl")
include("framebuffer.jl")
include("uniformbuffer.jl")
include("shader/uniforms.jl")
include("shader/shader.jl")
include("shader/program.jl")
Expand Down
Loading