def compute():
    #Create two input buffers and one for the output.
    buffer1, buffer1srv = createBufferAndView()
    buffer2, buffer2srv = createBufferAndView()
    bufferOut, bufferOutUav = createBufferAndView()
    bufferOut.resize(NUMITEMS)

    #Staging buffer which will be used to copy data
    #between GPU and CPU.
    stager = createStagingBuffer(INPUTDATA, CPU_ACCESS_WRITE | CPU_ACCESS_READ)
    buffer1.copy(stager)
    buffer2.copy(stager)

    #Load the effect and set buffers.
    effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "Compute.fx"))
    effect.set("buffer1", buffer1srv)
    effect.set("buffer2", buffer2srv)
    effect.set("bufferOut", bufferOutUav)
    effect.set("bufferSize", NUMITEMS)
    effect.apply(0, 0)

    compStart = time.clock()
    #Start the compute operation.
    device.dispatch(NUMITEMS, 1, 1)

    #Copy data back for CPU access.
    stager.copy(bufferOut)
    outputData = []
    with d3d11x.Mapper(stager, MAP_READ):
        outputData = stager[:]

    print("Compute shader took %f seconds" % (time.clock() - compStart))

    verifyResults(outputData)
Пример #2
0
 def build(self):
     effectName = self.effecName
     if not self.effecName:
         effectName = "marker.fx"
     effectPath = d3d11x.getResourceDir(".", "effects/marker.fx")
     self.effect = d3d11.Effect(effectPath)
     #Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
     #the pass's input signature is compatible with that combination.
     self.inputLayout = d3d11.InputLayout(g_vertexDesc, self.effect, 0, 0)
Пример #3
0
    def setDesc(self, desc):
        self.desc = desc

        effectPath = d3d11x.getResourceDir(".", self.desc.effect)
        self.effect = d3d11.Effect(effectPath)
        self.vertexDesc = self.desc.vtdesc

        print self.desc.effect, self.vertexDesc
        print self.effect
        #Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
        #the pass's input signature is compatible with that combination.
        self.inputLayout = d3d11.InputLayout(self.vertexDesc, self.effect, 0,
                                             0)
Пример #4
0
    def build(self):
        effectName = self.effecName
        if not self.effecName:
            effectName = "marker.fx"
        effectPath = d3d11x.getResourceDir(".", "effects/marker.fx")
        self.effect = d3d11.Effect(effectPath)
        #Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
        #the pass's input signature is compatible with that combination.
        self.inputLayout = d3d11.InputLayout(g_vertexDesc, self.effect, 0, 0)

        vertexData = []
        for i in xrange(self.gridx + 1):
            if i % 2 == 0:
                vertexData.append((0, 0, i * self.gridsize, 1, 1, 1, 1))
                vertexData.append(
                    (self.width, 0, i * self.gridsize, 1, 1, 1, 1))
            else:
                vertexData.append(
                    (self.width, 0, i * self.gridsize, 1, 1, 1, 1))
                vertexData.append((0, 0, i * self.gridsize, 1, 1, 1, 1))

        for i in xrange(self.gridy + 1):
            if self.height % 2 == 0:
                if i % 2 == 0:
                    vertexData.append(
                        (i * self.gridsize, 0, self.height, 1, 1, 1, 1))
                    vertexData.append((i * self.gridsize, 0, 0, 1, 1, 1, 1))
                else:
                    vertexData.append((i * self.gridsize, 0, 0, 1, 1, 1, 1))
                    vertexData.append(
                        (i * self.gridsize, 0, self.height, 1, 1, 1, 1))
            else:
                if i % 2 == 0:
                    vertexData.append(((self.width - i) * self.gridsize, 0,
                                       self.height, 1, 1, 1, 1))
                    vertexData.append(
                        ((self.width - i) * self.gridsize, 0, 0, 1, 1, 1, 1))
                else:
                    vertexData.append(
                        ((self.width - i) * self.gridsize, 0, 0, 1, 1, 1, 1))
                    vertexData.append(((self.width - i) * self.gridsize, 0,
                                       self.height, 1, 1, 1, 1))

        self.vertexBuffer = d3d11.Buffer(
            g_vertexDesc,
            vertexData,  # D3D11_SUBRESOURCE_DATA
            BIND_VERTEX_BUFFER,  # D3D11_BUFFER_DESC.BinadFlags
            USAGE_DYNAMIC,  # D3D11_BUFFER_DESC.Usage
            CPU_ACCESS_WRITE,  # D3D11_BUFFER_DESC.CPUAccessFlags
        )
    def __init__(self, parent, id, title, pos, size=(800, 600)):
        wx.Frame.__init__(self, parent, id, title, pos, size)

        self.mainpanel = wx.Panel(self, -1, size=(800, 600))
        self.mainpanel.SetAutoLayout(True)

        self.leftwindow = wx.Panel(self.mainpanel, -1, (10, 10), (380, 450))
        self.leftwindow.SetBackgroundColour(wx.WHITE)
        self.leftwindow.SetConstraints(
            anchors.LayoutAnchors(self.leftwindow, True, True, True, True))

        self.rightwindow = wx.Panel(self.mainpanel, -1, (400, 10), (380, 450))
        self.rightwindow.SetBackgroundColour(wx.WHITE)
        self.rightwindow.SetConstraints(
            anchors.LayoutAnchors(self.rightwindow, False, True, True, True))

        playvideo = wx.Button(self.mainpanel, -1,
                              "Play media on this window...", (500, 500))
        playvideo.SetConstraints(
            anchors.LayoutAnchors(playvideo, False, False, True, True))
        self.Bind(wx.EVT_BUTTON, self.playVideo, playvideo)

        #Create a DirectPython window from an existing wxPython window.
        tempWindow = d3d11.Window(handle=self.leftwindow.GetHandle())

        #Create our resources. Note that if the size of the window
        #changes, you should call self.device.reset().
        self.device = d3d11.Device(tempWindow, DRIVER_TYPE_WARP)
        self.effect = d3d11.Effect(
            d3d11x.getResourceDir("Effects", "Tutorial2.fx"))
        self.inputLayout = d3d11.InputLayout(vertexDesc, self.effect, 0, 0)
        self.vertexBuffer = d3d11.Buffer(vertexDesc, triangle,
                                         BIND_VERTEX_BUFFER)

        #We need to detach() the window. This means that it is up to
        #us (or wxPython) to mange the window from now on.
        tempWindow.detach()

        self.media = None

        self.Bind(wx.EVT_PAINT, self.onPaint)
        self.Bind(wx.EVT_TIMER, self.onTimer)
        self.Bind(wx.EVT_IDLE, self.onIdle)
        self.leftwindow.Bind(wx.EVT_SIZE, self.onSize)

        #Use a timer for rendering. It is not a very smooth
        #solution, you might want to tweak the time interval
        #or do something else, now it is jerky.
        self.timer = wx.Timer(self)
        self.timer.Start(10)
    def onCreate(self):
        self.renderTarget = None
        self.renderTargetView = None

        meshPath = d3d11x.getResourceDir("Mesh", "barrel.obj")
        self.mesh = d3d11x.Mesh(self.device, meshPath)
        self.mesh.textureView = self.loadTextureView("static-barrel.dds")

        self.skyBox = d3d11x.SkyBox(self.device)
        self.skyBox.textureView = self.loadTextureView("skybox-clear.dds")

        effectPath = d3d11x.getResourceDir("Effects", "SamplePostProcess.fx")
        self.postEffect = d3d11.Effect(effectPath)
        self.postInputLayout = d3d11.InputLayout(vertexLayoutDesc,
                                                 self.postEffect, 0, 0)

        #Vertex buffer for 2D stuff.
        self.vertexBuffer = d3d11.Buffer(vertexLayoutDesc, 32,
                                         BIND_VERTEX_BUFFER, USAGE_DYNAMIC,
                                         CPU_ACCESS_WRITE)
    def onCreate(self):
        self.heightmap = d3d11x.HeightMap(self.device, None, (32, 32),
                                          heightFunc, (2, 1, 2), (10, 10),
                                          False)
        self.heightmap.textureView = self.loadTextureView("ground-marble.dds")

        effectPath = d3d11x.getResourceDir("Effects", "SampleSprites.fx")
        self.spriteEffect = d3d11.Effect(effectPath)
        self.spriteInputLayout = d3d11.InputLayout(spriteLayoutDesc,
                                                   self.spriteEffect, 0, 0)
        self.spriteTexture = self.loadTextureView("misc-particle.dds")

        self.camera = d3d11x.Camera()

        #Create a dynamic vertex buffer for our sprites. Double the
        #size for shadow sprites.
        self.spriteBuffer = d3d11.Buffer(spriteLayoutDesc, POINT_COUNT * 2,
                                         BIND_VERTEX_BUFFER, USAGE_DYNAMIC,
                                         CPU_ACCESS_WRITE)

        self.points = []
Пример #8
0
    #("COLOR", 0, FORMAT_R32G32B32A32_FLOAT),
]

#Our triangle - three vertices with position and color. The layout must match 'vertexDesc'.
triangle = [
    (-5, 0, 0) + (1, 0, 0, 1),  #Red vertex.
    (0, 10, 0) + (0, 1, 0, 1),  #Green vertex.
    (5, 0, 0) + (0, 0, 1, 1),  #Blue vertex.
]

vertices = []
for p in cdata.Box:
    vertices.append((p[0], p[1], p[2], 1, 1, 1, 1))

#Effect for rendering. The file contains trivial vertex- and pixel-shader.
effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "simple.fx"))

#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
#the pass's input signature is compatible with that combination.
inputLayout = d3d11.InputLayout(vertexDesc, effect, 0, 0)

#Create a hardware buffer to hold our triangle.
vertexBuffer = d3d11.Buffer(vertexDesc, vertices, BIND_VERTEX_BUFFER)

#Precalculate view matrix. Eye position is (0, 5, -15) and it is looking at (0, 5, 0). (0, 1, 0) points up.
viewMatrix = d3d11.Matrix()
viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0))


def mainloop():
    while 1:
Пример #9
0
    #This is functionally same as above, only easier to read. I use the complex one now
    #so that you don't get confused when you encounter it in samples.
    #("POSITION", 0, FORMAT_R32G32B32_FLOAT),
    #("COLOR", 0, FORMAT_R32G32B32A32_FLOAT),
]

#Our triangle - three vertices with position and color. The layout must match 'vertexDesc'.
triangle = [
    (-5, 0, 0) + (1, 0, 0, 1),  #Red vertex.
    (0, 10, 0) + (0, 1, 0, 1),  #Green vertex.
    (5, 0, 0) + (0, 0, 1, 1),  #Blue vertex.
]

#Effect for rendering. The file contains trivial vertex- and pixel-shader.
effect = d3d11.Effect(d3d11x.getResourceDir("Effects", "Tutorial2.fx"))

#Input layout for the effect. Valid when technique index == 0 and it's pass index == 0 or
#the pass's input signature is compatible with that combination.
inputLayout = d3d11.InputLayout(vertexDesc, effect, 0, 0)

#Create a hardware buffer to hold our triangle.
vertexBuffer = d3d11.Buffer(vertexDesc, triangle, BIND_VERTEX_BUFFER)

#Precalculate view matrix. Eye position is (0, 5, -15) and it is looking at (0, 5, 0). (0, 1, 0) points up.
viewMatrix = d3d11.Matrix()
viewMatrix.lookAt((0, 5, -15), (0, 5, 0), (0, 1, 0))


def mainloop():
    while 1: